Shop OBEX P1 Docs P2 Docs Learn Events
setting up a time statement — Parallax Forums

setting up a time statement

sambeauxsambeaux Posts: 3
edited 2006-02-08 20:23 in BASIC Stamp
I am new to this programming. Im wanting a program to do this: if an input goes low for 10 minutes I want to output a low at another pin. Can someone get me in the right direction. Ive read about the pause command but in milliseconds it would need 600000 milliseconds in 10 minutes and I believe a pause will only count to 65000. thanks very much...

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-08 19:56
    Since you're new to programming you might want to download our What's A Microcontroller? book.·

    Here's a routine that will wait until an input has been low for 10 minutes (100 ms granularity) before making the alarm output low:

    Wait_For_10m:
    · timer = 0
    · DO
    ··· timer = (timer +·AlarmIn) * AlarmIn
    ··· PAUSE 100
    · LOOP UNTIL (timer = 6000)
    · AlarmOut = Active
    · RETURN

    There's a bit of a trick here: the value of timer will get incremented as long as the AlarmIn pin is high (1); if the pin goes low then timer gets cleared (because we ould be multiplying by zero), forcing the AlarmIn pin to stay high for the entire period.· I've used this technique in a commercial product I developed using a BS2 before my employment at Parallax.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-02-08 20:23
    You could always put the PAUSE in a loop:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    TimerLoop VAR Byte 'Create a variable for the timer loop
    LoopCount CON 10 'Set number of iterations for the loop
    Minute CON 60000 '1 minute = 60000 milliseconds


    Init:
    TimerLoop = 1

    FOR TimerLoop = 1 TO LoopCount

    PAUSE Minute
    DEBUG "Loop ", DEC TimerLoop, CR 'For debugging loop, gives visual output, remove or comment out for final code

    NEXT
Sign In or Register to comment.