Color music or music visualization

It all started with one post that really interested me about creating a laser show. It was just before the new year and it was necessary to come up with something for the impending New Year's party. And the laser-driven laser show was what the doctor ordered! Chinese pointers burned one by one, and their brightness was very mediocre. Just somewhere I found an article on how to make a laser pointer from a DVD drive. The new year has long passed, the LPT port burned out, but the ATTiny2313 I ordered and a bunch of other electronic components came along. A lot of time passed for a soldering iron, a lot of redone boards assembled by a rake ... In the end, I decided to order a powerful RGB LED on 3W. Then the laser show was already running on a 30mW green laser using the Winamp visualization plug-in via the COM port. In general, the LED made a huge impression on me, and I decided to add color music to the laser show.

Device


What was given to us: three coolers and a laser for the laser show module; two powerful RGB LEDs at 3W. It is necessary for this to make a control unit so that it has the opportunity to communicate with the computer through the COM port with a special program.

I must say right away that in the end the laser died and the code was not even written for the laser show, so from here on we will talk only about color music. There is also a USB port in the circuit, but it was also not possible to implement it. The ATMega8 microcontroller was selected for the control unit. Programming on it is simple, the Internet is full of articles. The EasyElectronics website helped me a lot , and there I learned how to make simple devices and learned a bit about circuitry.

image



I did not have a large selection of LEDs, in fact there was only one option: ARPL-STAR 3W RGB. ARPL-STAR 3W RG.
It has 6 pins, so each of the three LEDs is controlled separately. In my case, the connection diagram was with a common anode. I must say that the LEDs consume a rather big current - each 350mA at maximum brightness. There are two RGB lamps in total and they are connected in parallel to the same MK terminals, so the current is very small. For switching, the same uln2003 was chosen from the article about the laser show, only two outputs were used for each LED lamp, because each pin holds only 500mA, so a total of 6 pins. I will say right away that the idea was not the best. Although everything is okay in terms of parameters, in reality, if the lamps are lit in white at full power, then uln overheats and turns off. I got an idea for a completely different design, which I will write about below.

In the diagram there is a standard body kit for MK, a Molex connector is integrated for power supply, which provides 12V for laser show coolers and 5V for everything else. It can be connected to a computer, but I used a separate power supply unit with molex type output for convenience. To program MK, the standard Gromov programmer was used . And here is the RS232 <-> UART adapter . In the future, it was planned to do everything via USB, but I used the wrong USB connector on the board, so now I can not find the cord to connect to the computer.

The color of the lamp depends on all three LEDs that are built into it. The color model is RGB. The brightness of each LED depends on the voltage. So to change the brightness of a particular component, PWM is used. Thus, to set the color for the controller, it is enough to transmit three values ​​from 0 to 255, where 255 means the maximum brightness. It is worth noting that the lamps are very hot, so you need to put them on radiators.

MK program was written in C in AVRStudio and it is quite simple: when a byte arrives by UART, it is entered into the queue; in the main loop, the program calls the current command. The command is the index of the procedure in the table to be run. There are only three commands used: simple, clear the color and set the color. In a simple program, it looks to see if there is data in the queue, and if so, the index of the current command changes to what is in the queue. The color set command takes 3 bytes of data, so it hangs in the main loop until there are 3 bytes in the data queue.

PWM is implemented in software. This is because there are only three PWM hardware channels in ATMega8, and I needed six of them: three for laser show coolers and three for lamps.

