Monthly Archives: October 2016

Flexible LED Fading

I’d like to introduce you to a method of fading RGB LEDs both smoothly and flexibly.

A common method of fading colours on the Arduino is to use simple for loops, such as:


  // fade from blue to violet
  for (r = 0; r  0; b--) { 
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  } 
  // fade from red to yellow
  for (g = 0; g < 255; g++) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 

And so on. And that is all very well if you just want to fade a single LED to a predefined brightness, or a couple of LEDs all to the same brightness. However if you want to get different combinations of colours and fade smoothly between them it all gets a lot more complex. Especially if you don’t know at the time what colour you are fading from.

Continue reading

Advertisements