Arduino Black Lightning Circle

tarafından
21294
Arduino Black Lightning Circle

We learned in our previous project how to turn the LED on and off with Arduino. Now we can do even more fantastic things by adding the learned information to our software knowledge. (See Led Burning with Arduino)
For this we need to know how to use a for loop. In this project, we’re going to flash the LEDs one by one with 2 buttons. In other words, if we press one button, all the leds will flash indefinitely, if we press the other button, the process is stopped. If you leave the same distance between the LEDs as in the picture above, our project will look nicer. delay (25); you can change the blinking speed of the LEDs at will by changing these codes.

The circuit elements required for the black flash circuit with the for loop in Arduino:

Jumper Cable
breadboard
6x resistor 220R
2xPush Button
6xled

The codes to be written to the Arduino IDE software:



int ledler[6] = {13, 12, 11, 10, 9, 8};
int i, buton1 = 2 , buton2 = 3;
void setup() {
for (i = 0; i < 6; i++)
pinMode(ledler[i], OUTPUT);
pinMode(buton1, INPUT_PULLUP);
pinMode(buton2, INPUT_PULLUP);
}
void loop() {
if (digitalRead(buton1) == LOW) {
for (;;) {
for (i = 0; i < 6; i++) {
digitalWrite(ledler[i], HIGH);
delay(10);
digitalWrite(ledler[i], LOW);
delay(10);
}
for (i = 5; i > 0; i--) {
digitalWrite(ledler[i], HIGH);
delay(10);
digitalWrite(ledler[i], LOW);
delay(10);
}
if (digitalRead(buton2) == LOW) {
break;
}
}
}
}