LED fader

russbow

Senior Member
I want to fade a string of christmas leds and found this in a forum search

http://www.picaxeforum.co.uk/showthread.php?t=12471&highlight=rgb+fader&page=2

As the lights take 100mA or so, the sample circuit isn't meaty enough. So I hooked up an L293 driver chip, the 08m outputs taken to the driver inputs and the LED strings connected between the driver outputs and 0 volts. The pwm pin2 of the 08m is connected to both the enable pins of the L293.

Using this code, I was pleased with the initial results.

Code:
'RGB LED Display
'PICAXE-08M

let dirs = %00010111	'set all used pins to outputs
main:



let pins = %00010000	'4
gosub fade

let pins = %00000001	'0
gosub fade

let pins = %00000010	'1
gosub fade

let pins = %00010001	'0,4
gosub fade

let pins = %00010010	'1,4
gosub fade

let pins = %00000011	'0,1
gosub fade

let pins = %00010011	'0,1,4
gosub fade

goto main

fade:	
	for w1 = 0 to 300
	pwmout 2,99,w1
	pause 20	'increasing brightness
	next w1
	pause 1000
	

for w1 = 300 to 0 step -1
	pwmout 2,99,w1
	pause 10	'decreasing brightness
	next w1

	
	pwmout 2,99,0
	pause 1000
return
I then thought that a bit of flashing might be nice so I extracted part of the above code and added a flsh routine.

Code:
'RGB LED Display
'PICAXE-08M

let dirs = %00010111	'set all used pins to outputs
main:


let pins = %00010011	'4
gosub fade

gosub flash
goto main



fade:	
	for w1 = 0 to 300
	pwmout 2,99,w1
	pause 20	'increasing brightness
	next w1
	pause 1000
	

for w1 = 300 to 0 step -1
	pwmout 2,99,w1
	pause 10	'decreasing brightness
	next w1

	pause 1000

return


flash:

for b6=0 to 5
toggle 2
pause 500
next b6

return

Doesn't work !!

If I just rem out the gosub fade, the LEDs flash. If I just rem out the gosub flash, the fade works.

If I leave them both in, the LEDs fade O.K. and then there is just a pause, with all LEDs off during the flash time.

Looks O.K. in the simulator.

Any ideas please.

Russ
 

russbow

Senior Member
Haku, thanks for that, spot on !

Would never have thought of that. Of course, have now looked in Man 2 and found it, but wolud not have given it a lot of significance if I'd spotted it before.

Why wouldn't let pins = %00010011 give me the same result?
 

hippy

Ex-Staff (retired)
Why wouldn't let pins = %00010011 give me the same result?

"Let pins=" simply requests the output pins to be set to a specific value and doesn't affect anything else within the chip, in this case doesn't disable the PWMOUT which overrides the pin 2 output once it's been enabled.

It's done this way so you can use PWMOUT and "Let pins=", or using the later would always disable PWM, forcing output to be low or high depending on bit 2 of the written value.
 

russbow

Senior Member
Thank you all for your inputs. I now understand the process.

Of course it raises further questions about pwm, pwmout, hpwm but I think that's for a separate thread later after a good forum trawl.

For now, all done and dusted. Thanks.

73s Russ
 

russbow

Senior Member
Yes of course Boriz. The original used trannies with the bases PWMd but I needed 100mA per string. It was easier to switch the strings with the 08M outputs and PWM with the L293 enable pins. Besides, if you've got, use it.

R.
 

Attachments

Top