Mini Simon Says code for 08M2, 2 Led, 2 Buttons

jackberg

New Member
Hello
After reading about " Simon Says " projects here in this forum.
I wonder if I can write some codes with a minimal hardware in mind as 08M2 chip and 2 led, and 2 buttons
I know the original game from Hasbro, and Milton & Bradley with 4 buttons, and most the users projects were about this original game.
This is a working version, assembled on the AXE091 from Picaxe, use only 224 bytes.
The sequence lookup is set at 15 (0~14), and can be increase easily.
Also included a basic circuit diagram.

the hardware:
1 x 08M2
1 x Piezo Module 5v
2 x Led (on Board)
2 x Tactile Switches (on Board)

Enjoy the game.

Code:
; Minimal SIMON SAYS , for 08m2 2 led 2 buttons
; project build on AXE091 Dev Board 
; Memory used 224 out of 2048 bytes
#picaxe 08M2
#no_data
Symbol k = b0
symbol i = b1
symbol j = b2
symbol sw1=pinc.3
symbol sw2=pinc.4
main:
k=0
; Intro Sound
gosub IntroSound
pause 1000
; Starting loop------------------------
do while k < 15 ;lookup array 1,2 limit 0~14
for i=0 to k    
    gosub Lookup1 'lookup1 array
    pause 800
    gosub DisplaySound
next i

; key input ------------------------------
for j=0 to k    

do while sw1=0 and sw2=0  ;wait for key 
loop    

if sw1=1 then 
    b4=1    
    elseif sw2=1 then b4=2
endif

gosub Lookup2    'lookup2 array
gosub DisplaySound

;fail section
if b5<>b4 then
    gosub FailSound
    pause 1000
    goto main    ; restart
endif

do while sw1=1 or sw2=1 ; wait for key release
loop    

next j
inc k
loop 

;Win final
    high c.1,c.2 
    gosub IntroSound
    low c.1,c.2 
    pause 200
    high c.1,c.2  
    gosub IntroSound
    low c.1,c.2 
end
Lookup1:; 0 to 14 simon entry
    lookup i,(1,2,1,2,2,1,1,1,2,2,1,2,1,2,2),b5
return
Lookup2:; 0 to 14 key entry
    lookup j,(1,2,1,2,2,1,1,1,2,2,1,2,1,2,2),b5
return
DisplaySound:
select case b5
    case = 1
    sound c.0,(100,10): high c.1 : pause 200 
case = 2
    sound c.0,(100,10): high c.2 : pause 200 
end select
    low c.1 ,c.2
return
IntroSound: ; Intro and Win sound
    for i=10 to 100 step 10
        sound c.0,(i,10): pause 10
    next i
return
FailSound:
    for i=100 to 10 step -10
        sound c.0,(i,10): pause 20
    next i
return

[\CODE]

[ATTACH type="full" alt="25495"]25495[/ATTACH]
 

Attachments

  • basic circuit.jpg
    basic circuit.jpg
    62.8 KB · Views: 13
Hello,
Here the revised code
remove the " Lookup2 ", and j variable.

Code:
; Minimal SIMON SAYS , for 08m2 2 led 2 buttons
; project build on AXE091 Dev Board 
; Memory used 213 out of 2048 bytes
; Date : Sep 3-2022
; File : "D:\PIC\PICAXE\08M2+\SIMON SAYS\SIMON.bas"
#picaxe 08M2
#no_data
Symbol k = b0
symbol i = b1
symbol sw1=pinc.3
symbol sw2=pinc.4
main:
k=0
; Intro Sound
gosub IntroSound
pause 1000
; Starting loop------------------------
do while k < 15 ;lookup array 1,2 limit 0~14
for i=0 to k    
    gosub Lookup1 'lookup1 array
    pause 800
    gosub DisplaySound
next i

; key input ------------------------------
i=0
for i=0 to k    

do while sw1=0 and sw2=0  ;wait for key 
loop    

if sw1=1 then 
    b4=1    
    elseif sw2=1 then b4=2
endif

gosub Lookup1    'lookup2 array
gosub DisplaySound

;fail section
if b5<>b4 then
    gosub FailSound
    pause 1000
    goto main    ; restart
endif

do while sw1=1 or sw2=1 ; wait for key release
loop    

next i
inc k
loop 

;Win final
    high c.1,c.2 
    gosub IntroSound
    pause 200
    high c.1,c.2  
    gosub IntroSound
end

Lookup1:; 0 to 14 simon entry
    lookup i,(1,2,1,2,2,1,1,1,2,2,1,2,1,2,2),b5
return

DisplaySound:
select case b5
    case = 1
    sound c.0,(80,10): high c.1 : pause 200 
case = 2
    sound c.0,(100,10): high c.2 : pause 200 
end select
    low c.0 ,c.1 ,c.2
return

IntroSound: ; Intro and Win sound
    for i=10 to 120 step 10
        sound c.0,(i,10): pause 10
    next i
    low c.0 ,c.1 ,c.2
return

FailSound:
    for i=100 to 10 step -10
        sound c.0,(i,10): pause 20
    next i
    low c.0 ,c.1 ,c.2
return

[\CODE]
 
Back
Top