Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LED2.h
- Committer:
- guibouu
- Date:
- 2022-03-28
- Revision:
- 11:0b85a680ad28
- Parent:
- 8:cfcf73c16fab
File content as of revision 11:0b85a680ad28:
// Rassurez vous, VOUS n'avez pas a changer ces lignes de commandes
extern int mvie;
extern int mvie2;
extern int autoritir1;
extern int autoritir2;
// variables propres Affichage vers led en 16 bandes
int AL ; int AP ; int AT ; // Affichae AL ligne AP pix AT temps
int g1 ; int g2 ; int g3 ; int g4 ; // durée des 4 temps d'allumage
char mm ;
char T[64][16][3]; // Tableau à afficher format R1R2V1V2B1B2 en 4 temps
// variables propres pix vers T en P dans 16 bandes
int PL ; int PP ; int PT ; // position PL ligne AP pix AT temps
int pB ; // pB 0 ou 1 bande
char T0 ; char T1 ; char T2 ; char T3; // recup tab 0 1 2 3
int ZL ; int ZP ; int ZT ; // position PL ligne AP pix AT temps
// variables liées à l'acceleromètre
int acx1; int acx2; int acx3 ; int acx4;
int acy1; int acy2; int acy3 ; int acy4;
float xin; float yin; // lecture accelero
void accel(void)
{
yin = canx.read(); xin= cany.read(); // lire accéléro
acx4 = acx3 ; acx3 = acx2 ; acx2 = acx1 ;
acy4 = acy3 ; acy3 = acy2 ; acy2 = acy1 ;
acx1 = xin * 150-75;
acy1 = yin * 150 - 75 ; // + calculs
accx = ( acx1 + acx2 + acx3 + acx4) ;
accy = ( acy1 + acy2 + acy3 + acy4) ;
ccx = ( acx1 + acx2 + acx3 + acx4)/4 ;
ccy = ( acy1 + acy2 + acy3 + acy4)/4 ;
}
void Tr2 () // T reset
{// efface tableau T led faire en x16
for ( ZL = 0 ; ZL < 16 ; ZL++ )
{
for ( ZT = 0 ; ZT < 3 ; ZT++ )
{
for ( ZP = 0 ; ZP < 64 ; ZP++) T[ZP][ZL][ZT] = 0 ;
}
}
}
void pix( int X, int Y , char cr , char cv , char cb )
{ // place un pixel RVB dans I en 64/32 max x y 0 normal
if ( X < 0 ) X = 0; // limites avant usage
if ( Y < 0 ) Y = 0;
if ( X > 63 ) X = 63;
if ( Y > 31 ) Y = 31;
if ( cr > 7 ) cr = 7; // max 7 niveaux de puissance
if ( cv > 7 ) cv = 7;
if ( cb > 7 ) cb = 7;
//calcul position PL et PP dans bande de 64 T[PP][PL][AT]
PP = X ;
pB = 0 ;
PL = Y ;
if (Y > 15 ) {PP = X-1 ; pB = 1 ;}
T0= T[PP][PL][0]; T1= T[PP][PL][1]; T2 =T[PP][PL][2] ;
if ( pB ==1 )
{
T0 = T0 & 62 ; // b0 = 0
if ( ( cb & 1 ) == 1 ) T0 = T0 + 1; // mis a 1
T0 = T0 & 59 ; // v0 = 0
if ( ( cv & 1 ) == 1 ) T0 = T0 + 4; // mis a 1
T0 = T0 & 47 ; // r0 = 0
if ( ( cr & 1 ) == 1 ) T0 = T0 + 16; // mis a 1
T[PP][PL][0] = T0; // retour dedans
T1 = T1 & 62 ; // b0 = 0
if ( ( cb & 2 ) == 2 ) T1 = T1 + 1; // mis a 1
T1 = T1 & 59 ; // v0 = 0
if ( ( cv & 2 ) == 2 ) T1 = T1 + 4; // mis a 1
T1 = T1 & 47 ; // r0 = 0
if ( ( cr & 2 ) == 2 ) T1 = T1 + 16; // mis a 1
T[PP][PL][1] = T1; // retour dedans
T2 = T2 & 62 ; // b0 = 0
if ( ( cb & 4 ) == 4 ) T2 = T2 + 1; // mis a 1
T2 = T2 & 59 ; // v0 = 0
if ( ( cv & 4 ) == 4 ) T2 = T2 + 4; // mis a 1
T2 = T2 & 47 ; // r0 = 0
if ( ( cr & 4 ) == 4 ) T2 = T2 + 16; // mis a 1
T[PP][PL][2] = T2; // retour dedans
}
if ( pB ==0)
{
T0 = T0 & 61 ; // b0 = 0
if ( ( cb & 1 ) == 1 ) T0 = T0 + 2; // mis a 1
T0 = T0 & 55 ; // v0 = 0
if ( ( cv & 1 ) == 1 ) T0 = T0 + 8; // mis a 1
T0 = T0 & 31 ; // r0 = 0
if ( ( cr & 1 ) == 1 ) T0 = T0 + 32; // mis a 1
T[PP][PL][0] = T0; // retour dedans
T1 = T1 & 61 ; // b0 = 0
if ( ( cb & 2 ) == 2 ) T1 = T1 + 2; // mis a 1
T1 = T1 & 55 ; // v0 = 0
if ( ( cv & 2 ) == 2 ) T1 = T1 + 8; // mis a 1
T1 = T1 & 31 ; // r0 = 0
if ( ( cr & 2 ) == 2 ) T1 = T1 + 32; // mis a 1
T[PP][PL][1] = T1; // retour dedans
T2 = T2 & 61 ; // b0 = 0
if ( ( cb & 4 ) == 4 ) T2 = T2 + 2; // mis a 1
T2 = T2 & 55 ; // v0 = 0
if ( ( cv & 4 ) == 4 ) T2 = T2 + 8; // mis a 1
T2 = T2 & 31 ; // r0 = 0
if ( ( cr & 4 ) == 4 ) T2 = T2 + 32; // mis a 1
T[PP][PL][2] = T2; // retour dedans
}
}
void Taffi()
{ // variables propres AL AT AP
OE = HIGH; // Disable output
for ( AL = 0 ; AL < 16 ; AL++)
{
ABCD = AL; //adresse ligne dans L
for ( AT = 0 ; AT < 3 ; AT++)
{
for( AP =0 ; AP < 32 ; AP++) //
{
mm = T[AP][AL][AT];
B1 = mm & 1 ;
B0 = mm & 2 ;
V1 = mm & 4 ;
V0 = mm & 8 ;
R1 = mm & 16 ;
R0 = mm & 32 ;
CLK = HIGH; // tick (clock bit in)
CLK = LOW; // tock
}
LAT = HIGH; // Latch ligne
LAT = LOW;
OE = LOW; // Enable output
if ( AT == 0 ) wait_us(g1);
if ( AT == 1 ) wait_us(g2);
if ( AT == 2 ) wait_us(g3); // 8*8*8 niveaux rapidement
OE = HIGH; // disable output
}
}
}
void circle(int px , int py , int r )
{
int rx = 0; int ry = 0 ;
for ( rx = r ; ry <= rx ; rx-- )
{
while((rx*rx+ry*ry)<(r*r))
{
pix ( px+rx , py+ry , br , bv , bb );
pix ( px+rx , py-ry , br , bv , bb );
pix ( px-rx , py+ry , br , bv , bb );
pix ( px-rx , py-ry , br , bv , bb );
pix ( px+ry , py+rx , br , bv , bb );
pix ( px-ry , py+rx , br , bv , bb );
pix ( px+ry , py-rx , br , bv , bb );
pix ( px-ry , py-rx , br , bv , bb );
ry++;
}
}
pix ( px , py , br , bv , bb );
}
void carre( int xd, int yd , int longueur , int hauteur , int vr , int vv , int vb )
{
int jesus;
int oui;
for(jesus=0;jesus<hauteur;jesus=jesus+1)
{
for(oui=0;oui<longueur;oui=oui+1)
{
pix(xd+oui,yd+jesus,vr,vv,vb);
}
}
}
void mob(int x,int y,int vie) // a éteindre
{
if(vie>=1)
{
pix(x,y,0,0,4);
pix(x,y+1,0,0,4);
pix(x-1,y+1,0,0,4);
pix(x+1,y+1,0,0,4);
pix(x+1,y+2,0,0,4);
pix(x-1,y+2,0,0,4);
}
}
/*hitmob(20,20,mvie,15+vaisseauy+ccyy+tir2/4,vaisseauy+ccyy+tir/4,tirx2,tirx,autoritir2,autoritir1) */
void hitmob(int x,int y,int vie,int ty2,int ty1,int tx2,int tx1,int auto2,int auto1)
{ if(tx2<x+2 && tx2>x-2 && ty2>=y-1 && ty2>=y-1 && auto2==1 && vie>0)
{
mvie=mvie-1;
autoritir2=0;
}
if(tx1<x+2 && tx1>x-2 && ty1>=y-1 && ty1>=y-1 && auto1==1 && vie>0)
{
mvie=mvie-1;
autoritir1=0;
}
}
void hitmob2(int x,int y,int vie,int ty2,int ty1,int tx2,int tx1,int auto2,int auto1)
{ if(tx2<x+2 && tx2>x-2 && ty2>=y-1 && ty2>=y-1 && auto2==1 && vie>0)
{
mvie2=mvie2-1;
autoritir2=0;
}
if(tx1<x+2 && tx1>x-2 && ty1>=y-1 && ty1>=y-1 && auto1==1 && vie>0)
{
mvie2=mvie2-1;
autoritir1=0;
}
}