Shop OBEX P1 Docs P2 Docs Learn Events
simon memory game? — Parallax Forums

simon memory game?

mrsteelemrsteele Posts: 4
edited 2009-10-28 21:21 in BASIC Stamp
im in school and we are working with the·bs2 microcontroller we have been trying to come up with this simon game (schematic and code) we thought we had it but its not working.· we are trying to make a 4 button simon game if anyone has any suggestions on either the schematic or a code that works that would be awesome. thanks for your time.

Comments

  • dandreaedandreae Posts: 1,375
    edited 2009-10-07 13:26
    Can you attach the code as a .bs2 file·that you wrote?· We can help point you in the right direction.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • mrsteelemrsteele Posts: 4
    edited 2009-10-07 13:38
    not sure how to attach as a .bs2 file but here it is... thank you

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' "Simon Says..."
    '
    '


    '--- Beep parameters ---
    kSpeakerPin CON 15
    kDuration CON 100 ' x miliSeconds
    kFreq4 CON 659
    kFreq3 CON 587
    kFreq2 CON 500
    kFreq1 CON 440
    kPause CON 200


    '--- Array parameters ---
    kWords CON 0 ' (see below)
    kWords1 CON 1 ' kWords1 * 8 = the length of the beep sequence


    '--- Game Speed ---
    kGameSpeed CON 255 ' Starting game speed

    '--- LCD ---
    kLCDPin CON 14
    N9600 CON $4054
    Esc CON 254
    CLR CON 1


    '--- Variables ---
    gArr VAR Word(kWords1) ' Where beep sequence is stored
    tRnd VAR Word ' Utility random#
    tNote VAR Word ' Frequency of beep
    i VAR Byte ' Utility bytes
    j VAR Byte '
    k VAR Byte '
    gWhich VAR Byte ' Which beep to play (0..3)
    tBeeps VAR Byte ' How many beeps to play
    tWords VAR Byte ' How many words to play
    tLoop VAR Byte
    gButton VAR Byte
    gPause VAR Word
    inNum VAR Byte


    '

    Start:
    gPause = kGameSpeed

    '--- Clear LCD ---
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,CLR]
    PAUSE 500

    '--- PIC Says ---
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"Simon Says..."]
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,192,"Press any button"]

    '--- Randomize Random# sequence while waiting for button press ---
    WaitForStart:
    RANDOM tRnd
    gButton = INS & %00001111
    IF gButton = %00001111 THEN WaitForStart

    GOSUB GameStartMusic

    '--- Save random numbers (Words) in array gArr() ---
    FOR i = 0 TO kWords
    RANDOM tRnd
    gArr(i) = tRnd
    NEXT


    '--- Playback the sequence repeatedly, each time playing one more note ---
    FOR tBeeps = 0 TO (kWords1 * 8) - 1
    GOSUB ShowScore
    GOSUB PlaySequence
    PAUSE 1000
    IF gPause < 20 THEN ItsFastEnough
    gPause = gPause - 10
    ItsFastEnough:
    NEXT

    PlayWinSong:
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,CLR]
    FREQOUT kSpeakerPin, 100, 900
    PAUSE 50
    FREQOUT kSpeakerPin, 1000, 900
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"*** BadAss! ***"]
    GOTO Start

    GameEnd:
    FREQOUT kSpeakerPin, 1000, 300
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,CLR]
    PAUSE 500
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"** GAME OVER! **"]
    GOSUB ShowScore
    PAUSE 3000
    GOTO Start


    '

    ShowScore:
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,192,"Score: "]
    inNum = tBeeps
    GOSUB ShowNum
    RETURN


    ShowNum:
    SEROUT kLCDPin, N9600, [noparse][[/noparse]48 + (inNum / 10)]
    SEROUT kLCDPin, N9600, [noparse][[/noparse]48 + (inNum // 10)]
    RETURN


    inDuration VAR Word
    inNote VAR Word

    '--- Game Start Music ---
    GameStartMusic:

    '--- Clear LCD ---
    inDuration = 100
    inNote = 700
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,CLR]
    GOSUB FlashAll
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"Get SET..."]
    PAUSE 1000

    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,CLR]
    GOSUB FlashAll
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"READY..."]
    PAUSE 1000

    inDuration = 600
    SEROUT kLCDPin, N9600, [noparse][[/noparse]Esc,128,"*** PLAY ***"]
    GOSUB FlashAll
    PAUSE 1000
    RETURN


    FlashAll:
    HIGH 0
    HIGH 1
    HIGH 2
    HIGH 3
    FREQOUT kSpeakerPin, inDuration, inNote
    LOW 0
    LOW 1
    LOW 2
    LOW 3
    RETURN

    '--- Playback random numbers two bits at a time ---
    ' Input: tBeeps = number of beeps to play
    PlaySequence:
    tWords = tBeeps / 8
    FOR tLoop = 0 TO 1 ' 0=play, 1=wait for buttons
    FOR i = 0 TO tWords
    tRnd = gArr(i)
    IF i = tWords THEN LastWord
    k = 7
    PlayWord:
    FOR j = 0 TO k
    gWhich = tRnd & 3 ' Get lowest two bits
    IF tLoop = 0 THEN JustBeep
    GOSUB WaitForButton
    IF gWhich <> gButton THEN GameEnd
    JustBeep:
    GOSUB BeepAndBlink
    tRnd = tRnd >> 2 ' Shift down two bits (clobbering the one we've just used)
    NEXT
    NEXT
    NEXT
    RETURN

    LastWord:
    k = tBeeps - (i*8)
    GOTO PlayWord


    '--- Play tone and blink LED ---
    ' Input: gWhich (0..3)
    BeepAndBlink:
    LOOKUP gWhich, [noparse][[/noparse]kFreq1, kFreq2, kFreq3, kFreq4], tNote
    HIGH 4 + gWhich
    FREQOUT kSpeakerPin, kDuration, tNote
    LOW 4 + gWhich
    PAUSE gPause
    RETURN


    '--- Wait for button press ---
    WaitForButton:
    i = 255
    KeepWaiting:
    gButton = 0
    IF IN0 = 0 THEN Pressed

    gButton = 1
    IF IN1 = 0 THEN Pressed

    gButton = 2
    IF IN2 = 0 THEN Pressed

    gButton = 3
    IF IN3 = 0 THEN Pressed

    ' Have we waited long enough?
    i = i - 1
    IF i > 0 THEN KeepWaiting

    ' If we got here, it means player did not press any button in time.
    gButton = -1
    Pressed:
    RETURN
  • mrsteelemrsteele Posts: 4
    edited 2009-10-07 13:40
    we are trying to add a 16x2 lcd display and a spaeker to it as well.
    i've asked my teacher about possible fixes but he has no clue... thanks again
  • dandreaedandreae Posts: 1,375
    edited 2009-10-08 15:27
    Have you looked at the sample code for the 2X16 LCD, I believe this will help you.· You can use a piezo speaker for sound.

    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • iDaveiDave Posts: 252
    edited 2009-10-08 21:06
    Here is an instructable post on this, but using a different microcontroller(the picaxe). The concept should be the same. It also uses 4 buttons. There is a link in there somewhere for the source code, but u would need the picaxe software to open it. Since i have that software already I can copy & paste it for u if u would like...just let me know. Good luck!

    www.instructables.com/id/MemAxe-8Bit-sound-effects-memory-game/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer."
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-10-09 00:22
    I seem to remember a very old post when The Forum was in E-mail format, of someone accomplishing a Simon Says memory game using a BS2, possibly even using a BS1. I'll have to dig this weekend and see if I can search for it.

    A Google search pulled up nothing, I thought it might have even been posted in the L.O.S.A. (List Of Stamp Applications).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2009-10-09 02:12
    · There is a YouTube video of a Simon-type game done with the BS2.· Here is the link http://www.youtube.com/watch?v=Y2QrqF9bxPk
  • mrsteelemrsteele Posts: 4
    edited 2009-10-28 16:19
    Hi guys sorry ive been off for a while, thanks for all your help... we pretty much finished the project, i'll take pics and all that good stuff.

    thanks again
  • ercoerco Posts: 20,256
    edited 2009-10-28 21:21
    I taught a toy design class at Otis College of Art, and I had students program a Simon game on a BS1. 5 pins: one speaker output and 4 i/o pins each with a switch and an LED. Tricky stuff with just 256 bytes of RAM!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
Sign In or Register to comment.