A Demonstration on use of Bluetooth to interface with apps on smartphone
Dependencies: mbed
Revision 0:69809c56f31a, committed 2015-11-05
- Comitter:
- benrammok
- Date:
- Thu Nov 05 12:10:57 2015 +0000
- Commit message:
- Bluetooth and app connection demonstration
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 05 12:10:57 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c \ No newline at end of file