Shop OBEX P1 Docs P2 Docs Learn Events
Button command — Parallax Forums

Button command

mike_smike_s Posts: 42
edited 2006-01-16 04:04 in BASIC Stamp
I have made much progress with the microwave oven controller that I am working on but have come up with a problem in using the bs2 for this project.
In the routine for the timer I have added a pause which is bascially the start button embedded in the countdown sub.
However the pause is not consistent or requires holding the button for an extended period while the rest of the code continues back to the point where I have inserted the button read.
Is there another way of handling this function?
I see that with higher models of stamp there is a pollin command which checks the state of a pin between executing each statement which is ideal but can I get the bs2 to operate the same way by some magic in code?
·

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-14 23:33
    mike_s,

    · Let's see your button subroutine.
  • mike_smike_s Posts: 42
    edited 2006-01-15 02:31
    Thanks had to attach
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-15 03:11
    Do you have P8, 9, 10, 11, 12 pulled HI (each Pin) and each button is a Normally Open pushbutton?·

    What's the flow -- at what point do you want to "engage"/start waving? With Dwnmin?

    Post Edited (PJ Allen) : 1/15/2006 3:33:41 AM GMT
    252 x 287 - 14K
    pb.jpg 13.7K
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-15 03:54
    PBASIC is quite flexible and will allow you to structure your program such that you could check the button in between tasks -- not lines of code.· I frequently use a program setup that looks something like this:

    Main:
    · DO
    · · Do_Something_Important
    ·· ·ON task GOSUB Task0, Task1, Task2
    ·· ·task = task + 1 // 3
    · LOOP

    By breaking your code into small tasks you can interleave critical process in between.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • mike_smike_s Posts: 42
    edited 2006-01-15 07:36
    Yes pj I have a 1k resistor pulling each·pin high with normally open contacts. Goes low when the button is pressed.

    I'll see how the sample you've supplied works Jon.Thanks to both of you.
  • mike_smike_s Posts: 42
    edited 2006-01-16 02:54
    I should ask in the example you provided Jon

    Main:
    DO
    Do_Something_Important
    ON task GOSUB Task0, Task1, Task2
    task = task + 1 // 3
    LOOP

    I'm not sure how the //3 affects task = task + 1
    does this limit task to the values 0-2?
    If so that is something I was unaware of and gives me a new method.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-16 04:04
    Yes, the modulus (//) operator returns the remainder of a divsion, hence the result will always be something between zero and the divisor-1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.