Go Down

Topic: Making a button switch codes? (Read 1 time) previous topic - next topic

Agent_47

I was wondering if there is a way to make a button switch from one code to the other.  I'm trying to make a lamp that switches from a potentiometer controlling an RGB LED to a rainbow mode that repeats itself when I press the button.  Any Ideas that may get me jump started on doing this would be great.

PaulS

Quote
I was wondering if there is a way to make a button switch from one code to the other.

Sure. You know how to connect the switch, right? You know how to read when the switch is pressed, right?

Create a variable to count the number of presses. When the number is even, do one thing. When it is odd, do the other thing.

Agent_47


Create a variable to count the number of presses. When the number is even, do one thing. When it is odd, do the other thing.
[/quote]

How do I do that?

Jack Christensen

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

AWOL

Quote
When the number is even, do one thing. When it is odd, do the other thing


Code: [Select]
if (myVariable & 1){
 // do the odd thing
} else {
 //do the even thing
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up