i''m new, need help with command
Archiver
Posts: 46,084
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
Original Message
From: andy_watson5 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=FyaVHaCzvCRBbq2JIIfFgW3bj4OIg2HinRPMQTSJRmRGOmn7AIfN26_einzl8IdSvZE5mjazrVrV]andywatson@m...[/url
Sent: Monday, February 09, 2004 9:45 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] i'm new, need help with command
I'm new to Basic Stamps. I've written lots of code, mainly C++ and a
little Basic years ago. I'm trying to write a program and I'm
stuck. I've got the main part of my program written, but I need help
getting switch inputs to trigger subroutines.
Here's a basic description of my circuit: A user can press one of 4
momentary switches, labeld A, B, C, and D. Pressing the A buttons
will cause the program to go into the A subroutine, pressing the B
button goes into the B subroutine, and so forth.
I just can't figure out how to make the program look for these
triggers. I want the stamp to be continuously looking for one of the
4 inputs. I originally thought POLLIN would work, but I can't find a
way for it to distinquish which button was pressed. And since it's
just a momentary pulse coming from the switch, I can't think of what
else to use.
Does anyone have any suggestions? By the way, it's a BS2p40, because
I have 20 I/O elements for this program.
Thanks for any help you might be able to offer.
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....
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
Original Message
From: andy_watson5 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=FyaVHaCzvCRBbq2JIIfFgW3bj4OIg2HinRPMQTSJRmRGOmn7AIfN26_einzl8IdSvZE5mjazrVrV]andywatson@m...[/url
Sent: Monday, February 09, 2004 9:45 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] i'm new, need help with command
I'm new to Basic Stamps. I've written lots of code, mainly C++ and a
little Basic years ago. I'm trying to write a program and I'm
stuck. I've got the main part of my program written, but I need help
getting switch inputs to trigger subroutines.
Here's a basic description of my circuit: A user can press one of 4
momentary switches, labeld A, B, C, and D. Pressing the A buttons
will cause the program to go into the A subroutine, pressing the B
button goes into the B subroutine, and so forth.
I just can't figure out how to make the program look for these
triggers. I want the stamp to be continuously looking for one of the
4 inputs. I originally thought POLLIN would work, but I can't find a
way for it to distinquish which button was pressed. And since it's
just a momentary pulse coming from the switch, I can't think of what
else to use.
Does anyone have any suggestions? By the way, it's a BS2p40, because
I have 20 I/O elements for this program.
Thanks for any help you might be able to offer.
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....