27404 Parallax Inc, 27404 Datasheet - Page 133

COMPETITION RING FOR SUMOBOT

27404

Manufacturer Part Number
27404
Description
COMPETITION RING FOR SUMOBOT
Manufacturer
Parallax Inc
Datasheet

Specifications of 27404

Accessory Type
Hobby and Education
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
SumoBot®
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
ACTIVITY #7: ORGANIZING SENSORS WITH FLAG BITS
Storing each sensor value as an individual bit is great for decision making, especially if
you want to isolate only one or two variables. In other cases, it's better to have all your
bits in a larger variable. It makes it easier for your program to analyze patterns in the
sensor flags. With PBASIC, you can have it both ways. This activity demonstrates how
to declare a sensors variable, and then declare individual flag bits within that variable.
Bit Declarations inside a Byte
By storing all your flag bits in a larger variable, they are still accessible as individual
values, but they are also accessible as a group for pattern analysis. It doesn't make
programming any more difficult. In fact, with PBASIC all you have to do is declare a
byte variable, and then declare the names of each individual bit in the byte.
For example, here are the 7 bit-variable declarations from TestAllSensorsYourTurn.bs2.
To arrange these in a byte, simply declare the byte variable, and then declare each bit as a
member of the byte variable. For example, if the byte is named
sensors.BIT0, irRF
variable declarations within a single
Repeat by using this feature to change
Some of the comments may now be out of alignment. Go through the program
and insert spaces to line the side comments back up to column 46.
Save your modified program; you will need it in the next couple activities.
irLS
irLF
irRF
irRS
qtiLF
qtiRF
pushbutton
sensors
pushbutton
qtiLF
qtiRF
can be
VAR
VAR
VAR
VAR
VAR
VAR
VAR
VAR
VAR
VAR
VAR
sensors.BIT1
Bit
Bit
Bit
Bit
Bit
Bit
Bit
Byte
sensors.BIT6
sensors.BIT5
sensors.BIT4
sensors
byte variable:
qtiStateLeft
, and so on. Here is the entire series of
' Sensor flags byte
' Stores pushbutton state
' Stores snapshot of QtiSigLeft
' Stores snapshot of QtiSigRight
' State of Left Side IR
' State of Left Front IR
' State of Right Front IR
' State of Right Side IR
' Stores snapshot of QtiSigLeft
' Stores snapshot of QtiSigRight
' Stores pushbutton state
to
sensors, irRS
qtiLF
.
can be

Related parts for 27404