Hema Vadlamudi
/
mbed_bluetooth_HC-06_communication
This program will enable the communication between bluetooth HC-06 module and mbed Nucleo STF401RE
main.cpp@0:4b83964a5228, 2015-06-08 (annotated)
- Committer:
- HemaChowdary
- Date:
- Mon Jun 08 10:10:53 2015 +0000
- Revision:
- 0:4b83964a5228
This program will enable the communication between bluetooth HC-06 module and mbed Nucleo STF401RE
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 | |
HemaChowdary | 0:4b83964a5228 | 3 | Serial bt(D10,D2); |
HemaChowdary | 0:4b83964a5228 | 4 | Serial pc(USBTX,USBRX); |
HemaChowdary | 0:4b83964a5228 | 5 | DigitalOut myled(D13); |
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 | } |
HemaChowdary | 0:4b83964a5228 | 24 | //tutn 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 | } |