[Arduino] ButtonWait - Wait For Button Press Before Further Execution.
Maybe your like
Instantly share code, notes, and snippets.
- Download ZIP
- Star (3) You must be signed in to star a gist
- Fork (0) You must be signed in to fork a gist
- Embed Select an option
- Embed Embed this gist in your website.
- Share Copy sharable link for this gist.
- Clone via HTTPS Clone using the web URL.
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/rahuldottech/839cb13140f24debae8f72343115de4b.js"></script> - Save rahuldottech/839cb13140f24debae8f72343115de4b to your computer and use it in GitHub Desktop.
- Embed Embed this gist in your website.
- Share Copy sharable link for this gist.
- Clone via HTTPS Clone using the web URL.
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/rahuldottech/839cb13140f24debae8f72343115de4b.js"></script> Save rahuldottech/839cb13140f24debae8f72343115de4b to your computer and use it in GitHub Desktop. Download ZIP [Arduino] buttonWait - wait for button press before further execution. Raw 1_details.txt This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters| buttonWait v0.1 by rahuldottech |
| --------------------------------- |
| (pause a script till a button is, y'know, *pressed*...) |
| This code is in the public domain. |
| Proper schematic at https://arduino.stackexchange.com/a/56805/50258 |
| -- |
| Circuit Diagram: |
| [pin]----|--------------[button] |
| | | |
| [10k resistor] | |
| | | |
| [ground] [vcc] |
| -- |
| Usage: |
| buttonWait(<pin_number>); |
| /* the function */ |
| void buttonWait(int buttonPin){ |
| int buttonState = 0; |
| while(1){ |
| buttonState = digitalRead(buttonPin); |
| if (buttonState == HIGH) { |
| return; |
| } |
| } |
| } |
| void loop() { |
| // put your main code here, to run repeatedly: |
| buttonWait(2); // wait for button press on pin 2 |
| // do something |
| // ... |
| } |
| /* the function */ |
| void buttonWait(int buttonPin){ |
| int buttonState = 0; |
| while(1){ |
| buttonState = digitalRead(buttonPin); |
| if (buttonState == HIGH) { |
| return; |
| } |
| } |
| } |
| void setup() { |
| // put your setup code here, to run once: |
| pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output. |
| } |
| void loop() { |
| // put your main code here, to run repeatedly: |
| buttonWait(2); // wait for button press on pin 2 |
| digitalWrite(LED_BUILTIN, HIGH); // turn the LED on |
| delay(1000); //wait for a second |
| buttonWait(2); // wait for another button press on pin 2 |
| digitalWrite(LED_BUILTIN, LOW); // turn the LED off |
| delay(1000); //wait for a second |
| } |
mexteele commented Jun 12, 2021
Hey there. I'm trying to use your function to enter an autocalibration program for a sensor.
I successfully made an LCD print some welcome text once the button was pressed.
buttonWait(8);
some code to initialize the calibration process.
However, when I enter another buttonWait(8) to continue (the user will keep pushing the button to continue the process), the first function executes.
Basically, it's as if I can't run 2 buttonWait functions simultaneously. Here is my code.
`void loop() {
while (digitalRead(buttonPin) == HIGH) {
Serial.println("Esperando"); lcd.setCursor(0, 0); lcd.print("Esperando");
} buttonWait(8); lcd.setCursor(0,0); lcd.print("Calibremos"); lcd.setCursor(0,1); lcd.print("el sensor"); delay(10000);
buttonWait(8); lcd.clear(); lcd.setCursor(0,0); lcd.print("Sumerja"); lcd.setCursor(0,1); lcd.print("en agua"); `
Any insights on why this happens?? Thank you.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mexteele commented Jun 12, 2021
What I'm trying to achieve is a sequential process that advances with each pressing of the same button.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
rahuldottech commented Jul 9, 2021
Hey, I'm so sorry for the delayed response. I took a cursory glance, and your code looks okay to me, I don't know why that would be happening.
Did you manage to figure it out?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mexteele commented Aug 4, 2021
Hey, yes I figured out! Thank you
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
oggysaud245 commented Aug 18, 2022
how did you solve it?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.Tag » Arduino Pause Loop Button
-
Pausing Code With A Button Push - Interfacing - Arduino Forum
-
How To Pause And Continue A Loop With A Button Press?
-
Pause Code Until Button Is Pressed. - Arduino Forum
-
How To Pause A Loop - Project Guidance - Arduino Forum
-
Pause Program Mid Loop Until Switch Is Pressed? - Arduino Forum
-
Pause And Un Pause Using A Push Button - Arduino Forum
-
Is There A Way To Pause And Resume Void Loop In Arduino Using Two ...
-
How To Pause Code Until A Button Is Pressed (Arduino Uno ... - Quora
-
Pause Code Untill A Button Is Pressed - Arduino Stack Exchange
-
How To Use Button To Start/stop The Loop | Arduino FAQs
-
How To Pause The Execution Of The Code Using Arduino IDE With ...
-
Pausing A Loop To Run Another In Arduino - Stack Overflow
-
Pause And Resume Arduino Program Using Arduino - YouTube
-
Trying To Pause The Code Until My Button Is Pressed And Will Continue ...