Programme de la première cellule du RC, celle uniquement connectée en BT avec l'autre ObCP. Le code reçoit des infos et renvoi le temps relevé.
Dependencies: mbed SimpleBLE X_NUCLEO_IDB0XA1 LIS3DH_spi
Diff: main.cpp
- Revision:
- 9:3d83d0b410b8
- Parent:
- 7:f5e10b18984d
- Child:
- 10:a15e07c7ad61
diff -r f9cd29526673 -r 3d83d0b410b8 main.cpp --- a/main.cpp Tue Dec 17 14:25:24 2019 +0000 +++ b/main.cpp Fri Jan 17 12:42:51 2020 +0000 @@ -3,6 +3,7 @@ #include "mbed.h" #include "SimpleBLE.h" #include "LIS3DH.h" +#include "stdlib.h" //Accelerometer @@ -11,9 +12,14 @@ #define CS PC_5 #define SCLK PC_10 +//Bluetooth hc05-6 + +#define TX PA_15 +#define RX PB_7 + //Init simpleBLE -SimpleBLE ble("ObCP_CROC_ENSMM"); +//SimpleBLE ble("ObCP_Roller_Catcher2"); // GPIO set @@ -21,6 +27,14 @@ //Interrupt input InterruptIn user1(PC_13); //User1 +InterruptIn boutton1(D3); +InterruptIn boutton2(D4); +InterruptIn event(A0); + +Timer timer; + +DigitalOut led1(D14); +DigitalOut transistor(D6); //PWM output @@ -35,22 +49,36 @@ // Characteristics Accelerometer input -SimpleChar<float> accX = ble.readOnly_float(0xA000, 0xA002); -SimpleChar<float> accY = ble.readOnly_float(0xA000, 0xA003); -SimpleChar<float> accZ = ble.readOnly_float(0xA000, 0xA004); +//SimpleChar<float> accX = ble.readOnly_float(0xA000, 0xA002); +//SimpleChar<float> compteur = ble.readOnly_float(0xA000, 0xA003); +//SimpleChar<float> Temps = ble.readOnly_float(0xA000, 0xA004); + +Serial BT(TX,RX); +Serial pc(USBTX, USBRX); + +int compteur; +bool flag = false; +float end,begin; + +void pressed(){ + compteur=1; + led1= !led1; + } + + // When characteristic LED RGB changing void LEDupdate(uint32_t newColor) -{ +{/* // read individual bytes uint8_t* channels = (uint8_t*)&newColor; // cast to float, as PwmOut expects a value between 0.0f and 1.0f Red = static_cast<float>(channels[0]) / 255.0f; Green = static_cast<float>(channels[1]) / 255.0f; - Blue = static_cast<float>(channels[2]) / 255.0f; + Blue = static_cast<float>(channels[2]) / 255.0f; */ } // When characteristic PWM output changing @@ -59,37 +87,98 @@ { // cast to float, as PwmOut expects a value between 0.0f and 1.0f - PWMoutput = static_cast<float>(pwmvalue) / 255.0f; +// PWMoutput = static_cast<float>(pwmvalue) / 255.0f; } // When characteristic input changing void Accupdate() { - accX = float(short((acc.read_reg(LIS3DH_OUT_X_H) << 8) | acc.read_reg(LIS3DH_OUT_X_L))) * 0.001F / 15; - accY = float(short((acc.read_reg(LIS3DH_OUT_Y_H) << 8) | acc.read_reg(LIS3DH_OUT_Y_L))) * 0.001F / 15; - accZ = float(short((acc.read_reg(LIS3DH_OUT_Z_H) << 8) | acc.read_reg(LIS3DH_OUT_Z_L))) * 0.001F / 15; + //accX = float(short((acc.read_reg(LIS3DH_OUT_X_H) << 8) | acc.read_reg(LIS3DH_OUT_X_L))) * 0.001F / 15; + //accY = float(short((acc.read_reg(LIS3DH_OUT_Y_H) << 8) | acc.read_reg(LIS3DH_OUT_Y_L))) * 0.001F / 15; + //accZ = float(short((acc.read_reg(LIS3DH_OUT_Z_H) << 8) | acc.read_reg(LIS3DH_OUT_Z_L))) * 0.001F / 15; + //Temps=15.68; } // Characteritic PWM LED RGB -SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate); +//SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate); // Characteristic PWM output -SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate); +//SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate); +void skater_d() +{ + if(flag==false) { + //printf("Ligne de depart coupee solo \n"); + if( flag == false) { + //printf("Depart skate \n"); + begin = timer.read_ms(); + compteur=100; + //pc.printf(" skater lance %.0f \n", begin); + flag = true; + } else if(flag == true) { + //printf("erreur \n"); + //pc.printf(" Temps du skater : %.0f \n", end-begin); + flag = false; + } + } + else if(flag==true) { + //printf("Ligne d'arrivee coupee \n"); + if( flag == false ) { + //printf("arrivee coupe sans depart\n"); + flag = true; + } else if(flag == true ) { + //printf("Arrivee skate \n"); + end = timer.read_ms(); + //Temps = end-begin; + compteur=200; + //wait(1); + //pc.printf(" Temps du skater : %.0f \n", end-begin); + flag = false; + } + } +} //Main program int main(int, char**) { - - ble.start(); + transistor=1; + //ble.start(); Ticker t; - t.attach(&Accupdate, 5.0f); - + //t.attach(&Accupdate, 15.0f); + timer.start(); + user1.fall(&pressed); + boutton1.fall(&pressed); + boutton2.fall(&pressed); + event.fall(&skater_d); + char c; + //char Buffer[10]; + int i = 0; + int begin2 = 0; + while (1) { - ble.waitForEvent(); + //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); + //} } } + +//blablabla \ No newline at end of file