
get value from bluetooth HC05 in order to control an engine
Dependencies: mbed BluetoothSerial
This little prog link a simple engine to an android application. This application was designed on MIT AppInventor.
Here is the sketch
Revision 0:01d1cf42e360, committed 2021-03-11
- Comitter:
- chamo
- Date:
- Thu Mar 11 15:50:53 2021 +0000
- Commit message:
- prog 1
Changed in this revision
diff -r 000000000000 -r 01d1cf42e360 BluetoothSerial.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BluetoothSerial.lib Thu Mar 11 15:50:53 2021 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/yihui/code/BluetoothSerial/#f56002898ee8
diff -r 000000000000 -r 01d1cf42e360 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 11 15:50:53 2021 +0000 @@ -0,0 +1,23 @@ +#include "mbed.h" +#include <cstdlib> //librairie pour convertir char en float (libraby that convert char into float) +#include <string> + +Serial tel(D8, D2); //module bluetooth HC-05 branché à D8 (TX) et D2 (RX) (Bluetooth Hc05, Tx is link to D8 pin and Rx to D2) +DigitalOut moteur(D5); //broche du moteur (Engine to D5 pin) +DigitalIn bouton(PC_13); //broche du bouton (if you want to use a button condition, it's PC_13 pin) +PwmOut pwm(D11); //broche de la PWM (PWM is on D11 pin) + + +int main() +{ + float puissance; + while(1) { + if(tel.readable()) { //Si on peut utiliser le bluetooth (if Bluetooth is readable) + tel.baud(9600); //FrameRate du bluetooth (Bluetooth framerate) + puissance = tel.getc(); //récupère l'info en char (save as char what the bluetooth module got) + printf("puissance: %f \n",puissance); //test (just a test to know the power between 1 and 255) + pwm.write(puissance/255); //Info du bluetooth en char que l'on applique a la pwm (dividing power by 255 in order to have a pwm ratio) + moteur=1; //On lance le moteur (starting engine) + } + } +}
diff -r 000000000000 -r 01d1cf42e360 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 11 15:50:53 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file