cualquier cosa

Dependencies:   mbed

Fork of 00_LAB_matrix8x8_SPI by ferney alberto beltran molina

Revision:
4:b38a9b0501dc
Parent:
3:4a8de2f71ed0
Child:
5:377b23953ba1
--- a/main.cpp	Thu Mar 16 22:56:47 2017 +0000
+++ b/main.cpp	Mon Sep 03 00:55:50 2018 +0000
@@ -1,142 +1,351 @@
+#include "mbed.h"
 
-#include "mbed.h"
-//#include "max7219.h"
+SPI deviceM(PB_5, PB_4, PB_3);
+DigitalOut ssel (PB_9);
+
+//#define  uint8_t unsigned char
+//uint8_t vcol2[8]={0,0,0,0,0,0,0,0};
 
-// ***************************************************************************
-// option 1 : use  SPI
-// ***************************************************************************
-SPI deviceM(PB_15, PB_14, PB_13);
-DigitalOut ssel (PB_12);
-
-#define  uint8_t unsigned char
-uint8_t vcol2[8]={0,0,0,0,0,0,0,0};
-
+int enviarficha(int x,int y)
+{
+    int k=y;
+    
+    if(x==1) // cuadrado
+        {
+        return k; 
+        }
+    else if (x==2) //linea
+        {
+        return k;
+        }
+    else if (x==3) //ele
+        {
+        return k;
+        }
+    else if (x==4) //te
+        {
+        return k;
+        }
+    else if (x==5) //ese
+        {
+        return k;
+        }         
+    else
+    return 1;
+}
  
 void sendSPI(uint8_t d1, uint8_t d2)
 {
     deviceM.unlock();
     ssel=0;
-    deviceM.write(d1); 
-    deviceM.write(d2);  
+    deviceM.write(d1);
+    deviceM.write(d2);
     ssel=1;
     deviceM.lock();
 };
 
+void test()  //test
+{
+    sendSPI(0x0F,1);
+    wait(0.5);
+    sendSPI(0x0F,0);
+    wait(0.5);    
+};
 
-void printMatrix(uint8_t*  vC)
-
+void cuadro(int x)
 {
-    uint8_t i =0;
-    for (i=1;i<9;i++){
-        sendSPI(i,*(vC+i));
-    }
-        
-    };
+    int j,r;
+
+    if (x==1)
+    r=0xC0;
+    else if(x==2)
+    r=0x60;
+    else if(x==3)
+    r=0x30;
+    else if(x==4)
+    r=0x18;
+    else if(x==5)
+    r=0xC;
+    else if(x==6)
+    r=0x06;
+    else if(x==7)
+    r=0x03;
+    else if(x==8)
+    r=0x01;
+    {
+         for(j=0;j<=7;j++)
+             {
+                sendSPI(0x0+j,r);
+                sendSPI(0x0+(j+1),r);
+                wait_ms(200);
+                sendSPI(0x0+j,0x00);
+                sendSPI(0x0+(j+1),0x00);
+                wait_us(10); 
+            } 
+                sendSPI(0x07,r);
+                sendSPI(0x08,r);  
+    }                
+};
 
