Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp Pushbutton Holder — Parallax Forums

Basic Stamp Pushbutton Holder

BibbiBibbi Posts: 4
edited 2011-05-13 09:21 in General Discussion
I'm starting with push buttons right now, and I've come across a little problem of sorts, and I'm sure I can't fix it in the code.

HIGH 1

Main:
IF (IN2 = 1) THEN
HIGH 10
PAUSE 500
LOW 10
PAUSE 500
ELSE
HIGH 5
PAUSE 500
LOW 5
PAUSE 500
ENDIF
GOTO Main

Here's a couple of note's:
1) The reason pin 1 is high, is because I currently don't have a 5V power supply for my push button.
2) The reason it's pin 1, is because I accidentally used 9V power supply that is powering my Basic Stamp on pin 0

Anyway, my question is, is there anyway to make it so that if I push the button on pin 2, that it'll say it was pressed when it gets back to the if statement? Because as of right now, I need to be holding it down when it reaches the if statement to activate the code in the if of the if statement, but I want it to activate something (probably will need to be something on the circuit) that will stay on until the if statement is reached, and then turn that something off.

Any ideas? If it's on the circuit board, please include a wiring diagram.

Comments

  • RiJoRiRiJoRi Posts: 157
    edited 2011-05-13 08:45
    Probably! But first you need to define when you want IN2 to reset. Or do you want the quick flashes only until the switch is active?

    This is pseudo-code. It will NOT run...
    1) Quick flash until switch is pressed:
    Main:
        S1 = IN2
        IF S1 <> 1
            Do quick flashes
        ELSE
    Loop:
            Do Slow Flashes
            GOTO Loop
        ENDIF
    GOTO Main
    

    It is also possible to do code so that the first press of the switch starts the slow flashes, and a second press stops the slow flashes, OR a second switch can be used in place of a second press. (Welcome to the world of software design!)

    --Rich
    P.S., this should probably have been posted in the BASIC Stamp forum!
  • BibbiBibbi Posts: 4
    edited 2011-05-13 09:21
    Okay, I guess I didn't specify it well enough, I'm probably not going to do a flashing light from a push button.

    All I want is if a button was pushed in let's say this code

    Main:
    IF IN1 = 1 THEN TOGGLE 2
    PAUSE 10000
    GOTO Main

    at the 5 second mark of the 10 second pause, that something would make sure the if statement would activate when this loops, even if the button was pressed for the shortest amount of time possible.
Sign In or Register to comment.