A Demonstration on use of Bluetooth to interface with apps on smartphone

Dependencies:   mbed

Revision:
0:69809c56f31a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 05 12:10:57 2015 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+
+
+Serial Bluetooth(PB_6, PA_10);
+DigitalIn button(USER_BUTTON); //Definerer bruker input på NUCLEO
+PwmOut led(PC_7); //Definerer LED objekt
+
+
+
+void toggleLed(int *ledOn){
+    *ledOn = !*ledOn;
+ }
+ 
+ 
+int main() {
+  float periodeTid=0.01f;
+  int ledOn = 0;
+  int prosent;
+  float periodeTid_ms=(int)periodeTid*1000;
+  led.period(periodeTid);
+  Bluetooth.baud(9600);
+  
+  while(1) {  
+    while(Bluetooth.readable()){    //Hvis vi kan lese av informasjon fra Bluetoothen
+        if(Bluetooth.getc()=='T'){
+            toggleLed(&ledOn);
+        }
+        if(ledOn){
+            led.pulsewidth(periodeTid*Bluetooth.getc()/100);   
+        }else{
+            led = 0;    
+        }
+    }
+  }
+}
+ 
\ No newline at end of file