Michael 2727
Senior Member
There are many ways you could fade an LED/s up and
down, here are just a couple.
A simple single LED.
Three fading LEDs chasing.
Good Luck !
down, here are just a couple.
A simple single LED.
Three fading LEDs chasing.
Code:
#picaxe 08m 'Sets the Program Editor config for an 08M Chip.
'This will fade an LED on Pin1 / Leg6, OFF to Full ON to OFF, etc, etc.
Main:
Up:
if b5 = 255 then goto Down
inc b5 'Increments the b5 value each time around.
'pause 1 'Pause values above 10 will flicker.
'pause 2
'pause 4
'pause 8
pwm 1,b5,1 'PWM Pulse on Pin1, value of b5, once.
goto Up
Down:
if b5 = 0 then goto Up
dec b5 'Decrements the b5 value each time around.
'pause 1 'Pause values above 10 will flicker.
'pause 2
'pause 4
'pause 8
pwm 1,b5,1 'PWM Pulse on Pin1, value of b5, once.
goto Down
Code:
'LED Fade Up then Down
'For PICAXE-08M
'Michael 2727 2005
'LEDs on Pins 0,1,2 on Schools Experimenter PCB ( AXE092 )
'The LEDs will chase 0/Red, 1/Yellow, 2/Green, 1/Yellow 0/Red, etc, etc.
#picaxe 08m 'Sets the Program Editor config for an 08M Chip.
symbol rampup=b0
symbol rampdwn=b1
main:
'[B]Edit: [/B] low 0 See notes in post below.
low 1
low 2
low 4
' '** Set all pins Low **
pause 20
' '*********Set which Pins/LED to pulse next here, values stored in b5 **
b5=1 ' Pin 1
gosub Fade ' The first RETURN comes back to HERE.
b5=2 ' Pin 2
gosub Fade ' The second RETURN comes back to HERE.
b5=4 ' Pin 4
gosub Fade ' The third RETURN comes back to HERE ect.
b5=2 ' Pin 2
gosub Fade '
' '*******************************************************
goto main ' Back to start
' ***** PWM ramp LED up /down drive section *****
Fade:
pause 20
' UPWARD FADE SECTION
for rampup=1 to 255 step 1 '** To speed up the change/fade step value = 1 to 15 **
pwm b5,rampup,1 '** LED 1 on first, 1 to 255 back to 1 **
pause 3 '** To slowdown the change/fade, insert pause 1 to 10 here **
next rampup
' DOWNWARD FADE SECTION
for rampdwn=225 to 1 step -1 '** To speed up the change/fade step value to 1 to 15 **
pwm b5,rampdwn,1
pause 3 '** To slowdown the change/fade insert pause 1 to 10 here **
next rampdwn
low 0
pause 300 '** Slight delay between the next LED used in the sequence **
return
'** By connecting the outputs to a MOSFET transistor
'** you should be able to make a string of DC Low
'** Voltage Christmas lights fade up and down.
Last edited: