' ' SIMON SAYS GAME FOR THE PICAXE-14M ' ------------------------------------------------------------------------------- ' Game starts with all LEDs turned on waiting for any push button to be pressed. ' Press any button to turn the LEDs off and a two LED starting sequence follows. ' The player uses the buttons (next to each LED) to repeat the starting sequence. ' This sequence will then be increased by one LED each time the player succeeds. ' Play will now continue until a mistake is made and the wrong button is pushed. ' Each error causes the game to be reset back to the start with all the LEDs on, ' Game also features sound effects and additional LED effects - see notes below. ' ------------------------------------------------------------------------------- start_up:'--------- turn all LEDs on and wait for any button to be pushed. ---- random w0 let pins = 30 pause 50 if input1 <>1 and input2 <>1 and input3 <>1 and input4 <>1 then start_up let b5 = 1 'goto load_numbers load_numbers:' ---- turn LEDs off,then load 60 random 1,2,3 or 4 numbers ---- let pins = 0 for b6 = 0 to 59 let b2 = 0 if b1 > 180 then: inc b2: endif if b1 > 120 then: inc b2: endif if b1 > 60 then: inc b2: endif if b1 >= 0 then: inc b2: endif write b6,b2 random w0 next b6 pause 500 ' goto play_back play_back:' ------ initially play back two stored numbers with LEDs and beeps ---- readadc 0, b7 for b6 = 0 to b5 read b6,b2 high b2 b4 = b2 * 25 sound 5,(b4,b7)' (each number has a different beep - VR1 adjusts beep duration) low b2 pause 500 next b6 b3 = 0 read %00000000,b2 ' goto players_turn players_turn:' --- player uses the push buttons to repeat the play back sequence --- pause 50 if input1 <>1 and input2 <>1 and input3 <>1 and input4 <>1 then players_turn if input1 = 1 and b2 = 1 then goto button_ok if input2 = 1 and b2 = 2 then goto button_ok if input3 = 1 and b2 = 3 then goto button_ok if input4 = 1 and b2 = 4 then goto button_ok ' goto button_fail 'button_fail:' ---- failed to choose correct button so beep and return to start ---- pause 250 sound 5,(100,300) goto start_up button_ok:' ---- button correct so turn on LED and beep - repeat for next number ---- inc b3 high b2 b4 = b2 * 25 sound 5,(b4,40)' (each button has a different beep) low b2 read b3,b2 if b3 > b5 then add_number goto players_turn add_number:' ---- beep and flash LEDs - add a number to the play back sequence ---- pause 300 let pins = 30 sound 5,(100,30) let pins = 0 pause 700 inc b5 goto play_back ' DEFINE THE VARIABLES USED ' ---------------------------------------------------------------------------------- ' w0 = random number word ' b1 = random number byte (part of w0) ' b2 = buttons or numbers 1,2,3 or 4 ' b3 = position of player in game ' b4 = determines beep frequency ' b5 = steps in the main counter ' b6 = for next loop step counter ' b7 = determines beep duration ' ----------------------------------------------------------------------------------- ' TYPICAL FRONT PANEL LAYOUT. '-----------------!--------------------------------------------------!--------------- ' ! ! ' ! (PB1) ! ' ! ! ' ! (L1) (PIEZO) ! ' ! ! ' ! ! ' ! ! ' ! (PB4) (L4) (L2) (PB2) ! ' ! ! ' ! off ! ' ! ! ' ! (L3) (SW1) ! ' ! ! ' ! (PB3) on ! ' ! ! '-----------------!--------------------------------------------------!--------------- ' Use tactile or snap action type push buttons