blinking a light in a loop
Archiver
Posts: 46,084
Andy-
Get yourself a blinking LED for $1.79 at Radio Shack. Too easy? OK,
here's another alternative:
delay_word VAR WORD
led_pin CON 0 (or whatever)
led_pin_out CON OUT0 (or whatever)
(during init[noparse]:)[/noparse]
HIGH led_pin
(inside your scanning loop[noparse]:)[/noparse]
led_pin_out = delay_word + 1 >> 4
The '4' above can be from 0 to 7. The higher the number, the slower
the blink.
Regards,
Steve
On 27 Feb 04 at 17:15, andy_watson5 wrote:
> I've got a loop that continuously scans 4 input buttons looking for
> a pulse. I'd like to blink a light while this scanning routine is
> running.
Get yourself a blinking LED for $1.79 at Radio Shack. Too easy? OK,
here's another alternative:
delay_word VAR WORD
led_pin CON 0 (or whatever)
led_pin_out CON OUT0 (or whatever)
(during init[noparse]:)[/noparse]
HIGH led_pin
(inside your scanning loop[noparse]:)[/noparse]
led_pin_out = delay_word + 1 >> 4
The '4' above can be from 0 to 7. The higher the number, the slower
the blink.
Regards,
Steve
On 27 Feb 04 at 17:15, andy_watson5 wrote:
> I've got a loop that continuously scans 4 input buttons looking for
> a pulse. I'd like to blink a light while this scanning routine is
> running.
Comments
pulse. I'd like to blink a light while this scanning routine is
running. But the only way I know how to blink a light with a stamp
is to set it high, then pause for a second, set it low, pause, and
repeat. But I don't want to pause the loop because I'm also looking
for those input pulses at the same time.
Is there an easy way to blink a light with the stamp? I know I could
do it with external circuitry, but I was hoping there was a way to do
it with just the stamp. Thanks.
>I've got a loop that continuously scans 4 input buttons looking for a
>pulse. I'd like to blink a light while this scanning routine is
>running. But the only way I know how to blink a light with a stamp
>is to set it high, then pause for a second, set it low, pause, and
>repeat. But I don't want to pause the loop because I'm also looking
>for those input pulses at the same time.
>
>Is there an easy way to blink a light with the stamp? I know I could
>do it with external circuitry, but I was hoping there was a way to do
>it with just the stamp. Thanks.
Take a look at the TOGGLE command and see if that fits your needs.
>To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
>from the same email address that you subscribed. Text in the Subject and Body
of the message will be ignored.
>
>Yahoo! Groups Links
>
>
>
>
remember that while it's operating you can't scan inputs. Another thing
to remember is that your scanning process takes time, so you can use
that time as your "on" delay fro the LED. Or use TOGGLE to change the
state of the LED every time you call your scan routine.
-- Jon Williams
-- Parallax
Original Message
From: andy_watson5 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=7x3zdCqCtkYPHMRfimPtGuMBI88WwCYelKmLDBpfT933hhkDKwnbEfqAvQOagsPBtpZIiOZ-OPuI7uDV5w]andywatson@m...[/url
Sent: Friday, February 27, 2004 11:16 AM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] blinking a light in a loop
I've got a loop that continuously scans 4 input buttons looking for a
pulse. I'd like to blink a light while this scanning routine is
running. But the only way I know how to blink a light with a stamp
is to set it high, then pause for a second, set it low, pause, and
repeat. But I don't want to pause the loop because I'm also looking
for those input pulses at the same time.
Is there an easy way to blink a light with the stamp? I know I could
do it with external circuitry, but I was hoping there was a way to do
it with just the stamp. Thanks.
>I've got a loop that continuously scans 4 input buttons looking for a
>pulse. I'd like to blink a light while this scanning routine is
>running. But the only way I know how to blink a light with a stamp
>is to set it high, then pause for a second, set it low, pause, and
>repeat. But I don't want to pause the loop because I'm also looking
>for those input pulses at the same time.
>
>Is there an easy way to blink a light with the stamp? I know I could
>do it with external circuitry, but I was hoping there was a way to do
>it with just the stamp. Thanks.
>
PSEUDO CODE:
Initialize:
BLINK_Delay=500 'WORD VAR Adjust this value to your liking.
BLINK_Counter=0 'WORD VAR
BLINK = 0 'Bit VAR
LED_Pin = Pin#
MainLoop:
Blink_Counter = Blink_Counter+1 'Increment Counter
if Blink_Counter = BLINK_Delay then 'Check Counter against Delay
Blink_Counter = 0 'Reset Counter
BLINK=1-BLINK 'Toggles Blink Bit
LED_Pin=BLINK 'Set LED pin HIGH or LOW
end if
...Other Program Stuff...
...Other Program Stuff...
...Other Program Stuff...
...Other Program Stuff...
...Other Program Stuff...
goto MainLoop
-Beau Schwabe (Old BS programmer - grin)
> led_pin_out = delay_word + 1 >> 4
>
>
> The '4' above can be from 0 to 7. The higher the number, the slower
> the blink.
Correction:
delay_word = delay_word + 1: led_pin_out = delay_word >> 4
The '4' above can be from 0 to 15. The higher the number, the
slower the blink.
Steve
DO
delay_word=delay_word+1
led_pin_out=delay_word.bit4 ' pick bitX for desired rate
' other stuff
LOOP
>On 27 Feb 04 at 10:49, S Parkis wrote:
>
>> led_pin_out = delay_word + 1 >> 4
>>
>>
>> The '4' above can be from 0 to 7. The higher the number, the slower
>> the blink.
>
>Correction:
>
>delay_word = delay_word + 1: led_pin_out = delay_word >> 4
>
>The '4' above can be from 0 to 15. The higher the number, the
>slower the blink.
>
>Steve
>
The Shift Right operator (>>) shifts the bits of a variable to the right a
specified number of places. Bits shifted off the right end of a number are
lost; bits shifted into the left end of the number are 0s. Shifting the bits
of a value right n number of times has the same effect as dividing that
number by 2 to the nth power. For instance 100 >> 3 (shift the bits of the
decimal number 100 right three places) is equivalent to 100 / 23.
value VAR Word
idx VAR Byte
Main:
value = %1111111111111111
FOR idx = 1 TO 16 ' loop 16 times
DEBUG BIN16 ? Value >> idx ' display shifted value
NEXT
END
delay_word VAR WORD
led_pin CON 0 (or whatever)
led_pin_out CON OUT0 (or whatever)
(during init[noparse]:)[/noparse]
HIGH led_pin
(inside your scanning loop[noparse]:)[/noparse]
led_pin_out = delay_word + 1 >> 4
The '4' above can be from 0 to 7. The higher the number, the slower
the blink.
[noparse][[/noparse]Non-text portions of this message have been removed]