Shop OBEX P1 Docs P2 Docs Learn Events
Need a 10-15 min. Timer with pin status checks — Parallax Forums

Need a 10-15 min. Timer with pin status checks

ArchiverArchiver Posts: 46,084
edited 2000-10-26 08:16 in General Discussion
What is the datatype of b4? Sounds like it is a byte and is wrapping around
when the number of iterations is more than 255. That would explain why the
for loop never finishes.

If you want to go from 1 to 400, b4 needs to be a word instead of a byte.

Original Message
From: Scott Manson [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=5xef-E0hfPOopSpIOBth8Sy_lgv895N5T_W9DstXt1kPA6EWfVqRzC0A6aW3v8tygm4nn7RCr2J7WAqH]bigorlando@h...[/url
Sent: Wednesday, October 25, 2000 3:06 PM
To: basicstamps@egroups.com
Subject: [noparse][[/noparse]basicstamps] Need a 10-15 min. Timer with pin status checks


The following is part of the code. For some reason, If I set the 2nd line
to a value of 400 or more (ex: for b4= 1 to 400), then the loop here
recycles and never times out and goes to the start of my program.
However, with the value of 200, it works fine.
Any ideas or any other more efficient way of accoplishing what the code
below does?
Also, this is a Basic Stamp 1 Rev. D

warmdown:
let pin3 = 0 'turn off LED
for b4 = 1 to 200 'initialize countdown timer
let indicat = 1 'turn on LED 1
let pin3 = 1 'turn on LED 2
pause 500 'used as a 1/2 sec. delay/ achieves flashing LED
let indicat = 0 'turn off LED 1
let pin3 = 0 'turn off LED 2
if switch1 = 0 then scan 'If switch active, goto scan sequence
pause 500 'other 1/2 sec. delay/ achieves flashing LED
next
let lighton = 0 'after timeout, turn off LED 1
let indicat = 0 'after timeout, turn off LED 2
goto start 'return to start of program


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at
http://profiles.msn.com.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-10-25 23:27
    At 10/25/2000 +0000 10:06 PM, you wrote:
    >The following is part of the code. For some reason, If I set the 2nd line
    >to a value of 400 or more (ex: for b4= 1 to 400), then the loop here
    >recycles and never times out and goes to the start of my program.
    Scott -

    It's possible the Stamp is being reset (brownout due to 2 x leds). Place
    DEBUG "Start" as the first line of the program, and see if it prints more
    than once. Additionally, B4 is a byte variable whose value can not exceed
    255 (&H'FF'). You need to use a word variable (w4) for numbers which exceed
    255. I diidn't study what the routine did carefully, but if you want to
    DECREMENT it (countDOWN), you need For b4 = .
    1 to 200 step -1 or b4 = 200 to 1 (without the step). Also, branching to
    SCAN will bypass the next, unless you carefully re-enter the loop.

    Just a few observations.

    Regards,

    Bruce Bates

    >However, with the value of 200, it works fine.
    >Any ideas or any other more efficient way of accoplishing what the code
    >below does?
    >Also, this is a Basic Stamp 1 Rev. D
    >
    >warmdown:
    > let pin3 = 0 'turn off LED
    > for b4 = 1 to 200 'initialize countdown timer
    > let indicat = 1 'turn on LED 1
    > let pin3 = 1 'turn on LED 2
    > pause 500 'used as a 1/2 sec. delay/ achieves flashing LED
    > let indicat = 0 'turn off LED 1
    > let pin3 = 0 'turn off LED 2
    > if switch1 = 0 then scan 'If switch active, goto scan sequence
    > pause 500 'other 1/2 sec. delay/ achieves flashing LED
    > next
    > let lighton = 0 'after timeout, turn off LED 1
    > let indicat = 0 'after timeout, turn off LED 2
    > goto start 'return to start of program
    >
    >
    >_________________________________________________________________________
    >Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
    >
    >Share information about yourself, create your own public profile at
    >http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-26 06:06
    The following is part of the code. For some reason, If I set the 2nd line
    to a value of 400 or more (ex: for b4= 1 to 400), then the loop here
    recycles and never times out and goes to the start of my program.
    However, with the value of 200, it works fine.
    Any ideas or any other more efficient way of accoplishing what the code
    below does?
    Also, this is a Basic Stamp 1 Rev. D

    warmdown:
    let pin3 = 0 'turn off LED
    for b4 = 1 to 200 'initialize countdown timer
    let indicat = 1 'turn on LED 1
    let pin3 = 1 'turn on LED 2
    pause 500 'used as a 1/2 sec. delay/ achieves flashing LED
    let indicat = 0 'turn off LED 1
    let pin3 = 0 'turn off LED 2
    if switch1 = 0 then scan 'If switch active, goto scan sequence
    pause 500 'other 1/2 sec. delay/ achieves flashing LED
    next
    let lighton = 0 'after timeout, turn off LED 1
    let indicat = 0 'after timeout, turn off LED 2
    goto start 'return to start of program


    _________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

    Share information about yourself, create your own public profile at
    http://profiles.msn.com.
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-26 08:16
    Sounds like that is the problem. I wasn't aware that I couldn't count
    above 255 using b4. I will try using a word instead as you suggested.

    Thanks for the tip!!

    -Scott-

    --- In basicstamps@egroups.com, Andrew Tucker <andrewt@a...> wrote:
    >
    > What is the datatype of b4? Sounds like it is a byte and is
    wrapping around
    > when the number of iterations is more than 255. That would explain
    why the
    > for loop never finishes.
    >
    > If you want to go from 1 to 400, b4 needs to be a word instead of a
    byte.
    >
    >
    Original Message
    > From: Scott Manson [noparse][[/noparse]mailto:bigorlando@h...]
    > Sent: Wednesday, October 25, 2000 3:06 PM
    > To: basicstamps@egroups.com
    > Subject: [noparse][[/noparse]basicstamps] Need a 10-15 min. Timer with pin status
    checks
    >
    >
    > The following is part of the code. For some reason, If I set the
    2nd line
    > to a value of 400 or more (ex: for b4= 1 to 400), then the loop here
    > recycles and never times out and goes to the start of my program.
    > However, with the value of 200, it works fine.
    > Any ideas or any other more efficient way of accoplishing what the
    code
    > below does?
    > Also, this is a Basic Stamp 1 Rev. D
    >
    > warmdown:
    > let pin3 = 0 'turn off LED
    > for b4 = 1 to 200 'initialize countdown timer
    > let indicat = 1 'turn on LED 1
    > let pin3 = 1 'turn on LED 2
    > pause 500 'used as a 1/2 sec. delay/ achieves flashing LED
    > let indicat = 0 'turn off LED 1
    > let pin3 = 0 'turn off LED 2
    > if switch1 = 0 then scan 'If switch active, goto scan sequence
    > pause 500 'other 1/2 sec. delay/ achieves flashing LED
    > next
    > let lighton = 0 'after timeout, turn off LED 1
    > let indicat = 0 'after timeout, turn off LED 2
    > goto start 'return to start of program
    >
    >
    >
    ______________________________________________________________________
    ___
    > Get Your Private, Free E-mail from MSN Hotmail at
    http://www.hotmail.com.
    >
    > Share information about yourself, create your own public profile at
    > http://profiles.msn.com.
Sign In or Register to comment.