Pilot 1 working code (excluding new patient after calculation). %d changed in %f sensordata serial log.
Dependencies: ADS1015 MPU6050 PixelArray mbed
Fork of Momo_New by
Diff: Sensorplate/main.cpp
- Revision:
- 26:9e130f7ee829
- Parent:
- 25:96c34634abda
- Child:
- 27:77065263c0ea
diff -r 96c34634abda -r 9e130f7ee829 Sensorplate/main.cpp --- a/Sensorplate/main.cpp Tue Oct 03 08:53:56 2017 +0000 +++ b/Sensorplate/main.cpp Tue Oct 03 15:30:36 2017 +0000 @@ -15,29 +15,29 @@ #define NLED (3) #define ONE_COLOR -InterruptIn lock(p16); // Interrupts for buttons. +InterruptIn lock(p15); // Interrupts for buttons. InterruptIn reposition(p17); -InterruptIn mute(p15); +InterruptIn mute(p16); InterruptIn new_patient(p18); DigitalIn supplyvoltage(p20); // Analog input between 0 and 1 for reading supplyvoltage from measuringpoint before power supply. DigitalOut LED_intern1(LED1); DigitalOut LED_intern2(LED2); DigitalOut LED_intern3(LED3); +DigitalOut LED_intern4(LED4); neopixel::PixelArray array(p11); Timer lock_hold_timer; Timer calibration_hold_timer; Timer delay; Timer speaker_timer; -//Timer led_timer; DigitalOut speaker1(p21); DigitalOut speaker2(p22); PwmOut lock_LED(p23); -PwmOut reposition_LED(p24); -PwmOut mute_LED(p25); -PwmOut new_patient_LED(p26); +PwmOut reposition_LED(p25); +PwmOut mute_LED(p26); +PwmOut new_patient_LED(p24); I2C i2c(p28, p27); // I2C I2C i2cAccu(p9, p10); // I2C for accupack @@ -237,10 +237,12 @@ red_var = 255; green_var = 255; blue_var = 255; + LED_intern4 = 1; } else { red_var = 0; green_var = 0; blue_var = 0; + LED_intern4 = 0; } calibration_flash--; } @@ -410,8 +412,8 @@ alarm = 1; // Else alarm is on. speaker_state = 1; } - - + + if (alarm == 1 && mute_state == 1 && (batteryvoltage_current > alarm_voltage)) { // Set speaker on for 750 ms. speaker1 = 0; // Set speaker. speaker2 = 0; @@ -435,7 +437,7 @@ batteryvoltage_current = adsAccu.readADC_SingleEnded(0); // Read channel 0 from external ADC. powervoltage_current = adsAccu.readADC_SingleEnded(1); // Read channel 1 from external ADC. - + if (powervoltage_current < 20000) { power_plug_state = 0; } else { @@ -448,7 +450,7 @@ t.reset(); t.start(); - if (pel.readADC_SingleEnded(0) > 0) { + if (agu.testConnection() == 1) { elec[0] = pel.readADC_SingleEnded(0); // First PE readout for (k = 0; k < 4; k = k + 1) { @@ -466,7 +468,12 @@ elec[2] = pel.readADC_SingleEnded(0); // Third PE readout agu.getAccelero(acce); // Get accelerometer data - angle = acce[2]*10; + angle = acce[2]*100; + if(angle == 0) { + MPU6050 agu(p28,p27); + agu.getAccelero(acce); + angle = acce[2]*100; + } agu.getGyro(gyro); // Get gyroscope data while(t.read_us()<(3*(cycle_time/5))) {} // Wait untill 60% of cycle @@ -488,7 +495,7 @@ while(t.read_us()<(4*(cycle_time/5))) {} // Wait untill 80% of cycle - if (pel.readADC_SingleEnded(0) > 0) { + if (agu.testConnection() == 1) { elec[4] = pel.readADC_SingleEnded(0); // Fifth PE readout } @@ -521,7 +528,7 @@ new_patient.rise(&timer_calibration); // Falling edge for calibration algorithm option. delay.reset(); // Delaytimer reset en start. delay.start(); - + set_intensity(); lock_LED = control_LED_intensity; // Lock LED initialization.