Turn ON & OFF an LED via Bluetooth using the HC06 module

Dependencies:   TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial bluetooth(PB_6, PB_3);//Pins used for communicating
00003 DigitalOut led(LED1);//LED1 is pin PA_5 or D13 / LED integrated in nucleoboard
00004 
00005 int main()
00006 {
00007     lcd.cls();
00008     bluetooth.baud(9600);//Default rate is 9600 bps
00009     bluetooth.printf("If '1' is sent then turn on LED1 , if '0' turn it off\n");
00010     while(1) {
00011         char c = bluetooth.getc(); // To read the data sent thorugh the bluetooth module
00012             if (c == '0') {// If value equals '0' 
00013                 led = 0; // Turn OFF LED1
00014         }
00015         if (c == '1') {// If value equals '1' 
00016                 led = 1; // Turn ON LED1      
00017         }
00018     }
00019 }
00020