Nucleo-transfer

Dependencies:   ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813

Fork of Nucleo-transfer by Momo Medical

Revision:
11:73c6def38fbd
Parent:
10:6b3034ec3c47
Child:
12:7b3a5940f911
--- a/Sensorplate/main.cpp	Wed Sep 27 15:55:32 2017 +0000
+++ b/Sensorplate/main.cpp	Thu Sep 28 09:44:38 2017 +0000
@@ -15,7 +15,8 @@
 
 PwmOut LED_intern1(LED1);
 DigitalOut LED_intern2(LED2);
-DigitalOut LED_intern3(LED4);
+DigitalOut LED_intern3(LED3);
+DigitalOut LED_intern4(LED4);
 neopixel::PixelArray array(p11);
 
 Timer hold_timer;
@@ -45,28 +46,28 @@
 float acce[3];                      // Raw accelerometer data
 float gyro[3];                      // Raw gyroscope data
 char LED_colour;                                                            // Variable to set LED colour.
-bool lock_state, lock_flag, mute_state, alarm, calibration_flag, intensity_select;            // Boolean variables for states lock, mute and alarm.
+bool lock_state, lock_flag, mute_state, alarm, calibration_flag, intensity_select;            // Boolean variables for states logging. 
 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;
+int locktime_ms = 2000;                                                     // Waittime for lock user interface in ms.
+int calibrationtime_ms = 5000;                                              // Time to press new_patient button for calibration system. 
+int calibration_flash;                                                      // Variable for flash LED's to indicate calibration. 
 int buttondelay_ms = 750;                                                   // Button delay in ms.
 int delay_lock_interface = 3000*60;                                         // Delay for non using interface locktime.
-int speaker_active_ms = 750;
+int speaker_active_ms = 750;                                                // Time to iterate speaker on and off when alarm occurs. 
 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 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
+void set_intensity()                                                        // Function to set the intensity for the LED's.
 {
-    if (intensity_select == 0) {
+    if (intensity_select == 1) {
         intensity = 50;
     } else { 
         intensity = 25;
     }
-    //intensity = (1-LDR_val)*100;                                          // Calculate intensity (use right part of the graphic)
+    //intensity = (1-LDR_val)*100;                                          // Calculate intensity (use right part of the graphic).
 
     //if (abs(intensity-current_intensity) > 5) {                           // If difference is greater then 5, change intensity dependent on range.
     //    if (intensity <= 20) {
@@ -92,6 +93,34 @@
     // current_intensity = intensity;                                       // Save intensisty to compare in first if statement of this set_intensity function.
 }
 
+void serial_read() {                                                        // Serial read for colourselect
+    if (pi.readable()) {
+        char message[3];
+        pi.scanf("%s",message);
+        message[strlen(message)] = '\n';
+        
+        if (message[0] == '0') {
+            intensity_select = 0;
+        } 
+        
+        if (message[0] == '1') { 
+            intensity_select = 1; 
+        } 
+        
+        if (message[1] == 'g') {
+            LED_colour = 'g'; 
+        }
+
+        if (message[1] == 'y') {
+            LED_colour = 'y'; 
+        }
+        
+        if (message[1] == 'r') {
+            LED_colour = 'r'; 
+        }
+    }
+}
+
 void colour_select(char LED_colour)                                         // Function to select the colour.
 {
     set_intensity();                                                        // Call function set_intensity
@@ -164,7 +193,6 @@
             LED_intern1 = 0.0;
         }
 
-        LED_colour = 'r';
         reposition_flag = 1;
     }
 }
@@ -184,8 +212,7 @@
         } else {
             LED_intern1 = 0.0;
         }
-
-        LED_colour = 'y';
+        
         mute_flag = 1;
     }
 }
@@ -213,8 +240,7 @@
             } else {
                 LED_intern1 = 0.0;
             }
-
-            LED_colour = 'g';
+            
         } else {
             calibration_flag = 0;
         }
@@ -332,12 +358,15 @@
     elec[4] = pel.readADC_SingleEnded(0);       //Fifth PE readout
 
     while(t.read_us()<(4.5*(cycle_time/5))) {}  //Wait untill 90% of cycle
-    pi.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
+    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
     
     if (mute_flag == 1) {
         pi.printf(">01\n");
         mute_flag = 0;
+        LED_intern4 = 1; 
+    } else {
+        LED_intern4 = 0;
     }
     
     if (new_patient_flag == 1) {