Shop OBEX P1 Docs P2 Docs Learn Events
I am trying to create a code with pushbuttons HELP — Parallax Forums

I am trying to create a code with pushbuttons HELP

MunifTheGreatMunifTheGreat Posts: 20
edited 2011-12-16 10:01 in BASIC Stamp
Basically, I want to create a pushbutton sequence.
For example, if I press the first push buttons (IN1) twice and the second push button (IN2) once in this order the light in P15 goes on.
And I want also to have time to press buttons in this sequence for 1 sec.
IF not a piezo will create a sound

as

FREQOUT 0, 500, 2000
PAUSE 50
FREQOUT 0, 500, 2000

Can you help me find the programming code for this?
Reply if you need clarification or you want to respond.

Thank you

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-16 09:36
    This sounds like a project for a class and we can't help you write the program other than to point you to useful information and help answer specific questions.

    There are general descriptions of how to handle pushbuttons in the "What's a Microcontroller?" tutorial, available by going to the main Parallax webpage and clicking on the Downloads button. You'll then see a "Stamps in Class Tutorials and Translations" button and you'll find a link to the tutorial's PDF there. On the Downloads page, you can also click on "Stamp Documentation" and you'll see "BS1 Application Notes". Even though this is written for the BS1, item #19 (page 159) covers the BUTTON statement which is on both the BS1 and BS2 Stamps.

    To handle multiple button pushes, you typically have a loop for each button push. The first loop waits for the first button push, then goes to the 2nd loop which waits for the 2nd button push, then goes to the 3rd loop which waits for the 3rd button push. Doing the timing is difficult since the Stamps don't have a timer that's accessible to the program. You can use a PAUSE statement to set up a time "tick" so that each time through one of the wait loops, your program does a known length PAUSE and you count the number of times the loop is executed to get an approximate time. Usually 100ms is a good "tick". It's long enough so the execution time of the statements around it doesn't affect the total time much and it's short enough so it won't significantly slow down the response of the program to a button push.
  • ercoerco Posts: 20,256
    edited 2011-12-16 10:01
    MTG: Take your shot at the code, then come back for more specific help if you need it.
Sign In or Register to comment.