beautypg.com

2 programming the digital i/o ports, 3 programming the a/d ports, 4 programming the speaker – Pioneer Module Mobile User Manual

Page 22

background image

Experimenter’s Module

18

5.2 Programming the Digital I/O Ports

Use the sfCOMDIGOUT PSOS command and the related Saphira convenience

command to manage the various digital output ports. They are described in detail in the
previous chapter. (PAI and P-LOGO support similar commands, too.)

For example, to turn the right LED on, use:

sfRobotCom2Bytes(sfCOMDIGOUT, sfRIGHTLEDBIT,
sfRIGHTLEDBIT)

Or alternatively, specify the state of an LED:

void sfGripperSetLed(int which, int state)

for which=sfLEFT or sfRIGHT, and state=sfON or sfOFF.

5.3 Programming the A/D Ports

The eight analog-to-digital (A/D) ports on the Experimenter’s Module (AN0-7) are

multiplexed from a single A/D port on the Pioneer 1 microcontroller. Hence, only one
port may be read at a time, although all eight ports may connect to individual sources.

Each AN port accepts a 0-5VDC analog input and outputs a proportionally related,

single byte value 0-255. Use the digital output ports OD5-7 to address which port PSOS
will read and return as the A/D value in the Server Information Packet (section 3.2, PSOS
Server Information Packet
).

For example, the following Saphira command addresses the AN4 port by masking the

OD5-7 ports, setting OD7, and resetting OD5 and OD6: (remaining output ports remain
untouched:

sfRobotCom2Bytes(sfCOMDIGOUT, 0xE0, 0x80)

5.4 Programming the Speaker

The latest PSOS implements a new command called SAY, which plays a sequence of

up to 20 notes through the Experimenter’s Module speaker. Now your Pioneer will be
humming a different tune!

The SAY command (number 15) has two arguments: a string up to 40 bytes long, and

the integer number of actual bytes in the string:

sfRobotComStrn(sfCOMSAY, str, n)

The string is comprised of duration and tone pairs; the duration byte is the number of

20 millisecond increments the following tone value half-cycle times—in 150
microsecond increments—should be played through the speaker.

For example, to play two short, high beeps using the Saphira equivalent command:

void sfPlayToneString ("\010\002\010\000\010\002", 6)