escaner RF - RTOS multitareas

Dependencies:   mbed Servo MFRC522_Updated HC-SR04 ssd1306_library

Revision:
2:ad8f0cdf7015
Parent:
1:849d12c9b2be
Child:
3:e7eaa479e804
--- a/main.cpp	Tue Jun 09 05:15:28 2020 +0000
+++ b/main.cpp	Wed Jun 10 15:41:43 2020 +0000
@@ -21,10 +21,13 @@
 
 Serial pc(USBTX, USBRX);
 HCSR04 sonar(D3,D4);
-int a,q;
+
 float menor;
 float da;
 float dis = 0.0;
+static const char tar[]={0xD7,0x4F,0x88,0x19};
+static const char llav[]={0x27,0x57,0xC1,0x7B};
+int q,a,al,b,w;
 
 
 int anodeComun[10] = {
@@ -48,7 +51,8 @@
         for(int i=0; i<40; i++) {
             myservo = i/40.0;
             da  = sonar.getCm();
-            pc.printf("%1.f  ,  %.2f \n\r",float(i*4.5),da);
+            w=i;
+            //pc.printf("%1.f  ,  %.2f \n\r",float(i*4.5),da);
             if(menor > da) {
                 menor = da;
                 a=(i*180)/40;
@@ -61,7 +65,8 @@
         for(int i=40; i>0; i--) {
             myservo = i/40.0;
             da = sonar.getCm();
-            pc.printf("%1.f  ,  %.2f \n\r",float(i*4.5),da);
+              w=i;
+            // pc.printf("%1.f  ,  %.2f \n\r",float(i*4.5),da);
             if(menor > da) {
                 menor = da;
                 a=(i*180)/40;
@@ -76,7 +81,7 @@
     while(1) {
         int d,u,n,c;
         n=int(menor);
-        
+
         c=  n/100;
         d = (n - (c*100))/10;
         u = n % 10;
@@ -96,16 +101,16 @@
 
         //ThisThread::sleep_for(25);
         wait(0.003);
-        
-         display1=0;
+
+        display1=0;
         display2=0;
         display3=1;
         display7Seg=anodeComun[c];
 
         //ThisThread::sleep_for(25);
         wait(0.003);
-        
-        
+
+
     }
 }
 void oled()
@@ -129,6 +134,8 @@
 void rf()
 {
     while(1) {
+        al=0;
+        b=0;
         lcd.init();
         lcd.speed (SSD1306::Fast);
         if ( ! RfChip.PICC_IsNewCardPresent()) {
@@ -145,12 +152,53 @@
         lcd.locate (6,3);
         lcd.printf(" %s ", RfChip.PICC_GetTypeName(piccType));
         lcd.redraw();
+         for (uint8_t i = 0; i < RfChip.uid.size; i++) {
+            
+         if(uint8_t (tar[i])==RfChip.uid.uidByte[i]){
+            al=al+1;
+            }else{
+                al=0;
+                }
+        }
+         for (uint8_t i = 0; i < RfChip.uid.size; i++) {
+            
+         if(uint8_t (llav[i])==RfChip.uid.uidByte[i]){
+            b=b+1;
+            }else{
+                b=0;
+                }
+        }
+     
         //ThisThread::sleep_for(1000);
         wait_ms(1000);
     }
 }
+void serial()
+{
+    while(1) {
 
+        time_t seconds = time(NULL);
 
+        char buffer2[32];
+        strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds));
+        pc.printf("%s", buffer2);
+
+        char buffer1[32];
+        strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds));
+        pc.printf(" , %s", buffer1);
+        pc.printf(" , %1.f  ,  %.2f , ",float(w*4.5),da);
+           if(al==4){
+        pc.printf("tarjeta");  
+            }else if(b==4){ 
+                pc.printf("llavero");
+                }else{
+                   pc.printf("sin lectura"); 
+                    }  
+        pc.printf("\n\r");
+        wait(0.04);
+        
+    }
+}
 int main()
 {
     myservo.calibrate(0.0015,360);
@@ -159,9 +207,11 @@
     t.start((servo));
     t.set_priority (osPriorityNormal3);
     t1.start(seg7);
-    t1.set_priority (osPriorityNormal2);
+    t1.set_priority (osPriorityNormal);
     t2.start(oled);
     t2.set_priority (osPriorityNormal1);
+    t3.start(serial);
+    t2.set_priority (osPriorityNormal2);
     t4.start(rf);
     t.join();
 }
\ No newline at end of file