Ok, I want to use a pushbutton as a type of “Mode” selector, and all of the Digital Pins are taken, so it will be connected to an analog one with a pull up or pull down resistor…
How do i make it select something different when it is pushed? like, cycle through 13 different things and then go back to number 1? I am unsure how to code this, but i believe it may consist of either a seperate loop to watch for button pushes and when it detects one, +1 to an integer variable, and then use if or possibly while statements to say…
My thoughts…(I think this would do it…)
int Button = 0;
int ButtonVal = 0;
void setup(){
ButtonVal = 0; //reset counter
}
void loop(){
ButtonVal = analogRead(Button);
//--------
Somehow convert (Button) to a on/off value, then store it’s count in (ButtonVal)
//--------
while (ButtonVal = 0){
Blah blah blah;}
while (ButtonVal = 1){
Blah blah blah;}
…
all the way to 13, and so on…
…
"Ok, if the value of (Variable) is 3, then do this…
If the value of (variable) is 10, then do this…
and then when it gets to say…13 or whatever…it will cycle back to 0.
and also will the button need to be debounced? and if the button is held on, it should just increase by 1, and not keep looping and +1 every loop.
can someone help me put these thoughts into code?
thanks a lot!