const int LED_PINS[] = {21, 19, 18, 5, 4, 2, 15, 22};
const int NUM_LEDS = sizeof(LED_PINS) / sizeof(int);
#define OFF (HIGH) // active-low LED
void setup() {
for ( int i = 0; i < NUM_LEDS; i++ ) {
// set the direction of the i-th LED pin
pinMode( LED_PINS[i], OUTPUT );
digitalWrite( LED_PINS[i], OFF );
}
}
const int PWM_RESOLUTION = 8;
const int PWM_FREQ = 1000;
const int DUTY_MAX = (1 << PWM_RESOLUTION);
const float DUTY_CYCLES[] = {0.1,0.25,0.5,1};
void loop() {
for ( int i=0; i < NUM_LEDS; i++) {
for ( int j=0; j < 4; j++) {
ledcSetup( j, PWM_FREQ, PWM_RESOLUTION );
ledcAttachPin( LED_PINS[(i+j)%NUM_LEDS], j );
ledcWrite( j, (1 - DUTY_CYCLES[j])*DUTY_MAX );
}
delay(100);
for ( int j=0; j < 4; j++) {
ledcDetachPin( LED_PINS[(i+j)%NUM_LEDS] );
digitalWrite( LED_PINS[(i+j)%NUM_LEDS], OFF );
}
}
}