multi thread test(rtos)

Dependencies:   mbed-rtos mbed

Revision:
0:76241820e391
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 18 06:49:19 2013 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "rtos.h"
+
+DigitalOut getcommand(LED1);
+Serial pc(USBTX, USBRX);
+DigitalOut leds[2] = {DigitalOut(LED2), DigitalOut(LED3)};
+DigitalOut threadled(LED4);
+
+char buf[2];
+char command[2];
+
+void led(void const *args) {
+    while(true) {
+        threadled = !threadled;
+        Thread::wait(100);
+    }
+}
+
+
+int main() {
+    Thread thread(led);
+
+    while(1) {
+    if (pc.readable()) {
+        pc.printf("something get\n");
+        buf[0] = pc.getc();
+        buf[1] = pc.getc();
+        if (buf[0] == 0xFF && buf[1] == 0xFF) {
+            getcommand = 1;
+            pc.printf("its a command!\n");
+            
+            for(int i = 0; i < 2; i++) {
+                pc.printf("mgmg\n");
+                command[i] = pc.getc();
+                pc.printf("%x\n", command[i]);
+            }
+            
+            switch (command[0]) {
+                case 0x01:
+                    leds[0] = !leds[0];
+                    pc.printf("led1 : on/off\n");
+                    break;
+                case 0x02:
+                    leds[1] = !leds[1];
+                    pc.printf("led2 : on/off\n");
+                    break;
+            }
+        }
+    }
+    }
+}