Shop OBEX P1 Docs P2 Docs Learn Events
duration of seven seg — Parallax Forums

duration of seven seg

I have a code that will cause the seven seg to count random numbers 0-9 once a button is pressed. I am have problems getting this to last for only for a certain amount of seconds though.
This is my code

"index VAR NIB
result VAR WORD
counter VAR WORD
time VAR WORD
duration VAR WORD


DO
RANDOM result
DEBUG ? IN0
IF (IN0 = 1) THEN
OUTH = %00000000
DIRH = %11111111
DO

RANDOM result
index = result//10
LOOKUP index , [ %11100111, %10000100, %11010011,
%11010110, %10110100, %01110110,
%01110111, %11000100, %11110111, %11110110 ], OUTH
DEBUG ? counter
LOOP
ENDIF
LOOP"


Comments

  • kwinnkwinn Posts: 8,697
    You need another loop to display the result once the button is released.
  • How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

  • userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    You can count twelve "PAUSE 1000"s, for example. Think about it.



  • I think I see what you're saying. I'm going to try that tonight. Thanks!
    userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    You can count twelve "PAUSE 1000"s, for example. Think about it.



  • kwinnkwinn Posts: 8,697
    userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    One loop runs while the button is not pressed and displays the counter value.

    The second loop runs while the button is pressed and counts from 0 to 9. If you want the display blanked do that before you enter the second loop.
  • Hey I'm still not sure on how to implement that into my code.. how would i get it to count the 12 "1000 pauses" it just makes my numbers random slower.
    userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    You can count twelve "PAUSE 1000"s, for example. Think about it.



  • kwinn wrote: »
    userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    One loop runs while the button is not pressed and displays the counter value.

    The second loop runs while the button is pressed and counts from 0 to 9. If you want the display blanked do that before you enter the second loop.

    Like kwinn said...
  • I think I'm asking the wrong question. My apologies.. I would like the display to be random after the the button is pressed and released.So after the one cycle of the button the display shows random numbers for infinity. I need to change the infinity to a specific time.
    kwinn wrote: »
    userjyjy wrote: »
    How does that help with making the action only last for 12 seconds for example?
    kwinn wrote: »
    You need another loop to display the result once the button is released.

    One loop runs while the button is not pressed and displays the counter value.

    The second loop runs while the button is pressed and counts from 0 to 9. If you want the display blanked do that before you enter the second loop.

    Like kwinn said...

  • This is the code for it running for infinity

    DO
    RANDOM result
    DEBUG ? IN0
    IF (IN0 = 1) THEN
    OUTH = %00000000
    DIRH = %11111111
    DO
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG ? counter
    LOOP
    ENDIF
    LOOP
  • I'm thinking a loop until but I'm not sure how to represent that as in the time that has passed since the cycle of the button being pressed .
  • After working on it some more here is an updated code

    index VAR NIB
    result VAR WORD
    counter VAR WORD
    time VAR WORD
    duration VAR WORD
    result = 12000

    DO
    RANDOM result
    DEBUG ? IN0
    IF (IN0 = 1) THEN
    FOR counter = 0 TO 9
    FOR counter = 0 TO 300
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    NEXT
    NEXT
    ENDIF
    DEBUG ? counter
    LOOP
  • Hey guys I have a new code..Now I'm trying to figure out the increments every 2 seconds until 12 seconds


    DO
    RANDOM result
    DEBUG ? IN0
    IF (IN0 = 1) THEN
    FOR counter = 1 TO 1
    FOR counter = 1 TO 10
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 20
    NEXT
    FOR counter = 1 TO 5
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 40
    NEXT

    FOR counter = 1 TO 3
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 66
    NEXT

    FOR counter = 1 TO 2
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 100
    NEXT
    FOR counter = 1 TO 1
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 200
    NEXT

    FOR counter = 1 TO 1
    OUTH = %00000000
    DIRH = %11111111
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH
    DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR
    PAUSE 400
    NEXT


    NEXT
    RANDOM result
    index = result//10
    LOOKUP index , [ %11100111, %10000100, %11010011,
    %11010110, %10110100, %01110110,
    %01110111, %11000100, %11110111, %11110110 ], OUTH

    ENDIF
    DEBUG ? counter
    LOOP
  • kwinnkwinn Posts: 8,697
    I think I may be misunderstanding what you are trying to do.
    userjyjy wrote: »
    I have a code that will cause the seven seg to count random numbers 0-9 once a button is pressed. I am have problems getting this to last for only for a certain amount of seconds though.

    By the above post and the code you have posted do you mean that when the button is pressed you want to generate a random number using the "random" command and then display it for a specific period of time (12 seconds) and then blank the display?
  • Yes! I would like to press the button and the display would randomly display numbers for 12 seconds. At the end of the 12 seconds a final number is displayed.

    I added pauses to each instruction to try to simulate a dice slowing down Every 2 seconds and then finally landing on a number at the end of the 12 seconds .

    quote="kwinn;c-1450429"]I think I may be misunderstanding what you are trying to do.
    userjyjy wrote: »
    I have a code that will cause the seven seg to count random numbers 0-9 once a button is pressed. I am have problems getting this to last for only for a certain amount of seconds though.

    By the above post and the code you have posted do you mean that when the button is pressed you want to generate a random number using the "random" command and then display it for a specific period of time (12 seconds) and then blank the display?[/quote]

  • The counter where I have 0 to 375 worked as far as randomly displaying numbers for 12 seconds. But I'm wanting to know the the time to be able to break it up so that I can slow the display down every two seconds leading up to the 12. I know how to slow it by using the pause. Just having trouble figuring out the time table for the 2 second intervals.
  • So you want to start out changing quickly and then slowing down until the final number is displayed.

    Loops inside loops:
    For I = 1 to 6          'loop changes the the pauses
      for J = 1 to 4        'arbitrarily four numbers displayed for each period
         get random
         display it
         loopup I, [125, 250, 500, 1000, 1500, 2000], Period     'choose how long to wait
         PAUSE Period
         Next
    Next
    
  • Would I add that inside the for counter loops that I already have ? Sorry for all of the questions. I'm not that good at coding ...
    So you want to start out changing quickly and then slowing down until the final number is displayed.

    Loops inside loops:
    For I = 1 to 6          'loop changes the the pauses
      for J = 1 to 4        'arbitrarily four numbers displayed for each period
         get random
         display it
         loopup I, [125, 250, 500, 1000, 1500, 2000], Period     'choose how long to wait
         PAUSE Period
         Next
    Next
    

  • Run it all by itself. You will need to define the variables I, J, and period. Replace the "get random" and "display it" with real code from your examples.

    See what it does. Study it in concert along with re-reading the relevant pages in the BASIC book. Change it to see how the results vary.

    You will almost certainly want to fiddle the constants 6 and 4, and likely the constants that end up in period.

    I see I wrote loopup when i meant LOOKUP.

    When you post more code, be sure and use the big "C" in the formatting bar so the indentations are preserved.
  • Ok thanks! I'll try it tonight. I'll update you on my progress. You're much appreciated !
    Run it all by itself. You will need to define the variables I, J, and period. Replace the "get random" and "display it" with real code from your examples.

    See what it does. Study it in concert along with re-reading the relevant pages in the BASIC book. Change it to see how the results vary.

    You will almost certainly want to fiddle the constants 6 and 4, and likely the constants that end up in period.

    I see I wrote loopup when i meant LOOKUP.

    When you post more code, be sure and use the big "C" in the formatting bar so the indentations are preserved.

  • kwinnkwinn Posts: 8,697
    userjyjy wrote: »
    Would I add that inside the for counter loops that I already have ? Sorry for all of the questions. I'm not that good at coding ...
    No one is until they have done a lot of coding. It takes practice and study.
    So you want to start out changing quickly and then slowing down until the final number is displayed.

    Loops inside loops:
    For I = 1 to 6          'loop changes the the pauses
      for J = 1 to 4        'arbitrarily four numbers displayed for each period
         get random
         display it
         lookup I, [125, 250, 500, 1000, 1500, 2000], Period     'choose how long to wait
         PAUSE Period
         Next
    Next
    

    This code Tom posted should get you close to the effect you want. Just keep in mind that pause is in milliseconds so the sum of all the numbers in the lookup should be close to the total time you want (so 12,000 for 12 seconds). The time it takes for the code to execute will add an insignificant bit of time to the total.

  • Thanks man! I appreciate you too. I'll update you guys tonight with my results.
    kwinn wrote: »
    userjyjy wrote: »
    Would I add that inside the for counter loops that I already have ? Sorry for all of the questions. I'm not that good at coding ...
    No one is until they have done a lot of coding. It takes practice and study.
    So you want to start out changing quickly and then slowing down until the final number is displayed.

    Loops inside loops:
    For I = 1 to 6          'loop changes the the pauses
      for J = 1 to 4        'arbitrarily four numbers displayed for each period
         get random
         display it
         lookup I, [125, 250, 500, 1000, 1500, 2000], Period     'choose how long to wait
         PAUSE Period
         Next
    Next
    

    This code Tom posted should get you close to the effect you want. Just keep in mind that pause is in milliseconds so the sum of all the numbers in the lookup should be close to the total time you want (so 12,000 for 12 seconds). The time it takes for the code to execute will add an insignificant bit of time to the total.

  • Hey guys! I appreciate you alls help! I got it to work!
Sign In or Register to comment.