-void clr_vcol()
+void linea(int x)
+{
+    int j,r;
+
+    if (x==1)
+    r=0x80;
+    else if(x==2)
+    r=0x40;
+    else if(x==3)
+    r=0x20;
+    else if(x==4)
+    r=0x10;
+    else if(x==5)
+    r=0x08;
+    else if(x==6)
+    r=0x04;
+    else if(x==7)
+    r=0x02;
+    else if(x==8)
+    r=0x01;
     {
-    for (int i=0; i<8;i++){
-            vcol2[i]=0;
-    }
-    
-}   
- 
-void print_Snake2()
+         for(j=0;j<=6;j++)
+             {
+                sendSPI(0x0+j,r);
+                sendSPI(0x0+(j+1),r);
+                sendSPI(0x0+(j+2),r);
+                wait_ms(200);
+                sendSPI(0x0+j,0x00);
+                sendSPI(0x0+(j+1),0x00);
+                sendSPI(0x0+(j+2),0x00);
+                wait_us(10); 
+            } 
+                sendSPI(0x06,r);
+                sendSPI(0x07,r);
+                sendSPI(0x08,r);  
+    }                
+};
+
+void ele(int x)
 {
-    
-    int j, i;
-      //reset
-    
-    for (j=0; j<8;j++){
-        clr_vcol();
-        if(j % 2 == 0)
-            vcol2[j]=1;
-        else
-            vcol2[j]=0b10000000;
-    
-        for (i=0; i<8;i++){
-            if(j % 2 == 0){
-                 vcol2[j]=3<<i;
-                }
-            else{
-                 vcol2[j]=0b1100000000>>i;
-                }
-            printMatrix(vcol2);
-            wait_ms(5);
-            }
-        }
-}
+    int j,r,r2;
+    if (x==1)
+    {
+    r=0xC0;
+    r2=0x80;
+    }
+    else if(x==2)
+    {
+    r=0x60;
+    r2=0x40;
+    }
+    else if(x==3)
+    {
+    r=0x30;
+    r2=0x20;
+    }
+    else if(x==4)
+    {
+    r=0x18;
+    r2=0x10;
+    }
+    else if(x==5)
+    {
+    r=0xC;
+    r2=0x08;
+    }
+    else if(x==6)
+    {
+    r=0x06;
+    r2=0x04;
+    }
+    else if(x==7)
+    {
+    r=0x03;
+    r2=0x02;
+    }
+    else if(x==8)
+    {
+    r=0x01;
+    r2=0x01;
+    }
+    {
+         for(j=0;j<=6;j++)
+             {
+                sendSPI(0x0+j,r2);
+                sendSPI(0x0+(j+1),r2);
+                sendSPI(0x0+(j+2),r);
+                wait_ms(200);
+                sendSPI(0x0+j,0x00);
+                sendSPI(0x0+(j+1),0x00);
+                sendSPI(0x0+(j+2),0x00);
+                wait_us(10); 
+            } 
+                sendSPI(0x06,r2);
+                sendSPI(0x07,r2);
+                sendSPI(0x08,r);  
+    }                
+};
 
