const int LED_PINS[] = {5,18,19,21};
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);
void loop() {
for ( int i=0; i < NUM_LEDS; i++ ) {
ledcSetup( i /*channel*/, PWM_FREQ, PWM_RESOLUTION );
ledcAttachPin( LED_PINS[i] /*pin*/, i /*channel*/ );
for ( int x=0; x <= DUTY_MAX; x++ ) {
ledcWrite( i, DUTY_MAX-x );
delay(1);
}
}
for ( int i=0; i < NUM_LEDS; i++ ) {
ledcSetup( i /*channel*/, PWM_FREQ, PWM_RESOLUTION );
ledcAttachPin( LED_PINS[i] /*pin*/, i /*channel*/ );
for ( int x=0; x <= DUTY_MAX; x++ ) {
ledcWrite( i, x );
delay(1);
}
ledcDetachPin( LED_PINS[i] );
digitalWrite( LED_PINS[i], OFF );
}
}