IF THEN Question
Oldbitcollector (Jeff)
Posts: 8,091
Sorry about the newbieness of this, my nose is still buried in the WebPM document...
Question:
Can someone give me an example of an IF THEN based on several pin inputs?
I'd like to create a type of lookup table based on 8 pins and have it activate routines based on the highs of the pins.
Thanks
Question:
Can someone give me an example of an IF THEN based on several pin inputs?
I'd like to create a type of lookup table based on 8 pins and have it activate routines based on the highs of the pins.
Thanks
Comments
··· if dira[noparse][[/noparse]1] == 1··· 'if Pin 1 is HIGH then
····· dotask·········· 'jump to a method
· ··else················'otherwise
····· start············'go back to beginning (or somewhere)
Watch the indentation - it is critical.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
What I'm attempting to create is a table lookup that can detect how any set of eight pins are, (high/low) and excute a route depending on the detected set.
Something along the lines of..
'PINS 10,11,12,13,14,15,16,17,18
IF = 00000000 THEN
IF = 00000001 THEN
IF = 00000010 THEN
I intend to use the pins as input only, creating an address bus.
I intend to slave the features of the propeller to another popular 80's microproccesor. [noparse]:)[/noparse]
Oldbit
This will take the 8-bit binary pattern on I/O pins 10 through 17 (where 17 is the LSB) and execute one routine, or block of code, for every possibility.· The "..." between the last line and the top needs to be filled in with all the other combinations, of course.
Depending on the nature of what you are doing, this may take MUCH more code space than another method (ie: if there are common routines to execute for a number of given input combinations, you can combine them in the case's MatchExpression (see manual)).· There's also an OTHER keyword you can use as the last MatchExpression as a "catch-all" for all the cases that were not explicitly stated by previous MatchExpressions.
Note: You listed 9 I/O pins (10 through 18)... I cut it to 10 through 17 (8 I/O pins) since I think that's what you're really after.
Critical Note: ina[noparse][[/noparse]10..17] makes pin 17 the LSB, and 10 the MSB, of the value... if you want to flip it around (17 as MSB and 10 as LSB), simply write it as ina[noparse][[/noparse]17..10].
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Jeff Martin
· Sr. Software Engineer
· Parallax, Inc.
Jeff's suggestion is really the most straightforward. What Jeff is referring to for combining routines would be something like this:
In case you haven't run across this yet, there are commands to wait and respond to a changed state of pins(or pins to equal a state). Look at WAITPEQ and WAITPNE in the manual. On a state change (or State = somedesiredState), actions can be taken. I mention this because of your note below, in which case decisions may need to happen quickly on a change of pin states.
Post Edited (originator) : 3/17/2007 10:46:05 PM GMT