Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Diff: Sensorplate/main.cpp
- Revision:
- 17:6ec7d594c1f1
- Parent:
- 16:adbbac0c79f9
- Child:
- 18:3b2686cdbcb7
diff -r adbbac0c79f9 -r 6ec7d594c1f1 Sensorplate/main.cpp --- a/Sensorplate/main.cpp Thu Sep 28 18:00:14 2017 +0000 +++ b/Sensorplate/main.cpp Thu Sep 28 20:19:21 2017 +0000 @@ -34,12 +34,12 @@ DigitalOut speaker2(p22); I2C i2c(p28, p27); // I2C -I2C i2cAccu(p23, p18); +I2C i2cAccu(p7, p6); 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); +Adafruit_ADS1015 adsAccu(&i2cAccu, 0x48); 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 +66,7 @@ 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; // 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 alarm_voltage = 5867; // Needed voltage for alarm expressed as a digital 15 bit value (=20% of max battery voltage) int red_var, green_var, blue_var, intensity; // Variables to set LED intensity. uint16_t batteryvoltage_current = 0, batteryvoltage_last = 0; int intensity_day = 50, intensity_night = 25; // Intensity settings for LED's to wall. @@ -246,7 +246,7 @@ { LED_intern3 = 0; - if (batteryvoltage.read() > alarm_voltage) { // If supplyvoltage (readed from input) is greater then the setted alarmvoltage. + if (batteryvoltage_current > alarm_voltage) { // If supplyvoltage (readed from input) is greater then the setted alarmvoltage. alarm = 0; // Alarm is off. speaker_state = 0; } else { @@ -278,7 +278,7 @@ speaker_timer.reset(); } - batteryvoltage_current = adsAccu.readADC_SingleEnded(0); // read channel 0 + batteryvoltage_current = adsAccu.readADC_SingleEnded(0); // Read channel 0 if (supplyvoltage.read() == 0) { power_plug_state = 1; @@ -346,7 +346,7 @@ elec[4] = pel.readADC_SingleEnded(0); //Fifth PE readout - while(t.read_us()<(4.5*(cycle_time/5))) {} //Wait untill 90% of cycle + while(t.read_us()<(4.25*(cycle_time/5))) {} //Wait untill 85% of cycle 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 //receiving order: 8 resistive sensors, 5 electric readings, 3 accelerometer axes, 3 gyroscope axes @@ -438,9 +438,9 @@ 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 + adsAccu.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V pi.format(8, SerialBase::None, 1); lock.rise(&trigger_lock); // Interrupt for rising edge lock button.