Simon Says using 20M

chlgibbons

New Member
Will the Simon Says game work on the 20M Picaxe.
I have made up my own PCB and seem to have made it using the same inputs and outputs as the code.
It programs but the LEDs dont perform as they should and the piezo does not sound.
Any help would be great. Even a tidied up bit of code.
Thanks
Chris
 

kewakl

Senior Member
Will the Simon Says game work on the 20M Picaxe.
I have made up my own PCB and seem to have made it using the same inputs and outputs as the code.
It programs but the LEDs dont perform as they should and the piezo does not sound.
Any help would be great. Even a tidied up bit of code.
Thanks
Chris
Pictures, Schematic and Program would help alot.
Thanks


The *modified* code from AXE106 fails in the simulator with a dialog:

Write error - overwriting program!


On or about Counter = 48

*preload* loop
Code:
write counter,value ‘ save in data memory
 
Last edited:

Technical

Technical Support
Staff member
The 20M has shared data memory when the 18A did not.
Change the preload section from 0 to 100 to 0 to 30. As suggested above when you use a number above 40 or so you will start overwriting the original program.

No one will ever remember above 30 steps anyway!
 

chlgibbons

New Member
I have changed the code with 'loop' to 'push' as I was aware of this glitch.
I was not aware of the changing preload 0 -100 to 30. I am not completely sure of what each section does or the intricacies of the chips memory allocations etc...
BUT
Thank you so much it now works. I messed up a bit with the board with the variable speed part but i have soldered a 100K resistor to + and 10K to Ov to stabilise the speed as a potential divider and the speed is fixed at a good level now.

I have included my PCB and finished code.
Many thanks for the help guys
Absolutely Fabulous support
Chris


‘ AXE106 Simon Says Game for 20M
‘ *** Define the variables used ***
‘ Push switches on inputs 0,1,6,7
‘ Speed preset on input 2
‘ LEDs on outputs 0-3
‘ Piezo on output 7
symbol rand = b1 ‘ random number store for loading memory
symbol value = b2 ‘ switch value 0-1-2-3
symbol playerstep = b3 ‘ position of player in game
symbol freq = b4 ‘ sound variable
symbol topstep = b5 ‘ number of steps in sequence
symbol counter = b6 ‘ general purpose counter
symbol speed = b7 ‘ speed
‘ *** Section 1 **********************
‘ *** This section waits for start ***
‘ ************************************
‘ wait for any switch to be pushed
‘ with all four LEDs lit
‘ preload rand with any number by repeatedly
‘ using the random command in the loop
init:
let pins = %00001111
random rand
if pin0 = 1 then preload
if pin1 = 1 then preload
if pin6 = 1 then preload
if pin7 = 1 then preload
goto init
‘ *** Section 2 ****************************
‘ *** This section loads memory for game ***
‘ ******************************************
‘ load EEPROM data memory with 100 numbers
‘ first get the random number (0 to 255)
‘ and then change to either 1,2,3 or 4
‘ and then save into data memory
preload:
let pins = %00000000 ‘ LEDs off
for counter = 0 to 30 ‘ for..next loop
let value = 0
random rand ‘ get random number 0-255
if rand > 180 then set0
if rand > 120 then set1
if rand > 60 then set2
set3: let value = value + 1 ‘1+1+1 = 3
set2: let value = value + 1 ‘1+1 = 2
set1: let value = value + 1 ‘1
set0: ‘0
write counter,value ‘ save in data memory
next counter ‘ next loop
‘ *** Section 3 ****************************
‘ *** This section plays back a sequence ***
‘ ******************************************
‘ switch off the LEDs and then start
‘ a game with the end counter as 1
let pins = %00000000 ‘ LEDs off
let topstep = 1 ‘ reset step number to 1
‘ playback the game sequence
playback:
readadc 2,speed ‘ read speed value
for counter = 1 to topstep ‘ for...next loop
read counter,value ‘ get value
gosub beep ‘ make the noise
pause 300 ‘ short delay
next counter ‘ loop
‘ *** Section 4 *****************************************
‘ *** This section detects the players reply sequence ***
‘ *******************************************************
‘ now the user responds
‘ reset the players position to 1
playerstep = 1
gameloop:
‘ if playerstep is greater than topstep then all done
if playerstep > topstep then success
‘ get the correct key value is supposed to hit
‘ from the EEPROM memory
read playerstep,value
‘ now wait for switch to be pressed
push: if pin7 = 1 then pushed0
if pin6 = 1 then pushed1
if pin1 = 1 then pushed2
if pin0 = 1 then pushed3
goto push
‘ switch pressed so check it is the correct one
‘ if it is make a beep sound and then continue
‘ else fail the game
pushed0:
if value <> 0 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed1:
if value <> 1 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed2:
if value <> 2 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed3:
if value <> 3 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
&#8216; *** Failed so make noise and jump back to start ***
&#8216; failed so make failed noise, switch off all LEDs
&#8216; and go back to start
fail:
let pins = %0000000 &#8216; all LEDs off
sound 7,(80,100) &#8216; make a noise
sound 7,(50,100)
goto init &#8216; back to start
&#8216; *** Succeeded so add another step to sequence and loop ***
&#8216; success so make a success sound
&#8216; and then increment topstep and do another sequence
success:
pause 100 &#8216; short delay
let pins = %00001111 &#8216; all LEDs on
sound 7,(120,50) &#8216; success beep
let pins = %00000000 &#8216; all LEDs off
pause 100 &#8216; short delay
let topstep = topstep + 1 &#8216; add another step
goto playback &#8216; loop again
&#8216; *** Section 5 ****************
&#8216; *** sub light LED and beep ***
&#8216; ******************************
&#8216;sub-procedure to light correct LED
&#8216;and make a different beep sound for each LED
&#8216;value always contains number 0,1,2 or 3.
&#8216;add 1 and multiply by 20 to give larger difference
&#8216;in the sound noise
beep:
high value &#8216; switch on LED
freq = value + 1 &#8216; generate sound freq.
freq = freq * 25
sound 7,(freq,speed) &#8216; play sound
low value &#8216; switch off lED
return &#8216; return
 

Attachments

Last edited:
Top