and I have this code to count the button, but it doesn't work.
if(sbA==1){
count++;}
I know I can put count++ directly to the button code above, but I am writing a program that have different modes and so the buttons have different functions. essentially, I am try to make an universal button state value, so that every mode can use them in different ways. any suggestion?
You must do the increment in the code that tests cButtonA != pButtonA etc.
The whole point is to only increment when the button state changes, not every time
round the loop(). If you set a variable saying "the button changed" then that will continue
to read true in the future, you need to execute your state-change code when the state
changes, not if you've seen it change at some point in the past.
This is the idiom to use, don't change it to something different!
MarkT:
You must do the increment in the code that tests cButtonA != pButtonA etc.
The whole point is to only increment when the button state changes, not every time
round the loop(). If you set a variable saying "the button changed" then that will continue
to read true in the future, you need to execute your state-change code when the state
changes, not if you've seen it change at some point in the past.
This is the idiom to use, don't change it to something different!
you kinda confuse me more. so, I need to write code to detect changes from LOW to HIGH, but not just HIGH?
Yes. You need to do the increment when the button state becomes HIGH, not when it is HIGH otherwise the increment will happen every time through loop() if the button state is HIGH.
you kinda confuse me more. so, I need to write code to detect changes from LOW to HIGH, but not just HIGH?
Yes. You need to do the increment when the button state becomes HIGH, not when it is HIGH otherwise the increment will happen every time through loop() if the button state is HIGH.
thanks...then, I need to write every button code for each function??
UKHeliBob:
If you want the button state to be available to all functions in your program declare it as global. Is that what you mean ?
I think my button is global. I want every function to interpret the button differently, and I don't want to write every button code for every function. Is there a simpler way to do that?