User Tools

Site Tools


Disco Lights

You can build easily a disco light using the Raspberry Pi and an RGB LED.

What you need?

  • Raspberry Pi Model B
  • an RGB LED
  • a breadboard
  • 3 resistors (220 Ohm)

Wiring it up

This is the schematics for wiring up the cables. I have connected a black wire from the ground pin to the blue line of the breadboard. This means that all the holes along the blue line will be connected to the ground.

Next, I have placed an RGB LED on the bread board. The LED is in fact build out of 3 LEDS and has 4 legs. One is the common cathode (-) and the other for are each of the LED's anodes(-). The order in the drawing is red, cathode, green, blue.

The cathode of the LED is connected to the blue line of the breadboard, that in turn is connected to board's ground.

The red, green and blue legs of the LED are connected through an 220 Ohm resistor to the pins 0, 1, 2 of the Raspberry Pi.

Installing Linuxeyes

You will need to use Linuxeyes. Please read how to install it on the Raspberry Pi.


Running linuxeyes with the Disco Lights is by typing

make playvumeterrgb 

This uses the wiringPi library to access Raspberry Pi GPIO pins that requires root access. make playvumeter rgb will run linuxeyes as root.

You can change the pins for the RGB LED using the Makefile RGB_LED variable. It signifies the first leg of the RGB LED. Open Makefile and change the playvumeterledrgb rule.

CC                 = g++ -g -Wno-deprecated -w 
LIBRARIES        = -L$(SDK_LIB) -lcurses -lpthread -ldl -lz -lbass -lwiringPi 
INCLUDES        = -I$(SDK_INC) 
xmp: xmp.cpp inc/*.cpp inc/help/*.cpp generators/*.pas generators/help.le generators/ 
        $(CC) $< $(INCLUDES) $(LIBRARIES) -o [email protected] 
        LD_LIBRARY_PATH=. ./xmp 

How it works?

The principle behind the disco light is simple. We take the level of each channel (left and right), average them and light up the RGB LED based on an array. Here is the source code.

We have an array called lights that specifies the colors for each of the sound intensities. The number is a three bit combination for RGB.

Number Bits Colors
0 000
1 001 –B
2 010 -G-
3 011 -GB
4 100 R–
5 101 R-B
6 110 RG-
7 111 RGB
if (vumeter & VUMETER_LED_RGB) 
        // lights based upon the level of the channels 
        // each number is a three bit combination for RGB 
        int lights[] = {0, 4, 6, 6, 2, 2, 3, 5, 5, 1, 1}; 
        // number of lights combination 
        int LEDS = 10; 
        if (getenv ("LED_RGB")) 
                // averaging and scaling the channel levels 
                int l = ((LOWORD(level)+HIWORD(level))/2 * (LEDS+1)) / 32768; // the left level  
                // first leg of the RGB LED 
                int LED_RGB = atoi (getenv ("LED_RGB")); 
                // light up the RGB LED colors 
                // last bit (LSB) is red 
                digitalWrite (LED_RGB, lights[l] & 1); 
                // middle bit is green  
                digitalWrite (LED_RGB+1, (lights[l] & 2)>>1); 
                // first bit (MSB) is blue 
                digitalWrite (LED_RGB+2, lights[l] >> 2); 
1) for more details about settings up Linuxeyes, please read Music Station (Linuxeyes)
projects/disco_lights.txt · Last modified: 2014/01/29 22:25 by alexandru.radovici