Hi Arduino Elders!
I'm doing a For Cycle for a project my cousin have. So basically the idea is kind of simple: I have a For Cycle that makes a Led Blink, after 9 blinks, the next led blinks and so on, after the 4th led has blinked 9 times, all leds blink 9 times and the code restart. The code works as it is, but I'm trying to a button to the code that will make the cycle change. (Sorry for my bad English, I'm not native xD). In other words, what I'm trying to do is: The code starts and the first led starts blinking, if I press the button, the first led turns off and the next one starts blinking, so on until every led start blinking and if a press the button, the cycle restarts.
I attach the code for the For Cycle, if you see any problems with it, your recommendations will be more than appreciated (Only try to keep the code as simple as possible as I'm still learning to code well and it's my first time coding after almost a year of not touching Arduino).
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int boton = 7;
int estado = 0;
int inter = 8;
int i;
int dt = 250;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(boton, INPUT);
}
void loop() {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
for (i = 0; i <= inter; i = i + 1) {
digitalWrite(led1, HIGH);
delay(dt);
digitalWrite(led1, LOW);
delay(dt);
}
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
for (i = 0; i <= inter; i = i + 1) {
digitalWrite(led2, HIGH);
delay(dt);
digitalWrite(led2, LOW);
delay(dt);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
for (i = 0; i <= inter; i = i + 1) {
digitalWrite(led3, HIGH);
delay(dt);
digitalWrite(led3, LOW);
delay(dt);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
for (i = 0; i <= inter; i = i + 1) {
digitalWrite(led4, HIGH);
delay(dt);
digitalWrite(led4, LOW);
delay(dt);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
for (i = 0; i <= inter; i = i + 1) {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
delay(dt);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(dt);
}
}