mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-29 08:27:17 +02:00
Fixed configuration button behavior
This commit is contained in:
@ -108,7 +108,7 @@ unsigned long previousTempHum = 0;
|
|||||||
float temp = 0;
|
float temp = 0;
|
||||||
int hum = 0;
|
int hum = 0;
|
||||||
|
|
||||||
int buttonConfig=4;
|
int buttonConfig=0;
|
||||||
int lastState = LOW;
|
int lastState = LOW;
|
||||||
int currentState;
|
int currentState;
|
||||||
unsigned long pressedTime = 0;
|
unsigned long pressedTime = 0;
|
||||||
@ -124,17 +124,20 @@ void setup() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
buttonConfig = String(EEPROM.read(addr)).toInt();
|
buttonConfig = String(EEPROM.read(addr)).toInt();
|
||||||
|
if (buttonConfig>3) buttonConfig=0;
|
||||||
|
delay(400);
|
||||||
setConfig();
|
setConfig();
|
||||||
|
Serial.println("buttonConfig: "+String(buttonConfig));
|
||||||
updateOLED2("Press Button", "Now for", "Config Menu");
|
updateOLED2("Press Button", "Now for", "Config Menu");
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
pinMode(D7, INPUT_PULLUP);
|
||||||
currentState = digitalRead(D7);
|
currentState = digitalRead(D7);
|
||||||
if (currentState == HIGH)
|
if (currentState == LOW)
|
||||||
{
|
{
|
||||||
updateOLED2("Entering", "Config Menu", "");
|
updateOLED2("Entering", "Config Menu", "");
|
||||||
delay(3000);
|
delay(3000);
|
||||||
lastState = LOW;
|
lastState = HIGH;
|
||||||
|
setConfig();
|
||||||
inConf();
|
inConf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,20 +167,26 @@ void inConf(){
|
|||||||
setConfig();
|
setConfig();
|
||||||
currentState = digitalRead(D7);
|
currentState = digitalRead(D7);
|
||||||
|
|
||||||
if(lastState == LOW && currentState == HIGH) {
|
if (currentState){
|
||||||
|
Serial.println("currentState: high");
|
||||||
|
} else {
|
||||||
|
Serial.println("currentState: low");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lastState == HIGH && currentState == LOW) {
|
||||||
pressedTime = millis();
|
pressedTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(lastState == HIGH && currentState == LOW) {
|
else if(lastState == LOW && currentState == HIGH) {
|
||||||
releasedTime = millis();
|
releasedTime = millis();
|
||||||
long pressDuration = releasedTime - pressedTime;
|
long pressDuration = releasedTime - pressedTime;
|
||||||
if( pressDuration < 1000 ) {
|
if( pressDuration < 1000 ) {
|
||||||
buttonConfig=buttonConfig+1;
|
buttonConfig=buttonConfig+1;
|
||||||
if (buttonConfig>7) buttonConfig=0;
|
if (buttonConfig>3) buttonConfig=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastState == HIGH && currentState == HIGH){
|
if (lastState == LOW && currentState == LOW){
|
||||||
long passedDuration = millis() - pressedTime;
|
long passedDuration = millis() - pressedTime;
|
||||||
if( passedDuration > 4000 ) {
|
if( passedDuration > 4000 ) {
|
||||||
// to do
|
// to do
|
||||||
@ -208,43 +217,23 @@ void inConf(){
|
|||||||
|
|
||||||
void setConfig() {
|
void setConfig() {
|
||||||
if (buttonConfig == 0) {
|
if (buttonConfig == 0) {
|
||||||
updateOLED2("Temp. in C", "PM in ug/m3", "Display Top");
|
updateOLED2("Temp. in C", "PM in ug/m3", "Long Press Saves");
|
||||||
u8g2.setDisplayRotation(U8G2_R2);
|
|
||||||
inF = false;
|
|
||||||
inUSAQI = false;
|
|
||||||
} else if (buttonConfig == 1) {
|
|
||||||
updateOLED2("Temp. in C", "PM in US AQI", "Display Top");
|
|
||||||
u8g2.setDisplayRotation(U8G2_R2);
|
|
||||||
inF = false;
|
|
||||||
inUSAQI = true;
|
|
||||||
} else if (buttonConfig == 2) {
|
|
||||||
updateOLED2("Temp. in F", "PM in ug/m3", "Display Top");
|
|
||||||
u8g2.setDisplayRotation(U8G2_R2);
|
|
||||||
inF = true;
|
|
||||||
inUSAQI = false;
|
|
||||||
} else if (buttonConfig == 3) {
|
|
||||||
updateOLED2("Temp. in F", "PM in US AQI", "Display Top");
|
|
||||||
u8g2.setDisplayRotation(U8G2_R2);
|
|
||||||
inF = true;
|
|
||||||
inUSAQI = true;
|
|
||||||
} else if (buttonConfig == 4) {
|
|
||||||
updateOLED2("Temp. in C", "PM in ug/m3", "Display Bottom");
|
|
||||||
u8g2.setDisplayRotation(U8G2_R0);
|
u8g2.setDisplayRotation(U8G2_R0);
|
||||||
inF = false;
|
inF = false;
|
||||||
inUSAQI = false;
|
inUSAQI = false;
|
||||||
}
|
}
|
||||||
if (buttonConfig == 5) {
|
if (buttonConfig == 1) {
|
||||||
updateOLED2("Temp. in C", "PM in US AQI", "Display Bottom");
|
updateOLED2("Temp. in C", "PM in US AQI", "Long Press Saves");
|
||||||
u8g2.setDisplayRotation(U8G2_R0);
|
u8g2.setDisplayRotation(U8G2_R0);
|
||||||
inF = false;
|
inF = false;
|
||||||
inUSAQI = true;
|
inUSAQI = true;
|
||||||
} else if (buttonConfig == 6) {
|
} else if (buttonConfig == 2) {
|
||||||
updateOLED2("Temp. in F", "PM in ug/m3", "Display Bottom");
|
updateOLED2("Temp. in F", "PM in ug/m3", "Long Press Saves");
|
||||||
u8g2.setDisplayRotation(U8G2_R0);
|
u8g2.setDisplayRotation(U8G2_R0);
|
||||||
inF = true;
|
inF = true;
|
||||||
inUSAQI = false;
|
inUSAQI = false;
|
||||||
} else if (buttonConfig == 7) {
|
} else if (buttonConfig == 3) {
|
||||||
updateOLED2("Temp. in F", "PM in US AQI", "Display Bottom");
|
updateOLED2("Temp. in F", "PM in US AQI", "Long Press Saves");
|
||||||
u8g2.setDisplayRotation(U8G2_R0);
|
u8g2.setDisplayRotation(U8G2_R0);
|
||||||
inF = true;
|
inF = true;
|
||||||
inUSAQI = true;
|
inUSAQI = true;
|
||||||
|
Reference in New Issue
Block a user