/********************************************************************************
Here's a code sample in C for the ESP32-C2 to implement
a LED chaser that starts from pin 0 to pin 15, and
alternates between turning on only even-numbered pins and only
odd-numbered pins after 20 cycles:
This code uses the Arduino.h library, which provides a lot
of helpful functions for working with the ESP32-C2.
In the setup function, all of the pins in the
pins[] array are configured as outputs.
The loop function implements the LED chaser
behavior as described in your requirement.
created by arvind patil 13 feb2023
*************************************************************************************/
#include <Arduino.h>
const int numPins = 16;
int pins[numPins] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
void setup() {
for (int i = 0; i < numPins; i++) {
pinMode(pins[i], OUTPUT);
}
}
void loop() {
for (int cycle = 0; cycle < 3; cycle++) {
for (int i = 0; i < numPins; i++) {
digitalWrite(pins[i], HIGH);
delay(500);
digitalWrite(pins[i], LOW);
}
}
for (int cycle = 0; cycle < 3; cycle++) {
for (int i = 0; i < numPins; i++) {
if (i % 2 == 0) {
digitalWrite(pins[i], HIGH);
}
}
delay(100);
for (int i = 0; i < numPins; i++) {
if (i % 2 == 0) {
digitalWrite(pins[i], LOW);
}
}
}
for (int cycle = 0; cycle < 3; cycle++) {
for (int i = 0; i < numPins; i++) {
if (i % 2 != 0) {
digitalWrite(pins[i], HIGH);
}
}
delay(100);
for (int i = 0; i < numPins; i++) {
if (i % 2 != 0) {
digitalWrite(pins[i], LOW);
}
}
}
}