I want to execute many lines but one line at a time, if (A) turned on then the first line will be executed when (A) turned off nothing happen, if it turns on again the second line will be executed, and so on.
i appreciate your help.
thank you
You create a variable called "state". Then you use if-statements to check what state you are currently in.
int state=0;
void loop() {
if (state==0) {
// do whatever you want to do, then remember to:
state=1;
}
if (state==1) {
// do whatever needs to be done...
state=2;
}
}
You could accomplish the same thing with a switch-case, but it would limit adding complexity to the if-conditions.
if (A) turned on then the first line will be executed
What is A? What does "turned on" mean? First line of what?
if it turns on again the second line will be executed, and so on.
If A is a switch pin going HIGH, then you need to keep track of the previous state of the pin, so you can tell when a transition occurs (the current state is not the same as the previous state). When a transition occurs, you need to determine whether it is to-pressed or to-released, based on the current state.
When a to-pressed transition occurs, increment a counter. Execute some code, or not, based on the current state and the value of the counter.
[quote author=James C4S link=topic=84767.msg634848#msg634848 date=1325003300]
You create a variable called "state". Then you use if-statements to check what state you are currently in.
int state=0;
void loop() {
if (state==0) {
// do whatever you want to do, then remember to:
state=1;
}
if (state==1) {
// do whatever needs to be done...
state=2;
}
}
You could accomplish the same thing with a switch-case, but it would limit adding complexity to the if-conditions.
How can i control more than one led with a push button, first couple press will turn on led 1 and will stay on, second couple press will turn on led 2 and will stay on and so on, in the end all the leds must be on until i reset the arduino.
thank you
How can i control more then one led with push button, first couple press will turn on led 1 and will stay on, second couple press will turn on led 2 and will stay on and so on, in the end all the leds must be on until i reset the arduino.
thank you
Have you tried any of the tutorials and examples?
[quote author=David - + link=topic=84767.msg634892#msg634892 date=1325005925]
How can i control more then one led with push button, first couple press will turn on led 1 and will stay on, second couple press will turn on led 2 and will stay on and so on, in the end all the leds must be on until i reset the arduino.
thank you[/quote]
Sounds like you are trying to learn and do too much at once. Start with how to make a button turn on (and off) a LED. Then how to tell when X-number of presses have occurred (hint, the compiler doesn't know what "a couple" is). From there, you'll start to see a path to do all of the above.