New Guy, some simple questions...
On 16 Jul 00 at 15:11, Nic Nicholson wrote:
> ...Is there any way to step through the input pins using a control
> loop? That is, something like the following:
>
> FOR index = 0 to pincount
> IF IN(index)=1 THEN dosomething
> NEXT
Nic-
Many moons ago the good Dr. Allen made the point that everything in
the variable space can be treated as an implicit array. In other
words, a single variable declaration is always element (0) of an
array of like-sized elements. An example:
byte_var VAR BYTE
bit_var VAR byte_var.LOWBIT
byte_var is the element 0 of an array of bytes stretching out into
the variable space beyond byte_var's storage location. Similarly,
bit_var, the low order bit of byte_var, even though not declared as
an array, can be treated as the 0th element of an array of bits
beginning at the low order bit of byte_var. bit_var(1) through
bit_var(7) can be used to address the remaining (ascending) bits of
byte_var.
Now put this trick together with the INS variable, which can be
treated like everything else in the variable space:
io_pin VAR INS.LOWBYE.LOWBIT
FOR index = 0 TO 15
IF io_pin(index) = 1 THEN dosomething
NEXT
Steve
> ...Is there any way to step through the input pins using a control
> loop? That is, something like the following:
>
> FOR index = 0 to pincount
> IF IN(index)=1 THEN dosomething
> NEXT
Nic-
Many moons ago the good Dr. Allen made the point that everything in
the variable space can be treated as an implicit array. In other
words, a single variable declaration is always element (0) of an
array of like-sized elements. An example:
byte_var VAR BYTE
bit_var VAR byte_var.LOWBIT
byte_var is the element 0 of an array of bytes stretching out into
the variable space beyond byte_var's storage location. Similarly,
bit_var, the low order bit of byte_var, even though not declared as
an array, can be treated as the 0th element of an array of bits
beginning at the low order bit of byte_var. bit_var(1) through
bit_var(7) can be used to address the remaining (ascending) bits of
byte_var.
Now put this trick together with the INS variable, which can be
treated like everything else in the variable space:
io_pin VAR INS.LOWBYE.LOWBIT
FOR index = 0 TO 15
IF io_pin(index) = 1 THEN dosomething
NEXT
Steve
Comments
time with it...I'm building up some basic skills on the way to my first
robot.
Within the first couple of days I've controlled an R/C servo (not hard, of
course) and ran a motor with an LM18200T.
Questions:
The motor ran rather roughly (lots of vibration) when I used PULSOUT and
PAUSE to set the duty cycle to the controller chip, but ran smoothly with
PWM, even with an 8 ms pause in between the 1-cycle PWMs. Was wondering if
anyone would know why...
Is there any way to step through the input pins using a control loop? That
is, something like the following:
FOR index = 0 to pincount
IF IN(index)=1 THEN dosomething
NEXT
or does it have to be
IF IN0=1 THEN dosomething
IF IN1=1...
spelling out each pin, one at a time.
Thanks in advance!
Nic
That
>is, something like the following:
>
>FOR index = 0 to pincount
> IF IN(index)=1 THEN dosomething
>NEXT
>
>>or does it have to be
>>IF IN0=1 THEN dosomething
>IF IN1=1...
Hi Nic,
It is almost as simple as your example. Try,
FOR index = 0 to pincount
IF IN0(index)=1 THEN dosomething
NEXT
The variable IN0 is a bit-size variable that refers to pin P0. The plain
variable IN0 and the array variable IN0(0) are the same thing. The
indexing counts up from there. IN0(1) is the same as IN1. And so on.
Read about modifiers and arrays in the stamp II v1.9 manual on page 223.
-- Tracy Allen
Electronically Monitored Ecosystems
http://www.emesystems.com