Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Need help counting momentary low input events — Parallax Forums

BS2 Need help counting momentary low input events

Donny23Donny23 Posts: 8
edited 2013-07-24 22:10 in BASIC Stamp
I am not an expert but, in desperate need of some help here.
I'm using the DS1302 and am trying to use 2 momentary reset switches #1 and #2. What I can't figure out is: how can I tap #1 THEN #2 to get it to start counting? With this, I need it only to stop counting by tap of #2 THEN #1 in that order. I've been trying to alter the demo DS1302 counter program. The switches are lowing the pins 4 and 5. Also, I need this to be able to be repeated but, keep the elapsed times history in debug somehow. Please, if someone can guide me in the right direction it would be greatly appreciated. I am using the BS2
I must not be adding to variables correctly or if I'm even going the right direction now. Thank you.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-24 21:04
    Whenever you want to do something a step at a time, you need to have a state machine of some kind. With the Stamp, you do this most easily by using a loop for each state like this:
    loop0: if IN4 = 1 or IN5 = 1 then goto loop0   ' initial state, wait for switches #1 and #2 to be released
    loop1: if IN4 = 0 then goto loop1   ' wait until switch #1 is pressed
    loop2: if IN5 = 0 then goto loop2   ' wait until switch #2 is pressed
    ' here you start the DS1302 clock
    loop3: if IN4 = 1 or IN5 = 1 then goto loop3   ' again, wait for switches #1 and #2 to be released
    loop4: if IN5 = 0 then goto loop4   ' wait until switch #2 is pressed
    loop5: if IN4 = 0 then goto loop5   ' wait until switch #1 is pressed
    ' here you stop the DS1302 clock
    
    The clock halt bit in the command byte is described on pages 5 and 7 of the DS1302 datasheet
  • Donny23Donny23 Posts: 8
    edited 2013-07-24 22:10
    This is what I've written so far. Works good. However, now I'm trying to figure out how to get it to stop or exit when counter = 4. It enters the subroutine first and stops counting the trips?
    That will be when switch #1 and #2 get pressed again.
    Also, for some reason the "generate object code" exe file says download ok but nothing happens. What am I doing wrong? This is gonna sound funny but is there a way to enlarge font size in debug or can I do that in the exe file when I finally get that to work?
    Your sample does help tremendously though and can think of many ways to make things easier doing that.
    Thanks













    counter VAR Byte
    DO
    DEBUG ? IN4
    IF (IN4 = 0)THEN
    PAUSE 1000
    counter = counter + 1


    ENDIF
    DEBUG CRSRDN
    DEBUG CRSRDN
    DEBUG ? IN5
    IF (IN5 = 0)THEN
    PAUSE 1000
    counter = counter + 1
    ENDIF
    DEBUG CRSRDN
    DEBUG ? counter
    PAUSE 100
    IF counter = 2 THEN
    GOTO Start
    ENDIF
    LOOP
    Start:
    mins = $00
    secs = $00


    GOSUB Set_Time


    DO
    GOSUB Get_Time
    DEBUG HOME, HEX2 mins, ":", HEX2 secs




    LOOP


    DEBUG CR, CR, "ELAPSED TIME"


    STOP
Sign In or Register to comment.