Note: ESP8266 defaults to 10bit pwm.
const int led_pins[] = {D0, D4}; int current_brt = 0; const int i_step = 4; int dir = i_step; unsigned long timestamp; const unsigned long time_interval = 10; void setup() { for ( int i = 0; i < sizeof(led_pins); i++ ) { pinMode( led_pins[i], OUTPUT ); } timestamp = millis(); } void loop() { unsigned long frame_ts = millis(); if ( frame_ts - timestamp >= time_interval ) { timestamp = frame_ts; for ( int i = 0; i < sizeof(led_pins); i++ ) { analogWrite(led_pins[i], i % 2?current_brt:1023 - current_brt); } current_brt += dir; if( current_brt >= 1023 ){ current_brt = 1023; dir = -i_step; } if( current_brt <= 0 ){ current_brt = 0; dir = i_step; } } }