timer

GFA BASIC-related articles in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
sashapont
Captain Atari
Captain Atari
Posts: 153
Joined: Sat Jun 03, 2017 9:40 pm

timer

Post by sashapont »

I have ode

Code: Select all

IF a<2
a=a+1
else
a=0
ENDIF
Print a
How I can create timer for endless repeat it after one second?
Atari Falcon, Firebee
vido
Atari Super Hero
Atari Super Hero
Posts: 719
Joined: Mon Jan 31, 2011 7:39 pm

Re: timer

Post by vido »

You would like to increase "a" every second while the other code is running?
sashapont
Captain Atari
Captain Atari
Posts: 153
Joined: Sat Jun 03, 2017 9:40 pm

Re: timer

Post by sashapont »

Yes and Print a too, because delay and pause is not usable for me I want create timer
Atari Falcon, Firebee
vido
Atari Super Hero
Atari Super Hero
Posts: 719
Joined: Mon Jan 31, 2011 7:39 pm

Re: timer

Post by vido »

sashapont wrote:Yes and Print a too, because delay and pause is not usable for me I want create timer
I did it with the timer function in my main loop long time ago:
  • TIMER
    Syntax: t%=TIMER
    Action: TIMER suuplies the elapsed time in 1/200 seconds since the
    system was started.

    Example: t%=TIMER
    FOR i%=1 TO 2500
    NEXT i%
    PRINT (TIMER-t%)/200;" Seconds"

Code: Select all

t%=TIMER
REPEAT
  IF TIMER-t% >= 200
    IF a<2
      a=a+1
    ELSE
      a=0
    ENDIF
    t%=TIMER
  ENDIF
  >> OTHER CODE
UNTIL
It is not exactly one second but it depends how accurate timer should be and you can adjust a bit "200" value depended on the other code.
Post Reply

Return to “GFA BASIC”