An m3pi demo program for Bluetooth control.
Dependencies: X_NUCLEO_53L0A1 m3pi mbed
Fork of m3pi_BT by
main.cpp@4:e2ab59ab0c80, 2017-05-03 (annotated)
- Committer:
- xmanwms95
- Date:
- Wed May 03 03:43:44 2017 +0000
- Revision:
- 4:e2ab59ab0c80
- Parent:
- 3:d5da5e6bc16f
An m3pi demo program for Bluetooth control.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexsaadfalcon | 0:b7ef99889b44 | 1 | #include "mbed.h" |
alexsaadfalcon | 0:b7ef99889b44 | 2 | #include "m3pi.h" |
alexsaadfalcon | 0:b7ef99889b44 | 3 | |
alexsaadfalcon | 0:b7ef99889b44 | 4 | m3pi m3pi; |
alexsaadfalcon | 2:2d0d003ca3b8 | 5 | DigitalOut led(LED1); |
alexsaadfalcon | 3:d5da5e6bc16f | 6 | DigitalOut pong(p20); |
alexsaadfalcon | 2:2d0d003ca3b8 | 7 | Serial bt(p13, p14); //TX, RX |
alexsaadfalcon | 0:b7ef99889b44 | 8 | |
alexsaadfalcon | 3:d5da5e6bc16f | 9 | int main() |
alexsaadfalcon | 3:d5da5e6bc16f | 10 | { |
alexsaadfalcon | 3:d5da5e6bc16f | 11 | m3pi.locate(0,1); |
alexsaadfalcon | 0:b7ef99889b44 | 12 | m3pi.printf("YO"); |
alexsaadfalcon | 3:d5da5e6bc16f | 13 | |
alexsaadfalcon | 2:2d0d003ca3b8 | 14 | while (!bt.readable()) { } //wait until the bt is ready |
alexsaadfalcon | 2:2d0d003ca3b8 | 15 | |
xmanwms95 | 4:e2ab59ab0c80 | 16 | ///////LED change will register if the command was recieved or not |
alexsaadfalcon | 0:b7ef99889b44 | 17 | while(1) { |
xmanwms95 | 4:e2ab59ab0c80 | 18 | |
xmanwms95 | 4:e2ab59ab0c80 | 19 | if (bt.getc()=='F') { |
xmanwms95 | 4:e2ab59ab0c80 | 20 | m3pi.forward(.25); |
xmanwms95 | 4:e2ab59ab0c80 | 21 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 22 | } |
xmanwms95 | 4:e2ab59ab0c80 | 23 | if (bt.getc()=='B') { |
xmanwms95 | 4:e2ab59ab0c80 | 24 | m3pi.backward(.25); |
xmanwms95 | 4:e2ab59ab0c80 | 25 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 26 | } |
xmanwms95 | 4:e2ab59ab0c80 | 27 | if (bt.getc()=='L') { |
xmanwms95 | 4:e2ab59ab0c80 | 28 | m3pi.left(.25); |
xmanwms95 | 4:e2ab59ab0c80 | 29 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 30 | } |
xmanwms95 | 4:e2ab59ab0c80 | 31 | if (bt.getc()=='R') { |
xmanwms95 | 4:e2ab59ab0c80 | 32 | m3pi.right(.25); |
xmanwms95 | 4:e2ab59ab0c80 | 33 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 34 | } |
xmanwms95 | 4:e2ab59ab0c80 | 35 | if (bt.getc()=='S') { |
xmanwms95 | 4:e2ab59ab0c80 | 36 | m3pi.stop(); |
xmanwms95 | 4:e2ab59ab0c80 | 37 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 38 | } |
xmanwms95 | 4:e2ab59ab0c80 | 39 | if (bt.getc()=='X') { |
xmanwms95 | 4:e2ab59ab0c80 | 40 | pong = 1; |
xmanwms95 | 4:e2ab59ab0c80 | 41 | led = !led; |
xmanwms95 | 4:e2ab59ab0c80 | 42 | wait(.001); |
xmanwms95 | 4:e2ab59ab0c80 | 43 | pong = 0; |
alexsaadfalcon | 2:2d0d003ca3b8 | 44 | } |
alexsaadfalcon | 3:d5da5e6bc16f | 45 | while (bt.readable()) char temp = bt.getc(); //flush buffer |
alexsaadfalcon | 2:2d0d003ca3b8 | 46 | } |
alexsaadfalcon | 0:b7ef99889b44 | 47 | } |