Shop OBEX P1 Docs P2 Docs Learn Events
BUTTON Command — Parallax Forums

BUTTON Command

ngilliamngilliam Posts: 2
edited 2011-03-11 20:20 in BASIC Stamp
This is a school project and am limited to what hardware I can use. This project is to test our ability to build a circuit, not test our programming abilities. The TAs are more than willing to help our programming but have been overrun by questions so I thought I would post here and see if I could get a quicker response.
I have a program that runs an LED matrix. I have added 3 buttons, one to change the pattern, one to change the speed, and one to turn it on or off. I gave each button a subroutine and was using GOSUB between each light to check the state of the buttons and act accordingly. I think it works (my hardware won't come in until Monday to do any testing), but the problem is, my program is huge so I knew there had to be a better way. Searching here I found the BUTTON command. I read the Basic Stamp Manual about BUTTON but have a question.

If I press a button, does it automatically run the BUTTON command even if it is in the middle of a different routine? Is there a better command to use? In the case of my speed button, is there any way to get it to pick up where it left off?

Thanks in advance.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-11 08:51
    The BUTTON statement is sort of like a fancy GOTO that tests the button and either does the GOTO or "falls through" to the next statement depending on the button. It also does what's called "debouncing" (look this up in the Wikipedia) and handles repeating the button if you hold it down. As with everything on the Stamps, things are done only when the statement is executed. The button is tested only when the BUTTON statement is executed.

    If you want more help with your question, you really have to post your program for us to look at. Use the "+Reply to Thread" button, but click on the "Go Advanced" button. This will bring up a more complex window that includes an Attachment Manager that will let you upload your source program as an attachment to your message. DO NOT use cut and paste to put your program into your message. That actually makes it hard to read and annoys people unless the program is really short.
  • ngilliamngilliam Posts: 2
    edited 2011-03-11 09:04
    Be nice, I don't take my first programming class until next semester.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-11 20:20
    In the nicest way possible, I need to tell you that you really need to start over from the beginning with your program. The BUTTON statement is useful, but it won't get your program to work. You need to make sure you have copies handy of the "What's a Microcontroller?" tutorial and the "Basic Stamp Syntax and Reference Manual". These normally come with the hardware kits and you can download them from Parallax's Downloads webpage. They come with the Stamp Editor's help files as well.

    First study how to use pushbuttons with the Stamp. Chapter 2 of "What's a Microcontroller?" discusses how to use LEDs with a Stamp. Chapter 3 discusses how to use pushbuttons including how to control LEDs with pushbuttons and a Stamp. Once you have that under control, come back with a description of how you want your Stamp program to behave ... what you want the pushbuttons to do and describe the LED patterns
Sign In or Register to comment.