Shop OBEX P1 Docs P2 Docs Learn Events
New To Basic Stamps - Help — Parallax Forums

New To Basic Stamps - Help

Lycan_GalenLycan_Galen Posts: 4
edited 2007-03-05 23:26 in BASIC Stamp
Hello.· I'm new to Basic stamps, so I'm just learning to code as I go.· Which also means I'm runing into trouble already, lol.

I'm trying to make a program where there are two buttons.· One button is a reset button which, obviously, sets everything back to where it was in the beginning, the other button I want to light up one LED the first time it is pressed, two the second time, three the third, etc.· all the way to ten LEDs.· I guess I should mention I'm working with a BS2.· I'm·attaching what I have coded in a txt file, can someone take a look and tell me where I'm going wrong?· Right now all I have is a bunch of LEDs that flicker on and off in synch, regardless of what I'm doing with the buttons.·

Thanks a lot in advance, and yes, I know there's probably a much cleaner way to write this, but like I said, I'm new to this whole thing. Though I'm open to suggestions to simplify all around [noparse]:)[/noparse]

Comments

  • MikeKMikeK Posts: 118
    edited 2007-03-04 13:34
    RETURN is used to return from subroutine calls (GOSUB). You're using BRANCH, which is basically a GOTO. You need to replace all the RETURN statements with GOTO statements to the top of your loop.

    Also, since your buttons appear to be active high, make sure you have pulldown resistors on the input pins you're using for the buttons (that is, make sure the pins aren't floating when the button isn't pressed).

    Mike
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-03-04 20:18
    Hi, you can shorten your code some by making use of the OUTS register (look at the Memory and Variables in the Pbasic help). The OUTS register can control any or all of the 16 I/O pins at once. I have attached a piece of code that shows the word variable "light" that is used to control·OUTS and sequence the outputs.·Run it in DEBUG so you can see the effect on the bits contained in "light" pressing the number 2 will reset "light" to 0.

    The changes you need to make to control your real world outputs are

    1) replace the DEBUG statement with OUTS=light

    2) replace DEBUGIN with the·command from your switches (taking Mike's advice about resistors)

    Jeff T.
  • Lycan_GalenLycan_Galen Posts: 4
    edited 2007-03-04 20:30
    Wow, you guys are awesome. Thanks a lot.

    Unsoundcode - I followed you all the way to "ELSEIF light<4093", I'm stumped as to where you got that number from, lol.
    Back to the books I guess.

    Thanks again.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-03-04 20:46
    4092 = 000111111111100 binary, which means all the outputs are high and we don't want to make any more high so it skips the bit shift command (ELSEIF light<4093) waiting for a reset.

    Jeff T.
  • Lycan_GalenLycan_Galen Posts: 4
    edited 2007-03-05 23:07
    Look slike I need a bit more help.· I had finally gotten my stamp to do what I wanted, then I transfered my stamp stack·over to a different breadboard (needed a smaller one to fit it into the project).· I moved all the wires etc. exactly the same, but now the LEDs won't stay on.· If I just code "HIGH 2" then the LED off of pin 2 stays on, but even a basic "if button one is pressed turn light on, if button two is pressed turn light off" just results in the LED only turning on when I have button one depressed, and turns off the minute I let go of the button. Obviously I messed something up but I can't figure out where.

    I've double checked my wires, the leds are going from the pins to ground, there are pull down resistors on the buttons, the buttons are plugged into the first two pins and positive, and the stamp stack is plugged in properly.· Any suggestions where to look?

    I've attached my updated coding, but I don't think the problem is there since it was working fine on the other breadboard.

    Thanks again.
  • Lycan_GalenLycan_Galen Posts: 4
    edited 2007-03-05 23:26
    NVM, got it. Just one of those weird karma things. Had a friend look over my shoulder and it magically started working :P
Sign In or Register to comment.