Page 370 - ARM Based Microcontroller Projects Using MBED
P. 370
356 14. ADVANCED PROJECTS
14.5.7 Program Listing
Theprogramlisting(program:Bluetooth)isshowninFig.14.27.Atthebeginningofthepro-
gram the interface between the HC-06 Bluetooth module and the development board are de-
finedandLEDAandLEDBareassignedtoGPIOportsPC_0andPC_1,respectively.Theseport
pins are configured as digital outputs and the two LEDs are turned OFF at the beginning of the
/***********************************************************************
BLUETOOTH LED CONTROL
=====================
In this program a serial HC-06 Bluetooth module is connected to UART
pins PA_9 and PA_10. Additonally, two LEDs are connected to PORTC
pins PC_0 and PC_0. Commands sent from a Bluetooth device (e.g. a
mobile phone or a laptop) control the LEDs. Commands ONx turn ON
LEDs where x is A for LEDA and B for LEDB. Similarly, commands
OFFx turn OFF the LEDs where x is A fo LEDA and B for LEDB
Author: Dogan Ibrahim
Date : September 2018
File : Bluetooth
**********************************************************************/
#include "mbed.h"
#define TX PA_9 // UART TX pin
#define RX PA_10 // UART RX pin
Serial bluetooth(TX, RX); // Bluetooth interface
//
// Configure the LEDs as outputs and turn them OFF at beginning
//
DigitalOut LEDA(PC_0, 0);
DigitalOut LEDB(PC_1, 0);
int main()
{
char Buffer[10];
//
// Receive commands and control the LEDs accordingly. The received
// commands are stored in character array Buffer.
//
while(1)
{
bluetooth.scanf("%s", &Buffer);
if(Buffer[0] == 'O' && Buffer[1] == 'N')
{
if(Buffer[2] == 'A') LEDA = 1;
else if(Buffer[2] == 'B')LEDB = 1;
}
else if(Buffer[0] == 'O' && Buffer[1] == 'F' && Buffer[2] == 'F')
{
if(Buffer[3] == 'A') LEDA = 0;
else if(Buffer[3] == 'B')LEDB = 0;
}
}
}
FIG. 14.27 Program listing.