Propeller Manual

Table Of Contents
2: Spin Language Reference – WAITPEQ
Propeller Manual v1.1 · Page 223
Using Variable Pin Numbers
For Propeller objects, quite often it is necessary to monitor a single pin whose pin number is
specified outside the object itself. An easy way to translate that pin number into the proper
32-bit State and Mask value is by using the Bitwise Decode operator “
|<” (See 160 for more
information). For example, if the pin number was specified by the variable
Pin, and we
needed to wait until that pin is high, we could use the following code:
waitpeq(|< Pin, |< Pin, 0) 'Wait for Pin to go high
The Mask parameter, |< Pin, evaluates to a long value where only one bit is high; the bit that
corresponds to the pin number given by
Pin.
Waiting for Transitions
If we needed to wait for a transition from one state to another (high-to-low, for example) we
could use the following code:
waitpeq(%100000, |< 5, 0) 'Wait for Pin 5 to go high
waitpeq(%000000, |< 5, 0) 'Then wait for Pin 5 to go low
This example first waits for P5 to go high, then waits for it to go low; a high-to-low
transition. If we had used the second line of code without the first, the cog would not have
paused at all if P5 had been low to start with.