The LEDs are controlled with pulse width modulation (PWM). That way, they are not only on or off, it is possible to control the brightness. Included in the device is a number of 'waveforms' that can be displayed on the LEDs. That way, one LED can display some kind of a sinus- or triangular wave without any interaction with the controlling host.
Every LED can be controlled individually, each one can display it's own waveforms.
You can assign three different waves to every LED: two 'eternal' waves (0 & 1). They are displayed alternating until anything different is required. The third wave (2) is only displayed once, afterwards the device will switch back to alternating between the first two waves.
One wave is described by three parameters: the waveform, the duration for one repetition of the wave and the number of repetitions before switching to the next wave.
This version supports four LEDs, it should be quite easy to change that number between one and eight. I have not tested any number greater than four, but I can imagine that the load on the controller can be too high to reliably communicate via USB.
There are three parts included in the distribution: The firmware for an ATmega8 microcontroller, a commandline-client that can be run under Linux, and the circuits needed to build the device.
This project is based on the PowerSwitch example application by Objective Development. Like that, it uses Objective Development's firmware-only USB driver for Atmel's AVR microcontrollers.
Objective Development's USB driver is a firmware-only implementation of the USB 1.1 standard (low speed device) on cheap single chip microcomputers of Atmel's AVR series, such as the ATtiny2313 or even some of the small 8 pin devices. It implements the standard to the point where useful applications can be implemented. See the file "firmware/usbdrv/usbdrv.h" for features and limitations.
Once you have the GNU toolchain for AVR microcontrollers installed, you can run "make" in the subdirectory "firmware". You may have to edit the Makefile to use your preferred downloader with "make program". The current version is built for avrdude with a parallel connection to an stk200-compatible programmer.
If working with a brand-new controller, you may have to set the fuse-bits to use the external crystal:
avrdude -p atmega8 -P /dev/parport0 -c stk200 -U hfuse:w:0xC9:m -U lfuse:w:0x9F:m
Afterwards, you can compile and flash to the device:
make program
make
This will build the unix executable "usb-led-fader" which can be used to control the device.
Then use the commandline-client as follows:
usb-led-fader status usb-led-fader set <ledId> <waveId> <waveformId> <periodDuration> <repetitionCount> usb-led-fader clear <ledId> usb-led-fader reset usb-led-fader show <waveformId> usb-led-fader test
When using the set-function, it is possible to define several waves at once. You simply have to give the parameters for all waves. See examples below.
usb-led-fader status
LED 0 curid curvalue curpos currep nextupd 0 2 26 0 23 wave waveform length repeat duration updtime 0 38 32 1 20 45 1 0 1 1 0 1 2 0 1 1 0 1 LED 1 curid curvalue curpos currep nextupd 0 14 19 0 19 wave waveform length repeat duration updtime 0 38 32 1 20 45 1 0 1 1 0 1 2 0 1 1 0 1 LED 2 curid curvalue curpos currep nextupd 0 31 16 0 43 wave waveform length repeat duration updtime 0 38 32 1 20 45 1 0 1 1 0 1 2 0 1 1 0 1 LED 3 curid curvalue curpos currep nextupd 0 6 9 0 39 wave waveform length repeat duration updtime 0 38 32 1 20 45 1 0 1 1 0 1 2 0 1 1 0 1
Set the first LED to keep a middle brightness:
usb-led-fader set 0 0 15 10 1
Now set a second wave on the first LED, a little brighter than the one before:
usb-led-fader set 0 1 25 10 1
Set a third wave on the first LED:
usb-led-fader set 0 2 36 20 5
Set multiple waves at once:
usb-led-fader set 0 0 15 10 1 0 1 25 10 1 0 2 36 20 5
Clear the first LED:
usb-led-fader clear 0
Reset the device:
usb-led-fader reset
Show a waveform on the screen:
usb-led-fader show 36
wave 36 - length 64 31: ***** 30: ********* 29: *********** 28: *************** 27: ***************** 26: ******************* 25: ******************* 24: ********************* 23: *********************** 22: ************************* 21: ************************* 20: *************************** 19: ***************************** 18: ***************************** 17: ******************************* 16: ********************************* 15: *********************************** 14: *********************************** 13: ************************************* 12: *************************************** 11: *************************************** 10: ***************************************** 9: ******************************************* 8: ********************************************* 7: ********************************************* 6: *********************************************** 5: ************************************************* 4: ***************************************************** 3: ******************************************************* 2: *********************************************************** 1: **************************************************************** ================================================================
Test the device:
usb-led-fader test
SO BE WARNED: You should not use this device to control the state of your nuclear reactor. If you intend to use it in that way despite of this warning, please let me know... ;-)
And I'd like to give special credits to Thomas Stegemann. He wrote the PWM-stuff, and I guess it would have been nearly to impossible to me to write the rest of the project without his help since C isn't my natural language.
(c) 2006 by Ronald Schaten - http://www.schatenseite.de