Shop OBEX P1 Docs P2 Docs Learn Events
Help with coding an LED puzzle game ? — Parallax Forums

Help with coding an LED puzzle game ?

kidsasukekidsasuke Posts: 8
edited 2011-02-17 14:08 in BASIC Stamp
Hi everyone,

I'm new to using the BASIC Stamp discovery kit and am not THAT familiar with proper syntax yet. I was looking to design a basic puzzle game where you're trying to turn all 7 LEDs in a line off without having them all turn on. The plan is that whenever you change the state of any LED, the adjacent ones will change states (which is probably going to be my biggest hurdle if possible at all with this kit).

So far, I've been trying to simply code a piezo speaker to sound either a failure or victory sound depending on the outcome of the game (all on or all off). I assumed that the following code would accomplish this (with the series of high/low statements at the bottom for testing whether or not the code worked)


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

' Creating a binary puzzle game with two pushbuttons/possibly debug inputs......probably debug inputs....but hey, who knows?
' Object of the game is to make all of the lights turn off without making them all turn on. When one light is turned on the
' adjacent lights will change states. There will be a total of 7 LEDs and they will start in a random pattern (hopefully).

' Pins 0 - 6 will be the LEDs and a piezo speaker (pin15) will make a fail sound upon losing, or a victory fanfare upon winning!

' Start by creating the victory and failure sounds.

state VAR Bit
counter VAR Word

IF (IN0 AND IN1 AND IN2 AND IN3 AND IN4 AND IN5 AND IN6 = 1) THEN
FOR counter = 1 TO 10
HIGH 15
PAUSE counter
LOW 15
PAUSE counter
NEXT

FOR counter = 1 TO 20
HIGH 15
PAUSE counter
LOW 15
PAUSE counter
NEXT

FOR counter = 1 TO 40
HIGH 15
PAUSE counter
LOW 15
PAUSE counter
NEXT

ENDIF

HIGH 0
LOW 1
HIGH 2
HIGH 3
HIGH 4
HIGH 5
HIGH 6


The sound comes out perfectly fine, but the code seems ambiguous about when the piezo will sound. It'll ALWAYS fire off when all pins are high, but then randomly fire off in any other state (sometimes it won't sound when the program is run, but then hitting the reset button on the board will cause it to sound. Other times, it'll fully take the code and won't make a sound even when reset.)

Can anybody help me out with this issue? If needed, I can pull together a list of the exact pin states that cause the different levels of ambiguity. This may actually become my final project for class, so any contributors with this work will definitely be cited for their help.

Many thanks in advance for any advice.

Comments

  • Qwaszx72Qwaszx72 Posts: 30
    edited 2011-01-16 11:18
    Well I recommend making the game itself first. If you want I can make the game and give you some of the source code to challenge you to find it out kind of by yourself.
  • kidsasukekidsasuke Posts: 8
    edited 2011-01-16 11:27
    Thanks for the advice, I guess I really should've developed the main software rather than trying to refer to statements that don't exactly exist at the moment. I'd definitely love to see some source code to get me started, as I'm not that aware of all of the syntax at the moment. As I stated before, if this ends up being my final project, then you'll definitely get credit for your contributions. Even if it doesn't, well you'll still be credited in the final code that I produce.

    Thanks again for your help.
  • Qwaszx72Qwaszx72 Posts: 30
    edited 2011-01-16 11:48
    Here is the Algorithm that I would use to toggle all the lights needing to be toggled on/off:

    light var nib 'This is the light that was "pressed"

    lights var bit(7)

    Toggle_Lights:
    if (light = 0) then
    lights(1) = lights(1) + 1
    elseif(light = 7) then
    lights(6) = lights(6) + 1
    else
    lights(light + 1) = lights(light + 1) + 1
    lights(light - 1) = lights(light - 1) + 1
    endif
    light = light + 1
  • Qwaszx72Qwaszx72 Posts: 30
    edited 2011-01-17 08:28
    Also, today I'm going to post my OPEN SOURCE Simon game using the BS2px
  • kidsasukekidsasuke Posts: 8
    edited 2011-02-17 14:08
    Oh hey, thanks for the reply. I kept on thinking that I'd receive emails everytime someone answered, lol. I was sitting here like "What the hell?" this whole time, thinking that no one cared.
Sign In or Register to comment.