You could use the PULSOUT command and change the duty cycle, or similarly write a loop that turns it on and off quickly for a certain duration. If you want to run other code while the led is dimmed, you could have an output of the stamp control a timer circuit to keep it at that level.
The PWM statement will let you produce an adjustable light output. Read the section in the manual on it and try it.
Unfortunately, the Stamp can't do anything else while it's executing the PWM statement, but you could do other
brief things as long as your program spends most of its time doing the PWM.
Read the Basic Stamp 1 application note "Fun With Trains" application 21.
It is a very cleaver way of creating a continuous PWM signal within a loop.
The application outputs three (3) unique PWM signals Continuously to modulate three (3) electric train motors.
If you create an 8 bit byte variable, and add a duty cycle of 0 to 255 (0% to 100%) to itself in a loop, output the variable.bit8 to a pin, clear variable.bit8 to 0, you will have created a continuous PWM signal. The higher the duty cycle, the more times variable.bit8 will be a logic 1.
thank you for the replies, I certainly will check out the servo application...PWM still is a problem as ideally I'd have something else running whil one or more leds are shingin on at a specific intensity...but I'll read the examples and try to figure something out
You can insert several the·code examples from the Trains application note or from EME systems into your code that is allready running. However, at some point the LEDs may start to flicker. Insert more examples as required.
thanks for that bit of code as well.
but in the end I think I have my solution (I should have mentioned that I was looking for optocoupling, controlling the leds from the stamp and needing various levels of brightness), I will use 74HC595's and have the number of leds lit to take care of brightness (ok, only 8 per 74, but working with colour combinations and positioning towards the LDR might give more gradation).
Comments
Regards,
Mike
Unfortunately, the Stamp can't do anything else while it's executing the PWM statement, but you could do other
brief things as long as your program spends most of its time doing the PWM.
Here's one example of a program that does LED fading with some motor control: http://forums.parallax.com/showthread.php?p=682581.
Read the Basic Stamp 1 application note "Fun With Trains" application 21.
It is a very cleaver way of creating a continuous PWM signal within a loop.
The application outputs three (3) unique PWM signals Continuously to modulate three (3) electric train motors.
If you create an 8 bit byte variable, and add a duty cycle of 0 to 255 (0% to 100%) to itself in a loop, output the variable.bit8 to a pin, clear variable.bit8 to 0, you will have created a continuous PWM signal. The higher the duty cycle, the more times variable.bit8 will be a logic 1.
http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
Also read this application from EME System. The code mimics the Parallax PWM statement.
http://www.emesystems.com/BS2PWM.htm.
Stephen J Wagner
You can insert several the·code examples from the Trains application note or from EME systems into your code that is allready running. However, at some point the LEDs may start to flicker. Insert more examples as required.
SJW
but in the end I think I have my solution (I should have mentioned that I was looking for optocoupling, controlling the leds from the stamp and needing various levels of brightness), I will use 74HC595's and have the number of leds lit to take care of brightness (ok, only 8 per 74, but working with colour combinations and positioning towards the LDR might give more gradation).