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

Dependencies:   mbed

Committer:
benrammok
Date:
Thu Nov 05 12:10:57 2015 +0000
Revision:
0:69809c56f31a
Bluetooth and app connection demonstration

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benrammok 0:69809c56f31a 1 #include "mbed.h"
benrammok 0:69809c56f31a 2
benrammok 0:69809c56f31a 3
benrammok 0:69809c56f31a 4 Serial Bluetooth(PB_6, PA_10);
benrammok 0:69809c56f31a 5 DigitalIn button(USER_BUTTON); //Definerer bruker input på NUCLEO
benrammok 0:69809c56f31a 6 PwmOut led(PC_7); //Definerer LED objekt
benrammok 0:69809c56f31a 7
benrammok 0:69809c56f31a 8
benrammok 0:69809c56f31a 9
benrammok 0:69809c56f31a 10 void toggleLed(int *ledOn){
benrammok 0:69809c56f31a 11 *ledOn = !*ledOn;
benrammok 0:69809c56f31a 12 }
benrammok 0:69809c56f31a 13
benrammok 0:69809c56f31a 14
benrammok 0:69809c56f31a 15 int main() {
benrammok 0:69809c56f31a 16 float periodeTid=0.01f;
benrammok 0:69809c56f31a 17 int ledOn = 0;
benrammok 0:69809c56f31a 18 int prosent;
benrammok 0:69809c56f31a 19 float periodeTid_ms=(int)periodeTid*1000;
benrammok 0:69809c56f31a 20 led.period(periodeTid);
benrammok 0:69809c56f31a 21 Bluetooth.baud(9600);
benrammok 0:69809c56f31a 22
benrammok 0:69809c56f31a 23 while(1) {
benrammok 0:69809c56f31a 24 while(Bluetooth.readable()){ //Hvis vi kan lese av informasjon fra Bluetoothen
benrammok 0:69809c56f31a 25 if(Bluetooth.getc()=='T'){
benrammok 0:69809c56f31a 26 toggleLed(&ledOn);
benrammok 0:69809c56f31a 27 }
benrammok 0:69809c56f31a 28 if(ledOn){
benrammok 0:69809c56f31a 29 led.pulsewidth(periodeTid*Bluetooth.getc()/100);
benrammok 0:69809c56f31a 30 }else{
benrammok 0:69809c56f31a 31 led = 0;
benrammok 0:69809c56f31a 32 }
benrammok 0:69809c56f31a 33 }
benrammok 0:69809c56f31a 34 }
benrammok 0:69809c56f31a 35 }
benrammok 0:69809c56f31a 36