Shop OBEX P1 Docs P2 Docs Learn Events
i''m new, need help with command — Parallax Forums

i''m new, need help with command

ArchiverArchiver Posts: 46,084
edited 2004-02-10 14:58 in General Discussion
Ah, I see. Thanks for the help. That sounds like it might work.

So if I have an infinite loop looking at the buttons:

Button_Scan:
IF (ButtonA = 1) THEN BtnA_Sub
IF (ButtonB = 1) THEN BtnB_Sub
IF (ButtonC = 1) THEN BtnC_Sub
IF (ButtonD = 1) THEN BtnD_Sub
GOTO Button_Scan
....

Is this loop quick enough to catch a quick pulse on one of the
momentary buttons? I just don't know how fast the stamp scans, and I
don't want the program to be looking at ButtonC when someone presses
ButtonA, but they release it by the time the program gets back to
looking at ButtonA again.

Thanks,
Andy

--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
wrote:
> You can do this simply and prioritize your scan through simple IF-
THEN
>
> Button_Scan:
> IF (ButtonA = 1) THEN BtnA_Sub
> IF (ButtonB = 1) THEN BtnB_Sub
> ...
>
> BtnA_Sub:
> ' code for button A
> GOTO Button_Scan
>
> This uses an implicit GOTO in IF-THEN. The sample above assumes
that
> your inputs are active-high (read a 1 when the button is pressed --
> change to 0 for active low). While this code is a bit "grunt" it is
> simple and allows you to prioritize the buttons in the event that
more
> than one get pressed.
>
> If you want to check all the buttons in order and process those
that are
> pressed, you can change your code like this:
>
> Button_Scan:
> IF (ButtonA = 1) THEN GOSUB BtnA_Sub
> IF (ButtonB = 1) THEN GOSUB BtnB_Sub
> ...
>
> BtnA_Sub:
> ' code for button A
> RETURN
>
>
> -- Jon Williams
> -- Applications Engineer, Parallax
> -- Dallas Office
>
>
>
Sign In or Register to comment.