MrDEB
Well-Known Member
During this pandemic one needs to find a way to pass the time and not waste watching the boob tube so I have a very simple swordfish code that seems to work very well AFTER I used the GOTO statement.
This is a simplistic drag race simulator/reaction timer. Plan to use a 4x20 lcd and making it a two player game.
Thinking of adding a 4 pole coded rotary switch to adjust the Christmas tree countdown (there are several different ones used on legal drag strips. The timing between each bulb) and adding a shift light to indicate when to "shift gears". A missed shift could cost you the race.
As an example, a pro-stock car shifts at about 10,000 rpm.
anyway here is my basic code if anyone wants something to pass the time away. A schematic is kind-a self explanatory.
This is a simplistic drag race simulator/reaction timer. Plan to use a 4x20 lcd and making it a two player game.
Thinking of adding a 4 pole coded rotary switch to adjust the Christmas tree countdown (there are several different ones used on legal drag strips. The timing between each bulb) and adding a shift light to indicate when to "shift gears". A missed shift could cost you the race.
As an example, a pro-stock car shifts at about 10,000 rpm.
anyway here is my basic code if anyone wants something to pass the time away. A schematic is kind-a self explanatory.
Code:
Device = 18F43k22
Clock = 8
//Config MCLRE = off
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// import LCD library...
Include "SetDigitalIO.bas"
Include "IntOSC.bas"
Include "LCD.bas"
Include "utils.bas"
'INCLUDE "Keypad16pullup.bas"
Include "Convert.bas"
Include "isrtimer.bas"
Dim s As String
Dim mS As Word
Dim GO As PORTC.2
Dim green As PORTE.0
Dim red As PORTE.1
Dim blue1 As PORTA.1
Dim blue2 As PORTA.2
Dim yellow1 As PORTA.3
Dim yellow2 As PORTA.4
Dim YELLOW3 As PORTA.5
Dim Reset As PORTC.0
Dim x As Byte
Sub Int_Timer()
Timer.Initialize(1)
Timer.Items(0).interval=1 //ms
Timer.Items(0).OnTimer=@OnTimer //timer event handler
//enable timers
Timer.Items(0).enabled=true
If GO=0 Then //insert this into all the sub sequences but only last key in sequence
Timer.Stop //need to insert GETKEY
End If
End Sub
//RED LIGHT FOUL
Sub Foul()
If GO=0 And green = 0 Then
red=1
WriteAt(1,1,"FOUL" )
DelayMS(3000)
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red=0
Cls
EndIf
End Sub
// OnTimer event, flash LED...
Sub OnTimer()
Inc(mS)
End Sub
Sub ET_time() //dis[;ay results
Timer.Stop //stop timer
Cls
s=DecToStr(mS/1000)+"."+DecToStr((mS Mod 1000))
WriteAt(1,1,"reaction ") //display players score
WriteAt(2,1,"seconds ",s," ")
DelayMS(5000)
Cls
End Sub
Sub End_of_game()
blue1 = 0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red=0
DelayMS(2000)
End Sub
Output (blue1)
Output(blue2)
Output(yellow1)
Output(yellow2)
Output(YELLOW3)
Output (green)
Output(red)
Input(GO) //button press
GO = 1 //input
blue1=0 //led
blue2=0 //led
green = 0 //led
mS=0 //timer set to zero
// initialise the timer module...
Timer.Initialize(1)
// initialise timer.items(0)
Timer.Items(0).Interval = 1 // 1mS
Timer.Items(0).OnTimer = @OnTimer // timer event handler
// enable the timers...
Timer.Items(0).Enabled = true
SetAllDigital
//START OF GAME
While True
'mS = 0
blue1=1
If GO=0 and green=0
goto skipcode
DelayMS(1000)
blue2=1
If GO=0 and green=0
goto skipcode
DelayMS(1000)
yellow1=1
If GO=0 and green=0
goto skipcode
DelayMS(500)
yellow2=1
If GO=0 and green=0
goto skipcode
DelayMS(500)
YELLOW3=1
If GO=0 and green=0
goto skipcode
DelayMS(500)
If GO=0 And green = 0 //Then //green = 0
goto skipcode
delayms(200)
green=1
timer.start
repeat
Until
go = 0
ET_time()
ms=0
skipcode:
foul()
end_of_game()
Wend