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
main.cpp
- Committer:
- Nthnthj
- Date:
- 2020-01-17
- Revision:
- 9:3d83d0b410b8
- Parent:
- 7:f5e10b18984d
- Child:
- 10:a15e07c7ad61
File content as of revision 9:3d83d0b410b8:
//Includes #include "mbed.h" #include "SimpleBLE.h" #include "LIS3DH.h" #include "stdlib.h" //Accelerometer #define MOSI PC_12 #define MISO PC_11 #define CS PC_5 #define SCLK PC_10 //Bluetooth hc05-6 #define TX PA_15 #define RX PB_7 //Init simpleBLE //SimpleBLE ble("ObCP_Roller_Catcher2"); // GPIO set //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 PwmOut PWMoutput(PB_1); //Main PWM output PwmOut Green(PC_8); //PWM Red LED PwmOut Red(PC_6); //PWM Green LED PwmOut Blue(PC_9); //PWM Blue LED //Init accelerometer LIS3DH acc(MOSI, MISO, SCLK, CS, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_2G); // Characteristics Accelerometer input //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; */ } // When characteristic PWM output changing void PWMupdate(uint8_t pwmvalue) { // cast to float, as PwmOut expects a value between 0.0f and 1.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; //Temps=15.68; } // Characteritic PWM LED RGB //SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate); // 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"); 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**) { transistor=1; //ble.start(); Ticker t; //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(); //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