dim buttons as byte
dim timer1, timer2 as word
//initialize timer
Timer.Initialize(1)
Timer.Items(0).interval=1 //ms
Timer.Items(0).OnTimer=@OnTimer //timer event handler
Timer.Items(0).enabled=true
// add your while loop and countdown code here...
// start race
green=1
mS = 0
timer1 = 0
timer2 = 0
Timer.Start()
buttons = 0
repeat
if (GO_1 = 0) and (timer1 = 0) then // player1 button press...
timer1 = mS
buttons = buttons or 1
endif
if (GO_2 = 0) and (timer2 = 0) then // player2 button press...
timer2 = mS
buttons = buttons or 2
endif
until (buttons = 3)
ET_time() //display timer1 and timer2
Timer.Stop()
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/11/2020 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
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"
Include "EEPROM.bas"
Dim s As String
Dim mS As Word
Dim GO_1 As PORTC.0 //goes LOW when player presses switch
Dim GO_2 As PORTC.2 //goes LOW when player presses switch
Dim green As PORTE.0
Dim red_1 As PORTE.1
Dim red_2 As PORTE.3
Dim Shift_led As PORTA.0 //SHIFT LED
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 S_press As PORTC.0 //SHIFT BUTTON
Dim x As Byte //USED FOR SHIFT POINTS
Dim RT_1 As LongWord //REACTION TIME player 1
Dim RT_2 As LongWord //REACTION TIME player 2
Dim ET_1 As LongWord //elasped time player 1
Dim ET_2 As LongWord //elasped time player 2
Dim Start_Time_1 As Word
Dim Start_Time_2 As Word
Dim End_Time_1 As Word
Dim End_Time_2 As Word
Dim timer1 As Word
Dim timer2 As Word
Dim buttons As Byte
Sub OnTimer()
Inc(mS)
End Sub
Sub Display()
//dispay results
Timer.Stop //stop timer
Cls
s=DecToStr(timer1/1000)+"."+DecToStr((timer1 Mod 1000))
WriteAt(1,1,"timer1 ") //display players score
WriteAt(2,1,"seconds ",s," ")
s=DecToStr(timer2/1000)+"."+DecToStr((timer2 Mod 1000))
WriteAt(3,1,"timer2 ") //display players score
WriteAt(4,1,"seconds ",s," ")
// EE.Write(6,RT_1)
// EE.Write(6,RT_1)
DelayMS(5000)
Cls
End Sub
Sub Foul()
If GO_1=0 And green = 0 Then
red_1=1
WriteAt(1,1,"FOUL" )
DelayMS(3000)
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red_1=0
Cls
EndIf
End Sub
Sub End_of_game()
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red_1=0
DelayMS(2000)
End Sub
//initialize timer
Timer.Initialize(1)
Timer.Items(0).interval=1 //ms
Timer.Items(0).OnTimer=@OnTimer //timer event handler
Timer.Items(0).enabled=true
mS=0
'timer1=mS
'timer2=mS
Start_Time_1=mS
Start_Time_2=mS
End_Time_1=mS
End_Time_2=mS
Output(Shift_led)
Output (blue1)
Output(blue2)
Output(yellow1)
Output(yellow2)
Output(YELLOW3)
Output (green)
Output(red_1)
Input(GO_1) //button press
Input(GO_2) //button press
//Input(S_press)//shift button
//GO_1 = 1 //input
blue1=0 //led
blue2=0 //led
green = 0 //led
mS=0 //timer set to zero
SetAllDigital
//initialize timer
Timer.Initialize(2)
Timer.Items(1).interval=1 //ms
Timer.Items(1).OnTimer=@OnTimer //timer event handler
Timer.Items(2).interval=1 //ms
Timer.Items(2).OnTimer=@OnTimer //timer event handler
//enable timers
Timer.Items(1).enabled=true
'Timer.Items(2).enabled=true
'mS = 0
'Timer.Start()
// add your while loop and countdown code here...
While True
DelayMS(1000)
blue1=1 //first stage light
If GO_1=0 And green=0
GoTo skipcode //skipcode is a foul start
DelayMS(1000)
blue2=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(1000)
yellow1=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
yellow2=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
YELLOW3=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
If GO_1=0 And green = 0 //Then //green = 0
GoTo skipcode
DelayMS(200)
// start race
green=1
mS = 0
timer1 = 0
timer2 = 0
Timer.Start()
buttons = 0
Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
buttons = buttons Or 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
buttons = buttons Or 2
EndIf
Until (buttons = 3)
Display() //display timer1 and timer2
Timer.Stop()
skipcode:
Foul()
End_of_game()
Wend
green=1 //start race
timer1=0
timer2=0
Repeat
Timer.Start
Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
counter = counter + 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
counter = counter +1
EndIf
Until (counter >= 2)
Display() //display timer1 and timer2
Timer.Stop()
Until (counter = 3)
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/11/2020 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
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 "Convert.bas"
Include "isrtimer.bas"
Include "EEPROM.bas"
Dim GO_1 As PORTC.0 //goes LOW when player presses switch
Dim GO_2 As PORTC.2 //goes LOW when player presses switch
Dim green As PORTE.0
Dim red_1 As PORTE.1
Dim red_2 As PORTE.3
Dim Shift_led As PORTA.0 //SHIFT LED
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 S_press As PORTC.0 //SHIFT BUTTON
Dim mS As Word
Dim timer1 As Word
Dim timer2 As Word
Dim buttons As Byte
Sub OnTimer()
Inc(mS)
End Sub
// display results
Sub Display()
Dim s As String
Cls
s=DecToStr(timer1/1000)+"."+DecToStr((timer1 Mod 1000))
WriteAt(1,1,"timer1 ") //display players score
WriteAt(2,1,"seconds ",s," ")
s=DecToStr(timer2/1000)+"."+DecToStr((timer2 Mod 1000))
WriteAt(3,1,"timer2 ") //display players score
WriteAt(4,1,"seconds ",s," ")
DelayMS(5000)
Cls
End Sub
Sub Foul()
If green = 0 Then
red_1=1
WriteAt(1,1,"FOUL" )
DelayMS(3000)
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
yellow3=0
green=0
red_1=0
Cls
EndIf
End Sub
Sub End_of_game()
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
yellow3=0
green=0
red_1=0
DelayMS(2000)
End Sub
SetAllDigital
low(Shift_led) // make led outputs, set 0
low(blue1)
low(blue2)
low(yellow1)
low(yellow2)
low(yellow3)
low(green)
low(red_1)
Input(GO_1) //button press
Input(GO_2) //button press
//Input(S_press)//shift button
//initialize timer
Timer.Initialize(1)
Timer.Items(0).interval=1 //ms
Timer.Items(0).OnTimer=@OnTimer //timer event handler
Timer.Items(0).enabled=true
// add your while loop and countdown code here...
While True
DelayMS(1000)
blue1=1 //first stage light
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(1000)
blue2=1
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(1000)
yellow1=1
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(500)
yellow2=1
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(500)
yellow3=1
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(500)
If (GO_1 = 0) or (GO_2 = 0) GoTo skipcode //skipcode is a foul start
DelayMS(200)
// start race
mS = 0
timer1 = 0
timer2 = 0
green=1
Timer.Start()
buttons = 0
Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
buttons = buttons Or 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
buttons = buttons Or 2
EndIf
Until (buttons = 3)
Display() //display timer1 and timer2
Timer.Stop()
skipcode:
Foul()
End_of_game()
Wend
//start race
mS=0
green=1
timer1=0
timer2=0
Repeat
Timer.Start
'Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
counter = counter + 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
counter = counter +2
EndIf
Until (counter = 3)
Timer.Stop()
Display() //display timer1 and timer2' Until (counter = 3)
// start race
mS = 0
timer1 = 0
timer2 = 0
green=1
Timer.Start()
buttons = 0
Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
buttons = buttons Or 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
buttons = buttons Or 2
EndIf
Until (buttons = 3)
Display() //display timer1 and timer2
Timer.Stop()
You did when you copy-pasted code from the help file.I don't think I used multiple timers but?
In this particular case they end up being the same.Am I to assume using a FLAG as Tumbleweed did (buttons) performs just like a counter as in my example?
buttons = 0
Repeat
If (GO_1 = 0) And (timer1 = 0) Then // player1 button press...
timer1 = mS
buttons.bits(0) = 1
EndIf
If (GO_2 = 0) And (timer2 = 0) Then // player2 button press...
timer2 = mS
buttons.bits(1) = 1
EndIf
Until (buttons = 3) // 3 is buttons.0=1 and buttons.1=1 (1 + 2)
dim buttons as byte
dim but1 as buttons.bits(0),
but2 as buttons.bits(1),
but3 as buttons.bits(2),
but4 as buttons.bits(3)
buttons = 1
but1 = 1
but2 = 0
if (but1 = 1) or (but2 = 0) then...
if (buttons = %1010) then...
Sub Stage()
//#1
Repeat
If (Go_1 = 0) And (blue1 = 0) Then // player1 button press...
blue1=1
blue2=0
Buttons = Buttons Or 1
EndIf
If (Go_2 = 0) And (blue_1= 0) Then // player2 button press...
blue_1=1
blue_2=0
Buttons = Buttons Or 2
EndIf
Until (Buttons = 3) //3
red=1
delayms(500)
red=0
delayms(500)
buttons=0
Repeat
If (Go_1 = 0) And (blue2 = 0)Then // player1 button press...
blue1=1
blue2=1
Buttons = Buttons Or 1
EndIf
If (Go_2 = 0) And (blue_2= 0) Then // player2 button press...
blue_1=1
blue_2=1
Buttons = Buttons Or 2
EndIf
Until (Buttons = 3) //3
green=1
delayms(500)
green=0
delayms(500)
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?