I was experimenting with pulsout to vary the brightness of an LED, its been done before but I wanted to
figure it out for myself. Using pulsout if you make your pulse longer (mark) and your off time shorter or
keep it the same (space) the effect will be that the led will be on longer than it is off and will be brighter.
PWM is the same but only the 18X you only have one and to drive an RGB led you need 3.
I used a FOR loop to count to 200 using b0, b0 is then used in Pulsout. As b0 increments the led gets brighter and when b0
reaches 200 the next part of the program decrements b0 which decreases the pulsout make the led dimmer.
do
let b=0
for b0 = 1 to 220
pulsout 0, b0
pause 10
next
for b1 = 1 to 220
pulsout 0, b0
pause 10
dec b0
next b1
pause 100
loop
The cycle lasts for about 5 seconds and the effect is very similar to the Apple charge indicator..
From there I was able to adapt the program to run an RGB led. To do this all I did was take the original program and
exploit the counters. In the second half of the program as b0 is counting down b1 is counting up so by adding a second
pulsout I was able to have one colour brightening up as another is dimming down.
I used 'w' variables as they allowed a larger number to be used as more on time means a brighter led but I got
rid of the short pauses as the w time is much larger and takes time to come to full brightness and an extra pause
made the cycle too long.
Intially the program brings the red led to full brightness, then the main loop starts and dims the red while bringing up
the green, then the green fades as the blue comes up, then the red comes up as the blue fades and then the cycle
repeats.
symbol rled = 0
symbol gled = 1
symbol bled = 2
setfreq m8
let w0 = 0
for w1 = 1 to 1200 'initially brightening red
pulsout rled, w0
next
main:
let w0 = 1200 'makes sure red starts at full brightness
for w1 = 1 to 1200
pulsout rled, w0 'dimming red
pulsout gled, w1 'brightening green
dec w0
next w1
for w0 = 1 to 1200
pulsout gled, w1 'dimming green
pulsout bled, w0 'brightening blue
dec w1
next w0
for w1 = 1 to 1200
pulsout bled, w0 'brightening red
pulsout rled, w1 'dimming blue
dec w0
next w1
goto main
By fiddling with the 1 to 1200 values can allow for the brightness differential in the led colours.
This is a work in progress and a lot more fun is to be had inducing all kinds of visual headaches with the
RGB led tape!
figure it out for myself. Using pulsout if you make your pulse longer (mark) and your off time shorter or
keep it the same (space) the effect will be that the led will be on longer than it is off and will be brighter.
PWM is the same but only the 18X you only have one and to drive an RGB led you need 3.
I used a FOR loop to count to 200 using b0, b0 is then used in Pulsout. As b0 increments the led gets brighter and when b0
reaches 200 the next part of the program decrements b0 which decreases the pulsout make the led dimmer.
do
let b=0
for b0 = 1 to 220
pulsout 0, b0
pause 10
next
for b1 = 1 to 220
pulsout 0, b0
pause 10
dec b0
next b1
pause 100
loop
The cycle lasts for about 5 seconds and the effect is very similar to the Apple charge indicator..
From there I was able to adapt the program to run an RGB led. To do this all I did was take the original program and
exploit the counters. In the second half of the program as b0 is counting down b1 is counting up so by adding a second
pulsout I was able to have one colour brightening up as another is dimming down.
I used 'w' variables as they allowed a larger number to be used as more on time means a brighter led but I got
rid of the short pauses as the w time is much larger and takes time to come to full brightness and an extra pause
made the cycle too long.
Intially the program brings the red led to full brightness, then the main loop starts and dims the red while bringing up
the green, then the green fades as the blue comes up, then the red comes up as the blue fades and then the cycle
repeats.
symbol rled = 0
symbol gled = 1
symbol bled = 2
setfreq m8
let w0 = 0
for w1 = 1 to 1200 'initially brightening red
pulsout rled, w0
next
main:
let w0 = 1200 'makes sure red starts at full brightness
for w1 = 1 to 1200
pulsout rled, w0 'dimming red
pulsout gled, w1 'brightening green
dec w0
next w1
for w0 = 1 to 1200
pulsout gled, w1 'dimming green
pulsout bled, w0 'brightening blue
dec w1
next w0
for w1 = 1 to 1200
pulsout bled, w0 'brightening red
pulsout rled, w1 'dimming blue
dec w0
next w1
goto main
By fiddling with the 1 to 1200 values can allow for the brightness differential in the led colours.
This is a work in progress and a lot more fun is to be had inducing all kinds of visual headaches with the
RGB led tape!