Bi-color memory game
I moved this post to the BS threads due to lack of viewers in the Education Threads.
http://forums.parallax.com/showthread.php?112438-A-Bi-Color-LED-Memory-Game#post1018658
I am trying to make the bicolor LED memory game, but with my own code I made up, (Otherwise I'd feel like I'm cheating) but I just can't get it to work. Here's the problem: I will get several levels in, but then randomly, the BS2 says I messed up and tells me I lost. Any help?
http://forums.parallax.com/showthread.php?112438-A-Bi-Color-LED-Memory-Game#post1018658
I am trying to make the bicolor LED memory game, but with my own code I made up, (Otherwise I'd feel like I'm cheating) but I just can't get it to work. Here's the problem: I will get several levels in, but then randomly, the BS2 says I messed up and tells me I lost. Any help?
' {$STAMP BS2}
' {$PBASIC 2.5}
outgreen PIN 15
outred PIN 14
green PIN 1
red PIN 0
nextcolor VAR Bit
eepromaddress VAR Word
currenteepromaddress VAR Word
redgreen VAR Bit
redgreencheck VAR Bit
nextcolor = 0
eepromaddress = 0
currenteepromaddress = 0
DEBUG CLS
DO
nextcolor = nextcolor + 1
DEBUG HOME, "Push either button to begin"
LOOP UNTIL (green = 1) OR (red = 1)
DEBUG CLS
WRITE 0, nextcolor
'Main Routine----------------------------------------------------------------------------
Main:
DO
GOSUB Out_LED
GOSUB Check_Response
LOOP
'Subroutine: Out_LED---------------------------------------------------------------------
Out_LED:
DEBUG HOME, "Round "
DEBUG DEC3 (currenteepromaddress + 1), " ", CR
FOR eepromaddress = 0 TO currenteepromaddress
READ eepromaddress, redgreen
IF (redgreen = 0) THEN
PAUSE 500
HIGH outred
LOW outgreen
PAUSE 500
LOW outgreen
LOW outred
ELSEIF (redgreen = 1) THEN
PAUSE 500
HIGH outgreen
LOW outred
PAUSE 500
LOW outgreen
LOW outred
ENDIF
NEXT
RETURN
'Subroutine: Check_Response--------------------------------------------------------------
Check_Response:
FOR eepromaddress = 0 TO currenteepromaddress
READ eepromaddress, redgreen
DO
nextcolor = nextcolor + 1
IF (red = 1) THEN
redgreencheck = 0
ELSEIF (green = 1) THEN
redgreencheck = 1
ENDIF
LOOP UNTIL (red = 1) OR (green = 1)
IF (redgreen <> redgreencheck) THEN DEBUG "You lose", CR : END
DO
LOOP UNTIL (red = 0) AND (green = 0)
PAUSE 55
NEXT
currenteepromaddress = currenteepromaddress + 1
WRITE currenteepromaddress, nextcolor
RETURN
