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@11:0b85a680ad28, 2022-03-28 (annotated)
- Committer:
- guibouu
- Date:
- Mon Mar 28 17:50:41 2022 +0000
- Revision:
- 11:0b85a680ad28
- Parent:
- 8:cfcf73c16fab
projet2
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dujardin | 8:cfcf73c16fab | 1 | // Rassurez vous, VOUS n'avez pas a changer ces lignes de commandes |
| guibouu | 11:0b85a680ad28 | 2 | extern int mvie; |
| guibouu | 11:0b85a680ad28 | 3 | extern int mvie2; |
| guibouu | 11:0b85a680ad28 | 4 | extern int autoritir1; |
| guibouu | 11:0b85a680ad28 | 5 | extern int autoritir2; |
| guibouu | 11:0b85a680ad28 | 6 | |
| dujardin | 8:cfcf73c16fab | 7 | |
| dujardin | 6:edb27e228558 | 8 | // variables propres Affichage vers led en 16 bandes |
| dujardin | 6:edb27e228558 | 9 | int AL ; int AP ; int AT ; // Affichae AL ligne AP pix AT temps |
| dujardin | 6:edb27e228558 | 10 | int g1 ; int g2 ; int g3 ; int g4 ; // durée des 4 temps d'allumage |
| dujardin | 6:edb27e228558 | 11 | char mm ; |
| dujardin | 6:edb27e228558 | 12 | char T[64][16][3]; // Tableau à afficher format R1R2V1V2B1B2 en 4 temps |
| dujardin | 6:edb27e228558 | 13 | // variables propres pix vers T en P dans 16 bandes |
| dujardin | 6:edb27e228558 | 14 | int PL ; int PP ; int PT ; // position PL ligne AP pix AT temps |
| dujardin | 6:edb27e228558 | 15 | int pB ; // pB 0 ou 1 bande |
| dujardin | 6:edb27e228558 | 16 | char T0 ; char T1 ; char T2 ; char T3; // recup tab 0 1 2 3 |
| dujardin | 6:edb27e228558 | 17 | int ZL ; int ZP ; int ZT ; // position PL ligne AP pix AT temps |
| dujardin | 6:edb27e228558 | 18 | |
| dujardin | 6:edb27e228558 | 19 | // variables liées à l'acceleromètre |
| dujardin | 6:edb27e228558 | 20 | int acx1; int acx2; int acx3 ; int acx4; |
| dujardin | 6:edb27e228558 | 21 | int acy1; int acy2; int acy3 ; int acy4; |
| dujardin | 6:edb27e228558 | 22 | float xin; float yin; // lecture accelero |
| dujardin | 6:edb27e228558 | 23 | |
| dujardin | 6:edb27e228558 | 24 | void accel(void) |
| dujardin | 6:edb27e228558 | 25 | { |
| dujardin | 6:edb27e228558 | 26 | yin = canx.read(); xin= cany.read(); // lire accéléro |
| dujardin | 6:edb27e228558 | 27 | acx4 = acx3 ; acx3 = acx2 ; acx2 = acx1 ; |
| dujardin | 6:edb27e228558 | 28 | acy4 = acy3 ; acy3 = acy2 ; acy2 = acy1 ; |
| dujardin | 6:edb27e228558 | 29 | acx1 = xin * 150-75; |
| dujardin | 6:edb27e228558 | 30 | acy1 = yin * 150 - 75 ; // + calculs |
| dujardin | 8:cfcf73c16fab | 31 | accx = ( acx1 + acx2 + acx3 + acx4) ; |
| dujardin | 8:cfcf73c16fab | 32 | accy = ( acy1 + acy2 + acy3 + acy4) ; |
| dujardin | 6:edb27e228558 | 33 | ccx = ( acx1 + acx2 + acx3 + acx4)/4 ; |
| dujardin | 6:edb27e228558 | 34 | ccy = ( acy1 + acy2 + acy3 + acy4)/4 ; |
| dujardin | 6:edb27e228558 | 35 | } |
| dujardin | 6:edb27e228558 | 36 | |
| dujardin | 8:cfcf73c16fab | 37 | |
| dujardin | 6:edb27e228558 | 38 | void Tr2 () // T reset |
| dujardin | 6:edb27e228558 | 39 | {// efface tableau T led faire en x16 |
| dujardin | 6:edb27e228558 | 40 | for ( ZL = 0 ; ZL < 16 ; ZL++ ) |
| dujardin | 6:edb27e228558 | 41 | { |
| dujardin | 6:edb27e228558 | 42 | for ( ZT = 0 ; ZT < 3 ; ZT++ ) |
| dujardin | 6:edb27e228558 | 43 | { |
| dujardin | 6:edb27e228558 | 44 | for ( ZP = 0 ; ZP < 64 ; ZP++) T[ZP][ZL][ZT] = 0 ; |
| dujardin | 6:edb27e228558 | 45 | } |
| dujardin | 6:edb27e228558 | 46 | } |
| dujardin | 6:edb27e228558 | 47 | } |
| dujardin | 6:edb27e228558 | 48 | |
| dujardin | 6:edb27e228558 | 49 | |
| dujardin | 6:edb27e228558 | 50 | void pix( int X, int Y , char cr , char cv , char cb ) |
| dujardin | 6:edb27e228558 | 51 | { // place un pixel RVB dans I en 64/32 max x y 0 normal |
| dujardin | 6:edb27e228558 | 52 | |
| dujardin | 6:edb27e228558 | 53 | if ( X < 0 ) X = 0; // limites avant usage |
| dujardin | 6:edb27e228558 | 54 | if ( Y < 0 ) Y = 0; |
| dujardin | 6:edb27e228558 | 55 | if ( X > 63 ) X = 63; |
| dujardin | 6:edb27e228558 | 56 | if ( Y > 31 ) Y = 31; |
| dujardin | 6:edb27e228558 | 57 | if ( cr > 7 ) cr = 7; // max 7 niveaux de puissance |
| dujardin | 6:edb27e228558 | 58 | if ( cv > 7 ) cv = 7; |
| dujardin | 6:edb27e228558 | 59 | if ( cb > 7 ) cb = 7; |
| dujardin | 6:edb27e228558 | 60 | //calcul position PL et PP dans bande de 64 T[PP][PL][AT] |
| dujardin | 6:edb27e228558 | 61 | PP = X ; |
| dujardin | 6:edb27e228558 | 62 | pB = 0 ; |
| dujardin | 6:edb27e228558 | 63 | PL = Y ; |
| dujardin | 6:edb27e228558 | 64 | if (Y > 15 ) {PP = X-1 ; pB = 1 ;} |
| dujardin | 6:edb27e228558 | 65 | |
| dujardin | 6:edb27e228558 | 66 | |
| dujardin | 6:edb27e228558 | 67 | T0= T[PP][PL][0]; T1= T[PP][PL][1]; T2 =T[PP][PL][2] ; |
| dujardin | 6:edb27e228558 | 68 | if ( pB ==1 ) |
| dujardin | 6:edb27e228558 | 69 | { |
| dujardin | 6:edb27e228558 | 70 | T0 = T0 & 62 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 71 | if ( ( cb & 1 ) == 1 ) T0 = T0 + 1; // mis a 1 |
| dujardin | 6:edb27e228558 | 72 | T0 = T0 & 59 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 73 | if ( ( cv & 1 ) == 1 ) T0 = T0 + 4; // mis a 1 |
| dujardin | 6:edb27e228558 | 74 | T0 = T0 & 47 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 75 | if ( ( cr & 1 ) == 1 ) T0 = T0 + 16; // mis a 1 |
| dujardin | 6:edb27e228558 | 76 | T[PP][PL][0] = T0; // retour dedans |
| dujardin | 6:edb27e228558 | 77 | |
| dujardin | 6:edb27e228558 | 78 | T1 = T1 & 62 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 79 | if ( ( cb & 2 ) == 2 ) T1 = T1 + 1; // mis a 1 |
| dujardin | 6:edb27e228558 | 80 | T1 = T1 & 59 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 81 | if ( ( cv & 2 ) == 2 ) T1 = T1 + 4; // mis a 1 |
| dujardin | 6:edb27e228558 | 82 | T1 = T1 & 47 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 83 | if ( ( cr & 2 ) == 2 ) T1 = T1 + 16; // mis a 1 |
| dujardin | 6:edb27e228558 | 84 | T[PP][PL][1] = T1; // retour dedans |
| dujardin | 6:edb27e228558 | 85 | |
| dujardin | 6:edb27e228558 | 86 | T2 = T2 & 62 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 87 | if ( ( cb & 4 ) == 4 ) T2 = T2 + 1; // mis a 1 |
| dujardin | 6:edb27e228558 | 88 | T2 = T2 & 59 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 89 | if ( ( cv & 4 ) == 4 ) T2 = T2 + 4; // mis a 1 |
| dujardin | 6:edb27e228558 | 90 | T2 = T2 & 47 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 91 | if ( ( cr & 4 ) == 4 ) T2 = T2 + 16; // mis a 1 |
| dujardin | 6:edb27e228558 | 92 | T[PP][PL][2] = T2; // retour dedans |
| dujardin | 6:edb27e228558 | 93 | } |
| dujardin | 6:edb27e228558 | 94 | |
| dujardin | 6:edb27e228558 | 95 | if ( pB ==0) |
| dujardin | 6:edb27e228558 | 96 | { |
| dujardin | 6:edb27e228558 | 97 | T0 = T0 & 61 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 98 | if ( ( cb & 1 ) == 1 ) T0 = T0 + 2; // mis a 1 |
| dujardin | 6:edb27e228558 | 99 | T0 = T0 & 55 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 100 | if ( ( cv & 1 ) == 1 ) T0 = T0 + 8; // mis a 1 |
| dujardin | 6:edb27e228558 | 101 | T0 = T0 & 31 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 102 | if ( ( cr & 1 ) == 1 ) T0 = T0 + 32; // mis a 1 |
| dujardin | 6:edb27e228558 | 103 | T[PP][PL][0] = T0; // retour dedans |
| dujardin | 6:edb27e228558 | 104 | |
| dujardin | 6:edb27e228558 | 105 | T1 = T1 & 61 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 106 | if ( ( cb & 2 ) == 2 ) T1 = T1 + 2; // mis a 1 |
| dujardin | 6:edb27e228558 | 107 | T1 = T1 & 55 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 108 | if ( ( cv & 2 ) == 2 ) T1 = T1 + 8; // mis a 1 |
| dujardin | 6:edb27e228558 | 109 | T1 = T1 & 31 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 110 | if ( ( cr & 2 ) == 2 ) T1 = T1 + 32; // mis a 1 |
| dujardin | 6:edb27e228558 | 111 | T[PP][PL][1] = T1; // retour dedans |
| dujardin | 6:edb27e228558 | 112 | |
| dujardin | 6:edb27e228558 | 113 | T2 = T2 & 61 ; // b0 = 0 |
| dujardin | 6:edb27e228558 | 114 | if ( ( cb & 4 ) == 4 ) T2 = T2 + 2; // mis a 1 |
| dujardin | 6:edb27e228558 | 115 | T2 = T2 & 55 ; // v0 = 0 |
| dujardin | 6:edb27e228558 | 116 | if ( ( cv & 4 ) == 4 ) T2 = T2 + 8; // mis a 1 |
| dujardin | 6:edb27e228558 | 117 | T2 = T2 & 31 ; // r0 = 0 |
| dujardin | 6:edb27e228558 | 118 | if ( ( cr & 4 ) == 4 ) T2 = T2 + 32; // mis a 1 |
| dujardin | 6:edb27e228558 | 119 | T[PP][PL][2] = T2; // retour dedans |
| dujardin | 6:edb27e228558 | 120 | } |
| dujardin | 6:edb27e228558 | 121 | } |
| dujardin | 6:edb27e228558 | 122 | |
| dujardin | 6:edb27e228558 | 123 | void Taffi() |
| dujardin | 6:edb27e228558 | 124 | { // variables propres AL AT AP |
| dujardin | 6:edb27e228558 | 125 | OE = HIGH; // Disable output |
| dujardin | 6:edb27e228558 | 126 | for ( AL = 0 ; AL < 16 ; AL++) |
| dujardin | 6:edb27e228558 | 127 | { |
| dujardin | 6:edb27e228558 | 128 | ABCD = AL; //adresse ligne dans L |
| dujardin | 6:edb27e228558 | 129 | for ( AT = 0 ; AT < 3 ; AT++) |
| dujardin | 6:edb27e228558 | 130 | { |
| dujardin | 6:edb27e228558 | 131 | for( AP =0 ; AP < 32 ; AP++) // |
| dujardin | 6:edb27e228558 | 132 | { |
| dujardin | 6:edb27e228558 | 133 | mm = T[AP][AL][AT]; |
| dujardin | 6:edb27e228558 | 134 | B1 = mm & 1 ; |
| dujardin | 6:edb27e228558 | 135 | B0 = mm & 2 ; |
| dujardin | 6:edb27e228558 | 136 | V1 = mm & 4 ; |
| dujardin | 6:edb27e228558 | 137 | V0 = mm & 8 ; |
| dujardin | 6:edb27e228558 | 138 | R1 = mm & 16 ; |
| dujardin | 6:edb27e228558 | 139 | R0 = mm & 32 ; |
| dujardin | 6:edb27e228558 | 140 | |
| dujardin | 6:edb27e228558 | 141 | CLK = HIGH; // tick (clock bit in) |
| dujardin | 6:edb27e228558 | 142 | CLK = LOW; // tock |
| dujardin | 6:edb27e228558 | 143 | } |
| dujardin | 6:edb27e228558 | 144 | LAT = HIGH; // Latch ligne |
| dujardin | 6:edb27e228558 | 145 | LAT = LOW; |
| dujardin | 6:edb27e228558 | 146 | OE = LOW; // Enable output |
| dujardin | 6:edb27e228558 | 147 | if ( AT == 0 ) wait_us(g1); |
| dujardin | 6:edb27e228558 | 148 | if ( AT == 1 ) wait_us(g2); |
| dujardin | 6:edb27e228558 | 149 | if ( AT == 2 ) wait_us(g3); // 8*8*8 niveaux rapidement |
| dujardin | 6:edb27e228558 | 150 | OE = HIGH; // disable output |
| dujardin | 6:edb27e228558 | 151 | } |
| dujardin | 6:edb27e228558 | 152 | } |
| dujardin | 6:edb27e228558 | 153 | } |
| dujardin | 6:edb27e228558 | 154 | |
| dujardin | 6:edb27e228558 | 155 | void circle(int px , int py , int r ) |
| dujardin | 6:edb27e228558 | 156 | { |
| dujardin | 6:edb27e228558 | 157 | int rx = 0; int ry = 0 ; |
| dujardin | 6:edb27e228558 | 158 | for ( rx = r ; ry <= rx ; rx-- ) |
| dujardin | 6:edb27e228558 | 159 | { |
| dujardin | 6:edb27e228558 | 160 | while((rx*rx+ry*ry)<(r*r)) |
| dujardin | 6:edb27e228558 | 161 | { |
| dujardin | 6:edb27e228558 | 162 | pix ( px+rx , py+ry , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 163 | pix ( px+rx , py-ry , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 164 | pix ( px-rx , py+ry , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 165 | pix ( px-rx , py-ry , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 166 | pix ( px+ry , py+rx , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 167 | pix ( px-ry , py+rx , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 168 | pix ( px+ry , py-rx , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 169 | pix ( px-ry , py-rx , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 170 | ry++; |
| dujardin | 6:edb27e228558 | 171 | } |
| dujardin | 6:edb27e228558 | 172 | } |
| dujardin | 6:edb27e228558 | 173 | |
| dujardin | 6:edb27e228558 | 174 | pix ( px , py , br , bv , bb ); |
| dujardin | 6:edb27e228558 | 175 | } |
| guibouu | 11:0b85a680ad28 | 176 | |
| guibouu | 11:0b85a680ad28 | 177 | void carre( int xd, int yd , int longueur , int hauteur , int vr , int vv , int vb ) |
| guibouu | 11:0b85a680ad28 | 178 | { |
| guibouu | 11:0b85a680ad28 | 179 | int jesus; |
| guibouu | 11:0b85a680ad28 | 180 | int oui; |
| guibouu | 11:0b85a680ad28 | 181 | for(jesus=0;jesus<hauteur;jesus=jesus+1) |
| guibouu | 11:0b85a680ad28 | 182 | { |
| guibouu | 11:0b85a680ad28 | 183 | for(oui=0;oui<longueur;oui=oui+1) |
| guibouu | 11:0b85a680ad28 | 184 | { |
| guibouu | 11:0b85a680ad28 | 185 | pix(xd+oui,yd+jesus,vr,vv,vb); |
| guibouu | 11:0b85a680ad28 | 186 | } |
| guibouu | 11:0b85a680ad28 | 187 | } |
| guibouu | 11:0b85a680ad28 | 188 | } |
| guibouu | 11:0b85a680ad28 | 189 | |
| guibouu | 11:0b85a680ad28 | 190 | void mob(int x,int y,int vie) // a éteindre |
| guibouu | 11:0b85a680ad28 | 191 | { |
| guibouu | 11:0b85a680ad28 | 192 | if(vie>=1) |
| guibouu | 11:0b85a680ad28 | 193 | { |
| guibouu | 11:0b85a680ad28 | 194 | pix(x,y,0,0,4); |
| guibouu | 11:0b85a680ad28 | 195 | pix(x,y+1,0,0,4); |
| guibouu | 11:0b85a680ad28 | 196 | pix(x-1,y+1,0,0,4); |
| guibouu | 11:0b85a680ad28 | 197 | pix(x+1,y+1,0,0,4); |
| guibouu | 11:0b85a680ad28 | 198 | pix(x+1,y+2,0,0,4); |
| guibouu | 11:0b85a680ad28 | 199 | pix(x-1,y+2,0,0,4); |
| guibouu | 11:0b85a680ad28 | 200 | } |
| guibouu | 11:0b85a680ad28 | 201 | |
| guibouu | 11:0b85a680ad28 | 202 | } |
| guibouu | 11:0b85a680ad28 | 203 | /*hitmob(20,20,mvie,15+vaisseauy+ccyy+tir2/4,vaisseauy+ccyy+tir/4,tirx2,tirx,autoritir2,autoritir1) */ |
| guibouu | 11:0b85a680ad28 | 204 | |
| guibouu | 11:0b85a680ad28 | 205 | void hitmob(int x,int y,int vie,int ty2,int ty1,int tx2,int tx1,int auto2,int auto1) |
| guibouu | 11:0b85a680ad28 | 206 | { if(tx2<x+2 && tx2>x-2 && ty2>=y-1 && ty2>=y-1 && auto2==1 && vie>0) |
| guibouu | 11:0b85a680ad28 | 207 | { |
| guibouu | 11:0b85a680ad28 | 208 | mvie=mvie-1; |
| guibouu | 11:0b85a680ad28 | 209 | autoritir2=0; |
| guibouu | 11:0b85a680ad28 | 210 | } |
| guibouu | 11:0b85a680ad28 | 211 | if(tx1<x+2 && tx1>x-2 && ty1>=y-1 && ty1>=y-1 && auto1==1 && vie>0) |
| guibouu | 11:0b85a680ad28 | 212 | { |
| guibouu | 11:0b85a680ad28 | 213 | mvie=mvie-1; |
| guibouu | 11:0b85a680ad28 | 214 | autoritir1=0; |
| guibouu | 11:0b85a680ad28 | 215 | } |
| guibouu | 11:0b85a680ad28 | 216 | } |
| guibouu | 11:0b85a680ad28 | 217 | |
| guibouu | 11:0b85a680ad28 | 218 | void hitmob2(int x,int y,int vie,int ty2,int ty1,int tx2,int tx1,int auto2,int auto1) |
| guibouu | 11:0b85a680ad28 | 219 | { if(tx2<x+2 && tx2>x-2 && ty2>=y-1 && ty2>=y-1 && auto2==1 && vie>0) |
| guibouu | 11:0b85a680ad28 | 220 | { |
| guibouu | 11:0b85a680ad28 | 221 | mvie2=mvie2-1; |
| guibouu | 11:0b85a680ad28 | 222 | autoritir2=0; |
| guibouu | 11:0b85a680ad28 | 223 | } |
| guibouu | 11:0b85a680ad28 | 224 | if(tx1<x+2 && tx1>x-2 && ty1>=y-1 && ty1>=y-1 && auto1==1 && vie>0) |
| guibouu | 11:0b85a680ad28 | 225 | { |
| guibouu | 11:0b85a680ad28 | 226 | mvie2=mvie2-1; |
| guibouu | 11:0b85a680ad28 | 227 | autoritir1=0; |
| guibouu | 11:0b85a680ad28 | 228 | } |
| guibouu | 11:0b85a680ad28 | 229 | } |
| guibouu | 11:0b85a680ad28 | 230 | |
| guibouu | 11:0b85a680ad28 | 231 |