pto el que lo lea

Dependencies:   mbed MAX7219

Files at this revision

API Documentation at this revision

Comitter:
michaelrodriguezg
Date:
Tue Nov 03 22:38:39 2020 +0000
Parent:
3:06223ec42c88
Commit message:
HOLA;

Changed in this revision

MAX7219.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
diff -r 06223ec42c88 -r fcfb02e6a11f MAX7219.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX7219.lib	Tue Nov 03 22:38:39 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Maxim-Integrated/code/MAX7219/#b5e4379a3d90
diff -r 06223ec42c88 -r fcfb02e6a11f main.cpp
--- a/main.cpp	Tue Nov 03 20:24:55 2020 +0000
+++ b/main.cpp	Tue Nov 03 22:38:39 2020 +0000
@@ -1,5 +1,3 @@
-
-
 char whoAmI ;
 #define MPU6050                          0x68<<1  // Device address when ADO = 0
 #define RA_WHO_AM_I         0x75
@@ -42,10 +40,12 @@
                               
 #include "mbed.h"
 #include "MFRC522.h"
-
+#include "main.h"
+#include "max7219.h" 
 // Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
 #define MF_RESET    D8
-
+Max7219 pantalla(D11, D12, D13, D10);//MOSI-MISO-CLK-SSEL
+void Print_pantalla_tabla(unsigned char *pValor);
 DigitalOut led(D4);
 DigitalOut ledG(D3);
 DigitalOut led3(D5);
@@ -53,6 +53,8 @@
 int aux = 0 ;
 int aux2 = 0;
 int signal = 0;
+unsigned char personal[8]= {0x0,0x0,0,0,0,0,0,0};  
+    unsigned char filas[8]= {1,3,7,0x0f,0x1f,0x3f,0x7f,0xff};
 //Serial connection to PC for output
 Serial pc(SERIAL_TX, SERIAL_RX);
 I2C i2c(D14, D15);
@@ -64,7 +66,6 @@
 char reg_value[2];
  void WriteData(uint8_t address, uint8_t subAddress, uint8_t data);
 int ReadData(int adress_L, int adress_H);
-
 void giroscope(){
     while(1) { 
                 pc.printf(" ");
@@ -78,16 +79,39 @@
         pc.printf("%i\t",ReadData(RA_GYRO_YOUT_L ,RA_GYRO_YOUT_H));
         //pc.printf("%i\t",ReadData(RA_GYRO_ZOUT_L ,RA_GYRO_ZOUT_H));
         pc.printf("\n\r");
-        //wait_us(2e6);
-        
+        //wait_us(2e6);        
   }
-    
-    
+}
+void Print_pantalla_tabla(unsigned char *pValor){
+    for (int i =0;i<8;i++)
+    pantalla.write_digit(1,i+1,pValor[i]);  
+}
+void matrix(){
+    max7219_configuration_t cfg = {
+        .device_number = 1,
+        .decode_mode = 0,
+        .intensity = Max7219::MAX7219_INTENSITY_5,
+        .scan_limit = Max7219::MAX7219_SCAN_8
+    };
+        pantalla.init_device(cfg);
+        pantalla.enable_device(1);
+        pantalla.set_display_test();
+        wait_ms(1000);
+        pantalla.clear_display_test();
+        while(ledG==1){
+                                    for(int i=0;i<3;i++){
+                                    i=i;
+                                    Print_pantalla_tabla(led2);
+                                    wait_ms(200);
+                                    Print_pantalla_tabla(led1);
+                                    wait_ms(200);
+                                    }
+                                    ledG=0;
+                                    Print_pantalla_tabla(personal);
+                                        wait_ms(100);
+                                    }
     }
