Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray-Nucleo mbed
Fork of Momo_Pilot_1 by
Diff: Sensorplate/main.cpp
- Revision:
- 8:bf0f7a6fb1fd
- Parent:
- 7:dba5091c8b7d
- Child:
- 9:514a44bf510f
diff -r dba5091c8b7d -r bf0f7a6fb1fd Sensorplate/main.cpp --- a/Sensorplate/main.cpp Wed Sep 27 09:04:08 2017 +0000 +++ b/Sensorplate/main.cpp Wed Sep 27 14:45:18 2017 +0000 @@ -9,8 +9,9 @@ InterruptIn reposition(p17); InterruptIn mute(p15); InterruptIn new_patient(p14); -AnalogIn LDR_val(p18); -AnalogIn supplyvoltage(p20); // Analog input between 0 and 1 (0 and 100 %) for reading supplyvoltage from accupack. +//AnalogIn LDR_val(p18); +AnalogIn batteryvoltage(p18); // Analog input between 0 and 1 (0 and 100 %) for reading batteryvoltage from accupack. +AnalogIn supplyvoltage(p20); // Analog input between 0 and 1 (0 and 100 %) for reading supplyvoltage from measuringpoint before power supply. PwmOut LED_intern1(LED1); DigitalOut LED_intern2(LED2); @@ -30,9 +31,10 @@ Adafruit_ADS1115 pr2(&i2c, 0x49); // second PiëzoResistive ADC Adafruit_ADS1115 pel(&i2c, 0x4B); // PiëzoElectric ADC Serial pc(USBTX, USBRX); // tx, rx // Serial USB connection -Serial pi(p9, p10, 9600); // Setup serial communication for pi. +Serial pi(p9, p10, 115200); // Setup serial communication for pi. Timer t; // Timer for equally time-spaced samples Ticker sample_cycle; // Polling cycle + int cycle_time = 100000; // Cycle time in us int i2c_freq = 400000; // I2C Frequency int usb_baud = 115200; // USB Baud rate @@ -43,10 +45,10 @@ float acce[3]; // Raw accelerometer data float gyro[3]; // Raw gyroscope data char LED_colour; // 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 lock, mute and alarm. -bool mute_flag = 0, new_patient_flag = 0, reposition_flag = 0, power_plug_flag = 0, battery_voltage_flag = 0; -bool speaker_flag_current = 0, LED_red_flag_current = 0, LED_yellow_flag_current = 0, LED_green_flag_current = 0; -bool speaker_flag_last = 0, LED_red_flag_current = 0, LED_yellow_flag_current = 0, LED_green_flag_current = 0; +bool lock_state, lock_flag, mute_state, alarm, calibration_flag, intensity_select; // Boolean variables for states lock, mute and alarm. +bool mute_flag, new_patient_flag, reposition_flag; +bool speaker_state, LED_red_state, LED_yellow_state, LED_green_state, power_plug_state; +bool speaker_logged, LED_red_logged, LED_yellow_logged, LED_green_logged, power_plug_logged; int locktime_ms = 2000; // Waittime in ms. int calibrationtime_ms = 5000; int calibration_flash; @@ -55,6 +57,7 @@ int speaker_active_ms = 750; double alarm_voltage = 0.2; // Needed voltage for alarm expressed as a percentage (0 - 100 % => 0 - 3.3 V). int red_var, green_var, blue_var, intensity, current_intensity = 0; // Variables to set LED intensity +int batteryvoltage_current = 0, batteryvoltage_last = 0; void set_intensity() // Function to set the intensity for the LED's { @@ -97,18 +100,27 @@ red_var = (2.55*intensity); green_var = 0; blue_var = 0; + LED_red_state = 1; + } else { + LED_red_state = 0; } if (LED_colour == 'y') { red_var = (2.55*intensity); green_var = (2.55*intensity); - blue_var = 0; + blue_var = 0; + LED_yellow_state = 1; + } else { + LED_green_state = 0; } if (LED_colour == 'g') { red_var = 0; green_var = (2.55*intensity); blue_var = 0; + LED_green_state = 1; + } else { + LED_green_state = 0; } if (calibration_flash >= 1) { @@ -145,7 +157,6 @@ } else { delay.reset(); delay.start(); - pi.printf("02\n"); // Seriele communicatie met PI. if (LED_intern1 == 0) { LED_intern1 = 1.0; @@ -154,6 +165,7 @@ } LED_colour = 'r'; + reposition_flag = 1; } } @@ -174,6 +186,7 @@ } LED_colour = 'y'; + mute_flag = 1; } } @@ -182,6 +195,7 @@ if (lock_state == 1) { } else { hold_timer.start(); + new_patient_flag = 1; } } @@ -193,9 +207,7 @@ if (lock_state == 1 | (delay.read_ms() < buttondelay_ms)) { // Control statement for lock interface and delay for non using buttons at the same time. } else { if (calibration_flag == 0) { - pi.printf("03\n"); - - + if (LED_intern1 == 0) { LED_intern1 = 1.0; } else { @@ -219,13 +231,15 @@ void read_voltage() { LED_intern3 = 0; - - if (supplyvoltage.read() > alarm_voltage) { // If supplyvoltage (readed from input) is greater then the setted alarmvoltage. + + if (batteryvoltage.read() > alarm_voltage) { // If supplyvoltage (readed from input) is greater then the setted alarmvoltage. alarm = 0; // Alarm is off. + speaker_state = 0; } else { alarm = 1; // Else alarm is on. + speaker_state = 1; } - + if (alarm == 1 && mute_state == 0 && (speaker_timer.read_ms() < speaker_active_ms)) { // Set speaker on for 750 ms. speaker1 = 1; // Set speaker. speaker2 = 1; @@ -249,6 +263,14 @@ speaker_timer.stop(); // Stop speaker timer. speaker_timer.reset(); } + + batteryvoltage_current = batteryvoltage.read(); + + if (supplyvoltage.read() == 0) { + power_plug_state = 1; + } else { + power_plug_state = 0; + } } void read_adc() @@ -297,8 +319,10 @@ LED_intern2 = 1; } + batteryvoltage_current = batteryvoltage_current*100; + batteryvoltage_current = batteryvoltage_last; read_voltage(); // Supplyvoltage control for alarm. - + uint32_t val = 0; colour_select(LED_colour); array.update(generate, NLED, val); @@ -308,7 +332,7 @@ elec[4] = pel.readADC_SingleEnded(0); //Fifth PE readout while(t.read_us()<(4.5*(cycle_time/5))) {} //Wait untill 90% of cycle - pc.printf(",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\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 + pc.printf("!,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\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 if (mute_flag == 1) { @@ -326,36 +350,54 @@ reposition_flag = 0; } - if (power_plug_flag == 1) { - pi.printf("#%d\n", power_plug_flag); - power_plug_flag = 0; - } - - if (battery_voltage_flag == 1) { - pi.printf("%%d\n", battery_voltage); - battery_voltage_flag = 0; + /*if () { + pi.printf("#1\n"); + power_plug_flag_current = 1; } - if (speaker_flag_current == speaker_flag_last) { - pi.printf("&07\n"); - } else if (speaker_flag_current != speaker_flag_last) { - pi.printf("&70\n"); + if () { + pi.printf("#0\n"); + power_plug_logged = 1; + } else { + + } + + if (batteryvoltage_current != batteryvoltage_last) { + pi.printf("%%d\n", batteryvoltage_current); + } else { + + } + + if () { + pi.printf("&04\n"); + LED_red_logged = 1; + } else { + LED_red_logged = 0; } - if (LED_red_flag == 1) { - pi.printf("& \n"); - LED_red_flag = 0; + if () { + pi.printf("&05\n"); + LED_yellow_logged = 1; + } else { + LED_yellow_logged = 0; } - - if (LED_yellow_flag == 1) { - pi.printf("& \n"); - LED_yellow_flag = 0; // Een event bij deactivatie + + if () { + pi.printf("&06\n"); + LED_green_logged = 1; + } else { + LED_green_logged = 0; + } + + if ((speaker_flag_current == 1) && (speaker_flag_last == 0)) { + pi.printf("&07\n"); + speaker_flag_current = 0; } - - if (LED_green_flag == 1) { - pi.printf("& \n"); - LED_green_flag = 0; - } + + if ((speaker_flag_current == 0) && (speaker_flag_last == 1)) { + pi.printf("&70\n"); + speaker_flag_last = 0; + } */ } int main()