pin = ASCIItoInt(pin); // Convert ASCCI to a 0-13 value
pinMode(pin, OUTPUT); // Set pin as an OUTPUT
digitalWrite(pin, hl); // Write pin accordingly
}
// Write Analog Pin
// Send 'w' or 'W' to enter
// Then send a pin #
//
Use numbers for 0-9, and hex (a, b, c, or d) for 10-13
//
(it's not smart enough (but it could be) to error on
//
a non-analog output pin)
// Then send a 3-digit analog value.
//
Must send all 3 digits, so use leading zeros if necessary.
void writeAPin()
{
while (XBee.available() < 4)
; // Wait for pin and three value numbers to be received
char pin = XBee.read(); // Read in the pin number
int value = ASCIItoInt(XBee.read()) * 100; // Convert next three
value += ASCIItoInt(XBee.read()) * 10;
value += ASCIItoInt(XBee.read());
value = constrain(value, 0, 255); // Constrain that number.
// Print a message to let the control know of our intentions:
XBee.print("Setting pin ");
XBee.print(pin);
XBee.print(" to ");
XBee.println(value);
pin = ASCIItoInt(pin); // Convert ASCCI to a 0-13 value
pinMode(pin, OUTPUT); // Set pin as an OUTPUT
analogWrite(pin, value); // Write pin accordingly
}
// Read Digital Pin
// Send 'r' or 'R' to enter
// Then send a digital pin # to be read
// The Arduino will print the digital reading of the pin to XBee.
void readDPin()
{
while (XBee.available() < 1)
; // Wait for pin # to be available.
char pin = XBee.read(); // Read in the pin value
// Print beggining of message
XBee.print("Pin ");
XBee.print(pin);
pin = ASCIItoInt(pin); // Convert pin to 0-13 value
pinMode(pin, INPUT); // Set as input
// Print the rest of the message:
XBee.print(" = ");
XBee.println(digitalRead(pin));
}
// chars to a 3-digit
// number.
Need help?
Do you have a question about the XBee Shield and is the answer not in the manual?
Questions and answers