amit ate
/
WRandomADC_valToPC
USART RX Interrupt
Diff: main.cpp
- Revision:
- 0:39c8feff805f
diff -r 000000000000 -r 39c8feff805f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jan 20 11:47:27 2017 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" +#include "string.h" +#include "stdio.h" + +DigitalOut led2(LED2); +DigitalOut led3(LED3); + +Serial device(p9, p10); // tx, rx +char msgPC[20],msgDEV[20]; + +void serialRXmon(){ + char msg1[] = "Your msg-> ",msg[30]; + msg[0] = '\0'; + int i=0; + while(msgDEV[i-1]!=0x0D){ + msgDEV[i] = device.getc(); + i++; + led3 = 1; + } + msgDEV[i] = '\0'; + strcat(msg,msg1); + strcat(msg,msgDEV); + device.puts(msg); + led3 = 0; + device.getc(); + } + +int main() { + int adcVal; + device.attach(&serialRXmon); + while(1) { + + adcVal = rand()%255+1; + + sprintf(msgPC,"adcVal -> %d\n",adcVal); + + if(device.writeable()) { + device.puts(msgPC); + } + led2 = 1; + wait(1); + led2 = 0; + wait(1); +} + + } +