Hello,
i've been trying to achieve the following:
if (buttonState == HIGH) {
//run this if statement for 10 seconds.
}
Does anyone know how i would be able to do this?
regards,
Hello,
i've been trying to achieve the following:
if (buttonState == HIGH) {
//run this if statement for 10 seconds.
}
Does anyone know how i would be able to do this?
regards,
First, know the difference between butonState is high and buttonState became high. Now just use millis() to know when the button became high. Now you can also calculate when to stop ![]()
You'll need to check when the buttonState "just went high", not do something "while" it is high. The way you have it, the timing of how long the user presses (or releases) the button will affect any timing code you put within the "if" statement.
if (buttonState == HIGH && previousButtonState == LOW) {
//run this if statement for 10 seconds.
}
Take a look at the "StateChangeDetection" example in the IDE or here. Also, "BlinkWithoutDelay" is a good reference.
Edit: Oops ... septillion is seconds quicker (need to improve my own delays) heh,heh.
septillion:
First, know the difference between butonState is high and buttonState became high. Now just use millis() to know when the button became high. Now you can also calculate when to stop
Seems logical
thanks for your response =)
dlloyd:
You'll need to check when the buttonState "just went high", not do something "while" it is high. The way you have it, the timing of how long the user presses (or releases) the button will affect any timing code you put within the "if" statement.if (buttonState == HIGH && previousButtonState == LOW) {
//run this if statement for 10 seconds.
}
Take a look at the "StateChangeDetection" example in the IDE or [here](https://www.arduino.cc/en/Tutorial/StateChangeDetection?from=Tutorial.ButtonStateChange). Also, "BlinkWithoutDelay" is a good reference. Edit: Oops ... septillion is seconds quicker (need to improve my own delays) heh,heh.
thanks for the answer and the reference included ![]()
normally it takes some time to get a response, now i got 2 responses in the same minute haha
edit: grammar