davejames
11-03-2009, 11:40 PM
Hi All,
(Using a BS2 w/PBasic 2.5)
I have the need to test P1, P2 and P3 for a 'high', and I thought the SELECT/CASE approach would be suitable.· So the initially, the code was:
DIRS $1111111111110000 'pins 0-3 inputs, 4-15 outputs
testpin PIN 0
DO WHILE (testpin) 'while P0 true
···· SELECT INA
········· CASE INA.BIT1 'P1 true
·············· GOSUB DoSomething1
········· CASE INA.BIT2 'P2 true
·············· GOSUB DoSomething2
········· CASE INA.BIT3 'P3 true
·············· GOSUB DoSomething3
···· ENDSELECT
LOOP
END
DoSomething1:
···· DEBUG "...do something 1", CR
RETURN
DoSomething2:
···· DEBUG "...do something 2", CR
RETURN
DoSomething3:
···· DEBUG "...do something 3", CR
RETURN
·
When this code is run, I never see the "...do something" messages when the appropriate BS2 pin is 'high', so I'm guessing that·I am using the SELECT/CASE construct incorrectly or I'm not understanding the intricacies of INS and INA.
·
If the code is modified as below, I do see the messages:
·
DO WHILE (testpin) 'while P0 true
···· IF IN1 THEN 'P1 true
········· GOSUB DoSomething1
···· ELSEIF IN2 THEN·'P2 true
········· GOSUB DoSomething2
···· ELSEIF IN3 THEN·'P3 true
········· GOSUB DoSomething3
···· ENDIF
LOOP
Since the above works, I can go ahead and use it...but I'd still like clarification on why the SELECT/CASE approach doesn't.
·
Any thoughts would be appreciated,
·
DJ
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Instead of:
"Those who can, do.· Those who can't, teach." (Shaw)
I prefer:
"Those who know, do.· Those who understand, teach." (Aristotle)
Post Edited (davejames) : 11/4/2009 5:13:49 PM GMT
(Using a BS2 w/PBasic 2.5)
I have the need to test P1, P2 and P3 for a 'high', and I thought the SELECT/CASE approach would be suitable.· So the initially, the code was:
DIRS $1111111111110000 'pins 0-3 inputs, 4-15 outputs
testpin PIN 0
DO WHILE (testpin) 'while P0 true
···· SELECT INA
········· CASE INA.BIT1 'P1 true
·············· GOSUB DoSomething1
········· CASE INA.BIT2 'P2 true
·············· GOSUB DoSomething2
········· CASE INA.BIT3 'P3 true
·············· GOSUB DoSomething3
···· ENDSELECT
LOOP
END
DoSomething1:
···· DEBUG "...do something 1", CR
RETURN
DoSomething2:
···· DEBUG "...do something 2", CR
RETURN
DoSomething3:
···· DEBUG "...do something 3", CR
RETURN
·
When this code is run, I never see the "...do something" messages when the appropriate BS2 pin is 'high', so I'm guessing that·I am using the SELECT/CASE construct incorrectly or I'm not understanding the intricacies of INS and INA.
·
If the code is modified as below, I do see the messages:
·
DO WHILE (testpin) 'while P0 true
···· IF IN1 THEN 'P1 true
········· GOSUB DoSomething1
···· ELSEIF IN2 THEN·'P2 true
········· GOSUB DoSomething2
···· ELSEIF IN3 THEN·'P3 true
········· GOSUB DoSomething3
···· ENDIF
LOOP
Since the above works, I can go ahead and use it...but I'd still like clarification on why the SELECT/CASE approach doesn't.
·
Any thoughts would be appreciated,
·
DJ
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Instead of:
"Those who can, do.· Those who can't, teach." (Shaw)
I prefer:
"Those who know, do.· Those who understand, teach." (Aristotle)
Post Edited (davejames) : 11/4/2009 5:13:49 PM GMT