Trust me, that sensor is a pain in the backside... Go with the -08 if cost is not a problem. It does the distance calculations for you, and lets you connect more than one unit to the same set of wires.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
Im having trouble understanding the code for the 08, wich brings up a few other questions I had.
What is the PIN command? (Ive never heard of it)
The basic stamp is divided up into 5 sections, in know pins 1-16 are divided into A-D. In a program I saw it was reading pins 12 and 13 and used the command
SPEED= (IND & %0011)
to get 0, 1, 2, or 3 out of any combination if pins 13 and 14. I get what the result is, but Im not sure what the & actually does with the %0011.
Same question goes for
MODE= (IND >> 2)
wich reads pins 14 and 15 and also converts to a number 0-3. There is no explination of what >> does.
Ill study the 08 program tonight and see what I can figure out.
PIN (new in PBASIC 2.5) is not a command, it's a type: it allows you to define an IO pin. Why is this important? Because some elements of the language want a pure numeric value for the pin (e.g, 1 for P1), others want the input register bit (e.g., IN1 for P1), and finally, some elements of the language want the output bit (e.g., OUT1 for P1). Before the PIN definition some programs required redundant definitions for the same physical IO pin.
%0011 is a 4-bit binary notation for the value 3. In the case you cited, it is being used as a mask value so that only bits 0 and 1 (pins 12 and 13) of that port IND (pins 12, 13, 14, and 15) are evaluated. The other bits, being ANDED with 0, get ignored.
>> is the right shift operator (see chapter 4 of the manual, or the operator section of the help file). It shifts a value n number of bits. For example, %1100 >> 2 = %0011.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
Another cool feature of the 08 is that you can set a register that controls how long the reciever will wait for the ping...so instead of ranging out to 6 meters·or so, you can set it to only range say 1 meter, which is perfect for obstacle avoidance. Doing so takes way less time to do, so you can make alot more measurements in the same amount of time. The 08 also has 2 light sensors onboard.
I dont think I can program it. I can follow the flow of the program, but I dont know what anything is doing. It looks too long also, the program needs to run faster for what I need.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
What is the PIN command? (Ive never heard of it)
The basic stamp is divided up into 5 sections, in know pins 1-16 are divided into A-D. In a program I saw it was reading pins 12 and 13 and used the command
SPEED= (IND & %0011)
to get 0, 1, 2, or 3 out of any combination if pins 13 and 14. I get what the result is, but Im not sure what the & actually does with the %0011.
Same question goes for
MODE= (IND >> 2)
wich reads pins 14 and 15 and also converts to a number 0-3. There is no explination of what >> does.
Ill study the 08 program tonight and see what I can figure out.
%0011 is a 4-bit binary notation for the value 3. In the case you cited, it is being used as a mask value so that only bits 0 and 1 (pins 12 and 13) of that port IND (pins 12, 13, 14, and 15) are evaluated. The other bits, being ANDED with 0, get ignored.
>> is the right shift operator (see chapter 4 of the manual, or the operator section of the help file). It shifts a value n number of bits. For example, %1100 >> 2 = %0011.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office