# First micro controller project. mood lamp

#### DavidLindh

Joined Jan 7, 2010
3
What I want to do is a mood lamp with 2 pots controlling the speed of the fade and the time on each color. The micro controller Im using is a PIC16F690 with 3 leds connected to 3 bits on port c.

Im new to pic programing and fairly new to programming. I have several problems but lets take one at a time.

My first problem is with the fading between colors.

This code have 10 for loops.

The first loop the blue is on for 255 us and the green for 0.
In the next loop blue is on for 225 and green for 25.
At last the blue is on for 0 us and the green for 255.

Rich (BB code):
for(i = 0 ; i < 255 ; i++)
{
PORTC = 0x04;
DelayUs(255);
PORTC = 0x02;
DelayUs(0);
}
for(i = 0 ; i < 255 ; i++)
{
PORTC = 0x04;
DelayUs(225);
PORTC = 0x02;
DelayUs(25);
}
...
for(i = 0 ; i < 255 ; i++)
{
PORTC = 0x04;
DelayUs(0);
PORTC = 0x02;
DelayUs(255);
}
The result is a smooth fade between blue and green.

Blue|--------------------|Green

But instead of having 10 for loops why not create another loop?

Rich (BB code):
for(j = 0 ; j < 250 ; j += 25)
{
for(i = 0 ; i < 255 ; i++)
{
PORTC = 0x04;
DelayUs(250-j);
PORTC = 0x02;
DelayUs(j);
}
}
Now the color is jumping from blue to cyan fade a little bit towards green and then make another jump to fully green.

Blue| |----------| |Green

Why?

Thanks for your help.

Last edited:

#### DavidLindh

Joined Jan 7, 2010
3
I found a couple of semi transparent bowls on IKEA and build a shelf with the leds built in.

Here is a video.

#### Attachments

• 95 KB Views: 7
• 74.9 KB Views: 6
• 97 KB Views: 11
• 78.8 KB Views: 9
• 83.6 KB Views: 10
• 72.8 KB Views: 9