Mohammad Mohammad
/
serial_buff
serial comm example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 00004 DigitalOut myled(PTD5); 00005 DigitalOut myled1(PTE29); 00006 00007 //DigitalIn enable(PTC3); 00008 //InterruptIn button(PTC3); 00009 //construct an object called button that represents one of the pins 00010 //constructor requires a pin name: PTC3 in this case 00011 PinDetect button(PTC3); 00012 Serial pc(USBTX,USBRX); 00013 00014 void flip(){ 00015 myled = !myled; 00016 myled1= !myled1; 00017 pc.puts("look at me bitch\r\n"); 00018 } 00019 00020 int main() { 00021 //setup LED with debounce 00022 myled = 1; 00023 myled1 = 0; 00024 button.mode(PullUp); 00025 wait(.001); 00026 // interrupt 00027 button.attach_deasserted(&flip); 00028 button.setSampleFrequency(); 00029 00030 char buffer[128]; 00031 00032 while(1) 00033 { 00034 // read in every character 00035 pc.gets(buffer, 2); 00036 // check if carriage return is pressed 00037 if((int)buffer[0] == 13) 00038 { 00039 // print return and new line 00040 pc.puts("\r\n"); 00041 } 00042 else 00043 { 00044 // otherwise just print the character that was typed 00045 pc.puts(buffer); 00046 } 00047 } 00048 }
Generated on Sun Jul 17 2022 02:03:04 by 1.7.2