This program will enable the communication between bluetooth HC-06 module and mbed Nucleo STF401RE
Dependencies: mbed
Fork of mbed_bluetooth_HC-06_communication by
main.cpp@1:22cda9aef3e6, 2018-08-01 (annotated)
- Committer:
- barry210110
- Date:
- Wed Aug 01 08:04:52 2018 +0000
- Revision:
- 1:22cda9aef3e6
- Parent:
- 0:4b83964a5228
HC05_TEST
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| HemaChowdary | 0:4b83964a5228 | 1 | #include "mbed.h" |
| HemaChowdary | 0:4b83964a5228 | 2 | |
| barry210110 | 1:22cda9aef3e6 | 3 | Serial bt(PA_11, PA_12); |
| HemaChowdary | 0:4b83964a5228 | 4 | Serial pc(USBTX,USBRX); |
| barry210110 | 1:22cda9aef3e6 | 5 | DigitalOut myled(LED2); |
| HemaChowdary | 0:4b83964a5228 | 6 | |
| HemaChowdary | 0:4b83964a5228 | 7 | int main() |
| HemaChowdary | 0:4b83964a5228 | 8 | { |
| HemaChowdary | 0:4b83964a5228 | 9 | bt.baud(9600); |
| HemaChowdary | 0:4b83964a5228 | 10 | //prints data on mobile |
| HemaChowdary | 0:4b83964a5228 | 11 | bt.printf("Connection Established"); |
| HemaChowdary | 0:4b83964a5228 | 12 | //print data on pc terminal |
| HemaChowdary | 0:4b83964a5228 | 13 | pc.printf("Connection Established"); |
| HemaChowdary | 0:4b83964a5228 | 14 | while(1) { |
| HemaChowdary | 0:4b83964a5228 | 15 | //For reading and writing data from/to bluetooth HC-06 |
| HemaChowdary | 0:4b83964a5228 | 16 | //check if bluetooth is readable and execute commands to toggle LED |
| HemaChowdary | 0:4b83964a5228 | 17 | if (bt.readable()) { |
| HemaChowdary | 0:4b83964a5228 | 18 | char input_key= bt.putc(bt.getc()); |
| HemaChowdary | 0:4b83964a5228 | 19 | //tutn on LED if "y" is entered |
| HemaChowdary | 0:4b83964a5228 | 20 | if(input_key == 'y') { |
| HemaChowdary | 0:4b83964a5228 | 21 | myled = 1; |
| HemaChowdary | 0:4b83964a5228 | 22 | bt.printf("LED is ON"); |
| HemaChowdary | 0:4b83964a5228 | 23 | } |
| barry210110 | 1:22cda9aef3e6 | 24 | //turn on LED if "n" is entered |
| HemaChowdary | 0:4b83964a5228 | 25 | if(input_key == 'n') { |
| HemaChowdary | 0:4b83964a5228 | 26 | myled = 0; |
| HemaChowdary | 0:4b83964a5228 | 27 | bt.printf("LED is OFF"); |
| HemaChowdary | 0:4b83964a5228 | 28 | } |
| HemaChowdary | 0:4b83964a5228 | 29 | } |
| HemaChowdary | 0:4b83964a5228 | 30 | |
| HemaChowdary | 0:4b83964a5228 | 31 | //For reading and writing data from/to pc terminal |
| HemaChowdary | 0:4b83964a5228 | 32 | //check if pc is readable and execute commands to toggle LED |
| HemaChowdary | 0:4b83964a5228 | 33 | if (pc.readable()) { |
| HemaChowdary | 0:4b83964a5228 | 34 | char input_key= pc.putc(pc.getc()); |
| HemaChowdary | 0:4b83964a5228 | 35 | |
| HemaChowdary | 0:4b83964a5228 | 36 | if(input_key == 'y') { |
| HemaChowdary | 0:4b83964a5228 | 37 | myled = 1; |
| HemaChowdary | 0:4b83964a5228 | 38 | pc.printf("LED is ON"); |
| HemaChowdary | 0:4b83964a5228 | 39 | } |
| HemaChowdary | 0:4b83964a5228 | 40 | if(input_key == 'n') { |
| HemaChowdary | 0:4b83964a5228 | 41 | myled = 0; |
| HemaChowdary | 0:4b83964a5228 | 42 | pc.printf("LED is OFF"); |
| HemaChowdary | 0:4b83964a5228 | 43 | } |
| HemaChowdary | 0:4b83964a5228 | 44 | } |
| HemaChowdary | 0:4b83964a5228 | 45 | } |
| HemaChowdary | 0:4b83964a5228 | 46 | } |
