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

Dependencies:   TextLCD

Committer:
brandongarcia
Date:
Thu Dec 17 17:03:31 2020 +0000
Revision:
0:3802a6cf8d31
Code to turn ON and OFF an LED via bluetooth using HC06

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brandongarcia 0:3802a6cf8d31 1 #include "mbed.h"
brandongarcia 0:3802a6cf8d31 2 Serial bluetooth(PB_6, PB_3);//Pins used for communicating
brandongarcia 0:3802a6cf8d31 3 DigitalOut led(LED1);//LED1 is pin PA_5 or D13 / LED integrated in nucleoboard
brandongarcia 0:3802a6cf8d31 4
brandongarcia 0:3802a6cf8d31 5 int main()
brandongarcia 0:3802a6cf8d31 6 {
brandongarcia 0:3802a6cf8d31 7 lcd.cls();
brandongarcia 0:3802a6cf8d31 8 bluetooth.baud(9600);//Default rate is 9600 bps
brandongarcia 0:3802a6cf8d31 9 bluetooth.printf("If '1' is sent then turn on LED1 , if '0' turn it off\n");
brandongarcia 0:3802a6cf8d31 10 while(1) {
brandongarcia 0:3802a6cf8d31 11 char c = bluetooth.getc(); // To read the data sent thorugh the bluetooth module
brandongarcia 0:3802a6cf8d31 12 if (c == '0') {// If value equals '0'
brandongarcia 0:3802a6cf8d31 13 led = 0; // Turn OFF LED1
brandongarcia 0:3802a6cf8d31 14 }
brandongarcia 0:3802a6cf8d31 15 if (c == '1') {// If value equals '1'
brandongarcia 0:3802a6cf8d31 16 led = 1; // Turn ON LED1
brandongarcia 0:3802a6cf8d31 17 }
brandongarcia 0:3802a6cf8d31 18 }
brandongarcia 0:3802a6cf8d31 19 }
brandongarcia 0:3802a6cf8d31 20