this is a rough draft that still needs cleaning up but it appears to work as desired.
Any suggestions appreciated.
Code: Select all
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 3/18/2017 *
* Version : 1.0 *
* Notes : Bullet train game *
* : *
*****************************************************************************
SET TIME BY PESSING tIME SWITCH {red led switch) to change tme of play
each press equals (1 PRESS = 250, 2 PRESS = 500, 3 PRESS = 750 )DELAYMS, (red led Portc.6 blinks for amount of time set)
first player that has the double domino required, presses the start button
1st green led comes ON then sequences from green portb.0 etc to red portc.5
to begin game after time is set, player presses red button C.5 this starts the countdown to red
When a player completes his/her turn he/she presses the red button and sequence starts again
Whemn a player times out the sequence automatically re-starts (countdown in a sub routine)
}
{
DEVICE = 18f2221
CLOCK = 8
INCLUDE "INTOSC8.bas"
INCLUDE "SetDigitalIO.bas"
}
DEVICE = 18F2420 ' Tell the compiler what chip we are using
CLOCK = 8 ' Tell the compiler what we will be setting the clock to (in Mhz)
CONFIG MCLRE = OFF
'CONFIG FOSC = intio67 ' Internal oscillator, IO on pins 6 and 7
'CONFIG BOREN = OFF
INCLUDE "utils.bas"
INCLUDE "convert.bas"
INCLUDE "InternalOscillator.bas"
DIM PRESS AS BYTE // end of players turn portB.5 used as an index pointer
DIM Time AS WORD
DIM index AS WORD
'DIM set AS portc.0 // CHANGES DELAYMS VARIABLE test
DIM x AS BYTE // BYTE IN FOR NEXT LOOPS
DIM red0 AS portc.0 //led test
DIM red1 AS portc.1
DIM red2 AS portc.2
DIM red3 AS portc.3
DIM red4 AS portc.4
DIM red5 AS portc.5 //led test
DIM red6 AS portc.6
DIM red7 AS portc.7
dim value as byte
DIM swt AS portB.1 // switch test
'DIM red2 AS portb.2
'DIM sec AS portb.4
DIM Buttonpress AS BYTE
DIM swt1 AS portb.0
DIM swt2 AS portb.4
DIM counter AS WORD
INTERRUPT MyInt()
END INTERRUPT
SUB Sequence() // set all green etc to = 0
while true
TOGGLE (red0) // turn on
DELAYMS(Time) // define time amount
TOGGLE (red0) // turn off
inc (index) // index = 1
if swt2 = 0 and index <=2
then
exit
else
swt2 = 1
end if
delayms(time)
TOGGLE (red1)
DELAYMS(Time) // define time amount
TOGGLE (red1)
INC (index)
if swt2 = 0 and index >=2
then
exit
else
swt2 = 1
end if
delayms(time)
'#2
TOGGLE (red2)
DELAYMS(Time)
TOGGLE (red2)
INC (index)
if swt2 = 0 and index >=3
then
exit
else
swt2 = 1
end if
delayms(time)
'#3
TOGGLE (red3)
DELAYMS(Time)
TOGGLE (red3)
INC (index)
if swt2 = 0 and index >=5
then
exit
else
swt2 = 1
end if
delayms(time)
'#4
TOGGLE (red4)
DELAYMS(Time)
TOGGLE (red4)
INC (index)
if swt2 = 0 and index >=6
then
exit
else
swt2 = 1
end if
delayms(time)
'#5
TOGGLE (red5)
DELAYMS(Time)
TOGGLE (red5)
INC (index)
if swt2 = 0 and index >=7
then
exit
else
swt2 = 1
end if
delayms(time)
'#6
TOGGLE (red6)
DELAYMS(Time)
TOGGLE (red6)
INC (index)
if swt2 = 0 and index >=8
then
exit
else
swt2 = 1
end if
delayms(time)
'#7
TOGGLE (red7)
DELAYMS(Time)
TOGGLE (red7)
INC (index)
{ '#8
TOGGLE (Yellow0)
DELAYMS(Time)
TOGGLE (Yellow0)
'#9
TOGGLE (Yellow3)
DELAYMS(Time)
TOGGLE (Yellow3)
'#10
TOGGLE (Red)
DELAYMS(Time)
TOGGLE (Red)
}
index = 0
wend
END SUB
SUB one_blink() ' NEED TO ADD IN DELAYMS(TIME)
IF PRESS = 0
THEN
PRESS = PRESS + 1
red0 = 1
DELAYMS(1000)
red0=0
DELAYMS(1000)
swt1 = 1
time = 250 ' player allotment time
ENDIF
END SUB
SUB two_blink()
IF PRESS = 1
THEN
PRESS = PRESS +1
END IF
IF PRESS = 2 THEN
red0 = 1
DELAYMS(1000)
red0 = 0
DELAYMS(1000)
red0 = 1
DELAYMS(1000)
red0 = 0
swt = 1
time = 500 ' player allotment time
ENDIF
END SUB
SUB three_blink()
IF PRESS = 2 THEN
PRESS = 3
END IF
IF PRESS = 3 THEN
red0 = 1
DELAYMS(1000)
red0 = 0
DELAYMS(1000)
red0 = 1
DELAYMS(1000)
red0 = 0
DELAYMS(1000)
red0 = 1
DELAYMS(1000)
red0 = 0
swt1 = 1
time = 750 ' player allotment time
ENDIF
END SUB
// SET THE TIMER AS PER # OF BLINKS OF PORTC.5
SUB ttt()
IF swt1 = 0 AND PRESS = 0
THEN
DELAYMS(400)
one_blink()
' press = 1
END IF
'if swt2 = 0 then sequence()
'end if
IF swt1 = 0 AND PRESS = 1
THEN
DELAYMS(400)
two_blink()
' press = 2
END IF
IF swt1 = 0 AND PRESS = 2
THEN
DELAYMS(400)
three_blink()
' press = 3
END IF
IF PRESS >= 3 THEN PRESS = 0
END IF
END SUB
OUTPUT (red0)
OUTPUT (red1)
OUTPUT (red2)
OUTPUT (red3)
OUTPUT (red4)
OUTPUT (red5)
OUTPUT (red6)
OUTPUT (red7)
trisb =%00000000
trisc =%00000000
trisA =%00000000
PRESS = 0
Buttonpress =1
swt1 = 1
swt2 = 1
red0 =0
red1 =0
red2 =0
red3 =0
red4 =0
red5 =0
red6 =0
red7 =0
Time = 1000
index = 0
WHILE true
REPEAT
ttt() ' input player time alotment
' index = 1
UNTIL swt2 = 0 ' select # of blinks (1-3) for time allotment
ENABLE(MyInt) ' interrupt jump if swt2 is pressed
Sequence()
'while true ' 10 leds blink to indicate count down of players time selected
{
for x = 0 to 5 testing and confirm code is returning
if index < 7 then
red0 = 1
delayms(500)
toggle (red0)
delayms(400)
end if
next
}
WEND
end if