NXP car drive in RF controlled state and in autonomous state

Dependencies:   Motors_Out mbed CAMERA

Revision:
0:7e6f69bdaf19
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 19 09:13:55 2018 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#include "CAMERA.h"
+#include "Motors_Out.h"
+
+Serial pc(USBTX,USBRX);
+Serial serial(NC, PTE23);
+Motors_Out motors(PTC3,PTC4,PTC1,PTC2,PTB0,PTE21);
+CAMERA camera(PTD7,PTE0,PTD5);
+DigitalOut led_man(LED1);
+DigitalOut led_auto(LED2);
+void mode(void);
+bool manual = true;
+uint8_t rx;
+Ticker t;
+
+void mode()
+{
+    if(serial.readable()) rx = serial.getc(); //receive data
+    wait_us(10);
+    if((rx & 0xF0) == 0x20) {                 //RF mode
+        manual = true;
+        led_man = 1;
+        led_auto = 0;
+    } else if((rx & 0xFF) == 0x56) {          //autonomous mode
+        manual = false;
+        led_auto = 1;
+        led_man = 0;
+    }
+    return;
+}
+
+int main()
+{
+    int a,path;
+    t.attach(&mode,0.01);
+    led_man = 1;
+    led_auto = 1;
+    serial.baud(1200);                      //frequency
+    serial.format(8,SerialBase::None,1);
+    while(1) {
+        while(manual) {
+            a = rx & 0x0F;
+            if((a & 0x6) != 6) motors.manualInfo(a);
+        }
+        while(!manual) {
+            path = camera.getPath();
+            motors.selfDrive(path);
+        }
+    }
+}
\ No newline at end of file