jensmith25
Senior Member
I have written code to perform various lighting effects using the 14M2 project board with IR reciever and sony remote from Picaxe.
Most of it is working ok but there seems to be issues where the code isn't switching from one effect to another, so when I push the next button on the remote, nothing happens. I also seem to have to wait for the one effect to finish before I can start another. It starts happening at "swon3". After that "swoffall" doesn't work either.
I am assuming that it's something to do with the pwm commands and that they're confusing the chip somehow but I can't figure out what it is. I wondered if the code needs to exit but I thought the "return" command did that. I can imagine it's somehting quite simple. I'm still a newbie with Picaxe but hopefully it's obvious to those of you with plenty of experience!
Any advice on this would be very much appreciated.
Most of it is working ok but there seems to be issues where the code isn't switching from one effect to another, so when I push the next button on the remote, nothing happens. I also seem to have to wait for the one effect to finish before I can start another. It starts happening at "swon3". After that "swoffall" doesn't work either.
I am assuming that it's something to do with the pwm commands and that they're confusing the chip somehow but I can't figure out what it is. I wondered if the code needs to exit but I thought the "return" command did that. I can imagine it's somehting quite simple. I'm still a newbie with Picaxe but hopefully it's obvious to those of you with plenty of experience!
Code:
#Picaxe 14M2
'Iron Man remote control lighting. Eyes, chest and hands.
'1) On - off for the eyes
'2) On - off for the chest and hands
'3) Slow fade from 'off ' to full 'on', on for 6 seconds, then a flash, then slow fade back to 'off' for the chest and hands
'4) Slow fade On-off for the eyes
'5) Slow fade On-off for chest & hands
main:
irin [1000,main],C.0,b0 ;wait for new signal
if b0 = 0 then swon1 ;switch on button 1 - eyes on
if b0 = 1 then swon2 ;switch on button 2 - chest & hands on
if b0 = 2 then swon3 ;switch on button 3 - eyes slow fade on
if b0 = 3 then swon4 ;switch on button 4 - chest & hands slow fade on
if b0 = 4 then swon5 ;switch on button 5 - slow fade from off to on for 6 seconds, flash, slow fade to off for chest and hands
if b0 = 5 then swoff1 ;button 6 - switch off eyes
if b0 = 6 then swoff2 ;button 7 - switch off chest & hands
if b0 = 7 then swoff3 ;button 8 - fade off eyes
if b0 = 8 then swoff4 ;button 9 - fade off chest & hands
if b0 = 21 then swoffall ;switch off all lights
goto main
swon1: ;switch on eyes - button 1
high B.4
goto main
swoff1: ;switch off eyes - button 6
low B.4
goto main
swon2: ;switch on chest & hands - button 2
high B.2
goto main
swoff2: ;switch off chest & hands - button 7
low B.2
goto main
swon3: ;fade on eyes - button 3
for b1=0 to 255
pwmout B.4,255,b1
pause 30
next
goto main
swoff3: ;fade off eyes - button 8
for b2=255 to 0 step -1
pwmout B.4,255,b2
pause 30
next
goto main
swon4: ;fade on chest & hands - button 4
for b3=0 to 255
pwmout B.2,255,b3
pause 30
next
goto main
swoff4: ;fade off chest & hands - button 9
for b4=255 to 0 step -1
pwmout B.2,255,b4
pause 30
next
goto main
swon5: ;fade on chest & hands, 6 secs on, flash, fade off - button 5
for b5=0 to 255 ;fade to full on
pwmout B.2,255,b5
pause 30
next
pause 6000 ;pause 6 seconds
pwmout 2, 255,1022:pause 140 ;briefly flash full brightness
for b5=255 to 0 step -1 ;fade to full off
pwmout B.2,255,b5
pause 30
next
goto main
swoffall: ;switch off all lights
low B.2
low B.4
goto main