Here is the main program code:
int main()
{
	#define baudrate 9600L
	#define bauddivider (F_CPU / (16 * baudrate) - 1)
	UBRRL = LO(bauddivider);
	UBRRH = HI(bauddivider);
	UCSRA = 0;
	UCSRB = 1< 0 && g_counter >= 0xff00)
		{
			g_currentColorSetup++;
			if (g_currentColorSetup == MAX_COLOR_PREDEFINES)
				g_currentColorSetup = 0;
			SetColorFromPredefines(g_currentColorSetup);
			ATOMIC_BLOCK(ATOMIC_FORCEON)
			{
				g_counter = 0;
			}
		}
		PCOMMAND pFunc = (PCOMMAND)pgm_read_word(g_commands + g_command);
		if (pFunc())
		{
			g_command = 0;
		}
	}
	return 0;
}
ISR(USART_RXC_vect)
{
	//прием байта
	UartOnRecieve();
}
ISR(TIMER0_OVF_vect)
{
	g_counter++;
	g_pwmValue++;
	//включение лампы по переполнению значения ШИМ
	if (g_pwmValue == 0)
	{
		LAMP_PORT |= LAMP_MASK;
	}
	//как только значение ШИМ достигает определенного значения
	//так определенный порт сразу выключается
	if (g_pwmValue == g_pwm[3]) CBI(LAMP_PORT, LAMP_RED);
	if (g_pwmValue == g_pwm[4]) CBI(LAMP_PORT, LAMP_GREEN);
	if (g_pwmValue == g_pwm[5]) CBI(LAMP_PORT, LAMP_BLUE);
}


Example color change command:
//Номер - 4
//Обновление цвета
bool UpdateColor()
{
	ColorData data;
	if (UartRead((byte*)&data, sizeof(ColorData)))
	{
		D_SEND('l');
		g_shit = 0;
		SetColor(&data);
		return true;
	}
	return false;
}
void SetColor(ColorData *pData)
{
	ATOMIC_BLOCK(ATOMIC_FORCEON)
	{
		g_pwm[3] = pData->red;
		g_pwm[4] = pData->green;
		g_pwm[5] = pData->blue;
	}
}


The printed circuit board is made by the LUT method .



Program




Initially, everything was controlled using the visualization plugin on Winamp. But it was not convenient, because often music was listened to vkontakte. It was decided to write in C #, as The application should be purely front-end. Searching the Internet for information about sound capture, I did not find anything practical, but I remembered that in the sound card you can configure the recorder to output what is being played back. So, using the Bass library, I quickly made an example. It also turned out that C # has a whole class for working with serial ports - everything turned out to be very simple.

Although the color model of the lamps is RGB for obvious reasons, it is not the most suitable for visualizing music, so the program uses the HSV model. Each color component — color, saturation, and brightness — is independently configured. I decided not to be limited only to color music: for each color component, you can choose one of the possible sources: manual input, random value, audio, and copying another component. In manual mode, you can adjust the color, brightness and saturation yourself. Using the random mode, you can make a mood lamp (there are settings for the range, shift frequency and shift speed). The most interesting mode is of course audio.

Everything is based on the frequency spectrum. A frequency range is selected that will affect the value of the color component, a signal level is selected (can be reduced, can be increased), offset, smoothing. You can also use not the signal level, but its change. I usually put this on the brightness of the lamps and get such a stroboscopic effect (a strobe, by the way, can also be realized) - when the signal level increases, the brightness increases, when it decreases, it decreases accordingly. This is where the shift comes in handy, with which you can adjust the initial brightness.

What can be done


Firstly, as I wrote above, if you turn on the lamps at full power, they will turn off pretty quickly due to uln. In addition, if the lamps need to be located at a relatively large distance from the head unit, then thick wires must be used, otherwise there will be big losses. So I got the idea of ​​a completely different design: to make each lamp as a separate module with its own power supply, its own MK and controls. These modules will be connected to the main device through a twisted pair cable, and avr tools allow the MK to communicate with each other. T.O. it will be possible to control the lamps separately.

Secondly, you can blink light bulbs not only to music, but also to video, you can do something like AmbLight, and the current architecture allows you to do this. Any info on video capture? The lamps themselves are very bright, especially two, and sufficiently illuminate a room of 35 squares, so you can take photo viewing to a new level! You look at photos from the sea, and the whole room is filled with a pleasant blue tint - beauty!

Conclusion


Much has been done, much remains to be done, unfortunately not in the near future. Finally - a video. Unfortunately, my camera does not differ in good photosensitivity, therefore on the video it seems that nothing is illuminated at all. In fact, the effects are very strong, and if you look at the lamps themselves, it puts great pressure on the eyes - the most for parties.





UPD: Added the source code of the control program to the archive

Also popular now: