Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 DigitalOut getcommand(LED1); 00005 Serial pc(USBTX, USBRX); 00006 DigitalOut leds[2] = {DigitalOut(LED2), DigitalOut(LED3)}; 00007 DigitalOut threadled(LED4); 00008 00009 char buf[2]; 00010 char command[2]; 00011 00012 void led(void const *args) { 00013 while(true) { 00014 threadled = !threadled; 00015 Thread::wait(100); 00016 } 00017 } 00018 00019 00020 int main() { 00021 Thread thread(led); 00022 00023 while(1) { 00024 if (pc.readable()) { 00025 pc.printf("something get\n"); 00026 buf[0] = pc.getc(); 00027 buf[1] = pc.getc(); 00028 if (buf[0] == 0xFF && buf[1] == 0xFF) { 00029 getcommand = 1; 00030 pc.printf("its a command!\n"); 00031 00032 for(int i = 0; i < 2; i++) { 00033 pc.printf("mgmg\n"); 00034 command[i] = pc.getc(); 00035 pc.printf("%x\n", command[i]); 00036 } 00037 00038 switch (command[0]) { 00039 case 0x01: 00040 leds[0] = !leds[0]; 00041 pc.printf("led1 : on/off\n"); 00042 break; 00043 case 0x02: 00044 leds[1] = !leds[1]; 00045 pc.printf("led2 : on/off\n"); 00046 break; 00047 } 00048 } 00049 } 00050 } 00051 }
Generated on Sat Jul 16 2022 16:12:49 by
1.7.2