How can I fade an LED on or off??
wolfdaddy33
Posts: 12
I'm a newbie to Basic Stamp. I am using Stamp BS2 and PBASIC 2.5.
I have a project which needs to fade an LED ON or OFF, and would like to dictate the speed of the fade.
Does anyone have code to perform this or a tutorial I can be directed to??
Thanks.
I have a project which needs to fade an LED ON or OFF, and would like to dictate the speed of the fade.
Does anyone have code to perform this or a tutorial I can be directed to??
Thanks.
Comments
You can basically just give the led a duty cycle from 100% to 0% in steps down with a 'for/next' loop.
Go, wolfdaddy33! It's yer birthday! Uh-huh!
I Will post updates, cause I'm sure to screw something up.
http://www.youtube.com/watch?v=OUpNYQgWRtM
--Rich
The perception of intensity depends a lot on ambient light level, so the limit of the fade may need to be adjusted to account for that.
This uses the Stamp's */ operator, which is the the Stamp's way to multiply times fractions. Unity=256. By that, I mean that x = x */ 256 makes no change in the value of x, but x = x */ 192 is like multiplying x times 192/256 = 3/4.
You can also get a pulsing effect with the FREQOUT command
FREQOUT 0,1000,1000,1001
That gives nice sinusoidal fade in and fade out due to the beat frequency of 1000 Hz with 1001 Hz .
Example....
BS2
Basic stamp 2.5
Warninglight:
FREQOUT 0, 1000, 1000, 1001
goto Warninglight
Very Impressive.
The same general idea ought to work for a servo, with either linear or decelerated movements. For servos, the program is periodically applying pulses between 1 and 2 milliseconds, not PWM. Quite different in that respect.
I know that Byte is 0-255 but what are you telling the stamp for x.BYTE1 variable?
Also I tried to go the other way to fade the light ON but was not very successful.
How would you fade ON to increase the same way?