Pause Code Until Button Is Pressed. - Arduino Forum
Maybe your like
After browsing through some forums, I found out that the simplest way to do this is with a while loop.
I am running the buttons using the built in pullup resistor so the the button is not pressed when HIGH and pressed when LOW. From what I understand, when the while loop condition is not true(so the button is pressed) it should end the loop and continue with the rest of the code. This isn't happening for me.
int bluebutton = 11; int redbutton = 12; void setup() { // put your setup code here, to run once: pinMode(redbutton, INPUT_PULLUP); pinMode(bluebutton, INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly while(digitalRead(bluebutton == HIGH or redbutton == HIGH)){ lcd.print("Which mode would you"); lcd.print(" like to play?"); delay(4000); lcd.clear(); lcd.print("Press red for singleplayer and blue for 2-player."); delay(3000); } //When the while loops condition is not true, the loop should break and continue with the rest of the code. } UKHeliBob September 3, 2020, 9:43pm 2 digitalRead(bluebutton == HIGH or redbutton == HIGH)Check that digitalRead() carefully. Which pin is it reading ?
keshmaster81 September 3, 2020, 9:45pm 3It's reading digital pins 11 and 12.
UKHeliBob September 3, 2020, 9:47pm 4keshmaster81: It's reading digital pins 11 and 12.
Try again
digitalRead() can only read one pin at a time. Check the syntax
digitalRead(pinNumber); keshmaster81 September 3, 2020, 9:54pm 5I changed it to this and it still doesn't work.
while(digitalRead(redbutton == HIGH)){
}
I also tried this but I get an error saying redbuttoninput was not declared in this scope.
void loop() { redbuttoninput = digitalRead(redbutton); while (redbuttoninput == HIGH)){ } } pmagowan September 3, 2020, 10:47pm 6Put an int in front of redbutton
IoT_hobbyist September 3, 2020, 11:38pm 7See the following FAQ:
- How to use button to start program
- How to use button to start/stop the loop
My example
digitalRead(pinNumber);Your code
while(digitalRead(redbutton == HIGH)){spot the difference
redbuttoninput = digitalRead(redbutton); while (redbuttoninput == HIGH)){Where is redbuttoninput declared ?
Related topics
| Topic | Replies | Views | Activity |
|---|---|---|---|
| While loop not working Programming | 7 | 113 | March 13, 2025 |
| While loop not working Programming | 16 | 2044 | November 20, 2022 |
| Basics Programming | 9 | 893 | May 5, 2021 |
| My code repeat only 1 time if I don't leave the button pressed. How I can fix it? Programming | 6 | 149 | October 22, 2024 |
| Digital input with a pushbutton General Electronics | 23 | 492 | November 28, 2024 |
Tag » Arduino Pause Loop Until Button Pressed
-
Pause Code Untill A Button Is Pressed - Arduino Stack Exchange
-
How To Pause And Continue A Loop With A Button Press?
-
Pause Program Mid Loop Until Switch Is Pressed? - Arduino Forum
-
How To Pause Code Until A Button Is Pressed (Arduino Uno ... - Quora
-
Is There A Way To Pause And Resume Void Loop In Arduino Using Two ...
-
[Arduino] ButtonWait - Wait For Button Press Before Further Execution.
-
Wait For A Button Press, Then Continue : R/arduino - Reddit
-
Arduino Continue With For-loop Only When Button Is Pressed
-
Trying To Pause The Code Until My Button Is Pressed And Will Continue ...
-
How To Use Button To Start/stop The Loop | Arduino FAQs
-
The Basics Of Arduino Programming: Loops, Conditions, Objects ...
-
Pausing A Arduino Shetch, And Wait For A Button Press - EEVblog
-
Tutorial_pushbutton_debounce_i...
-
Detecting Other Conditions - Code: Robotics