Return to the Home Page...
Features on BBC BASIC programming...
Your questions and answers...
Buy or Sell an NC...
The NC200 manual and data sheets for BBC BASIC...
Information about BBC BASIC on the NC...
Free software for you to download...

Tim's Amstrad NC Users' Site

Lap-Time Program

By Ian Greenwood
Extra program notes by Tim Surtell

As users will know, NC100's are unprecedented in their lightness, portability, practicality, etc. To add to this, BBC BASIC is a widely-used and powerful programming language providing as much power as most users will realistically want.
As such they are ideally suited to work 'out in the field' by users, and adaptation to fresh tasks.

As a hobby of mine is watching motor racing, I wondered if I could use my NC100 to assist. Again as users will know, there is a powerful built-in and accurate clock, so it was fairly easy to devise a program to record lap times, by pressing the T key. Taking this on a stage further, it became possible (with the help of comp.sys.acorn.misc) to program in the length of the circuit and from that to get average lap speeds. In the program you will see that it is set to a lap distance of 1.84 miles. Note too how the program writes the times recorded to a file called "TIMES" (this was the part that caused most problems).

The program would be of some use where any kind of time/distance/speed calculations needed to be made.

Here is the program listing:

Lap-time Program ... 1.1kb

10 REM ****************
20 REM Laptime Program
30 REM By Ian Greenwood
40 REM ****************
50 REM NC100/200 Version 1.1
60 REM Downloaded from Tim's NC Users' Site
70 REM
80 CLS
90 LAP=1.84:REM Miles
100 VDU 17
120 VDU 18
140 IF D$="Q" GOTO 340
150 PRINT "TIMING....."'
160 TIME=0
180 X=GET
190 UNTIL X=84 OR X=116 OR X=81
200 IF X=81 GOTO130
210 Y=TIME/100
220 A=Y/LAP
230 Z=3600/A
240 Z$=STR$(Z)
250 K$=LEFT$(Z$,6)
260 PRINT D$ Y " SECONDS "K$ " MPH "
270 Channel=OPENIN"TIMES"
280 CLOSE#Channel
290 IFChannel=0 Channel=OPENOUT"TIMES":PRINT#Channel,"Times from Laptime program"+CHR$13+CHR$13+">-----------------!---------------!-----------!----------------------R" ELSEChannel=OPENUP"TIMES"
300 PTR#Channel=EXT#Channel
310 PRINT #Channel,D$+CHR$9+STR$Y+" SECONDS"+CHR$9+K$+" MPH "+CHR$9+TIME$
320 CLOSE#Channel
330 GOTO160
340 END

Before the program is run, set the variable 'LAP' to the distance of the race track in miles. Run the program and type in the driver's name and number. When ENTER is pressed timing will start. Press T each time a lap is finished -- the time and average speed will be shown. Press Q to enter a new driver's name. Press Q and ENTER here to quit.

The times for the race will be stored in a file called 'TIMES'.
This file can be displayed in the word processor, where each item will be properly tabulated.

Program Analysis:

Line 90 The variable 'LAP' holds the length of the race track in miles.

Lines 160 to 190 These take care of the timing. The NC's internal clock is set to zero in line 160 and then a loop is entered which waits until either T or Q is pressed.

Line 200 If Q is pressed the program returns to line 130 where the name of a new driver is entered.

Lines 210 to 250 Convert the time to seconds and work out the average speed in mph. Line 240 turns this number into a string, then line 250 removes unnecessary decimal places.

Lines 270 to 290 Check to see if the file 'TIMES' has already been created. If it hasn't, it is opened and the title and ruler line (for the word processor)are stored.

Line 300 Moves the file pointer to the end of the file (if it wasn't already).

Line 310 Stores the driver's name, time and average speed, plus the time and date of the reading. The CHR$9 is the tab character used to tabulate the columns of data.
1997 – 2024 Tim Surtell

Tim's Amstrad NC Users' Site

Return to top of page...

| Home | Features | Data Sheets | Questions | BBC BASIC | Software |