Page 373 - ARM Based Microcontroller Projects Using MBED
P. 373

14.5 PROJECT 3—ANDROID—NUCLEO BOARD COMMUNICATION USING BLUETOOTH  359
              We can modify the program in Fig. 14.27 by sending a confirmation to the mobile phone
            when there is change in the LED status. The modified program listing (program:
            BluetoothConfirm) is shown in Fig. 14.30 where printf statements are used to send confir-
            mation to the mobile device. For example, as shown in Fig. 14.31, the text LEDB is ON is
            displayed on the screen after the command ONB is sent.






                  /***********************************************************************
                                      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

                  In this version of the program, confirmation is sent back to the
                  mobile device when the status of an LED changes
                  Author: Dogan Ibrahim
                  Date  : September 2018
                  File  : BluetoothConfirm
                  **********************************************************************/
                  #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.
                  //
            FIG. 14.30  Modified program.
                                                                                     (Continued)
   368   369   370   371   372   373   374   375   376   377   378