escaner RF - RTOS multitareas

Dependencies:   mbed Servo MFRC522_Updated HC-SR04 ssd1306_library

Revision:
0:366b3e64c83c
Child:
1:849d12c9b2be
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jun 06 21:46:44 2020 +0000
@@ -0,0 +1,129 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "Servo.h"
+#include "HCSR04.h"
+#include "MFRC522.h"
+#include "ssd1306.h"
+SSD1306 lcd (D7,D6);
+BusOut display7Seg(PTC10, PTC7, PTC6, PTC4, PTC0, PTB19, PTB18);
+DigitalOut display1(PTC11);
+DigitalOut display2(PTC13);
+Servo myservo(D2);
+Thread thread;
+Thread t;
+Thread t1;
+Thread t2;
+Thread t3;
+Serial pc(USBTX, USBRX);
+HCSR04 sonar(D3,D4);
+int a,q;
+float menor;
+float da;
+float dis = 0.0;
+
+
+int anodeComun[10] = {
+    0b0000001, // 0
+    0b1001111, // 1
+    0b0010010, // 2
+    0b0000110, // 3
+    0b1001100, // 4
+    0b0100100, // 5
+    0b0100000, // 6
+    0b0001111, // 7
+    0b0000000, // 8
+    0b0001100, // 9
+};
+
+void  servo()
+{
+    while(true) {
+        menor = sonar.getCm();
+        a=0;
+        for(int i=0; i<40; i++) {
+            myservo = i/40.0;
+            da  = sonar.getCm();
+            pc.printf("Distancia %.2f cm \n\r",da);
+            if(menor > da) {
+                menor = da;
+                a=(i*180)/40;
+            }
+            //ThisThread::sleep_for(500);
+            wait(0.5);
+        }
+        pc.printf("menor final %.2f cm \n\r",menor);
+        menor=sonar.getCm();
+        a=0;
+        for(int i=40; i>0; i--) {
+            myservo = i/40.0;
+            da = sonar.getCm();
+            pc.printf("Distancia %.2f cm \n\r",da);
+            if(menor > da) {
+                menor = da;
+                a=(i*180)/40;
+            }
+            //ThisThread::sleep_for(500);
+             wait(0.5);
+        }
+        pc.printf("menor %.2f cm \n\r",menor);
+    }
+}
+void seg7()
+{
+    while(1) {
+        int d,u,n;
+        n=int(menor);
+
+        d = n /10;
+        u = n % 10;
+
+        display1=1;
+        display2=0;
+        display7Seg=anodeComun[d];
+        //ThisThread::sleep_for(25);
+        wait(0.025);
+        display1=0;
+        display2=1;
+        display7Seg=anodeComun[u];
+        //ThisThread::sleep_for(25);
+         wait(0.025);
+    }
+}
+void oled()
+{
+    while(1) {
+        lcd.init();
+        lcd.speed (SSD1306::Fast);
+        lcd.cls();
+        lcd.locate (3,1);
+        lcd.printf ("angulo :%d ",a);
+        lcd.locate (5,1);
+        lcd.printf ("dis menor :%2.f ",menor);
+        set_time(q);
+        lcd.locate (1,0);
+        time_t seconds = time(NULL);
+        lcd.printf("fecha %s",ctime(&seconds));
+        lcd.redraw();
+        wait(0.5);
+    }
+}
+void tiempo()
+{
+    while(1) {
+        q=q+1;
+        //ThisThread::sleep_for(1000);
+        wait(1);
+    }
+}
+int main()
+{
+    myservo.calibrate(0.0015,360);
+    t.start((servo));
+    t1.start(seg7);
+    t2.start(oled);
+    t3.start(tiempo);
+     q=1590029272;
+     q=q-((5*60)*60);
+    //thread.flags_set(STOP_FLAG);
+    //thread.join();
+}
\ No newline at end of file