Configuring xbee example

/** 
 * demonstrates xbee module configuration from Arduino
 * it uses software serial to debug communications with xbee module
 * it reads an analog value on analog pin 0
 *
 * example taken from Tom Igoe and developed
 *
 * (cleft) 2008 Gonzalo Garcia-Perate
 * http://www.makingsenseofspace.com/arduino-wireless-workshop/
 *
 * Additions by Massimo Banzi / Tinker.it
 * 
 */


#include 
#include "string.h"

AFSoftSerial debug =  AFSoftSerial(3, 2);


int my_id = 20;
//int my_net = 0;

int i = 0;

char buffer[32];

void setup() {
  // configure serial communications:
  Serial.begin(9600);
  debug.begin(9600);
  debug.println("I'm awake");


  pinMode(13,OUTPUT);

  blink();
  blink();
  blink();

  debug.println("Configuring Module");
  // set XBee's parameters
  setupXbee();

  debug.println("Configuration done");

}



// reads data into a buffer with a timeout
// then it prints it for debugging purposes
int readUntil(char target) {
  long startTime;
  char thisByte;
  int pointer = 0;
  long currTime = 0;

  //set all items of buffer to 0
  memset(buffer,0,sizeof(buffer));

  //pointer to current time 
  startTime = millis();

  while (thisByte != target) {
    currTime= millis() - startTime;
    debug.print('.');
    if (Serial.available() > 0) {
      buffer[pointer] = thisByte;
      pointer++;
      thisByte = Serial.read();
      if (thisByte < 32) {
        debug.print('{');
        debug.print( thisByte,HEX );
        debug.print('}');
      }
      debug.print(thisByte);
    }
    if (currTime > 3000) 
      continue; 
  } 
  return pointer;
}




void setupXbee() {
  // put the radio in command mode:
  Serial.print("+++");
  delay(1100);
  // wait for the radio to respond with "OK\r"
  i = readUntil('\r');

  // 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, DL0\r");
  // set my address using 16-bit addressing:
  Serial.print("ATMY");
  Serial.print(my_id);
  Serial.print("\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("ATID4000\r");

  //commit changes to memmory
  //Serial.print("ATWR\r");

  // put the radio in data mode:
  Serial.print("ATCN\r");

}

//blinks LEd on in 13 for visual feedback
void blink() {
  digitalWrite(13,HIGH);
  delay(300);
  digitalWrite(13,LOW); 
  delay(300);
}

void loop() {
  Serial.print(my_id);
  Serial.print(",");
  Serial.print(analogRead(0));
  Serial.print("\r");
  delay( 100 );

}