AmbiLight

While wandering through the shops, looking at those nice Phillips TV’s with ambilight, I decided that it was time to build one myself (the ambilight that is).

First off I googled a bit in search for exsisting projects. There I stumbled uppon a lot of similar projects.
I figured, the Moodlight protocol was easy enough to implement, while easy extentable with more channels.
The boblight software looked very promissing. After installing it on my Nas/media player (XBMC), which is atom based, all that was left todo was to hookup a microcontroller to a USB->Serial port converter..

Unfortunaly all moodlight like systems where based on the Microchip chip-family (PIC). As i’m more of a Atmelguy (is that an actual word?). Therefore I decided to implement the protocol using Atmels avr branch, the atTiny, which is fast (20Mhz), has an Usart (serial-port) and is cheap.

The source-code:

/*
	-AMBILIGHT-
	-AVR Attiny2313-
	Vincent Gijsen
	13-12-2010

	momo protocol:
		R1,R2,R3,G1,G2,G3,B1,B2,B3
		PREFIX 0XFF;

*/

#define CLOCK 8000000
#define F_CPU CLOCK
#define TIMER0PRESCALER 1
#define BAUD 9600

#define C1R 0x01
#define C1G 0x02
#define C1B 0x04

#define C2R 0x08
#define C2G 0x10
#define C2B 0x20

#define C3R 0x40
#define C3G 0x80

//andere poort! poortD
#define C3B 0x40 

#include
#include
#include
// nemen prescaler van clockio/64

/*
		We nemen software pwm, dus 1 timer, die voor alle outputs loopt.
 */

volatile unsigned char counter;
volatile unsigned char portStateB;
volatile unsigned char portStateD;

volatile unsigned char led1R;
volatile unsigned char led1G;
volatile unsigned char led1B;

volatile unsigned char led2R;
volatile unsigned char led2G;
volatile unsigned char led2B;

volatile unsigned char led3R;
volatile unsigned char led3G;
volatile unsigned char led3B;

volatile unsigned char db1;
volatile unsigned char db2;

volatile unsigned char rxSync;
volatile unsigned char rxPackage;
volatile unsigned char r;
volatile unsigned char dis;

void USART_Init(void);
void USARTWriteChar(char);

int main(void)
{
	db1 = 0xFF;
	db2 = 0xFF;

	rxSync = 0xFF;
	rxPackage = 0x00;
	dis=0;

	USART_Init();

	for (int x= 0;x  0x00)
			led1R--;

		if (led2R > 0x00)
			led2R--;

		if (led3R > 0x00)
			led3R--;

		if (led1G > 0x00)
			led1G--;

		if (led2G > 0x00)
			led2G--;

		if (led3G > 0x00)
			led3G--;

		if (led1B > 0x00)
			led1B--;

		if (led2B > 0x00)
			led2B--;

		if (led3B > 0x00)
			led3B--;
	}

	*/

}

void USART_Init(void)
{
	/* Set baud rate */
	UBRRL = 25;   //19200 Baud with 8mHz clock
	UBRRH = 0;
	/* Enable transmitter */
	UCSRB = (1 << RXEN) | (1<