Programme RC test publication
Dependencies: mbed SimpleBLE X_NUCLEO_IDB0XA1 LIS3DH_spi
main.cpp
- Committer:
- Nthnthj
- Date:
- 2020-01-22
- Revision:
- 10:a15e07c7ad61
- Parent:
- 9:3d83d0b410b8
- Child:
- 11:72c976e0d889
File content as of revision 10:a15e07c7ad61:
//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 D0 #define RX D1 //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(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(){ // 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(); } // 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) { // pc.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; } } } 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; //t.attach(&Accupdate, 15.0f); timer.start(); BT.attach(&RXevent); //BT.attach(&RXevent); user1.fall(&pressed); //boutton1.fall(&pressed); //boutton2.fall(&pressed); event.fall(&pressed); //BT.attach(&RXevent); while (1) { //begin2 = timer.read_ms(); Green = 0.001; wait(1); //BT.puts("Test"); Green = 0; wait(1); //} } } //blablabla