Shop OBEX P1 Docs P2 Docs Learn Events
Simon Says — Parallax Forums

Simon Says

lynnhhlynnhh Posts: 10
edited 2022-01-23 10:13 in BASIC Stamp

Hello.

I am trying to make a program with 4 LED play Simon says. IE a randomly generated light pattern is created each round then the player has to follow the pattern by pushing 4 buttons.

I know my circuit is correct but I cannot get my code correct. Any suggestions?

'{$STAMP BS2}
'{$PBASIC 2.5}


PAUSE 1000
array    VAR Byte(10)
counter  VAR Word
i        VAR Nib
k        VAR Nib
j        VAR Nib
n        VAR Nib
btn1     VAR Word
btn5     VAR Word
btn9     VAR Word
btn13    VAR Word
seed     VAR Word
btnWrk   VAR Word


  DO WHILE (IN1=0) AND (IN5=0) AND (IN9=0) AND (IN13=0)
seed = seed + 1
LOOP

FOR k = 0 TO 9
RANDOM seed
array (k) = seed //4
DEBUG ? array
NEXT

  GOTO start

  start:
   FOR k = 0 TO 9
BRANCH  array (k), [check1, check2, check3, check4]
  NEXT

     check1:
BUTTON 1, 1, 255, 5, btnWrk , 0, Continue
BUTTON 5, 1, 255, 5, btnWrk , 0, Lost
BUTTON 9, 1, 255, 5, btnWrk , 0, Lost
BUTTON 13, 1, 255, 5, btnWrk , 0, Lost

       check2:
BUTTON 1, 1, 255, 5, btnWrk , 0, Lost
BUTTON 5, 1, 255, 5, btnWrk , 0, Continue
BUTTON 9, 1, 255, 5, btnWrk , 0, Lost
BUTTON 13, 1, 255, 5, btnWrk , 0, Lost

     check3:
BUTTON 1, 1, 255, 5, btnWrk , 0, Lost
BUTTON 5, 1, 255, 5, btnWrk , 0, Lost
BUTTON 9, 1, 255, 5, btnWrk , 0, Continue
BUTTON 13, 1, 255, 5, btnWrk , 0, Lost

     check4:
BUTTON 1, 1, 255, 5, btnWrk , 0, Lost
BUTTON 5, 1, 255, 5, btnWrk , 0, Lost
BUTTON 9, 1, 255, 5, btnWrk , 0, Lost
BUTTON 13, 1, 255, 5, btnWrk , 0, Continue

  Continue:

     DO
    IF (array(k)=0) THEN
      HIGH 15
      PAUSE 100
      LOW 15
      PAUSE 100
    ELSEIF (array(k)=1) THEN
      HIGH 11
      PAUSE 100
      LOW 11
      PAUSE 100
    ELSEIF (array(k)=2) THEN
    HIGH 7
    PAUSE 100
    LOW 7
    PAUSE 100
    ELSEIF (array(k)=3) THEN
    HIGH 3
    PAUSE 100
    LOW 3
    ENDIF

    LOW 15
    LOW 11
    LOW 7
    LOW 3
    PAUSE 100
     LOOP
 END

Winner:

FOR counter = 1 TO 5
HIGH 15
PAUSE 50
LOW 15
HIGH 11
PAUSE 50
LOW 11
HIGH 7
PAUSE 50
LOW 7
HIGH 3
PAUSE 50
LOW 3
NEXT

Lost:

FOR counter = 1 TO 5
HIGH 15
HIGH 3
HIGH 11
HIGH 7
PAUSE 500
LOW 15
LOW 11
LOW 7
LOW 3
PAUSE 100
NEXT

LED1:
 HIGH 15
 PAUSE 250
 LOW 15


LED2:
 HIGH 11
 PAUSE 250
 LOW 11


LED3:
 HIGH 7
 PAUSE 250
 LOW 7


LED4:
 HIGH 3
 PAUSE 250
 LOW 3

Comments

  • @lynnhh said:
    Hello.

    I am trying to make a program with 4 LED play Simon says. IE a randomly generated light pattern is created each round then the player has to follow the pattern by pushing 4 buttons.

    I know my circuit is correct but I cannot get my code correct. Any suggestions?

    At first look, there doesn't appear to be any "return" action at the end of Winner, Lost, and LED routines.

    As @Erco mentioned in your other post, comments would greatly help understanding.

    Also, FYI, double-posting on the Forum is kinda a no-no.

  • Also, FYI, double-posting on the Forum is kinda a no-no.

    Fixed that. :)

  • @Publison said:

    Also, FYI, double-posting on the Forum is kinda a no-no.

    Fixed that. :)

    ...does this mean we can now double-post? :open_mouth:

  • I apologize for the double posting. I am new here. thank you for fixing that.

    I got a little further. My problem now is that the game always loses. Even when hitting the correct button I lose.

    I attached my code.

  • @davejames said:

    @Publison said:

    Also, FYI, double-posting on the Forum is kinda a no-no.

    Fixed that. :)

    ...does this mean we can now double-post? :open_mouth:

    Nah That's still a no-no.

  • Buck RogersBuck Rogers Posts: 2,160
    edited 2022-01-26 02:42

    But the other post is still there...........
    EDIT:
    And now the other post is gone.

  • ercoerco Posts: 20,244

    @lynnhh: Did you ever sort this out or do you still need help? Posting a video would be helpful.

  • @erco said:
    @lynnhh: Did you ever sort this out or do you still need help? Posting a video would be helpful.

    I did get it fixed. Thank you for all the suggestions

  • JonnyMacJonnyMac Posts: 8,912
    edited 2022-02-04 22:36

    Chip Gracey wrote a version of Simon for the BS1 that you can probably port or, at the very least, learn from. The BS1 is very trim on resources, so the code is a bit terse (Chip's style); still, it will be valuable to explore and consider.

    Tip: Since RANDOM is a PRNG, the only thing you need to know is the starting seed. This allows you to have sequences of any length, and you don't have to store them in an array.

    Tip #2: Embrace the use of named constants; it will make your programs easier to read and maintain.

  • @lynnhh said:

    @erco said:
    @lynnhh: Did you ever sort this out or do you still need help? Posting a video would be helpful.

    I did get it fixed. Thank you for all the suggestions

    ...sooooo, pray tell? How did you fix it?

    Inquisitive minds want to know.

  • @davejames said:

    @lynnhh said:

    @erco said:
    @lynnhh: Did you ever sort this out or do you still need help? Posting a video would be helpful.

    I did get it fixed. Thank you for all the suggestions

    ...sooooo, pray tell? How did you fix it?

    Inquisitive minds want to know.

    I had a bad button. Once I got a replacement it worked.

  • @lynnhh said:

    I had a bad button. Once I got a replacement it worked.

    So, only a bad button? There were no code changes?

  • ercoerco Posts: 20,244

    @lynnhh said:
    I had a bad button. Once I got a replacement it worked.

    Why would you choose a BAD button? Seems best avoided IMO. :)

Sign In or Register to comment.