The Raspberry Pi cannot do multiple levels of output on its GPIO pins. It is often cited as one of the advantages of Arduino over the RPi (and it is). However, for simple applications, different output levels can be simulated. This is easily demonstrated by making an LED glow on and off:
This effect is achieved by switching the GPIO pin on and off. Not much is needed for that: the code running in the video is only using the standard /sys/class/gpio interface. I used Perl, as I’m comfortable with it. The code can be found on github. It could be done in bash without any extra drivers needed.
The LED I use is a ledborg, a simple and cheap addon that allows for easy and risk free experimentation with GPIO output, but the technique works on any LED wired to the RPi GPIO pins.
Update: as pointed out it is basically pulse-width modulation, although the code doesn’t store the state of the pulse during a phase.
It’s really a cool and useful piece of info. I’m glad that you shared this useful info with us. Please keep us informed like this. Thanks for sharing.
Would it be possible to do random colours and not just the base RGB?
Yes, easy: https://gist.github.com/basbloemsaat/5023239. However, it doesn’t work well because the switching frequency is too low.
Hi, thank you for the sample code, I do see what you mean – it does match my own experimenting yesterday.