Sub Stage()
buttons=0 // init buttons BEFORE entering loop
Repeat
// first loop goes here...
Until (Buttons = 3) //3
buttons=0 // init buttons BEFORE entering loop
Repeat
// second loop goes here...
Until (Buttons = 3) //3
end sub
That's YOUR assumption as to what's going on.The leds indicate the code is progressing but the code reverts back to the first loop? as in post #60
Sub Stage()
// 'buttons' holds keypressed info...
// bit 0=Go_1 pressed and bit 1=Go_2 pressed
dim buttons as byte
buttons=0 // clear keypressed info
Repeat
If (blue1 = 0) Then
If (Go_1 = 0) And (blue1 = 0) Then // player2 button press...
blue1=1
blue2=0
buttons.bits(0) = 1
EndIf
If (Go_2 = 0) And (blue_1 = 0) Then // player2 button press...
blue_1=1
blue_2=0
buttons.bits(1) = 1
EndIf
EndIf
Until (buttons = 3) // both keys have been pressed
red=1
delayms(500)
red=0
delayms(500)
buttons=0 // clear keypressed info
Repeat
If (Go_1 = 0) And (blue2 = 0) Then // player1 button press...
blue1=1
blue2=1
buttons.bits(0) = 1
EndIf
If (Go_2 = 0) And (blue_2 = 0) Then // player2 button press...
blue_1=1
blue_2=1
buttons.bits(1) = 1
EndIf
Until (buttons = 3) // both keys have been pressed
green=1
delayms(500)
green=0
delayms(500)
End Sub
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/23/2020 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
{
*****************************************************************************
* 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 FOSC = INTIO67 'internal oscillator
//Config MCLRE = off
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
#option DIGITALIO_INIT = true
Include "setdigitalio.bas"
Include "utils.bas"
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "intosc.bas"
Include "isrtimer.bas"
Include "utils.bas"
Include "convert.bas"
// read the AD port and scale for 0 - 5 volts...
Function Player_1_Volt() As Word
result = (ADC.Read(0)) //porta.0
End Function
Function Player_2_volt() As Word
result = (ADC.Read(1)) //porta.1
End Function
// sampled AD value...
Dim led As PORTC.7 //test yellow
Dim gear1_led As PORTD.0 // player1 shift led
Dim gear2_led As PORTD.1 // player1 shift led
Dim Gear1_Press As PORTC.2 //player1 shift button
Dim Gear2_press As PORTC.3 //player2 shift button
//white player2
Dim SHIFT1 As Byte
Dim yellow1 As PORTB.1 //yellow1
Dim yellow2 As PORTB.2 //yellow3
Dim yellow3 As PORTB.3
Dim green As PORTB.4 // yellow
Dim red As PORTB.5
Dim blue2 As PORTB.0 //player1 stage1
Dim blue1 As PORTB.7 //player1 stage2
Dim blue_1 As PORTC.6
Dim blue_2 As PORTC.5
Dim counter As Byte
Dim ms As Word
Dim RT1 As Word
Dim RT2 As Word
Dim Go_1 As PORTA.7
Dim Go_2 As PORTA.6
Dim Buttons As Byte
Dim stage1 As Byte //blue leds
Dim stage2 As Byte
Dim index1 As Byte
Dim index2 As Byte
Dim counter1 As Byte
Dim counter2 As Byte
Dim x As LongWord
Dim gear1 As Word
Dim gear2 As Word
Dim Stage_press As LongWord
Sub OnTimer()
Inc(ms)
End Sub
Sub test1()
blue1=1
blue_1=1
DelayMS(2000)
Toggle(blue1)
Toggle(blue_1)
DelayMS(2000)
End Sub
Sub TEST()
gear1_led=1
gear2_led=1
Buttons = 0
Repeat //shift1
If (Gear1_Press = 0) And (gear1_led= 1) Then // player1 button press...
DelayMS(300)
Buttons = Buttons Or 1
gear1_led=0
DelayMS(300)
EndIf
If (Gear2_press= 0) And (gear2_led = 1) Then // player2 button press...
DelayMS(300)
Buttons = Buttons Or 2
gear2_led=0
DelayMS(300)
EndIf
Until (Buttons = 3) //3
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
gear1_led=1
gear2_led=1
Buttons = 0
Repeat //shift2
If (Gear1_Press = 0) And (gear1_led= 1) Then // player1 button press...
DelayMS(300)
Buttons = Buttons Or 1
gear1_led=0
DelayMS(300)
EndIf
If (Gear2_press= 0) And (gear2_led = 1) Then // player2 button press...
DelayMS(300)
Buttons = Buttons Or 2
gear2_led=0
DelayMS(300)
EndIf
Until (Buttons = 3) //3
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
gear1_led=1
gear2_led=1
Buttons = 0
Repeat //shift3
If (Gear1_Press = 0) And (gear1_led= 1) Then // player1 button press...
DelayMS(300)
Buttons = Buttons Or 1
gear1_led=0
DelayMS(300)
EndIf
If (Gear2_press= 0) And (gear2_led = 1) Then // player2 button press...
DelayMS(300)
Buttons = Buttons Or 2
gear2_led=0
DelayMS(300)
EndIf
Until (Buttons = 3) //3
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
gear1_led=1
gear2_led=1
Buttons = 0
Repeat //shift4
If (Gear1_Press = 0) And (gear1_led= 1) Then // player1 button press...
DelayMS(300)
Buttons = Buttons Or 1
gear1_led=0
DelayMS(300)
EndIf
If (Gear2_press= 0) And (gear2_led = 1) Then // player2 button press...
DelayMS(300)
Buttons = Buttons Or 2
gear2_led=0
DelayMS(300)
EndIf
Until (Buttons = 3) //3
End Sub
// display results
Sub Display()
Dim s As String
Cls
s=DecToStr(RT1/1000)+"."+DecToStr((RT1 Mod 1000))
WriteAt(2,1,"timer1 win") //display players score
WriteAt(1,1,"rt1 ",s," ")
s=DecToStr(RT2/1000)+"."+DecToStr((RT2 Mod 1000))
WriteAt(3,1,"timer2 ") //display players score
WriteAt(4,1,"rt2 ",s," ")
DelayMS(5000)
Cls
s=DecToStr(gear1/1000)+"."+DecToStr((gear1 Mod 1000))
WriteAt(1,1,"timer1 ") //display players score
WriteAt(2,1,"GEAR1 ",s," ")
s=DecToStr(gear2/1000)+"."+DecToStr((gear2 Mod 1000))
WriteAt(3,1,"timer2 ") //display players score
WriteAt(4,1,"GEAR2 ",s," ")
DelayMS(10000)
Cls
' WriteAt(1,1,"counter1 = " ,DecToStr(counter1))
'WriteAt(3,1,"counter2 = " ,DecToStr(counter2))
End Sub
Sub Foul()
If 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
Sub End_of_game()
blue1=0 //led is off
blue2=0
blue_1=0
blue_2=0
yellow1=0
yellow2=0
yellow3=0
green=0
red=0
DelayMS(2000)
End Sub
Sub Stage()
//#1
Repeat
'buttons=0
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
counter1=1
EndIf
If (Go_2 = 0) And (blue_2= 0) Then // player2 button press...
blue_1=1
blue_2=1
Buttons = Buttons Or 2
counter2=1
EndIf
'writeat(1,1,"buttons",dectostr(buttons))
' delayms(4000)
Until (Buttons = 3) //3
green=1
DelayMS(500)
green=0
DelayMS(500)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Timer.Start
Repeat
'stage_press=stage_press+1
DelayMS(500)
If (Go_1 = 0) And counter1=1Then // player1 button press...
blue1=0
blue2=1
'Buttons = Buttons Or 1
EndIf
If(Go_2 = 0) And counter2=1Then // player2 button press...
blue_1=0
blue_2=1
'Buttons = Buttons Or 2
EndIf
' endif
Until ms=7000
yellow1=1
DelayMS(500)
yellow1=0
DelayMS(500)
End Sub
Sub Start_race()
Repeat
If (Go_1 = 0) And (RT1 = 0) Then // player1 button press...
RT1 = ms
Buttons = Buttons Or 1
EndIf
If (Go_2 = 0) And (RT2 = 0) Then // player2 button press...
RT2 = ms
Buttons = Buttons Or 2
EndIf
Until (Buttons = 3) //3
End Sub
Sub Gear_shifts() //lowest rt is first shift light to come on
For x = 0 To 3 //4 shifts
gear1_led=1
gear2_led=1
DelayMS(400)
Repeat //gear1
If gear1_led=1 And(Gear1_Press = 0) Then // player1 button press...
gear1_led=0
Buttons = Buttons Or 1
' delayms(500) //a FLAG to keep track
' delayms(500)
'gear1_led=0
'gear2_led=0
'delayms(500)
'EndIf
'gear2_led=1
If gear2_led=1 And(Gear2_press = 0) Then // player2 button press...
gear2_led=0
Buttons = Buttons Or 2
DelayMS(500)
'delayms(500)
'gear2_led=0
'delayms(500)
EndIf
EndIf
Until (Buttons = 3) //3
Buttons=0
Next
'GEAR1_LED=0 //turn off shift leds
'gear2_led=0
gear1=ms+RT1
gear2=ms+RT2
End Sub
'SetAllDigital
Buttons=0
x=0
Output(gear1_led)
Output(gear2_led)
Output(blue1)
Output(blue2)
Output(yellow1)
Output(yellow2)
Output(yellow3)
Output(green)
Output(red)
Output(blue_1)
Output(blue_2)
Output(led)
Low(gear1_led) // make led outputs, set 0
Low(gear2_led)
Low(blue1)
Low(blue2)
Low(yellow1)
Low(yellow2)
Low(yellow3)
Low(green)
Low(red)
index1=0 //keep track of staging lights
index2=0
counter1=0
counter2=0
counter=0
stage1=0
stage2=0
Stage_press=0
Input(Go_1) //button press A.7
Input(Go_2) //button press A.6
gear1=0
gear2=0
Input(Gear2_press)
Input(Gear1_Press)
//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
led=1
DelayMS(100)
Stage()
'test1()
Wend
{
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
RT1 = 0
RT2 = 0
green=1
SHIFT1=0
Buttons = 0
Timer.Start() //start race
Start_race()
//both players are deep staged
'for x = 0 to 3
'DelayMS(500)//1.5 SECONDS BEFORE FIRST SHIFT
'gear1_led=1 //TURN LED ON
'gear2_led=1 //led on
'if gear1_press=0 then
'toggle(gear1_led)
'if gear2_press=0 then
'toggle(gear2_led)
'endif
'endif
'next
'DelayMS(500)
Timer.Stop
'Timer.Adjust(-1500)
Timer.Start
' gear_shifts()
TEST()
Timer.Stop()
Display() //display timer1 and timer2
skipcode:
'WriteAt(1,1,"gear11 = " ,DecToStr(gear1))
' WriteAt(3,1,"gear2 = " ,DecToStr(gear2))
' DelayMS(3000)
Foul()
End_of_game()
Wend
See in the big red circle how you reset buttons =:0 after the first repeat/until loop?
Follow the big red arrow. Notice how you don't reset it after the second repeat/until loop?
So the next time you get to that subroutine, what happens? Whether or not the buttons are pressed, buttons = 3 and the red LED turns on.
Tumbleweed is also reseting buttons =:0 for each repeat/until loop, just in a better way. Either will work. Time to THINK about how the code reacts.
I never should have asked.here is my entire code
If you're happy with that, more power to you!It appears to work but?
**SIGH**But in the code you just posted, the one line you needed to add STILL isn't there.
**SIGH**
You mean the one that makes it work? The one that SETS BUTTONS=0 BEFORE CALLING STAGE() A SECOND TIME?
Oh, I see now. You're talking about the ONE LINE THAT THIS ENTIRE PAGE OF POSTS HAS BEEN POINTING OUT.Yeah, that would be the one....THE ONE SPECIFICALLY ASKED ABOUT IN THE LATEST VOLLEY.
Sub Stage()
//#1
index1=0
Repeat
If (Go_1 = 0) And (blue1 = 0) Then // player1 button press...
blue1=1
blue2=0
index1 = index1 Or 1
EndIf
If (Go_2 = 0) And (blue_1= 0) Then // player2 button press...
blue_1=1
blue_2=0
index1 = index1 Or 2
EndIf
Until (index1 = 3) //3
red=1 // code progression indication
DelayMS(500)
red=0
DelayMS(500)
//stage#2
index1=0
Repeat
If (Go_1 = 0) And (blue2 = 0)Then // player1 button press...
blue1=1
blue2=1
index1 = index1 Or 1
counter1=1
EndIf
If (Go_2 = 0) And (blue_2= 0) Then // player2 button press...
blue_1=1
blue_2=1
index1 = index1 Or 2
counter2=1
EndIf
Until (index1 = 3) //3
green=1 // code progression indication
DelayMS(500)
green=0
DelayMS(500)
//DEEP STAGING
'Timer.Start
index1=0 //this section needs to exit AFTER 7 SECONDS
Repeat
If (Go_1 = 0) And counter1=1Then // player1 button press...
blue1=0
blue2=1
index1=index1 Or 1
EndIf
If(Go_2 = 0) And counter2=1Then // player2 button press...
blue_1=0
blue_2=1
index1=index1 Or 2
EndIf
Until ms=700 //need to time for 7 seconds
yellow1=1
DelayMS(500) // code progression indication
yellow1=0
DelayMS(500)
...got the stage sub route to work....
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?