#include <Arduino.h>
int pins[] {23,22,21,19};
const int NUMBER_OF_PINS = sizeof(pins)/sizeof(pins[0]);
const int NUMBER_OF_LEDS = NUMBER_OF_PINS * (NUMBER_OF_PINS-1);
byte pairs[NUMBER_OF_LEDS/2][2] = {{0,1}, {1,2}, {0,2}, {2,3}, {1,3}, {0,3} };
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while(!Serial);
Serial.println("Hello, ESP32!");
Serial.println(String(NUMBER_OF_PINS));
Serial.println(String(NUMBER_OF_LEDS));
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < NUMBER_OF_LEDS;i++){
lightLed(i);
delay(300);
}
}
void lightLed(int led){
int indexA = pairs[led/2][0];
int indexB = pairs[led/2][1];
int pinA = pins[indexA];
int pinB = pins[indexB];
for (int i = 0; i < NUMBER_OF_PINS;i++){
if (pins[i] != pinA && pins[i] != pinB){
pinMode(pins[i], INPUT);
digitalWrite(pins[i], LOW);
}
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
}
if (led % 2 == 0){
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
}
else
{
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
}
}