Shop OBEX P1 Docs P2 Docs Learn Events
stampworks question — Parallax Forums

stampworks question

studentstudent Posts: 12
edited 2004-10-17 03:01 in Learn with BlocklyProp
I Have put together experiment #10, LED Clock Display. I need to modify the experiment to a stopwatch using pushbutton D0 and port 12 to begin the watch, and D7 and port 13 to stop watch.·What changes do I make to the program? I appreciate any help with this.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-15 20:54
    Why don't you post your attempt and let the group guide you -- you'll learn more that way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-10-15 22:00
    This is the experiment that needs to be modified (with start button and stop button).


    '·{$STAMP BS2}
    ' =========================================================================
    ' File:Experiment 10.BS2
    ' ' =========================================================================
    ' { I/O Pins }
    segs··· VAR· OUTL······· ' segments
    digSel·· VAR· OUTC········ ' digit select
    tic······ VAR· IN15········· ' 1 Hz Pulse Generator input
    '
    ' { constants }

    DPoint······ CON· %10000000······· ' decimal point bit
    '
    ' { variables }
    secs···· VAR· Word······· ' seconds
    time······ VAR· Word······· ' formatted time
    digit······· VAR· Nib······· ' current display digit
    '
    ' { DATA statements }
    '············· .abcdefg
    '·············
    DecDig· DATA· %01111110····· ' 0
    ······· DATA· %00110000····· ' 1
    ······· DATA· %01101101····· ' 2
    ······· DATA· %01111001····· ' 3
    ······· DATA· %00110011····· ' 4
    ······· DATA· %01011011····· ' 5
    ······· DATA· %01011111····· ' 6
    ······· DATA· %01110000····· ' 7
    ······· DATA· %01111111····· ' 8
    ······· DATA· %01111011····· ' 9
    '
    ' { initialization }
    Initialize:
    · DIRL = %11111111······· ' make segments outputs
    · DIRC = %1111··········· ' make digit selects outputs
    · digSel = %1111········· ' all digits off
    '


    Main:
    · GOSUB ShowTime··········· ' show current digit
    ·· IF tic = 1 THEN IncSec····· ' new second?

    · GOTO Main··················· ' do it again
    IncSec:
    · secs = (secs + 1) // 3600··· ' update seconds counter
    Waiting:
    · GOSUB ShowTime············· ' show current digit
    ·· IF tic = 0 THEN Main········ ' if last tic gone, go back

    · ' additional code could go here
    · GOTO Waiting········· ' do tic check again
    · END
    '
    ' { subroutines }
    ShowTime:
    · time = (secs / 60) * 100····· ' get minutes, put in hundreds
    · time = time + (secs // 60)····· ' get seconds, put in 10s & 1s
    · segs = %00000000················· ' blank display
    · ' enable digit
    · LOOKUP digit,[noparse][[/noparse]%1110,%1101,%1011,%0111],digSel
    · READ (DecDig + (time DIG digit)),segs· ' put segment pattern in digit
    · IF (digit <> 2) THEN SkipDP
    · segs = segs + DPoint······· ' illuminate decimal point
    SkipDP:
    · PAUSE 1···················· ' show it
    · digit = (digit + 1) // 4··· ' get next digit
    · RETURN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-15 23:20
    I don't see your modifications. Where are they?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-10-16 00:04
    I did have two BUTTON commands with IF-THEN statements, but it didn't work, so I deleted them. The program is now in its original form. What I tried was: BUTTON startButton, 12, 1,· 0,· swData,· 1, Main and BUTTON stopButton, 13,· 1,· 0,· swData, 1,··-- Thought probably a subroutine, but wasn't sure what. I'm not even sure that I'm·on the right track.·roll.gif···
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-16 04:20
    Here's something you can try -- you'll have to test as I'm writing this on-the-fly at the end of a long day:

    Before Main, add this to start the clock:

    RunCheck:
    · IF (IN12 = 1) THEN RunCheck


    Add a line at the top of Main to stop the clock:

    Main:
    · IF (IN13 = 0) THEN RunCheck


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-10-16 04:59
    This is decidedly on the right track. The start button works great, and the stop button does stop the clock, but only displays one of the digits (depends on when button is pressed). Do I need an additional subroutine to display all four digits?
    Thanks for the help!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-16 14:59
    Yes, I was not thinking about that -- what you need to do is create a flag (bit variable) that tells the program if it's running or not.· Try this:

    running··· VAR··· Bit

    ...

    RunCheck:
    · IF (IN12 = 1) THEN RunCheck

    · running = 1


    Main:
    · IF (IN13 = 0) THEN

    ··· running = 0
    · ENDIF
    · IF (running·= 0) THEN Waiting


    After you stop the clock you will need to press reset before you can start it again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-10-16 22:30
    I tried the running flag (if I entered it correctly) and get all zero's on the display, clock not running. The·ENDIF is black.·If I·put a space after END, it is blue, but has a syntax error.
    ·Here is how the code is entered:
    ' {$STAMP BS2}
    ' =========================================================================
    ' File:Experiment 10.BS2
    ' Simulate a digital stopwatch using four, 7-segment LED displays
    ' =========================================================================
    ' { I/O Pins }
    segs··· VAR· OUTL······· ' segments
    digSel·· VAR· OUTC········ ' digit select
    tic······ VAR· IN15········· ' 1 Hz Pulse Generator input
    '
    ' { constants }

    DPoint······ CON· %10000000······· ' decimal point bit
    '
    ' { variables }
    secs···· VAR· Word······· ' seconds
    time······ VAR· Word······· ' formatted time
    digit······· VAR· Nib······· ' current display digit
    running······ VAR· Bit······· ' clock is running
    '
    ' { DATA statements }
    '················ ······· .abcdefg
    '······················ ·
    DecDig· DATA· %01111110····· ' 0
    ··········· DATA· %00110000····· ' 1
    ·········· ·DATA· %01101101····· ' 2
    ·········· ·DATA· %01111001····· ' 3
    ·········· ·DATA· %00110011····· ' 4
    ··········· DATA· %01011011····· ' 5
    ··········· DATA· %01011111····· ' 6
    ·········· ·DATA· %01110000····· ' 7
    ········ ·· DATA· %01111111····· ' 8
    ········· · DATA· %01111011····· ' 9
    '
    ' { initialization }
    Initialize:
    · DIRL = %11111111······· ' make segments outputs
    · DIRC = %1111··········· ' make digit selects outputs
    · digSel = %1111········· ' all digits off
    '

    RunCheck:
    · IF (IN12 = 1) THEN RunCheck···· ' start clock with D0
    · running = 1···················· ' clock is running
    Main:
    · IF (IN13 = 0) THEN RunCheck····· ' stop clock with D7
    · running = 0····················· ' clock is stopped
    ·ENDIF
    · IF (running = 0) THEN waiting···· ' display elapsed time
    · GOSUB ShowTime··········· ' show current digit
    ·· IF tic = 1 THEN IncSec····· ' new second?

    · GOTO Main··················· ' do it again
    IncSec:
    · secs = (secs + 1) // 3600··· ' update seconds counter
    Waiting:
    · GOSUB ShowTime············· ' show current digit
    ·· IF tic = 0 THEN Main········ ' if last tic gone, go back

    · ' additional code could go here
    · GOTO Waiting········· ' do tic check again
    · END
    '
    ' { subroutines }
    ShowTime:
    · time = (secs / 60) * 100····· ' get minutes, put in hundreds
    · time = time + (secs // 60)····· ' get seconds, put in 10s & 1s
    · segs = %00000000················· ' blank display
    · ' enable digit
    · LOOKUP digit,[noparse][[/noparse]%1110,%1101,%1011,%0111],digSel
    · READ (DecDig + (time DIG digit)),segs· ' put segment pattern in digit
    · IF (digit <> 2) THEN SkipDP
    · segs = segs + DPoint······· ' illuminate decimal point
    SkipDP:
    · PAUSE 1···················· ' show it
    · digit = (digit + 1) // 4··· ' get next digit

    · RETURN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-17 01:57
    You need to select PBASIC 2.5 syntax to use ENDIF.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-10-17 03:01
    That did it! yeah.gif Thanx Jon, you've been a tremendous help.
Sign In or Register to comment.