Count Down - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Count Down

NinthAngleNinthAngle Posts: 98Member
If I want to display an image or a text for a certain number of seconds, what code do I use?

Comments

  • zibadianzibadian Posts: 6,349Member
    : If I want to display an image or a text for a certain number of seconds, what code do I use?
    :
    Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    [code]
    repeat
    t := Time();
    DecodeTime(t, h, m, s, hs);
    if s mod 10 = 0 then
    { Do something every 10 seconds }
    until { Some condition }
    [/code]
  • NinthAngleNinthAngle Posts: 98Member
    Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    Hope you dont mind helping a novice.

    : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : :
    : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : [code]
    : repeat
    : t := Time();
    : DecodeTime(t, h, m, s, hs);
    : if s mod 10 = 0 then
    : { Do something every 10 seconds }
    : until { Some condition }
    : [/code]
    :

  • zibadianzibadian Posts: 6,349Member
    : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : Hope you dont mind helping a novice.
    :
    : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : :
    : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : [code]
    : : repeat
    : : t := Time();
    : : DecodeTime(t, h, m, s, hs);
    : : if s mod 10 = 0 then
    : : { Do something every 10 seconds }
    : : until { Some condition }
    : : [/code]
    : :
    :
    :
    As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    [code]
    : : t := Time();
    : : DecodeTime(t, h, m, s, hs);
    s := s + TimeToWait;
    t := EncodeTime(h, m, s, hs)
    repeat until Time() >= t;
    [/code]
  • NinthAngleNinthAngle Posts: 98Member
    Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?

    : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : Hope you dont mind helping a novice.
    : :
    : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : :
    : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : [code]
    : : : repeat
    : : : t := Time();
    : : : DecodeTime(t, h, m, s, hs);
    : : : if s mod 10 = 0 then
    : : : { Do something every 10 seconds }
    : : : until { Some condition }
    : : : [/code]
    : : :
    : :
    : :
    : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : [code]
    : : : t := Time();
    : : : DecodeTime(t, h, m, s, hs);
    : s := s + TimeToWait;
    : t := EncodeTime(h, m, s, hs)
    : repeat until Time() >= t;
    : [/code]
    :

  • zibadianzibadian Posts: 6,349Member
    : Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?
    :
    : : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : : Hope you dont mind helping a novice.
    : : :
    : : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : : :
    : : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : : [code]
    : : : : repeat
    : : : : t := Time();
    : : : : DecodeTime(t, h, m, s, hs);
    : : : : if s mod 10 = 0 then
    : : : : { Do something every 10 seconds }
    : : : : until { Some condition }
    : : : : [/code]
    : : : :
    : : :
    : : :
    : : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : : [code]
    : : : : t := Time();
    : : : : DecodeTime(t, h, m, s, hs);
    : : s := s + TimeToWait;
    : : t := EncodeTime(h, m, s, hs)
    : : repeat until Time() >= t;
    : : [/code]
    : :
    :
    :
    See the help files for the use of Time(), DecodeTime(), and EncodeTime(). These are all predefined functions/procedures. As for the variables, they must match the parameter types of the functions/procedures.
  • NinthAngleNinthAngle Posts: 98Member
    : : Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?
    : :
    : : : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : : : Hope you dont mind helping a novice.
    : : : :
    : : : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : : : :
    : : : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : : : [code]
    : : : : : repeat
    : : : : : t := Time();
    : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : if s mod 10 = 0 then
    : : : : : { Do something every 10 seconds }
    : : : : : until { Some condition }
    : : : : : [/code]
    : : : : :
    : : : :
    : : : :
    : : : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : : : [code]
    : : : : : t := Time();
    : : : : : DecodeTime(t, h, m, s, hs);
    : : : s := s + TimeToWait;
    : : : t := EncodeTime(h, m, s, hs)
    : : : repeat until Time() >= t;
    : : : [/code]
    : : :
    : :
    : :
    : See the help files for the use of Time(), DecodeTime(), and EncodeTime(). These are all predefined functions/procedures. As for the variables, they must match the parameter types of the functions/procedures.
    :

    the help file does not include anything by the name of "Time" "DecodeTime" or "EncodeTime"...? But your right, I should generally check the help file before I ask questions.

  • zibadianzibadian Posts: 6,349Member
    : : : Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?
    : : :
    : : : : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : : : : Hope you dont mind helping a novice.
    : : : : :
    : : : : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : : : : :
    : : : : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : : : : [code]
    : : : : : : repeat
    : : : : : : t := Time();
    : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : : if s mod 10 = 0 then
    : : : : : : { Do something every 10 seconds }
    : : : : : : until { Some condition }
    : : : : : : [/code]
    : : : : : :
    : : : : :
    : : : : :
    : : : : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : : : : [code]
    : : : : : : t := Time();
    : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : s := s + TimeToWait;
    : : : : t := EncodeTime(h, m, s, hs)
    : : : : repeat until Time() >= t;
    : : : : [/code]
    : : : :
    : : :
    : : :
    : : See the help files for the use of Time(), DecodeTime(), and EncodeTime(). These are all predefined functions/procedures. As for the variables, they must match the parameter types of the functions/procedures.
    : :
    :
    : the help file does not include anything by the name of "Time" "DecodeTime" or "EncodeTime"...? But your right, I should generally check the help file before I ask questions.
    :
    :
    Check out GetTime(). If that exists, then you don't need to worry about DecodeTime() and EncodeTime().
  • NinthAngleNinthAngle Posts: 98Member
    : : : : Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?
    : : : :
    : : : : : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : : : : : Hope you dont mind helping a novice.
    : : : : : :
    : : : : : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : : : : : :
    : : : : : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : : : : : [code]
    : : : : : : : repeat
    : : : : : : : t := Time();
    : : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : : : if s mod 10 = 0 then
    : : : : : : : { Do something every 10 seconds }
    : : : : : : : until { Some condition }
    : : : : : : : [/code]
    : : : : : : :
    : : : : : :
    : : : : : :
    : : : : : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : : : : : [code]
    : : : : : : : t := Time();
    : : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : s := s + TimeToWait;
    : : : : : t := EncodeTime(h, m, s, hs)
    : : : : : repeat until Time() >= t;
    : : : : : [/code]
    : : : : :
    : : : :
    : : : :
    : : : See the help files for the use of Time(), DecodeTime(), and EncodeTime(). These are all predefined functions/procedures. As for the variables, they must match the parameter types of the functions/procedures.
    : : :
    : :
    : : the help file does not include anything by the name of "Time" "DecodeTime" or "EncodeTime"...? But your right, I should generally check the help file before I ask questions.
    : :
    : :
    : Check out GetTime(). If that exists, then you don't need to worry about DecodeTime() and EncodeTime().
    :


    Ive modified the program according to your advice. However, I cant assign the time I get from the computer to another variable since pascal always gives me the following error:
    error 143 invalid procedure or function reference

    When I try to assign the time to "t"


    PROGRAM TimerX;
    USES Crt, Dos;
    VAR Time: integer;
    t, h, m, s, hs: word;

    BEGIN
    t := GetTime(h, m, s, hs);
    GetTime(h,m,s,hs);
    s := s + 10;
    {t :=} GetTime(h, m, s, hs);
    repeat until Time() >= t;
    END.


  • zibadianzibadian Posts: 6,349Member
    : : : : : Im not too sure what to place in the Time() brackets and what variable types I should assign to 't' and to 'Time'?
    : : : : :
    : : : : : : : Yes, but I dont want to do something every 10 seconds but have an image displayed at the end of a loop FOR 10 seconds. I cand use delay since I am in image mode...
    : : : : : : : Hope you dont mind helping a novice.
    : : : : : : :
    : : : : : : : : : If I want to display an image or a text for a certain number of seconds, what code do I use?
    : : : : : : : : :
    : : : : : : : : Use Time() to get the system time. Then use DecodeTime() to split the time into hours, minutes, and seconds. Finally use the mod operator on the one of the fields to make the step.
    : : : : : : : : [code]
    : : : : : : : : repeat
    : : : : : : : : t := Time();
    : : : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : : : : if s mod 10 = 0 then
    : : : : : : : : { Do something every 10 seconds }
    : : : : : : : : until { Some condition }
    : : : : : : : : [/code]
    : : : : : : : :
    : : : : : : :
    : : : : : : :
    : : : : : : As you can see this code does rely on the Delay() procedure. To wait for 10 seconds, simply get the time before a loop. Then add the time you want to wait. Finally loop while getting the time until that time is equal or larger than the starting time + time to wait:
    : : : : : : [code]
    : : : : : : : : t := Time();
    : : : : : : : : DecodeTime(t, h, m, s, hs);
    : : : : : : s := s + TimeToWait;
    : : : : : : t := EncodeTime(h, m, s, hs)
    : : : : : : repeat until Time() >= t;
    : : : : : : [/code]
    : : : : : :
    : : : : :
    : : : : :
    : : : : See the help files for the use of Time(), DecodeTime(), and EncodeTime(). These are all predefined functions/procedures. As for the variables, they must match the parameter types of the functions/procedures.
    : : : :
    : : :
    : : : the help file does not include anything by the name of "Time" "DecodeTime" or "EncodeTime"...? But your right, I should generally check the help file before I ask questions.
    : : :
    : : :
    : : Check out GetTime(). If that exists, then you don't need to worry about DecodeTime() and EncodeTime().
    : :
    :
    :
    : Ive modified the program according to your advice. However, I cant assign the time I get from the computer to another variable since pascal always gives me the following error:
    : error 143 invalid procedure or function reference
    :
    : When I try to assign the time to "t"
    :
    :
    : PROGRAM TimerX;
    : USES Crt, Dos;
    : VAR Time: integer;
    : t, h, m, s, hs: word;
    :
    : BEGIN
    : t := GetTime(h, m, s, hs);
    : GetTime(h,m,s,hs);
    : s := s + 10;
    : {t :=} GetTime(h, m, s, hs);
    : repeat until Time() >= t;
    : END.
    :
    :
    :
    The t variable is not necessary anymore, since GetTime() is a procedure (see help files). Also, you've created a perfect infinite loop. Here's the correct code:
    [code]
    VAR
    t, h, m, s, hs: word;

    BEGIN
    GetTime(h, m, s, hs);
    t := m*60+s + 10;
    repeat
    GetTime(h, m, s, hs); { get the time within the loop to update
    the variables every step of the loop }
    until m*60+s >= t;
    END.
    [/code]

Sign In or Register to comment.