jason berry
/
mbed_bot
mbed_bot
main.cpp@2:1fd9d55f66e0, 2021-04-19 (annotated)
- Committer:
- jasonberry
- Date:
- Mon Apr 19 11:54:16 2021 +0000
- Revision:
- 2:1fd9d55f66e0
- Parent:
- 1:dfc4375f3eb5
mbed bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasonberry | 0:d44946656cbe | 1 | #include "mbed.h" |
jasonberry | 0:d44946656cbe | 2 | |
jasonberry | 0:d44946656cbe | 3 | Serial pc(USBTX, USBRX); |
jasonberry | 0:d44946656cbe | 4 | Serial blue(p9, p10); // TX, RX |
jasonberry | 0:d44946656cbe | 5 | |
jasonberry | 0:d44946656cbe | 6 | DigitalOut myled(LED1); |
jasonberry | 0:d44946656cbe | 7 | DigitalOut myled2(LED2); |
jasonberry | 0:d44946656cbe | 8 | DigitalOut myled4(LED4); |
jasonberry | 0:d44946656cbe | 9 | |
jasonberry | 0:d44946656cbe | 10 | |
jasonberry | 0:d44946656cbe | 11 | int main() |
jasonberry | 0:d44946656cbe | 12 | { |
jasonberry | 1:dfc4375f3eb5 | 13 | char receive_buffer[30]; |
jasonberry | 1:dfc4375f3eb5 | 14 | |
jasonberry | 1:dfc4375f3eb5 | 15 | |
jasonberry | 0:d44946656cbe | 16 | |
jasonberry | 0:d44946656cbe | 17 | blue.baud(9600); |
jasonberry | 0:d44946656cbe | 18 | pc.baud(115200); |
jasonberry | 0:d44946656cbe | 19 | pc.printf("Bluetooth Start\r\n"); |
jasonberry | 0:d44946656cbe | 20 | blue.printf("Bluetooth Start\r\n"); |
jasonberry | 0:d44946656cbe | 21 | |
jasonberry | 0:d44946656cbe | 22 | // echo back characters and toggle the LED |
jasonberry | 0:d44946656cbe | 23 | while (1) |
jasonberry | 0:d44946656cbe | 24 | { |
jasonberry | 0:d44946656cbe | 25 | myled2 = !myled2; |
jasonberry | 0:d44946656cbe | 26 | if (blue.readable()) |
jasonberry | 2:1fd9d55f66e0 | 27 | { |
jasonberry | 2:1fd9d55f66e0 | 28 | myled = !myled; |
jasonberry | 2:1fd9d55f66e0 | 29 | blue.gets(receive_buffer,30); // read all ascii chars (string) into buffer |
jasonberry | 2:1fd9d55f66e0 | 30 | |
jasonberry | 2:1fd9d55f66e0 | 31 | long int slider = strtol(receive_buffer,NULL,10); // convert string to a long integer |
jasonberry | 2:1fd9d55f66e0 | 32 | pc.printf("%ld ",slider);//printf long int slider |
jasonberry | 2:1fd9d55f66e0 | 33 | |
jasonberry | 1:dfc4375f3eb5 | 34 | |
jasonberry | 1:dfc4375f3eb5 | 35 | //pc.putc(blue.getc()); |
jasonberry | 1:dfc4375f3eb5 | 36 | |
jasonberry | 1:dfc4375f3eb5 | 37 | |
jasonberry | 0:d44946656cbe | 38 | } |
jasonberry | 0:d44946656cbe | 39 | if (pc.readable()) |
jasonberry | 0:d44946656cbe | 40 | { |
jasonberry | 0:d44946656cbe | 41 | blue.putc(pc.getc()); |
jasonberry | 0:d44946656cbe | 42 | myled4 = !myled4; |
jasonberry | 0:d44946656cbe | 43 | } |
jasonberry | 0:d44946656cbe | 44 | |
jasonberry | 0:d44946656cbe | 45 | } |
jasonberry | 0:d44946656cbe | 46 | } |