Pico help config


Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 2085
Posted: 01:33pm 22 Oct 2021      

Hi Lewis,

You're dealing with the real world, and I'm just a poor software engineer who likes writing games. Does this help:

'Const DURATION% = 5 * 60 * 1000 ' 5 minutes - for reality
Const DURATION% = 10 * 1000 ' 10 seconds - for testing
Dim speed% = 5

Print "Speed" speed%

' Sit in a loop, "A" accelerates, "Z" decelerates.
Do
 Select Case UCase$(Inkey$)
   Case "A" : speed% = Min(10, speed% + 1) : Print "Speed" speed%
   Case "Z" : speed% = Max(0, speed% - 1) : Print "Speed" speed%
 End Select

 ' If speed has been <= 2 mph for more than DURATION% milliseconds then exit loop.
 If is_stopped%(speed%) Then Exit Do
Loop

Print "I have stopped"
End

Function is_stopped%(speed%)
 Static start% = 0
 If speed% >= 3 Then
   start% = 0
   Exit Function
 EndIf

 Local now% = Timer ' You don't use VAL() as TIMER isn't a string.
 If start% = 0 Then
   start% = now%
 ElseIf now% >= start% + DURATION% Then
   is_stopped% = 1
 EndIf
End Function


Best wishes,

Tom
Edited 2021-10-22 23:35 by thwill