Seongbin Lim
/
sb_first_project
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
main.cpp
- Committer:
- sb8718
- Date:
- 2020-04-17
- Revision:
- 119:d879334e3d87
- Parent:
- 118:88f30fadf08f
- Child:
- 120:a1dd83d9c036
File content as of revision 119:d879334e3d87:
#include "mbed.h" #include <string.h> RawSerial pc(PA_2, PA_3, 115200); // USART2 //Serial pc(USBTX, USBRX); //RawSerial phone(PA_10, PA_9, 115200); DigitalOut rLed(D3); DigitalOut gLed(D4); char buf[256]; int index = 0; void rx_handler(void) { int ch = pc.getc(); pc.putc(ch); // phone.putc(ch); if(ch == 0x0D) { while(!pc.writeable()); pc.putc(0x0A); // phone.putc(0x0A); if(strcmp(buf,"Rled on") == 0) { rLed = 1; pc.printf("Rled status: %s\r\n", "on"); // phone.printf("Rled status: %s\r\n", "on"); } else if(strcmp(buf,"Rled off") == 0){ rLed = 0; pc.printf("Rled status: %s\r\n", "off"); // phone.printf("Rled status: %s\r\n", "off"); } else if(strcmp(buf,"Rled status") == 0){ pc.printf("Rled status: %s\r\n", rLed? "on" : "off"); // phone.printf("Rled status: %s\r\n", rLed? "on" : "off"); } else if(strcmp(buf,"Gled on") == 0) { gLed = 1; pc.printf("Gled status: %s\r\n", "on"); // phone.printf("Gled status: %s\r\n", "on"); } else if(strcmp(buf,"Gled off") == 0){ gLed = 0; pc.printf("Gled status: %s\r\n", "off"); // phone.printf("Gled status: %s\r\n", "off"); } else if(strcmp(buf,"Gled status") == 0){ pc.printf("Gled status: %s\r\n", gLed? "on" : "off"); // phone.printf("Gled status: %s\r\n", gLed? "on" : "off"); } else { pc.printf("Undefined command\r\n"); // phone.printf("Undefined command\r\n"); } strncpy(buf,"",index); index = 0; } else { buf[index] = ch; index ++; } } int main() { strcpy(buf,""); pc.attach(&rx_handler); pc.printf("\r\n Welcome to UART Lab_3_4!\r\n"); pc.printf("Enter 'Rled/Gled on/off/status'\r\n"); // phone.attach(&rx_handler); // phone.printf("\r\n Welcome to UART Lab_3_4!\r\n"); // phone.printf("Enter 'Rled/Gled on/off/status'\r\n"); while(true) { } }