Shop OBEX P1 Docs P2 Docs Learn Events
7 segment digital counter 28312 — Parallax Forums

7 segment digital counter 28312

WRD5WRD5 Posts: 9
edited 2010-03-21 13:20 in BASIC Stamp
My son and I·are working on a project to trigger a servo motor, and want it to fire at 59.99 seconds.·

We are using a·seven segment counter, and are controlling it with a BS2pe motherboard.· We have started with the odomoter sample project as our code, and can get the counter to mimic a stopwatch fairly accurately, but need to add a decimal point between the second and third digit.· What command or·code accomplishes this?· Basically, we want it to act as a stop watch, with 100th of a second readout (two decimal points).

Hoping for some help with this and then will need some help with the code for driving the servo within this 60 second window.
Thanks for any and all help!
B & N

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-20 19:11
    WRD5,

    Suppose your time in hundredths of a second is in a variable called Timer. Using the following code, you can print it out with the decimal:

    OWOUT Owio, 0, [noparse][[/noparse]"z", 1, DEC2 Timer / 100, ".", DEC2 Timer // 100]
    
    
    


    The "z", 1 provides one digit of leading zero suppression for the following decimal number, which is Timer / 100, printed as two decimal digits. Then comes the decimal point, followed by Timer // 100 (the remainder from Timer / 100), printed without leading zero suppression, since it's to the right of the decimal point.

    -Phil
  • WRD5WRD5 Posts: 9
    edited 2010-03-20 20:12
    This added the decimal in the middle of the 4 numeric spots, but after counting to 0.99, it did not roll over to a "1" in the first spot to the left of the decimal...and the decimal disappeared, as the counter went back to counting, starting again at 1....and continues onward without any decimal...

    I am not sure what is the "correct" definition to use for defining timer at the start of my program...We called it a nib and var with no difference.

    Thanks for this start to show a decimal.
    b

    Post Edited (WRD5) : 3/20/2010 8:20:16 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-20 20:32
    Can you post your entire program, please?

    -Phil
  • WRD5WRD5 Posts: 9
    edited 2010-03-20 21:43
    ' =========================================================================
    '
    ' File...... odometer.bpe
    ' Purpose... modified counter and scrolling with the 7Seg-DB.
    ' Author.... N & B
    ' E-mail.... ' Started... 3/12/07
    ' Updated... 3/20/10
    '
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================


    '
    [noparse][[/noparse] Program Description ]

    'Program to demonstrate scrolling on the 7Seg-DB.
    'It operates like the odometer in a car,
    'scrolling up the digits that change.
    'This program requires a single 7Seg-DB master.

    '
    [noparse][[/noparse] I/O Definitions ]

    Owio CON 6

    '
    [noparse][[/noparse] Variables ]

    cnt VAR Word······································· 'The counter: 0000-9999.
    val VAR Word········································'Changed part of cnt.
    win VAR Nib·········································· 'Left side of changed window.
    i VAR Nib···············································'Scroll counter.
    Timer VAR Word··································· 'adds timer for Phil Pilgrim code

    '
    [noparse][[/noparse] Initialization ]

    PAUSE 10············································· 'Wait for AVR to come out of reset.

    '
    [noparse][[/noparse] Program Code ]

    cnt = 9940·············································'start at 0.0 like a stopwatch.

    OWOUT Owio, 0, [noparse][[/noparse]"z", 1, DEC2 Timer / 100, ".", DEC2 Timer // 100] 'code from Phil Pilgrim for decimal.
    ····························································· ' The "z", 1 provides one digit of leading zero suppression for the following decimal
    ····························································· 'number, which is Timer / 100, printed as two decimal digits.
    ····························································· 'THEN comes the decimal point, followed by Timer // 100 (the remainder from Timer / 100),
    ····························································· 'printed without leading zero suppression, since it's to the right of the decimal point.
    DO························································ 'Counts·to 60.
    PAUSE 71·············································· 'best count to get tenth of secs correct by stopwatch est on march 20th.
    cnt = cnt + 1 // 10000····························'Increment count modulo 10000.
    val = 1000············································ 'We'll see if it's a multiple of 1000 first.
    win = 0················································· 'Set the window to the left edge of display.
    DO WHILE val········································'Val decreases, so loop terminates.
    IF cnt // val = 0 THEN····························'Is cnt a multiple of val?
    val = cnt // (val * 10)···························· ' Yes: Set val to the digits of cnt that changed.
    EXIT ' Exit LOOP.
    ENDIF
    val = val / 10········································ ' No: Try a smaller value for val
    win = win + 1······································· ' Move the left window border to the right.
    LOOP···················································· ' Try again.
    OWOUT Owio, 0, [noparse][[/noparse]"w", win, 3]··············· 'Define the new window.
    FOR i = 1 TO 3······································ 'Scroll current contents of window up by three (off the screen).
    OWOUT Owio, 0, [noparse][[/noparse]"u"]··························· ' Scroll up one.
    PAUSE 1················································ ' Wait, for animation effect.
    NEXT
    IF val THEN··········································· 'Is val equal to 0?
    OWOUT Owio, 0, [noparse][[/noparse]DEC val]·····················' No: Display it in the window (still scrolled off).
    ELSE
    OWOUT Owio, 0, [noparse][[/noparse]DEC4 val]·················· ' Yes: Display "0000" in the full window (still scrolled off).
    ENDIF
    FOR i = 1 TO 3······································· 'Scroll new value onto window. (It takes three scrolls.)
    OWOUT Owio, 0, [noparse][[/noparse]"u"]···························· ' Scroll up one.
    PAUSE 1················································· ' Wait, for animation effect.
    NEXT
    LOOP······················································ 'And so ON...

    Post Edited (WRD5) : 3/21/2010 4:15:55 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-20 22:01
    WRD5,

    If you put your code between [noparse][[/noparse]code] and [noparse][[/noparse]/code] tags, it will preserve indentation and use a monospaced font, making it easier to read. (You can modify your post by clicking the pencil icon in the upper righthand corner.)

    -Phil
  • WRD5WRD5 Posts: 9
    edited 2010-03-21 04:16
    i went back and spaced the code and comments manually, line by line, but do not understand the comments about [noparse][[/noparse]code] and [noparse][[/noparse]/code] nomenclature?

    Thanks,

    b
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-21 06:11
    WRD5,

    Read the forum guidelines here: forums.parallax.com/forums/mCode.aspx#1.12. It explains what the code tags are for and how to use them.

    I think you misunderstood my use of the Timer variable. And I misunderstood that you still wanted to do the odometer roll. What I meant by using Timer is that it should replace (or take the name of) your own time variable, which appears to be cnt. If you still want to use the odometer roll, you will have to send a "." after the ones digit whenever that digit changes. But for numbers that change every hundredth of a second, I'm not sure you'll even be able to see the transition taking place.

    My recommendation would be to skip the odometer roll for now and just concentrate on displaying numbers using the format I showed you, until you have a working familiarity with PBASIC and the commands used to write to the display. Trying to modify example code that you don't fully understand will be an exercise in frustration. Later on, you can embellish things if you like. But you'll have more success and garner more enjoyment for yourself and your son if you start simple and build up from there.

    -Phil
  • WRD5WRD5 Posts: 9
    edited 2010-03-21 13:20
    Phil
    you are absolutely RIGHT! We have NO interest in the artisitic function of the odometer rolling function, and were just using it as a starting point to understand, and try to make our 7 seg display work and do something similar to our clocking function.
    And YES....much of the nomenclature is still baffling, but some of the logic is starting to sink in. N is also getting a kick out of changing the variables and seeing their result, so it hasnt all been for naught!

    We appreciate your help!
    b
Sign In or Register to comment.