RGB LED Controller

Thread Starter

brmo

Joined Jun 21, 2010
3
I am seeking a circuit that will allow me to use RGB LED's and push different colors out of them via RGB or even hex. If its programmable once, then standalone, that would be the ultimate goal. My main issue is that i would like a button that would scroll through the available colors that i program in, then when hitting the end, scroll right back through. Also, a save into non-volatile memory would be great so that the color i last selected will be chosen the next time the circuit becomes active.

Any ideas or links on how to accomplish this task?

Thanks!
 

Wendy

Joined Mar 24, 2008
23,052
Can't help you with the code, but you'll need 3 different PWM signals, each will control the intensity of the particular color your interested in. I have some Voltage to PWM designs if you're interested.
 

MMcLaren

Joined Feb 14, 2010
858
I threw together this SIRC RGB Accent Light Controller last week to see if I could generate 25-usec soft PWM "steps" while decoding Sony SIRC remote codes. The program works well but I still need to add 64 step gamma correction to smooth out color changes.

You could probably use something like this circuit and program a few additional remote codes to save color settings and then "run" the saved settings in animation.

Have you searched for existing projects or products which may already do everything you want?

Regards, Mike
 

Attachments

Last edited:
Here you go for a PIC10F200.

Rich (BB code):
;Soft PWM for RGB led, common anode
#chip 10f200, 4 
#config INTRC_OSC, MCLRE_OFF    

#define Red GPIO.0
#define Green GPIO.1
#define Blue GPIO.2
#define Button GPIO.3
dir GPIO b'001000'
GPIO = b'111'

red_duty = 0
green_duty = 0
blue_duty = 0
color = 0

Main:
If button = 0 Then
    ButtonCount = 0
    Do While Button = 0
        wait 1 10ms
        ButtonCount += 1
    Loop
end if
If ButtonCount > 3 then
    Call ChangeColor
    ButtonCount = 0
end if
Call SoftPWM
goto Main

sub ChangeColor
If color = 6 Then color = 0
    Select Case color
        Case 0    ;Red
            Red_Duty = 255
            Green_Duty = 0
            Blue_Duty = 0
        Case 1    ;Green
            Red_Duty = 0
            Green_Duty = 255
            Blue_Duty = 0
        Case 2    ;Yellow
            Red_Duty = 255
            Green_Duty = 80
            Blue_Duty = 0
        Case 3    ;Blue
            Red_Duty = 0
            Green_Duty = 0
            Blue_Duty = 255
        Case 4    ;Purple
            Red_Duty = 255
            Green_Duty = 0
            Blue_Duty = 55
        Case 5    ;White
            Red_Duty = 255
            Green_Duty = 255
            Blue_Duty = 255
    end Select
color += 1
end sub

sub SoftPWM
    For duty = 1 to 255
        If red_duty > duty then
            red = 0
        else
            red = 1
        end if
        If green_duty > duty then
            green = 0
        else
            green = 1
        end if        
        If blue_duty > duty then
            blue = 0
        else
            blue = 1
        end if
    Next
end sub
 
Last edited:

Wendy

Joined Mar 24, 2008
23,052
I have an article in my blog,

LEDs, 555s, Flashers, and Light Chasers

I have a second copy in the forum I use to rewrite and check changes. The title is the same.

LEDs, 555s, Flashers, and Light Chasers

I've been working on a schematic using a DC voltage to PWM circuit to do this. At the moment it looks like this.



I have another schematic in the works that will be a bit closer to what you want.

Here is the base schematic for the concept.

 

Attachments

John P

Joined Oct 14, 2008
1,986
If you want memory, then a processor is definitely the way to go. Even if you just wanted some kind of random operation of the 3 colors, I'd still do it with a processor. (It would actually be pseudo-random, but you can have it follow a sequence that's so long that most likely nobody would notice.)
 
nickelflipper,

can you note which language that program is in, please?
Sorry, .....it's GCBasic. Mostly holding up the code as a template for a state machine (i.e. button press menu), with a soft pwm for the rgb led.

Down to just two spare variables with the supplied "high level" code on the PIC10F200.
 

MMcLaren

Joined Feb 14, 2010
858
Sorry, .....it's GCBasic. Mostly holding up the code as a template for a state machine (i.e. button press menu), with a soft pwm for the rgb led.

Down to just two spare variables with the supplied "high level" code on the PIC10F200.
That's still pretty darn impressive when you consider that the 10F200 only has 255 words of program memory and 16 bytes of RAM.

The software for that SIRC RGB controller uses 155 words of memory and 12 bytes of RAM so I think it might fit on a 10F200 after I add the gamma correction code.

Regards, Mike
 
That's still pretty darn impressive when you consider that the 10F200 only has 255 words of program memory and 16 bytes of RAM.

The software for that SIRC RGB controller uses 155 words of memory and 12 bytes of RAM so I think it might fit on a 10F200 after I add the gamma correction code.

Regards, Mike
Good luck with your port. These brain dead Pics make you think.

