Timeline for Input state is stuck HIGH when function called using input also uses same input to call another function
Current License: CC BY-SA 4.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 11, 2020 at 18:45 | vote | accept | Snyper | ||
Nov 11, 2020 at 18:45 | answer | added | Snyper | timeline score: 2 | |
Nov 9, 2020 at 17:36 | comment | added | Juraj♦ | reading a button is not so simple as it seams. and for multiple buttons and long press detection etc, the code in sketch gets complicated. I use a library. Bounce2 maintained by Thomas O Fredericks | |
Nov 9, 2020 at 16:34 | comment | added | chrisl | This answer might also help you. There are sure many more questions about reading buttons on this site. You can just search for them. | |
Nov 9, 2020 at 16:31 | comment | added | chrisl | You want to count each button press once. So you don't want to look for the button pin being HIGH (as it will stay high for quite some time, like tens of milliseconds, ages for a microcontroller), you want to look for the transition from LOW to HIGH. Also you need to consider the button bounce, thus you need debouncing (you can google that). I suggest you have a look at the Bounce2 library, which will help a lot with reading mechanical buttons. Try the examples to understand, how the library is used | |
Nov 9, 2020 at 16:30 | comment | added | Snyper | Do you suggest using the state of the button to assign a value to a variable, and then using that variable to call the respective function? | |
Nov 9, 2020 at 16:27 | comment | added | Gerben | You have to wait for the button to be released. Currently you wait for a button to be pressed in question1, which is fine. Once a button1 is pressed you go to question2, but since the button is still pressed it immediately goes on to question 4. | |
Nov 9, 2020 at 15:55 | comment | added | Snyper |
If it's pressed twice nothing should happen unless the textX() function has ran, at which time it's time for user input again and the button press call the next function
|
|
Nov 9, 2020 at 15:48 | comment | added | jsotola | what is the sequence of events when you press a button twice? | |
Nov 9, 2020 at 15:45 | comment | added | Snyper | @jsotola Yeah that's kind of what I'm trying to figure out | |
Nov 9, 2020 at 15:44 | comment | added | jsotola | think about this .... how do you detect two presses of one button? | |
Nov 9, 2020 at 15:34 | comment | added | Snyper |
Yeah the behavior is still the same. Since the state of the button is the condition of my if statement, perhaps that's what is holding this up?
|
|
Nov 9, 2020 at 15:27 | history | edited | Snyper | CC BY-SA 4.0 |
Tried comment suggestion
|
Nov 9, 2020 at 15:24 | comment | added | Snyper | I was reading the button state at the beginning of each function and that wasn't seeming to do anything. Let me retry that though, thank you | |
Nov 9, 2020 at 15:23 | comment | added | StarCat |
You're reading the (physical) button states in one location, inside loop() with button1State = digitalRead(9); ... . Once you call question1() from loop() , the values of buttonState1 and buttonState2 are fixed and will not change until your code returns to loop() to re-read the physical button state into buttonState1 and buttonState2 .
|
|
Nov 9, 2020 at 15:12 | review | First posts | |||
Nov 9, 2020 at 18:05 | |||||
Nov 9, 2020 at 15:08 | history | asked | Snyper | CC BY-SA 4.0 |