Ryo Nakabayashi
/
rtos_serial_command_test
multi thread test(rtos)
main.cpp
- Committer:
- ryought
- Date:
- 2013-03-18
- Revision:
- 0:76241820e391
File content as of revision 0:76241820e391:
#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; } } } } }