I am working on a sketch that will turn on/off 10 LEDs. i.e., LED1, LED2, etc
Is there a way to use for 'for' command to define the individual LEDs like
for (int i = 0; i <= 10 i++) {
LED_(i);
I'm not sure of the format
I am working on a sketch that will turn on/off 10 LEDs. i.e., LED1, LED2, etc
Is there a way to use for 'for' command to define the individual LEDs like
for (int i = 0; i <= 10 i++) {
LED_(i);
I'm not sure of the format
Try this code:
Connect the LEDs to pins 2 to 11.
" LED_Sequence - Wokwi ESP32, STM32, Arduino Simulator
byte LED[] {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
//---------------------------------------------------------
void setup() {
for (int i = 0; i < 10; i++)
{
pinMode(LED[i], OUTPUT);
}
}
//---------------------------------------------------------
void loop() {
for (int i = 0; i < 10; i++)
{
digitalWrite(LED[i], HIGH);
delay(500);
}
for (int i = 0; i < 10; i++)
{
digitalWrite(LED[i], LOW);
delay(500);
}
for (int i = 0; i < 10; i++)
{
digitalWrite(LED[i], HIGH);
delay(500);
digitalWrite(LED[i], LOW);
}
}
See some tricks in these examples:
What is 'LED_(i)' supposed to do? Is it a function? Is it a new syntax for defining a variable that you just made up?
Any variable defined in a 'for' loop will cease to exist upon exit from that loop.
Thank you both.. looks like I need to read up on byte