Code final
Dependencies: mbed SimpleBLE X_NUCLEO_IDB0XA1 LIS3DH_spi
Revision 10:a15e07c7ad61, committed 2020-01-22
- Comitter:
- Nthnthj
- Date:
- Wed Jan 22 09:33:01 2020 +0000
- Parent:
- 9:3d83d0b410b8
- Commit message:
- Code final
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3d83d0b410b8 -r a15e07c7ad61 main.cpp --- a/main.cpp Fri Jan 17 12:42:51 2020 +0000 +++ b/main.cpp Wed Jan 22 09:33:01 2020 +0000 @@ -14,8 +14,8 @@ //Bluetooth hc05-6 -#define TX PA_15 -#define RX PB_7 +#define TX D0 +#define RX D1 //Init simpleBLE @@ -53,16 +53,35 @@ //SimpleChar<float> compteur = ble.readOnly_float(0xA000, 0xA003); //SimpleChar<float> Temps = ble.readOnly_float(0xA000, 0xA004); -Serial BT(TX,RX); -Serial pc(USBTX, USBRX); +Serial BT(USBTX,USBRX); +//Serial pc(USBTX, USBRX); int compteur; bool flag = false; float end,begin; +int message = 0; +int temps1 = 0; +string course; +char Buffer[10]; +int i = 0; +int begin2 = 0; + +void envoi(int message){ + BT.printf("%i\n", message); + // pc.printf("Message envoye \r\n"); +} + void pressed(){ - compteur=1; - led1= !led1; + // pc.printf("Test 2 \n "); + led1 = !led1; + temps1 = timer.read_ms(); + + // pc.printf("%i \r\n",temps1); + message = temps1; + envoi(message); + //timer.stop(); + //timer.start(); } @@ -107,10 +126,12 @@ // Characteristic PWM output //SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate); + + void skater_d() { if(flag==false) { - //printf("Ligne de depart coupee solo \n"); + // pc.printf("Ligne de depart coupee solo \n"); if( flag == false) { //printf("Depart skate \n"); begin = timer.read_ms(); @@ -140,42 +161,79 @@ } } +void test_mode(char Buffer[10]){ + if(Buffer[0] == 'S'){ + // pc.printf("mode solo \n"); + timer.reset(); + flag = false; + }else if(Buffer[0]=='D'){ + // pc.printf("mode duo \n"); + flag=true; + timer.reset(); + } + else if (Buffer[0] == 'R'){ + // pc.printf("Reset timer \n "); + timer.reset(); + //wait(1); + //timer.start(); + } + // pc.printf(" Test \n"); +} + + +void RXevent (){ + //c=BT.getc(); + if(BT.readable()){ + BT.scanf("%s", &Buffer); + wait(1); + } + + //pc.printf(" Message recu :%s \n",Buffer); + //timer.start(); + + //test_mode(Buffer); + + if (Buffer[0] == 'R'){ + // pc.printf("Reset timer \r\n "); + timer.reset(); + //wait(1); + //timer.start(); + //temps1=timer.read_ms(); + //envoi(temps1); + } + // pc.printf(" Message recu :%s \n", Buffer); + return; +} + + + //Main program int main(int, char**) { transistor=1; //ble.start(); - Ticker t; + //Ticker t; //t.attach(&Accupdate, 15.0f); timer.start(); + BT.attach(&RXevent); + //BT.attach(&RXevent); user1.fall(&pressed); - boutton1.fall(&pressed); - boutton2.fall(&pressed); - event.fall(&skater_d); - char c; - //char Buffer[10]; - int i = 0; - int begin2 = 0; + //boutton1.fall(&pressed); + //boutton2.fall(&pressed); + event.fall(&pressed); + //BT.attach(&RXevent); + while (1) { - //ble.waitForEvent(); - //if(timer.read_ms()>5000){ - timer.stop(); - timer.start(); - begin2 = timer.read_ms(); - //pc.printf("hello"); - Green = 0.001; - c = compteur; - BT.putc(i); - BT.putc(begin2); - wait(1); - //BT.puts("Test"); - Green = 0; - compteur = 0; - i=i+1; - wait(1); + + //begin2 = timer.read_ms(); + Green = 0.001; + wait(1); + //BT.puts("Test"); + Green = 0; + wait(1); //} }