Make timers more better, add uncrustify config
This commit is contained in:
parent
34f37b9dda
commit
91c21a02d5
3593
.uncrustify.cfg
Normal file
3593
.uncrustify.cfg
Normal file
File diff suppressed because it is too large
Load diff
44
src/main.cpp
44
src/main.cpp
|
@ -7,27 +7,32 @@ MHZ19 myMHZ19;
|
|||
Adafruit_AHTX0 aht;
|
||||
LiquidCrystal_I2C LCD(0x27,2,1,0,4,5,6,7,3,POSITIVE);
|
||||
|
||||
int greenpin = 25;
|
||||
int yellownpin = 33;
|
||||
int redpin = 32;
|
||||
#define PIN_LED_GREEN 25
|
||||
#define PIN_LED_YELLOW 33
|
||||
#define PIN_LED_RED 32
|
||||
|
||||
int backlightState = HIGH;
|
||||
int backlightUpdate = 0;
|
||||
|
||||
int update_ival = 0;
|
||||
int override = 0;
|
||||
volatile bool interruptFired = false;
|
||||
unsigned long lastInterrupt = 0;
|
||||
unsigned long lastUpdated = 0;
|
||||
|
||||
unsigned const int updateTimer = 5000;
|
||||
unsigned const int interruptTimer = 500;
|
||||
|
||||
int ready = 0;
|
||||
int cal_time = 5; //minutes
|
||||
|
||||
void led(int red, int green, int yellow)
|
||||
{
|
||||
analogWrite(redpin, red);
|
||||
analogWrite(greenpin, green);
|
||||
analogWrite(yellownpin, yellow);
|
||||
analogWrite(PIN_LED_RED, red);
|
||||
analogWrite(PIN_LED_GREEN, green);
|
||||
analogWrite(PIN_LED_YELLOW, yellow);
|
||||
}
|
||||
|
||||
void IRAM_ATTR BacklightToggle() {
|
||||
backlightUpdate = true;
|
||||
if (!interruptFired)
|
||||
interruptFired = true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
@ -72,20 +77,23 @@ void setup()
|
|||
}
|
||||
|
||||
void loop() {
|
||||
if (backlightUpdate) {
|
||||
if (interruptFired) {
|
||||
if (millis() - lastInterrupt > interruptTimer || lastInterrupt == 0) {
|
||||
backlightState = !backlightState;
|
||||
backlightUpdate = false;
|
||||
Serial.printf("Setting backlight to %i \n", backlightState);
|
||||
LCD.setBacklight(backlightState);
|
||||
lastInterrupt = millis();
|
||||
}
|
||||
|
||||
if (update_ival-- > 0) {
|
||||
delay(1000);
|
||||
interruptFired = false;
|
||||
}
|
||||
|
||||
if (millis() - lastUpdated > updateTimer || lastUpdated == 0) {
|
||||
lastUpdated = millis();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
update_ival = 5; //5sec
|
||||
|
||||
sensors_event_t humidity, temp;
|
||||
aht.getEvent(&humidity, &temp);
|
||||
LCD.setCursor(0, 0);
|
||||
|
@ -95,10 +103,10 @@ void loop() {
|
|||
LCD.print(humidity.relative_humidity, 1);
|
||||
LCD.print("%rH");
|
||||
|
||||
if (millis() >= (cal_time * 60000) && !override) {
|
||||
if (millis() >= (cal_time * 60000) && !ready) {
|
||||
LCD.setCursor(0, 1);
|
||||
LCD.print(" Ready.");
|
||||
override = true;
|
||||
ready = true;
|
||||
}
|
||||
|
||||
int co2 = myMHZ19.getCO2(false);
|
||||
|
|
Loading…
Reference in a new issue