How do you scan multiple input pins inside a FOR ...NEXT loop?
Lighter Man
Posts: 3
I can do it using brute force:
IF IN1 = 1 THEN GOHERE1
IF IN2 = 1 THEN GOHERE2
IF IN3 = 1 THEN GOHERE3
IF IN4 = 1 THEN GOHERE4
IF IN5 = 1 THEN GOHERE5
IF IN6 = 1 THEN GOHERE6
But I'd like to do it using something like:
FOR N= 1·TO 6
IF IN(N) = 1·THEN GOHERE(N)
NEXT N
This does not work. Any ideas?· Thanks, Perry
IF IN1 = 1 THEN GOHERE1
IF IN2 = 1 THEN GOHERE2
IF IN3 = 1 THEN GOHERE3
IF IN4 = 1 THEN GOHERE4
IF IN5 = 1 THEN GOHERE5
IF IN6 = 1 THEN GOHERE6
But I'd like to do it using something like:
FOR N= 1·TO 6
IF IN(N) = 1·THEN GOHERE(N)
NEXT N
This does not work. Any ideas?· Thanks, Perry
Comments
Syntax: ON Offset GOTO Address1, Address2, ...AddressN
Function
Go to the address specified by offset (if in range).
Quick Facts
Explanation
The ON...GOTO instruction is useful when you want to write something like this:
IF idx = 0 THEN Case_0 ' idx = 0: jump to label "Case_0" IF idx = 1 THEN Case_1 ' idx = 1: jump to label "Case_1" IF idx = 2 THEN Case_2 ' idx = 2: jump to label "Case_2"
You can use ON...GOTO to organize this into a single statement:
ON idx GOTO Case_0, Case_1, Case_2This works exactly the same as the previous [url=mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2\PBASIC.chm::/if_then.htm]IF...THEN[/url] example. If the value isn't in range (in this case if value is greater than 2), ON...GOTO does nothing and the program continues with the next instruction after ON...GOTO.
When referencing inputs your must specify the index from an actual pin, for example: IN0(N). Also, you can’t specify a label with an offset like that. If I were trying to do this I would probably try something like:
Note that this will look at all 8 I/O pins from P0 through P7 and that you will need 9 addresses unless you filter the input. Also, in cases where multiple inputs are high the lower pins will have priority.· I hope this helps. If you have additional questions let me know. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks!
-john
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Post Edited (Chris Savage (Parallax)) : 7/6/2007 2:41:12 PM GMT