USB LED dimmer

Source: InternetPublisher:zeNNH4 Keywords: USB LED dimmer Updated: 2026/03/27

USB LED Gradient

A USB-LED gradient is a device that controls multiple LEDs via USB. I built it to display my internet connection status, video recorder (VDR) recording status, and low disk space warnings. You can imagine countless application scenarios.

LEDs are controlled using pulse width modulation (PWM). This allows them to not only be turned on or off, but also their brightness to be controlled. The device contains many "waveforms" that can be displayed via LEDs. Thus, an LED can display a sine wave or a triangle wave without interacting with the control host. Each LED can be controlled independently; each can display its own waveform.

USB LED Fader

You can assign three different waveforms to each LED. The first two (0 and 1) are "permanent" waveforms. They are displayed alternately until a different waveform is needed. The third waveform (2) is displayed only once; afterwards, the device will switch back to the alternation of the first two waveforms.

They are displayed alternately until a different waveform is needed. The third waveform (2) is displayed only once, after which the device will switch back to the alternation of the first two waveforms.

A waveform is described by three parameters: the waveform, the duration of a waveform repetition, and the number of repetitions before switching to the next waveform.

This version supports four LEDs. It's easy to change the number from one to eight. I haven't tested more than four, but I can imagine the controller load might be too high for reliable USB communication.

The distribution consists of three parts: the firmware for the ATmega8 microcontroller, a command-line client that can run under Linux, and the circuitry needed to build the device.

This project is based on Objective Development's PowerSwitch sample application. Similarly, it uses Objective Development's pure firmware USB driver for Atmel's AVR microcontroller.

Objective Development's USB driver is a pure firmware implementation of the USB 1.1 standard (low-speed devices) on inexpensive Atmel AVR series single-chip microcomputers, such as the ATtiny2313 and even some small 8-pin devices. It implements the standard, enabling useful applications to be implemented. For features and limitations, see the file "firmware/usbdrv/usbdrv.h".

Build and install

circuit

The circuit contains only a few standard components. No special USB chips are involved.

The installation process is described in the documentation.

usage

Connect the device to the USB port. All LEDs should blink to indicate that the device has been initialized.

Then use the command-line client as follows:

usb-led-fader status

usb-led-fader set    

usb-led-fader clear

USB LED Fader Reset

usb-led-fader show

usb-led-fader test

When using the `set` function, you can define multiple waveforms at once. You only need to provide parameters for all the waveforms. See the example below.

parameter

ledId: The ID of the LED (0-n, depending on the number of LEDs in the circuit).

waveId: The ID of the waveform (0-1: constant waveform, 2: overlay).

waveformId: The ID of the waveform (0-31: brightness, 32-37: mode). For a reference on modes, please use the show function.

periodDuration: The duration for which a waveform repeats, in seconds per 10. A value of 0 can be used to reset the waveform.

repetitionCount: The number of repetitions before switching to the next waveform. A value of 0 will allow the waveform to repeat indefinitely.

Example

Get the status of all LEDs:

usb-led-fader status

This will produce output similar to the following:

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

In this output, the values ​​curvalue, curpos, nextupd, and updtime are for debugging purposes only. Regular users should not need to concern themselves with them. The meanings of the other values ​​should be self-evident.

Set the first LED to a medium brightness:

The above-mentioned equipment

I know I could have welded it much better... ;-)

usb-led-fader set 0 0 15 10 1

Therefore, on LED 0, waveform 0 is set to waveform 15. It will remain for one second and repeat once before switching to the next waveform. Since we have not defined a next waveform, this waveform will remain indefinitely.

Now set a second waveform on the first LED, slightly brighter than the first:

usb-led-fader set 0 1 25 10 1

This is waveform 1 on LED 0. Waveform 25 is defined as a constant brightness level. Once the second waveform is set, it will alternate with the first waveform once per second, because both waveforms have the same duration and the same number of repetitions.

Set the third waveform on the first LED:

usb-led-fader set 0 2 36 20 5

This will set the third waveform (waveform 2) on the first LED. Waveform 36 is a good sine wave, so the LED begins to change gradually. One change cycle takes 2 seconds and is repeated 5 times. Since this is the third waveform, after the repetition, the LED returns to alternating displays of waveform 0 and waveform 1, and this waveform is discarded.

Set multiple waveforms at once:

usb-led-fader set 0 0 15 10 1 0 1 25 10 1 0 2 36 20 5

This will set all the above waveforms at once. Therefore, the first LED will first transition to a sine wave five times, and then begin to alternate between two brightness levels at a rate of one second.

Clear the first LED:

usb-led-fader clear 0

This will clear all three waveforms on the first LED.

Reset device:

USB LED Fader Reset

All LEDs will flash once to indicate that the device has been reset and the LEDs are working properly.

Display the waveform on the screen:

USB-LED-Fender Show 36

This will produce output similar to the following:

wave 36 - length 64

31: *****

30: *********

29: ***********

28: ***************

27: *****************

26: *******************

25: *******************

twenty four: *********************

twenty three: ***********************

twenty two: *************************

twenty one: *************************

20: ***************************

19: *****************************

18: *****************************

17: *******************************

16: *********************************

15: ***********************************

14: ***********************************

13: *************************************

12: ***************************************

11: ***************************************

10: *****************************************

9: *******************************************

8: *********************************************

7: *********************************************

6: ***********************************************

5: *************************************************

4: *****************************************************

3: ***********************************************************

2: ******************************************************************

1: ****************************************************************

================================================================

Please remember that the width of the displayed waveform corresponds to the length of the waveform. If you are displaying a very simple waveform, such as a constant brightness level (0-31), the length is 1. Therefore, only one column will be displayed.

Test equipment:

usb-led-fader test

This function sends a series of random numbers to the device. The device returns data packets, and the client looks up the differences between the sent and received numbers.

shortcoming

As mentioned above, controlling multiple LEDs with PWM is a significant workload for a small microcontroller. The same applies to USB protocol communication. These together operations place a heavy load on the device, making communication with the device not 100% reliable. However, at least in our tests, it was over 99%.

USB LED Fader

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号