-
-
 void rfid(){
-    
     while(true){
     if (boton == 0){
         led = !led;
@@ -96,74 +120,59 @@
         }
              led=0;
             // Look for new cards
-            if ( ! RfChip.PICC_IsNewCardPresent())
-            {
+            if ( ! RfChip.PICC_IsNewCardPresent()){
               wait_ms(200);
               //pc.printf("1 ");
               pc.printf("%i\t\n\r",ReadData(RA_GYRO_YOUT_L ,RA_GYRO_YOUT_H));
+              
               continue;
             }
-        
             // Select one of the cards
             if ( ! RfChip.PICC_ReadCardSerial())
             {
               wait_ms(200);
               continue;
             }
-        
-        
             led=1;
             // Print Card UID
            // pc.printf("Card UID: ");
-            for (uint8_t i = 0; i < RfChip.uid.size; i++)
-            {
+            for (uint8_t i = 0; i < RfChip.uid.size; i++){
              /* pc.printf(" %X02", RfChip.uid.uidByte[i]);
               pc.printf("-A1-\n\r");*/
-                         if (aux == 0) {
-              
+                         if (aux == 0) {    
                           aux = RfChip.uid.uidByte[i]; //registra la primera tarjeta que entre
                           led3 = 1;
-                          aux2 = 2;
-                         
+                          aux2 = 2;                         
                         }else if (aux2 ==2){
-                            
-                            
                             aux2 = RfChip.uid.uidByte[i]; //registrar tarjeta
-                            ledG = 1;  
+                            ledG = 1;
                             led3 = 0; 
                             signal = 1;
-                            
-                                                       
-                       }else if (RfChip.uid.uidByte[i] == aux){ 
-                         
+                       }else if (RfChip.uid.uidByte[i] == aux){                         
                             ledG = 1;  
                             led3 = 0;
                             signal = 1; 
                             pc.printf("15000\n\r");
                             /*------*/
-                            wait_us(5e6);
+                            wait_us(5e6);                                          
+                            matrix();
                             ledG = 0;
                             signal = 0;
                             pc.printf("-15000\n\r");
-                            led3 = 1;
-                                                       
+                            led3 = 1;    
                        }     
-            }    
-    
-        pc.printf("\n\r");
-        
+            }        
+        pc.printf("\n\r");        
     }
 }
-
-void leer (){
+/*void leer (){
     if (boton == 1){
         led = !led;
         pc.printf("boton presionado\n\r");
         }
-        
-}
+}*/
 int ReadData(int adress_L, int adress_H){
-        char data_L;
+    char data_L;
     char data_H;
     char adress_data_L[1] ;
     char adress_data_H[1] ;
@@ -173,18 +182,14 @@
     i2c.read(MPU6050,&data_L, 1,0);
     i2c.write(MPU6050, adress_data_H, 1,1);
     i2c.read(MPU6050,&data_H, 1,0);
-
     return (int16_t)((data_H<<8) | data_L);
-    
 }
- void WriteData(uint8_t address, uint8_t subAddress, uint8_t data)
-{
+ void WriteData(uint8_t address, uint8_t subAddress, uint8_t data){
    char data_write[2];
    data_write[0] = subAddress;
    data_write[1] = data;
    i2c.write(address, data_write, 2, false);
 }
-
 void InitMPU(){
     WriteData(MPU6050,RA_PWR_ADDR,RA_PWR_MGMT_1);   
     wait(0.1);
@@ -195,27 +200,17 @@
     int AConfig = ACC_SELF_TEST_X | ACC_SELF_TEST_Y | ACC_SELF_TEST_Z | AF_SEL | ACC_HPF;
     WriteData(MPU6050,RA_GYRO_CONFIG,GConfig); 
     WriteData(MPU6050,RA_ACCEL_CONFIG,AConfig); 
-
 }
-
-int main(void) {
+int main(void) { //MENSAJE INICIAL
   pc.baud(9600);
   i2c.frequency(400000);
-  InitMPU();
-  
-  pc.printf("starting...\n\r");
-   
-    
+  InitMPU(); 
+  pc.printf(".............STARTING.............\n\r");
   // Init. RC522 Chip
-  RfChip.PCD_Init();
-    
-    
+  RfChip.PCD_Init();  
     
   while (true) {
-    pc.printf("buscando\n\r");
-    //pc.attach(&leer);
-    
+    pc.printf(".............BUSCANDO.............\n\r");   
     rfid();
-     //wait_ms(200);
   }
 }
\ No newline at end of file
diff -r 06223ec42c88 -r fcfb02e6a11f main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Tue Nov 03 22:38:39 2020 +0000
@@ -0,0 +1,3 @@
+#include "mbed.h" 
+unsigned char led1[]= {0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55};  
+unsigned char led2[]= {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa}; 
\ No newline at end of file