version panneau d'octobre 2018 pour TR de S2 et projet de S3

Dependencies:   mbed

Fork of duj401 by dujardin stephane

Revision:
6:edb27e228558
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LED2.h	Fri Oct 12 09:16:23 2018 +0000
@@ -0,0 +1,220 @@
+// 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  
+    ccx = ( acx1 + acx2 + acx3 + acx4)/4  ;
+    ccy = ( acy1 + acy2 + acy3 + acy4)/4  ;
+  }
+  
+void coul( int cc )
+  {
+  switch (cc) 
+        {
+        case 0 :
+            ZR = 7 ; ZV = 0 ; ZB = 0 ;
+            break;
+        case 1 :
+            ZR = 0 ; ZV = 7 ; ZB = 0 ;
+            break;
+        case 2 :
+            ZR = 0 ; ZV = 0 ; ZB = 7 ;
+            break;
+        case 3 :
+            ZR = 7 ; ZV = 2 ; ZB = 0 ;
+            break;
+        case 4 :
+             ZR = 7 ; ZV = 0 ; ZB = 2 ;
+             break;
+        case 6 :
+             ZR = 5 ; ZV = 15 ; ZB = 0 ;
+            break;
+        case 7 :
+             ZR = 0 ; ZV = 7 ; ZB = 2 ;
+            break;
+        case 8 :
+            ZR = 0 ; ZV = 2 ; ZB = 7 ;
+            break;
+        case 9 :
+            ZR = 15 ; ZV = 0 ; ZB = 15 ;
+            break;
+        case 10 :
+            ZR = 0 ; ZV = 7 ; ZB = 7 ;
+            break;
+        case 11 :
+            ZR = 7 ; ZV = 0 ; ZB = 7 ;
+            break;
+        case 12 :
+            ZR = 7 ; ZV = 7 ; ZB = 0 ;        
+            break;
+        case 13 :
+            ZR = 7 ; ZV = 7 ; ZB = 7 ;        
+            break;
+        case 14 :
+           ZR = 2 ; ZV = 0 ; ZB = 0 ;        
+            break;
+        case 15 :
+             ZR = 0 ; ZV = 2 ; ZB = 0 ;         
+            break;
+        default:
+             ZR = 0 ; ZV = 0 ; ZB = 0 ;
+             break;
+        }
+ }
+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 );  
+    }
+ 
\ No newline at end of file