Afternoon All,
I recently finish my code for an RGB circuit I was working on. It all works great and Im happy with the results.
I was just wondering though, is there a more efficient way to code the below section of the code. As you can see, at the moment I a fade loop (both on and off) for each colour, but was wondering if there was a better method of coding it that would use only 1 on fade loop and 1 off fade loop, but would then loop through the colours as well?
Only asking to learn really.
I recently finish my code for an RGB circuit I was working on. It all works great and Im happy with the results.
I was just wondering though, is there a more efficient way to code the below section of the code. As you can see, at the moment I a fade loop (both on and off) for each colour, but was wondering if there was a better method of coding it that would use only 1 on fade loop and 1 off fade loop, but would then loop through the colours as well?
Only asking to learn really.
Code:
symbol Red = 0
symbol Blue = 1
symbol Green = 2
symbol speed = w0
symbol on_time = w2
symbol off_time = w3
setint %00001000, %00001000
main:
readadc C.4,b1 ‘read the value
if b1<20 then chase ‘range 0-20
goto main
chase:
speed = b0 * 10000
RedOn:
for on_time = 0 to 5000 step 2
pulsout Red,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
high Red
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
GreenOff:
for on_time = 0 to 5000 step 2
pulsout Green,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
low Green
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
BlueOn:
for on_time = 0 to 5000 step 2
pulsout Blue,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
high Blue
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
RedOff:
for on_time = 0 to 5000 step 2
pulsout Red ,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
low Red
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
GreenOn:
for on_time = 0 to 5000 step 2
pulsout Green,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
high Green
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
BlueOff:
for on_time = 0 to 5000 step 2
pulsout Blue ,on_time
off_time = 5000 - on_time
pauseus off_time
next on_time
low Blue
pause speed
pause speed
pause speed
pause speed
pause speed
pause speed
goto main