#picaxe 08m2
symbol REDLED = 2
symbol GRNLED = 1
symbol BLULED = 4
symbol SPEED = 10
symbol REDLEVEL = w3
symbol REDDIR = b2
main:
setfreq m8
do
; begin colour fading
REDLEVEL = 800
REDDIR = 0
pwmout REDLED, 200, REDLEVEL
do while 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
b0 = REDLED : 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