First micro controller project. mood lamp

Discussion in 'The Projects Forum' started by DavidLindh, Jan 10, 2010.

  1. DavidLindh

    Thread Starter New Member

    Jan 7, 2010
    3
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. [COLOR="Navy"]for(i = [COLOR="DarkRed"]0[/COLOR] ; i < [COLOR="DarkRed"]255[/COLOR] ; i++)
    3. {
    4.     PORTC = [COLOR="DarkRed"]0x04[/COLOR];
    5.     DelayUs([COLOR="DarkRed"]255[/COLOR]);
    6.     PORTC = [COLOR="DarkRed"]0x02[/COLOR];
    7.     DelayUs([COLOR="DarkRed"]0[/COLOR]);
    8. }
    9. for(i = [COLOR="DarkRed"]0[/COLOR] ; i < [COLOR="DarkRed"]255[/COLOR] ; i++)
    10. {
    11.     PORTC = [COLOR="DarkRed"]0x04[/COLOR];
    12.     DelayUs([COLOR="DarkRed"]225[/COLOR]);
    13.     PORTC = [COLOR="DarkRed"]0x02[/COLOR];
    14.     DelayUs([COLOR="DarkRed"]25[/COLOR]);
    15. }
    16. ...
    17. for(i = [COLOR="DarkRed"]0[/COLOR] ; i < [COLOR="DarkRed"]255[/COLOR] ; i++)
    18. {
    19.     PORTC = [COLOR="DarkRed"]0x04[/COLOR];
    20.     DelayUs([COLOR="DarkRed"]0[/COLOR]);
    21.     PORTC = [COLOR="DarkRed"]0x02[/COLOR];
    22.     DelayUs([COLOR="DarkRed"]255[/COLOR]);
    23. }[/COLOR]
    24.  
    The result is a smooth fade between blue and green.

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

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

    Code ( (Unknown Language)):
    1.  
    2. [COLOR="Navy"]for(j = [COLOR="DarkRed"]0[/COLOR] ; j < [COLOR="DarkRed"]250[/COLOR] ; j += [COLOR="DarkRed"]25[/COLOR])
    3. {
    4.     for(i = [COLOR="DarkRed"]0[/COLOR] ; i < [COLOR="DarkRed"]255[/COLOR] ; i++)
    5.     {
    6.         PORTC = [COLOR="DarkRed"]0x04[/COLOR];
    7.         DelayUs([COLOR="DarkRed"]250[/COLOR]-j);
    8.         PORTC = [COLOR="DarkRed"]0x02[/COLOR];
    9.         DelayUs(j);
    10.     }
    11. }[/COLOR]
    12.  
    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: Jan 10, 2010
  2. DavidLindh

    Thread Starter New Member

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

    Here is a video.
     
Loading...