Premier programme pour la cellule de départ : L476RG HC05 + BLE

Dependencies:   mbed SimpleBLE X_NUCLEO_IDB0XA1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //Includes
00002 
00003 #include "mbed.h"
00004 #include "SimpleBLE.h"
00005 
00006 
00007 ///////////Init STM32 pins///////////
00008 DigitalOut myLed(PC_8);
00009 DigitalIn my_button(PC_13);  //User1
00010 /////////////////////////////////////
00011 
00012 
00013 
00014 
00015 ///////////Init HC05/////////////////
00016 Serial HC05(PA_2, PA_3);
00017 //Bluetooth
00018 //Maitre (Tanguy) : ADDR = 0019,10,08FCD3
00019 //Esclave (Dorian) : ADDR = 0019,10,08FCB5
00020 /////////////////////////////////////
00021 
00022 
00023 
00024 
00025 //////////////Init BLE///////////////
00026 SimpleBLE ble("ObCP_CROC_ENSMM");
00027 
00028 /////////////READ////////////////////
00029 SimpleChar<float> trigger_value = ble.readOnly_float(0xA000, 0xA002);
00030 SimpleChar<float> chrono_value = ble.readOnly_float(0xA000, 0xA003);
00031 /////////////////////////////////////
00032 
00033 
00034 
00035 
00036 ////////////TIMER////////////////////
00037 Timer timer;
00038 int begin;
00039 int end;
00040 float chrono=0;
00041 void Timer_triggered()
00042 {
00043     timer.start();
00044     begin = timer.read_ms();
00045 }
00046 void Timer_Reset()
00047 {
00048     timer.stop();
00049     begin=0;
00050     end=0;
00051     chrono=0;
00052 }
00053 /////////////////////////////////////
00054 
00055 
00056 
00057 
00058 /////////COMMUNICATION///////////////
00059 void HC05_receive()
00060 {
00061     char IncomingValue = HC05.getc();
00062     if(IncomingValue == 'u') {
00063         end = timer.read_ms();
00064         timer.stop();
00065         chrono = end-begin;
00066 
00067     }
00068     HC05.putc(IncomingValue);
00069 }
00070 /////////////////////////////////////
00071 
00072 
00073 
00074 
00075 /////////////GAMEMODES///////////////
00076 void solo()
00077 {
00078     trigger_value = float(my_button);
00079     chrono_value = float(chrono)* 0.001F;
00080 
00081 
00082     if (my_button==0) {
00083         Timer_triggered();
00084         myLed=1;
00085     } else {
00086         myLed = 0;
00087     }
00088     //while bluetooth device is receiving data
00089     while(HC05.readable()) {
00090         HC05_receive();
00091     }
00092 }
00093 /////////////////////////////////////
00094 
00095 
00096 
00097 
00098 /////////GAMEMODES UPDATE////////////
00099 float gamemode = 0;
00100 void updateGM(float newValue)
00101 {
00102     gamemode = newValue;
00103 }
00104 SimpleChar<float> gamemode_command = ble.writeOnly_float(0xA000, 0xA004, &updateGM);
00105 /////////////////////////////////////
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 int main(int, char**)
00115 {
00116     HC05.baud(9600);
00117     ble.start();
00118     while (1) {
00119         ble.waitForEvent();
00120         solo();
00121 
00122     }
00123 }
00124 
00125 
00126 
00127 
00128 
00129 
00130