Chapter 03 - Reaction Timer Game - Alternate program with a different Circuit
Hi Folks,
Total Parallax Noobie here
If I've posted this in the wrong section, I apologize in advance.
Here's my first attempt at writing a program for the Reaction Timer Game from Chapter 03 in the Parallax Basic Stamp "What's a Microcontroller" book.
For those who're already familiar with this, I haven't yet included the random timer feature because I wanted this program to swith LED colors within the predicatable time of 1 second to test the cheat feature.
Here are some of my changes:
Cheers,
Andy
Total Parallax Noobie here
Here's my first attempt at writing a program for the Reaction Timer Game from Chapter 03 in the Parallax Basic Stamp "What's a Microcontroller" book.
For those who're already familiar with this, I haven't yet included the random timer feature because I wanted this program to swith LED colors within the predicatable time of 1 second to test the cheat feature.
Here are some of my changes:
- I lost the Bi-Color LED, and therefore used the Dual LED program from Chapter 03 with the pull-down resistor. Pic is attached .
- For now, the upper push button has no part to play in the game, and can therefore be ignored
- My program manipulates the 2 LEDs to change colors instead of working with a single Bi-Color LED.
- Also, I have incorporated an alternate solution to detect if the player is letting go of the button before the LED turns yellow and displays a message appropriately.
Cheers,
Andy



Comments
' What's a Microcontroller - ReactionTimerRandomTwoPlayer.Bs2 ' Test random reaction time with a pushbutton and a Bicolor LED. ' Added second player, with second pushbutton. Both players ' play at once using the same LED. Quikest to release wins. Includes random switchtime, and anti cheat code. ' Pin P3: Player A pushbutton, Active High ' Pin P4: Player B pushbutton, Active High ' {$STAMP BS2} ' {$PBASIC 2.5} PAUSE 1000 timecounter VAR Byte timecounter2 VAR Byte timecounterA VAR Word timecounterB VAR Word value VAR Byte value = 23 DEBUG "Press and hold Pushbuttons", CR, "to make the LED turn Red",CR ,CR, "When LED turns Green, let",CR, "go as fast as you can.", CR, CR DO DO LOOP UNTIL (IN3 = 1) AND (IN4 = 1) HIGH 14 LOW 15 RANDOM value DEBUG "Delay: ", ? 1000 + (value*4), CR PAUSE 1000 + (value*4) LOW 14 HIGH 15 timecounterA = 0 timecounterB = 0 DO PAUSE 1 IF (IN3 = 1) THEN timecounterA = timecounterA + 1 ENDIF IF (IN4 = 1) THEN timecounterB = timecounterB + 1 ENDIF LOOP UNTIL (IN3 = 0) AND (IN4 = 0) IF (timecounterA <=2) OR (timecounterB <=2) THEN DEBUG CLS, HOME, "You Must wait for the LED to change to Green...FAIL!", CR, CR timecounter2 = 0 DO DEBUG "NO CHEATING!", CR LOW 15 HIGH 14 PAUSE 250 HIGH 15 LOW 14 PAUSE 250 timecounter2 = timecounter2 + 1 LOOP UNTIL timecounter2 = 20 DEBUG CLS, HOME, "To play again, hold the", CR, "button down.", CR, CR ELSEIF (timecounterA >1) AND (timecounterB >1) THEN LOW 15 LOW 14 timecounterA = timecounterA */254 timecounterB = timecounterB */254 DEBUG "Player A Time: ", DEC timecounterA," ms.", CR, CR, "Player B Time: ", DEC timecounterB," ms.", CR, CR IF (timecounterA < timecounterB) THEN DEBUG "Player A Wins!!!", CR timecounter = 0 DO LOW 15 HIGH 14 PAUSE 250 LOW 14 PAUSE 125 timecounter = timecounter + 1 LOOP UNTIL timecounter = 10 ELSEIF (timecounterB < timecounterA) THEN DEBUG "Player B Wins!!!", CR timecounter = 0 DO LOW 14 HIGH 15 PAUSE 250 LOW 15 PAUSE 125 timecounter = timecounter + 1 LOOP UNTIL timecounter = 10 ELSE DEBUG "It's a Tie!", CR timecounter = 0 DO LOW 15 HIGH 14 PAUSE 125 HIGH 15 LOW 14 PAUSE 125 timecounter = timecounter + 1 LOOP UNTIL timecounter = 10 LOW 15 LOW 14 ENDIF ELSE DEBUG "To play again, hold the", CR, "buttons down again.", CR, CR ENDIF LOW 14 LOW 15 LOOPHere's what I mean - In the pseudocode section, we have 3 items to fix
Item 1 Fix: Removing the PAUSE 1 inside the FOR LOOP removes the code overage
Item 2 Fix: Adding randomness to the LED change time, increases the pause time from 1 to 2 seconds
Item 3 Fix: In the pseudocode section there are 2 conditions:
If timeCounter <=2
Display Cheat Message
Else (if timeCounter > 1)
Display ReactionTime
But when timeCounter > 1, it may also mean that it can fall under the first condition timeCounter <=2, in which case the program never gets to go into the Else condition.
Am I reading this wrong, or does my reasoning make sense?
Thanks and Happy Coding!
Andy
Does that make sense?