Skip to content

Commit

Permalink
Comment and format button code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sitinut Waisara committed Mar 26, 2020
1 parent 0d8a9cf commit bc0ad14
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Node main module/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ void asyncBlink(unsigned long ms = 0)

void checkButton(){
static unsigned long pushedDownTime = NULL;
if (pushedDownTime == NULL && digitalRead(BUTTON_PIN) == LOW){ //Button pressed
if (pushedDownTime == NULL && digitalRead(BUTTON_PIN) == LOW){ // Button being pressed
pushedDownTime = millis();


}else if (pushedDownTime != NULL && digitalRead(BUTTON_PIN) == HIGH ){ //Button released
}else if (pushedDownTime != NULL && digitalRead(BUTTON_PIN) == LOW){ // Pressing the button, change the LED light according to the pressing time.
unsigned int pressingDuration = millis() - pushedDownTime;
if (pressingDuration > REBOOT_BUTTON_HOLD_DURATION && pressingDuration < FACTORY_RESET_BUTTON_HOLD_DURATION){
asyncBlink(FACTORY_RESET_BUTTON_HOLD_DURATION - pressingDuration);
}
}
else if (pushedDownTime != NULL && digitalRead(BUTTON_PIN) == HIGH ){ // Button released, check the pressed duration and peform action
unsigned int pressingDuration = millis() - pushedDownTime;

if (pressingDuration > FACTORY_RESET_BUTTON_HOLD_DURATION){
Expand All @@ -149,13 +154,7 @@ void checkButton(){
pushedDownTime = NULL;
}

// indicate the led to let user know when to release button
if (pushedDownTime != NULL && digitalRead(BUTTON_PIN) == LOW){
unsigned int pressingDuration = millis() - pushedDownTime;
if (pressingDuration > REBOOT_BUTTON_HOLD_DURATION && pressingDuration < FACTORY_RESET_BUTTON_HOLD_DURATION){
asyncBlink(FACTORY_RESET_BUTTON_HOLD_DURATION - pressingDuration);
}
}

}


Expand Down

0 comments on commit bc0ad14

Please sign in to comment.