-void print_Snake()
+void te(int x)
 {
-       
-    uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff};
-    uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111};
-    
-      
-    int j, i;
-      //reset
-    clr_vcol();
-    for (j=0; j<8;j++){
-        for (i=0; i<8;i++){
-            if(j % 2 == 0){
-                vcol2[j]=vt1[i];
-            }else{
-                vcol2[j]=vt2[i];
-            }
-            printMatrix(vcol2);
-            wait_ms(5);
-        }
-        }    
-}   
-int main() {
-                    uint8_t vcol[8]={0,0,0,0,0,0,0,0};
-                    sendSPI(0x0c,1);
-                    sendSPI(0x0F,1);
-                    wait (0.1);
-                    sendSPI(0x0f,0);
-                    wait (0.1);
-                    int i =0;
-                    while(1){
-                        print_Snake();
-                        }
-}
-// ***************************************************************************
-// option two: use maz7219 library
+    int j,r,r2;
+
+    if (x==1)
+    {
+    r=0xE0;
+    r2=0x40;
+    }
+    else if(x==2)
+    {
+    r=0x70;
+    r2=0x20;
+    }
+    else if(x==3)
+    {
+    r=0x38;
+    r2=0x10;
+    }
+    else if(x==4)
+    {
+    r=0x1C;
+    r2=0x8;
+    }
+    else if(x==5)
+    {
+    r=0xE;
+    r2=0x4;
+    }
+    else if(x==6)
+    {
+    r=0x7;
+    r2=0x2;
+    }
+    else if(x==7)
+    {
+    r=0x03;
+    r2=0x1;
+    }
+    else if(x==8)
+    r=0x01;
+    {
+         for(j=0;j<=7;j++)
+             {
+                sendSPI(0x0+j,r2);
+                sendSPI(0x0+(j+1),r);
+                wait_ms(200);
+                sendSPI(0x0+j,0x00);
+                sendSPI(0x0+(j+1),0x00);
+                wait_us(10); 
+            } 
+                sendSPI(0x07,r2);
+                sendSPI(0x08,r);  
+    }                
+};
+
+void ese(int x)
+{
+    int j,r,r2;
 
-// ***************************************************************************    
-/*
-Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
+    if (x==1)
+    {
+    r=0xC0;
+    r2=0x60;
+    }
+    else if(x==2)
+    {
+    r=0x60;
+    r2=0x30;
+    }
+    else if(x==3)
+    {
+    r=0x30;
+    r2=0x18;
+    }
+    else if(x==4)
+    {
+    r=0x18;
+    r2=0xC;
+    }
+    else if(x==5)
+    {
+    r=0xC;
+    r2=0x6;
+    }
+    else if(x==6)
+    {
+    r=0x6;
+    r2=0x3;
+    }
+    else if(x==7)
+    {
+    r=0x03;
+    r2=0x1;
+    }
+    else if(x==8)
+    r=0x01;
+    {
+         for(j=0;j<=7;j++)
+             {
+                sendSPI(0x0+j,r2);
+                sendSPI(0x0+(j+1),r);
+                wait_ms(200);
+                sendSPI(0x0+j,0x00);
+                sendSPI(0x0+(j+1),0x00);
+                wait_us(10); 
+            } 
+                sendSPI(0x07,r2);
+                sendSPI(0x08,r);  
+    }                
+};
+
+void borrar()
+{
+    int i;
+    for(i=0;i<=8;i++)
+    {
+        sendSPI(0x0+i,0x00);
+    }
+};
 
 
 int main() {
-    
-    max7219_configuration_t cfg = {
-    .device_number = 1,
-    .decode_mode = 0,
-    .intensity = Max7219::MAX7219_INTENSITY_8,
-    .scan_limit = Max7219::MAX7219_SCAN_8
-};
-   
-    deviceM.init_device(cfg);
+    sendSPI(0x09,0);        //no decodificacion
+    sendSPI(0x0A,0x0);     //intensidad
+    sendSPI(0x0B,0x07);     //usa 7 leds                     
+    sendSPI(0x0C,1);        //no apaga
+    sendSPI(0x0F,0);        //operacion normal  
+ 
+    int x=5,y=6;  // enviar ficha y columna
     
-    deviceM.enable_device(1);
-   
-    deviceM.set_display_test();
-    wait(1);   
-   deviceM.clear_display_test();
-    wait(1);
-  
-    while(1){
-         deviceM.write_digit(1,8,0b11111111);
-         deviceM.write_digit(1,1,0b01010101);
-         deviceM.write_digit(1,2,0b10101010);
-         deviceM.write_digit(1,3,0b01010101);
-         deviceM.write_digit(1,4,0b10101010);
-         deviceM.write_digit(1,5,0b01010101);
-         deviceM.write_digit(1,6,0b10101010);
-         deviceM.write_digit(1,7,0b01010101);
-        }
+    if (x==1)  //cuadro
+    {
+    borrar();
+    int r=enviarficha(x,y);
+    cuadro(r);
+    }
+    else if (x==2)  //linea
+    {
+    borrar();    
+    int r=enviarficha(x,y);
+    linea(r);
+    }
+    else if (x==3)  //l
+    {
+    borrar();    
+    int r=enviarficha(x,y);
+    ele(r);
+    }
+    else if(x==4)  //t
+    {
+    borrar();    
+    int r=enviarficha(x,y);
+    te(r);
+    }
+    else if(x==5)  //s
+    {
+    borrar();    
+    int r=enviarficha(x,y);
+    ese(r);
+    }
 }
-*/