Freedom demo featuring Seeed Grove BLE module
Dependencies: BluetoothSerial mbed
main.cpp@0:6c24e6f21f08, 2016-04-26 (annotated)
- Committer:
- GregC
- Date:
- Tue Apr 26 22:46:08 2016 +0000
- Revision:
- 0:6c24e6f21f08
Freedom demo featuring Seeed Grove BLE module
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregC | 0:6c24e6f21f08 | 1 | #include "mbed.h" |
GregC | 0:6c24e6f21f08 | 2 | #include "BluetoothSerial.h" |
GregC | 0:6c24e6f21f08 | 3 | |
GregC | 0:6c24e6f21f08 | 4 | DigitalOut led1(LED1); |
GregC | 0:6c24e6f21f08 | 5 | DigitalOut led2(LED2); |
GregC | 0:6c24e6f21f08 | 6 | BluetoothSerial bluetooth(D1, D0); |
GregC | 0:6c24e6f21f08 | 7 | |
GregC | 0:6c24e6f21f08 | 8 | int main() |
GregC | 0:6c24e6f21f08 | 9 | { |
GregC | 0:6c24e6f21f08 | 10 | int count = 0; |
GregC | 0:6c24e6f21f08 | 11 | |
GregC | 0:6c24e6f21f08 | 12 | bluetooth.setup(); |
GregC | 0:6c24e6f21f08 | 13 | #if 1 |
GregC | 0:6c24e6f21f08 | 14 | bluetooth.slave("btslave8seeed"); // default PIN code: 0000 |
GregC | 0:6c24e6f21f08 | 15 | wait(2); |
GregC | 0:6c24e6f21f08 | 16 | bluetooth.connect(); |
GregC | 0:6c24e6f21f08 | 17 | #else |
GregC | 0:6c24e6f21f08 | 18 | bluetooth.master("btmaster8seeed"); |
GregC | 0:6c24e6f21f08 | 19 | wait(2); |
GregC | 0:6c24e6f21f08 | 20 | bluetooth.connect("btslave8seeed"); |
GregC | 0:6c24e6f21f08 | 21 | #endif |
GregC | 0:6c24e6f21f08 | 22 | |
GregC | 0:6c24e6f21f08 | 23 | while (1) { |
GregC | 0:6c24e6f21f08 | 24 | if (bluetooth.readable()) { |
GregC | 0:6c24e6f21f08 | 25 | led2 = !led2; |
GregC | 0:6c24e6f21f08 | 26 | } |
GregC | 0:6c24e6f21f08 | 27 | |
GregC | 0:6c24e6f21f08 | 28 | count++; |
GregC | 0:6c24e6f21f08 | 29 | if (count >= 1000000) { |
GregC | 0:6c24e6f21f08 | 30 | led1 = !led1; |
GregC | 0:6c24e6f21f08 | 31 | count = 0; |
GregC | 0:6c24e6f21f08 | 32 | } |
GregC | 0:6c24e6f21f08 | 33 | } |
GregC | 0:6c24e6f21f08 | 34 | |
GregC | 0:6c24e6f21f08 | 35 | } |