Hardware Reference
In-Depth Information
First, give the I/O pins
names, and set up
some variables for tracking the change
in the potentiometer.
Make It
const int sensorPin = A0; // input sensor
const int analogLed = 3; // LED that changes brightness w/incoming value
const int threshold = 10; // threshold for sensor's change
int lastSensorReading = 0; // previous state of the sensor
String inputString = "";
Next, in the setup() method,
configure serial transmission, set the
modes on the I/O pin, and configure
the XBee's destination address.
8
void setup() {
// configure serial communications:
Serial.begin(9600);
// configure output pin:
pinMode (analogLed, OUTPUT);
// set XBee's destination address:
setDestination();
// blink the TX LED indicating that the main program's about to start:
blink(analogLed, 3);
}
The XBee configuration, handled
by the setDestination() method, looks
just like what you did earlier, only now
you're instructing the microcontroller
to do it.
8
void setDestination() {
// put the radio in command mode:
Serial.print("+++");
// wait for the radio to respond with "OK\r"
char thisByte = 0;
while (thisByte != '\r') {
if (Serial.available() > 0) {
thisByte = Serial.read();
}
}
8 Change the destination address to that of
the radio you're attaching to your personal
computer, not the one that's attached to your
microcontroller.
// set the destination address, using 16-bit addressing.
// if you're using two radios, one radio's destination
// should be the other radio's MY address, and vice versa:
Serial.print("ATDH0, DL 5678 \r");
// set my address using 16-bit addressing:
Serial.print("ATMY1234\r");
// set the PAN ID. If you're working in a place where many people
// are using XBees, you should set your own PAN ID distinct
// from other projects.
Serial.print("ATID1111\r");
// put the radio in data mode:
Serial.print("ATCN\r");
}
 
Search WWH ::




Custom Search