Yawn! Another RGB LED Fader with 08M

PaulRB

Senior Member
Here's my take on the old favourite project... feel free to suggest improvements.

I made the circuit to go inside a stained glass box that my wife built in evening class. The box was very beautifully built (especially for a beginner) with red, blue, green, yellow and clear glass panels and was originally designed to hold a candle. The RGB LED fader really brings out the colours in the glass and looks spectacular in a dark room.

I included an LDR to switch the circuit on and off automatically, and used the PWMOUT command to slowly increase and decrease one colour, while simultaneously varying one of the other two colours with the PWM command. The third colour is always either fully on or off while the second colour is fading in or out, then they swap over. This means you get a good range of colours, but not every possible variation. However, the fading is smooth with only very slight flickering at certain points in the cycle, which can't be seen at a distance.

I spend quite a lot of time getting the series resistors just right to give maximum brightness, bearing in mind the 20mA maximum that the 08M's outputs can sink.

I was also quite proud of the tiny size of circuit board I managed to cram the circuit on to!

IMAG0431.jpgIMAG0432.jpg

Code:
; RGB LED Fader
; P.Beard 8/9/2011

#picaxe 08m2

symbol	REDLED = 2
symbol	GRNLED = 1
symbol	BLULED = 4

symbol	LDR = pin3
symbol	SPEED = 10
symbol	REDLEVEL = w3
symbol	REDDIR = b2


main:

	setfreq m8

	do

		; LEDS off to save power
		high REDLED
		high GRNLED
		high BLULED

		; Wait for dark
		do while LDR = 1
			nap 7
		loop
		
		; begin colour fading
		REDLEVEL = 800
		REDDIR = 0
		pwmout REDLED, 200, REDLEVEL
				
		do while LDR = 0 or REDLEVEL > 0

			call cycle
	
		loop
		
		pwmout REDLED, off
	
	loop
	
cycle:

	b0 = GRNLED : call fadeup 
	b0 = BLULED : call fadeup 
	b0 = GRNLED : call fadedown
	b0 = BLULED : call fadedown
	return

fadedown:
	for b1 = 0 to 255
		pwm b0, b1, SPEED
	next
	high b0
	Call fadered
	return
	
fadeup:
	for b1 = 255 to 0 step -1
		pwm b0, b1, SPEED
	next
	low b0
	Call fadered
	return

fadered:
	if REDDIR = 1 Then
		if REDLEVEL = 800 then
			REDDIR = 0
		else
			REDLEVEL = REDLEVEL + 25
		endif
	else
		if REDLEVEL = 0 then
			REDDIR = 1
		else
			REDLEVEL = REDLEVEL - 25
		endif
	endif
	pwmduty REDLED, REDLEVEL
	return
	
end
 

fishscale77

New Member
neat!

Hey man thanks for posting your code, I am a total noob and I would like to do one of these for my first project.
The stained glass looks great. very neat!

thanks again for posting :cool:
 
Top