Trying to get the button to work as a color and a blink rate changer, not quite there yet. Will post if I can get the pwm timing part down. Down to zero variables and 9 program words at the moment.
 
Re: Braindead PICs was referring to the 10F's

Here's code for selectable rgb color and blink rate. Still room for more, a random function? .... might be stretching it. Cutting loose of the delay library's saved a bunch of variables/ram.
Rich (BB code):
;GCBasic program for RGB led (common anode)
;with selectable color and blink rate
;Kent Schafer 6/23/2010

#chip 10f200, 4 
#config INTRC_OSC, MCLRE_OFF    

#define Red GPIO.0
#define Green GPIO.1
#define Blue GPIO.2
#define Button GPIO.3
dir GPIO b'001000'
GPIO = b'111'

red_duty = 255
green_duty = 0
blue_duty = 0
color = 0
BlinkRate = 0
BlinkPeriod = 0

clrwdt    ;must do prior to changing prescale, per data sheet
movlw    B'11000110'    ;asign prescaler to TMR0, prescale 1:128
asm    option

Main:
NoBlink:
;LED On time
For Blinky1 = 1 to BlinkPeriod
    Call SoftPWM
    If button = 0 Then
        ButtonCount = 0
        Do While Button = 0
            clrf TMR0    ;use TMR0 as a delay mechanism
            Delay1:
            btfss TMR0,7
            goto Delay1
            ButtonCount += 1
        Loop
        If ButtonCount > 3 Then
            ;it's a long press to change BlinkRate
            If ButtonCount > 25 then
                BlinkRate += 1
                Call Blink
                ButtonCount = 0
            ;it's a short press to change the color
            Else
                color += 1
                Call ChangeColor
                ButtonCount = 0
            end if
        end if
    end if
If BlinkRate = 0 Then goto NoBlink
Next

;LED Off Time
GPIO = b'111'    ;turn off Common Anode rgb led
For Blinky2 = 1 to BlinkPeriod
    clrf TMR0
    Delay3:
    btfss TMR0,7
    goto Delay3
    If button = 0 Then
        ButtonCount = 0
        Do While Button = 0
            clrf TMR0
            Delay2:
            btfss TMR0,7
            goto Delay2
            ButtonCount += 1
        Loop
        If ButtonCount > 3 Then
            If ButtonCount > 25 then
                BlinkRate += 1
                Call Blink
                ButtonCount = 0
            Else
                color += 1
                Call ChangeColor
                ButtonCount = 0
            end if
        end if
    end if
Next
goto Main

;***********************************
sub Blink
If BlinkRate = 5 Then BlinkRate = 0
Select Case BlinkRate
    Case 0
        BlinkPeriod = 0
    Case 1
        BlinkPeriod = 5
    Case 2
        BlinkPeriod = 10
    Case 3
        BlinkPeriod = 20
    Case 4
        BlinkPeriod = 60
end Select
end sub

sub ChangeColor
If color = 6 Then color = 0
    Select Case color
        Case 0    ;Red
            Red_Duty = 255
            Green_Duty = 0
            Blue_Duty = 0
        Case 1    ;Green
            Red_Duty = 0
            Green_Duty = 255
            Blue_Duty = 0
        Case 2    ;Yellow
            Red_Duty = 255
            Green_Duty = 80
            Blue_Duty = 0
        Case 3    ;Blue
            Red_Duty = 0
            Green_Duty = 0
            Blue_Duty = 255
        Case 4    ;Purple
            Red_Duty = 255
            Green_Duty = 0
            Blue_Duty = 55
        Case 5    ;White
            Red_Duty = 255
            Green_Duty = 255
            Blue_Duty = 255
    end Select
end sub

sub SoftPWM
    For duty = 1 to 255
        If red_duty > duty then
            red = 0
        else
            red = 1
        end if
        If green_duty > duty then
            green = 0
        else
            green = 1
        end if        
        If blue_duty > duty then
            blue = 0
        else
            blue = 1
        end if
    Next
end sub
 

Thread Starter

brmo

Joined Jun 21, 2010
3
nickelflipper,

you are amazing. The blink feature is a great touch that i never thought about. Not that its needed, but what would need to change if the LED's had a common cathode instead? I just have 10 or so common cathode's lying around.

Thanks to all of you, this community has been great and i hope to return the favor.
 
nickelflipper,

you are amazing. The blink feature is a great touch that i never thought about. Not that its needed, but what would need to change if the LED's had a common cathode instead? I just have 10 or so common cathode's lying around.

Thanks to all of you, this community has been great and i hope to return the favor.
This has been a great project for the PIC10F, thanks for the motivation.

One thing to consider for the blink feature, is to turn off the GPIO/leds and put the PIC to sleep, to save on batteries.

For common cathode operation, just invert the sense of the GPIO, which would be red, green, blue in the SoftPWM sub. Using a pre-compiler conditional like #ifdef ComCathode would make for a proper library.

A pseudo random function fits easily. With a ramp function, it might work just like those solar pond lights.
 
Top