From ab43067717cb462c01b0c2687459ab3db10a2746 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 25 Jun 2021 07:05:20 -0400 Subject: [PATCH] added first_read to detect baseline accel reading for LED --- .../Payload_BME280_MPU6050_XS_Temp.ino | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/stempayload/Payload_BME280_MPU6050_XS_Temp.ino b/stempayload/Payload_BME280_MPU6050_XS_Temp.ino index 70270360..43e758c1 100644 --- a/stempayload/Payload_BME280_MPU6050_XS_Temp.ino +++ b/stempayload/Payload_BME280_MPU6050_XS_Temp.ino @@ -19,12 +19,14 @@ float Sensor2 = 0; void eeprom_word_write(int addr, int val); short eeprom_word_read(int addr); int first_time = true; +int first_read = true; float T2 = 26.3; // Temperature data point 1 float R2 = 167; // Reading data point 1 float T1 = 2; // Temperature data point 2 float R1 = 179; // Reading data point 2 int sensorValue; float Temp; +float rest; void setup() { @@ -99,10 +101,16 @@ void loop() { if (result == 'R') { Serial.println("OK"); - delay(500); + delay(100); + first_time = true; + setup(); + } + else if (result == 'C') { + Serial.println("Clearing stored gyro offsets in EEPROM\n"); + eeprom_word_write(0, 0x00); + first_time = true; setup(); } - if ((result == '?') || first_time == true) { first_time = false; @@ -171,7 +179,8 @@ void loop() { if (result == 'R') { Serial1.println("OK"); - delay(500); + delay(100); + first_read = true; setup(); } @@ -221,7 +230,12 @@ void loop() { // Serial.print(" "); // Serial.println(acceleration); - if (acceleration > 1.2) + if (first_read == true) { + first_read = false; + rest = acceleration; + } + + if (acceleration > 1.2 * rest) led_set(greenLED, HIGH); else led_set(greenLED, LOW);