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
- Committer:
- barry210110
- Date:
- 2018-08-01
- Revision:
- 1:22cda9aef3e6
- Parent:
- 0:4b83964a5228
File content as of revision 1:22cda9aef3e6:
#include "mbed.h"
Serial bt(PA_11, PA_12);
Serial pc(USBTX,USBRX);
DigitalOut myled(LED2);
int main()
{
bt.baud(9600);
//prints data on mobile
bt.printf("Connection Established");
//print data on pc terminal
pc.printf("Connection Established");
while(1) {
//For reading and writing data from/to bluetooth HC-06
//check if bluetooth is readable and execute commands to toggle LED
if (bt.readable()) {
char input_key= bt.putc(bt.getc());
//tutn on LED if "y" is entered
if(input_key == 'y') {
myled = 1;
bt.printf("LED is ON");
}
//turn on LED if "n" is entered
if(input_key == 'n') {
myled = 0;
bt.printf("LED is OFF");
}
}
//For reading and writing data from/to pc terminal
//check if pc is readable and execute commands to toggle LED
if (pc.readable()) {
char input_key= pc.putc(pc.getc());
if(input_key == 'y') {
myled = 1;
pc.printf("LED is ON");
}
if(input_key == 'n') {
myled = 0;
pc.printf("LED is OFF");
}
}
}
}
