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:
- 16:adbbac0c79f9
- Parent:
- 14:3e7c3044d48b
- Child:
- 17:6ec7d594c1f1
--- a/Sensorplate/main.cpp Thu Sep 28 15:23:17 2017 +0000 +++ b/Sensorplate/main.cpp Thu Sep 28 18:00:14 2017 +0000 @@ -17,7 +17,7 @@ InterruptIn reposition(p17); InterruptIn mute(p15); InterruptIn new_patient(p14); -AnalogIn batteryvoltage(p18); // Analog input between 0 and 1 (0 and 100 %) for reading batteryvoltage from accupack. + // Analog input between 0 and 1 (0 and 100 %) for reading batteryvoltage from accupack. DigitalIn supplyvoltage(p20); // Analog input between 0 and 1 for reading supplyvoltage from measuringpoint before power supply. PwmOut LED_intern1(LED1); @@ -34,10 +34,12 @@ DigitalOut speaker2(p22); I2C i2c(p28, p27); // I2C +I2C i2cAccu(p23, p18); MPU6050 agu(p28,p27); // Accelerometer/Gyroscope Unit Adafruit_ADS1115 pr1(&i2c, 0x48); // first PiëzoResistive ADC Adafruit_ADS1115 pr2(&i2c, 0x49); // second PiëzoResistive ADC Adafruit_ADS1115 pel(&i2c, 0x4B); // PiëzoElectric ADC +Adafruit_ADS1015 adsAccu(&i2cAccu); Serial pc(USBTX, USBRX); // tx, rx // Serial USB connection Serial pi(p9, p10); // tx, rx // Setup serial communication for pi. Timer t; // Timer for equally time-spaced samples @@ -66,7 +68,7 @@ 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; // Variables to set LED intensity. -int batteryvoltage_current = 0, batteryvoltage_last = 0; +uint16_t batteryvoltage_current = 0, batteryvoltage_last = 0; int intensity_day = 50, intensity_night = 25; // Intensity settings for LED's to wall. void set_intensity() // Function to set the intensity for the LED's. @@ -81,10 +83,9 @@ void serial_read() // Serial read for select LED intensity and colour. { if (pi.readable()) { - char message[3]; + char message[10]; pi.scanf("%s",message); pc.printf("%s", message); - message[strlen(message)] = '\n'; if (message[0] == '0') { intensity_select = 0; @@ -186,12 +187,12 @@ void trigger_mute() { + pc.printf("Mute_triggered.\n"); if (lock_state == 1 | (delay.read_ms() < buttondelay_ms)) { // Control statement for lock interface and delay for non using buttons at the same time. mute_state = 0; } else { delay.reset(); delay.start(); - pi.printf("01\n"); mute_state = !mute_state; if (LED_intern1 == 0) { @@ -276,8 +277,8 @@ speaker_timer.stop(); // Stop speaker timer. speaker_timer.reset(); } - - batteryvoltage_current = batteryvoltage.read(); + + batteryvoltage_current = adsAccu.readADC_SingleEnded(0); // read channel 0 if (supplyvoltage.read() == 0) { power_plug_state = 1; @@ -285,9 +286,10 @@ power_plug_state = 0; } } - + void read_adc() { + pc.printf("Read_adc\n"); t.reset(); t.start(); @@ -370,6 +372,7 @@ if (batteryvoltage_current != batteryvoltage_last) { pi.printf("%%d\n", batteryvoltage_current); + batteryvoltage_last = batteryvoltage_current; } if (LED_red_logged != LED_red_state) { @@ -435,7 +438,8 @@ pc.baud(baud); pi.baud(baud); pr1.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V - pr2.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V + pr2.setGain(GAIN_TWOTHIRDS) + ; // set range to +/-6.144V pel.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V pi.format(8, SerialBase::None, 1); @@ -452,5 +456,6 @@ while (1) { wait_us(cycle_time+1); // wait indefinitely because the ticker restarts every 50 ms + pc.printf("while\n"); } } \ No newline at end of file