This a great example of how Bluetooth (BT) reads incoming chars. This program constantly check if a char has been sent over BT and then turns on or off a digital output on the K64F board. We used MIT App Inventor to download an app to a android phone. This app would connect to our HC06 BT module on the K64F. The app would send chars when certain buttons were pressed. The K64F would then receive them and take appropriate action. Our digital output would send signal to relays, that's why you see variables called relay1,2,3... The relays then allowed power to got to a power strip.

Dependencies:   mbed

Revision:
0:2fb6b3ddfcbd
Child:
1:9ba4f4c2b414
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 02 18:37:58 2019 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+CAN can1(PA_11, PA_12);
+Serial bluetooth(PA_9, PA_10); //PINS TO CONECT. PA_9 WITH RX PIN HC-06
+int dato=0;
+
+
+DigitalOut led(PC_13);// LED BUILT IN BOARD STM32F103C8T6 
+
+int main()
+
+{
+    bluetooth.baud(9600);
+    bluetooth.printf("\nSTM32 bluetooth\n");
+    while(1) {
+
+    if(bluetooth.readable()) {
+          
+            dato=bluetooth.getc();
+            bluetooth.putc(dato);
+           
+       
+            }
+       if (dato=='a'){
+        led=0;
+        }
+        else if(dato=='b')
+        {
+            led=1;
+            }
+        
+        
+        
+    }
+}