Skip to main content
corrected missing closing bracket
Source Link
towe
  • 875
  • 4
  • 15

Your flowchart seems to be in conflict with the code. button1 and button2 are self-explainatory, but what is the selectButton?

Here's some code which may accomplish what you're trying to do:

uint8_t bool_waitforbutton2 = 0;
uint32_t num_timeatbutton1 = 0;
void loop() {
  //your other looping code here
  if(digitalRead(button1) == LOW) {
    num_timeatbutton1 = millis();
    bool_waitforbutton2 = 1;
  }
  if(bool_waitforbutton2 == 1 && digitalRead(button2) == LOW){
    bool_waitforbutton2 = 0;
    //Your code here
  }
  if (millis() > (num_timeatbutton1 + 3000)) {
    bool_waitforbutton2 = 0;
  }
}

This would give you 3000 ms to press button2 after you've let go of button1 to execute your code, otherwise the "readyness-flag" bool_waitforbutton2 is reset.

Your flowchart seems to be in conflict with the code. button1 and button2 are self-explainatory, but what is the selectButton?

Here's some code which may accomplish what you're trying to do:

uint8_t bool_waitforbutton2 = 0;
uint32_t num_timeatbutton1 = 0;
void loop() {
  //your other looping code here
  if(digitalRead(button1) == LOW) {
    num_timeatbutton1 = millis();
    bool_waitforbutton2 = 1;
  }
  if(bool_waitforbutton2 == 1 && digitalRead(button2) == LOW){
    bool_waitforbutton2 = 0;
    //Your code here
  }
  if (millis() > (num_timeatbutton1 + 3000) {
    bool_waitforbutton2 = 0;
  }
}

This would give you 3000 ms to press button2 after you've let go of button1 to execute your code, otherwise the "readyness-flag" bool_waitforbutton2 is reset.

Your flowchart seems to be in conflict with the code. button1 and button2 are self-explainatory, but what is the selectButton?

Here's some code which may accomplish what you're trying to do:

uint8_t bool_waitforbutton2 = 0;
uint32_t num_timeatbutton1 = 0;
void loop() {
  //your other looping code here
  if(digitalRead(button1) == LOW) {
    num_timeatbutton1 = millis();
    bool_waitforbutton2 = 1;
  }
  if(bool_waitforbutton2 == 1 && digitalRead(button2) == LOW){
    bool_waitforbutton2 = 0;
    //Your code here
  }
  if (millis() > (num_timeatbutton1 + 3000)) {
    bool_waitforbutton2 = 0;
  }
}

This would give you 3000 ms to press button2 after you've let go of button1 to execute your code, otherwise the "readyness-flag" bool_waitforbutton2 is reset.

Source Link
towe
  • 875
  • 4
  • 15

Your flowchart seems to be in conflict with the code. button1 and button2 are self-explainatory, but what is the selectButton?

Here's some code which may accomplish what you're trying to do:

uint8_t bool_waitforbutton2 = 0;
uint32_t num_timeatbutton1 = 0;
void loop() {
  //your other looping code here
  if(digitalRead(button1) == LOW) {
    num_timeatbutton1 = millis();
    bool_waitforbutton2 = 1;
  }
  if(bool_waitforbutton2 == 1 && digitalRead(button2) == LOW){
    bool_waitforbutton2 = 0;
    //Your code here
  }
  if (millis() > (num_timeatbutton1 + 3000) {
    bool_waitforbutton2 = 0;
  }
}

This would give you 3000 ms to press button2 after you've let go of button1 to execute your code, otherwise the "readyness-flag" bool_waitforbutton2 is reset.