Shop OBEX P1 Docs P2 Docs Learn Events
Help with pushbuttons — Parallax Forums

Help with pushbuttons

ctodd901ctodd901 Posts: 5
edited 2012-10-01 15:26 in BASIC Stamp
i have to design and simulate a intersection with two stop lights and a push button to simulate a pedestrian crosswalk. and im having trouble getting the pushbutton to do what i want it to. I have to be able to push the pushbutton at any time during the two stop light sequences and then have the crosswalk go green after the street lights turn red. so my question is there a way to store the status of a push button and store that in a variable until the end of the stoplight sequence and then use that variable in some sort of if statement?

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-01 08:03
    Use a button that goes to logical 1 when pressed. Initialize a state variable to zero. Continue to read the push button value and bitwise or the current reading with the state variable and assign the result to the state variable. If at any point during the interval the button goes high, the variable will stay high.
  • ctodd901ctodd901 Posts: 5
    edited 2012-10-01 10:05
    Martin_H wrote: »
    Use a button that goes to logical 1 when pressed. Initialize a state variable to zero. Continue to read the push button value and bitwise or the current reading with the state variable and assign the result to the state variable. If at any point during the interval the button goes high, the variable will stay high.

    thanks for the quick response but im still having trouble getting the push button state to hold it value. Every time the light switches from green to yellow to red the push button resets itself to 0?
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-01 10:45
    I'd suggest posting your code with a question about a specific section. I'm not sure what you mean.
  • PublisonPublison Posts: 12,366
    edited 2012-10-01 11:20
    As Martin_H suggested, please post your code.

    Are you using the BUTTON command to debounce your switches?
  • ctodd901ctodd901 Posts: 5
    edited 2012-10-01 12:51
    not on my home pc right now but here are my instructions hopefully this will clear thing up

    1. Design and implement a basic stamp based circuit that would simulate the working of two sets of traffic lights at an intersection.
    2. Add a pushbutton to allow pedestrians to cross one street. When the button is pushed, all traffic should stop (not immediately). The pedestrian light will turn green and will stay so for 30 seconds, unless the button is pressed again before the pedestrian light turns red. The last 10 second, the green light will be flashing to indicate that time is almost up to crossing the street. The push button can be only pushed twice at a time for a maximum of one minute. After that, it will return to red and normal operation will resume. Use the bi-color LED for your pedestrian light.
  • PublisonPublison Posts: 12,366
    edited 2012-10-01 13:38
    ctodd901 wrote: »
    not on my home pc right now but here are my instructions hopefully this will clear thing up

    1. Design and implement a basic stamp based circuit that would simulate the working of two sets of traffic lights at an intersection.
    2. Add a pushbutton to allow pedestrians to cross one street. When the button is pushed, all traffic should stop (not immediately). The pedestrian light will turn green and will stay so for 30 seconds, unless the button is pressed again before the pedestrian light turns red. The last 10 second, the green light will be flashing to indicate that time is almost up to crossing the street. The push button can be only pushed twice at a time for a maximum of one minute. After that, it will return to red and normal operation will resume. Use the bi-color LED for your pedestrian light.

    Sounds like a school project?

    It would not be fair to write the code for you, but if you have some code that you have already written, and are stumped in a certain area, we would be glad to help.
  • ctodd901ctodd901 Posts: 5
    edited 2012-10-01 14:06
    DO


    HIGH 2
    HIGH 13
    PAUSE 2000


    '1st traffic light sequence


    LOW 13
    HIGH 15
    PAUSE 2500


    LOW 15
    HIGH 14
    PAUSE 2000


    LOW 14
    HIGH 13




    PAUSE 5000
    ' second traffic light sequence






    LOW 2
    HIGH 0
    PAUSE 2500


    LOW 0
    HIGH 1
    PAUSE 2000


    LOW 1
    HIGH 2


    PAUSE 2500


    LOOP
  • ctodd901ctodd901 Posts: 5
    edited 2012-10-01 14:10
    thats the first part ive written which is just gettin the leds to work correctly. ive also partially written the led sequence for the crosswalk leds. im stuck on how to get one push of the push button at anytime during the previous code. to hold the input state of 1 or on.... if i figure that out i think i can figure out how to direct everything else by using if statements or my goto routines or something like that
  • PublisonPublison Posts: 12,366
    edited 2012-10-01 15:23
    ctodd901 wrote: »
    thats the first part ive written which is just gettin the leds to work correctly. ive also partially written the led sequence for the crosswalk leds. im stuck on how to get one push of the push button at anytime during the previous code. to hold the input state of 1 or on.... if i figure that out i think i can figure out how to direct everything else by using if statements or my goto routines or something like that

    Are you familiar with Flowcharts?

    http://en.wikipedia.org/wiki/Flowchart

    T
    hey are really helpful to get an idea together, and helps out a lot with the programming down the road.

    .
  • PublisonPublison Posts: 12,366
    edited 2012-10-01 15:26
    attachment.php?attachmentid=78421&d=1297987572



Sign In or Register to comment.