jason berry
/
mbed_bot
mbed_bot
main.cpp@1:dfc4375f3eb5, 2021-03-22 (annotated)
- Committer:
- jasonberry
- Date:
- Mon Mar 22 19:33:03 2021 +0000
- Revision:
- 1:dfc4375f3eb5
- Parent:
- 0:d44946656cbe
- Child:
- 2:1fd9d55f66e0
mbed_bot
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 | 0:d44946656cbe | 27 | { |
jasonberry | 1:dfc4375f3eb5 | 28 | pc.gets(receive_buffer,30); // read all ascii chars (string) into buffer |
jasonberry | 1:dfc4375f3eb5 | 29 | |
jasonberry | 1:dfc4375f3eb5 | 30 | long int slider = strtol(receive_buffer,NULL,10); // convert string to a long integer |
jasonberry | 1:dfc4375f3eb5 | 31 | pc.printf("%ld ",slider);//printf long int slider |
jasonberry | 0:d44946656cbe | 32 | myled = !myled; |
jasonberry | 1:dfc4375f3eb5 | 33 | |
jasonberry | 1:dfc4375f3eb5 | 34 | //pc.putc(blue.getc()); |
jasonberry | 1:dfc4375f3eb5 | 35 | |
jasonberry | 1:dfc4375f3eb5 | 36 | |
jasonberry | 0:d44946656cbe | 37 | } |
jasonberry | 0:d44946656cbe | 38 | if (pc.readable()) |
jasonberry | 0:d44946656cbe | 39 | { |
jasonberry | 0:d44946656cbe | 40 | blue.putc(pc.getc()); |
jasonberry | 0:d44946656cbe | 41 | myled4 = !myled4; |
jasonberry | 0:d44946656cbe | 42 | } |
jasonberry | 0:d44946656cbe | 43 | |
jasonberry | 0:d44946656cbe | 44 | } |
jasonberry | 0:d44946656cbe | 45 | } |