Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Diff: Sensorplate/main.cpp
- Revision:
- 28:b4bee068780d
- Parent:
- 27:77065263c0ea
- Child:
- 29:45647b61f4cf
--- a/Sensorplate/main.cpp Tue Oct 03 16:07:01 2017 +0000 +++ b/Sensorplate/main.cpp Thu Oct 05 11:07:32 2017 +0000 @@ -31,6 +31,7 @@ Timer calibration_hold_timer; Timer delay; Timer speaker_timer; +Timer test_timer; DigitalOut speaker1(p21); DigitalOut speaker2(p22); @@ -62,7 +63,7 @@ float acce[3]; // Raw accelerometer data float gyro[3]; // Raw gyroscope data char LED_colour = 'g'; // Variable to set LED colour. -bool lock_state = 0, lock_flag = 0, mute_state = 0, alarm = 0, calibration_flag = 0, intensity_select = 0; // Boolean variables for states logging. +bool lock_state = 0, lock_flag = 0, mute_state = 0, alarm = 0, calibration_flag = 0, intensity_select = 1; // Boolean variables for states logging. bool mute_flag = 0, new_patient_flag = 0, reposition_flag = 0; bool speaker_state = 0, LED_red_state = 0, LED_yellow_state = 0, LED_green_state = 0, power_plug_state = 0; bool speaker_logged = 0, LED_red_logged = 0, LED_yellow_logged = 0, LED_green_logged = 0, power_plug_logged = 0; @@ -77,6 +78,7 @@ short batteryvoltage_current = 0, batteryvoltage_last = 0, powervoltage_current, powervoltage_last; // Variables to manage batteryvoltage. int intensity_day = 50, intensity_night = 25; // Intensity settings for LED's to wall. double intensity, control_LED_intensity = 0; // Variable between 0 and 1 to set the intensity of the LED's above the buttons. +int a; //test /*************************** CODE ********************************/ @@ -96,7 +98,7 @@ if (pi.readable()) { char message[10]; pi.scanf("%s", message); - + if (message[0] == '0') { intensity_select = 0; } @@ -200,8 +202,9 @@ power_plug_logged = power_plug_state; } } - - pi.printf("!,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%f,%f,\n", res[4], res[7], res[6], res[5], res[1], res[0], res[2], res[3], elec[0], elec[1], elec[2], elec[3], elec[4], acce[0]*100, acce[1]*100, acce[2]*100, gyro[0]*100, gyro[1]*100, gyro[2]*100); // print all to serial port + if(a == 1) { + pi.printf("!,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n", res[4], res[7], res[6], res[5], res[1], res[0], res[2], res[3], elec[0], elec[1], elec[2], elec[3], elec[4], acce[0]*100, acce[1]*100, acce[2]*100, gyro[0]*100, gyro[1]*100, gyro[2]*100); // print all to serial port + } //receiving order: 8 resistive sensors, 5 electric readings, 3 accelerometer axes, 3 gyroscope axes } @@ -209,6 +212,10 @@ { set_intensity(); // Call function set_intensity + red_var = 0; + green_var = 0; + blue_var = 0; + if (LED_colour == 'r') { red_var = (2.55*intensity); green_var = 0; @@ -236,6 +243,12 @@ LED_green_state = 0; } + if (LED_colour == 'b') { + red_var = 0; + green_var = 0; + blue_var = (2.55*intensity); + } + if (calibration_flash >= 1) { if ((calibration_flash % 2) == 0) { red_var = 255; @@ -357,6 +370,7 @@ void timer_functions() { + pc.printf("locktime= %d\n",lock_hold_timer.read_ms()); if ((lock_hold_timer.read_ms() > locktime_ms) && lock_flag == 0 && lock == 0) { // If statement for lock function. lock_flag = 1; LED_intern2 = !LED_intern2; @@ -444,6 +458,7 @@ if (powervoltage_current < 20000) { power_plug_state = 0; + LED_colour = 'b'; } else { power_plug_state = 1; } @@ -453,8 +468,15 @@ { t.reset(); t.start(); - - if (agu.testConnection() == 1) { + a = agu.testConnection();/* + pc.printf("a= %d\n",a); + if( a==0) + { + lock_state = 1; + LED_intern2 = 1; + lock_LED = 0; + }*/ + if (a == 1) { elec[0] = pel.readADC_SingleEnded(0); // First PE readout for (k = 0; k < 4; k = k + 1) { @@ -499,12 +521,13 @@ while(t.read_us()<(4*(cycle_time/5))) {} // Wait untill 80% of cycle - if (agu.testConnection() == 1) { +// pc.printf("2e = %d\n",agu.testConnection()); + if (a == 1) { elec[4] = pel.readADC_SingleEnded(0); // Fifth PE readout } while(t.read_us()<(4.25*(cycle_time/5))) {} // Wait untill 85% of cycle - + serial_read(); serial_log(); }