@rsaeful better use gw.wait() i.s.o. of delay. during the gw.wait() you are still receiving and sending MyS messages. delay is blocking So the function will look like this void fadeToLevel( int toLevel ) { int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1; while ( currentLevel != toLevel ) { currentLevel += delta; analogWrite( LED_PIN, (int)(currentLevel * 2.55)); gw.wait( FADE_DELAY ); } }