Do a search for something to the effect of slow speed pwm.
What you want is Pulse Width Modulation. You turn an LED on and off, faster than your eyes can detect that your turning it on and off really fast (above about 25 times per second in general), but you vary the time it's actually on during that on and off period. Do a search on wiki for 'persistence of vision' and you should get the idea.
Code:
'your general setup code like you had before
brightness var byte 'can vary from 0 (off) to 255 (full brightness)
pwmcount var word
led var gpio.0
output led
low led
button var gpio.5
input button ' i assume your button is on gpio.5
main:
pwmcount = pwmcount + 1
if brightness < pwmcount then
high led
else
low led
endif
if pwmcount = 0 then 'check state of button whenever pwmcount rolls over to zero
if button = 0 then 'if button pressed (not pressed?), decrease brightness
if brightness > 0 then 'only if brightness isn't already zero
brightness = brightness - 1 'decrease it
endif
endif
else 'if the button isn't pressed (or is pressed? depending on how you have it wired),
if brightness < 255 then 'increase the brightness if it isn't already at maximum
brightness = brightness + 1 'increase it
endif
endif
goto main
This will only run one LED, with one button. Push it, it gets brighter, let go, it gets dimmer.
Not sure how well it'll run, if it'll flicker or not, or even if it'll be agonizingly slow.
See what happens...
Bookmarks