/////////////////////////////////////////// // // // Created by Glen Turner // // turner.glen@gmail.com // /////////////////////////////////////////// //These functions are used for serial communication with Xbee // Usefull so that Serial can be reserved for Serial communication with the // the computer. If this is not done, the XBee will have to be unpluged every // time code is uploaded. char returnChar(int serialNumber){ // return char waits for a single char from the given serial number // input perameters: 0, 1, 2, 3 // output: returned char char ch; switch(serialNumber){ case 0: while ( !Serial.available()) { //wait for a character delay(10); } ch = Serial.read(); break; case 1: while ( !Serial1.available()) { //wait for a character delay(10); } ch = Serial1.read(); break; case 2: while ( !Serial2.available()) { //wait for a character delay(10); } ch = Serial2.read(); break; case 3: while ( !Serial1.available()) { //wait for a character delay(10); } ch = Serial1.read(); break; } return ch; } /////////////////////////////////// // printing functions for xBee // /////////////////////////////////// // these are over loaded functions to replace Serial.print() and Serial.println() functions // this way serial zero (serial.print) can be resurved for uploading code to the arduino // this prevents the XBee from having to be unplugged when uploading and downloading code void Xprint(char stringIn[]){ Serial1.print(stringIn); } void Xprint(String& stringIn){ Serial1.print(stringIn); } void Xprintln(String& stringIn){ Serial1.println(stringIn); } void Xprint(char charIn){ Serial1.print(charIn); } void Xprintln(char charIn){ Serial1.println(charIn); } void Xprint(int in){ Serial1.print(in); } void Xprint(float in){ Serial1.print(in); } void Xprint(float in, int intIn){ Serial1.print(in, intIn); } void Xprint(double in){ Serial1.print(in); } void Xprint(double in, int intIn){ Serial1.print(in, intIn); } void Xprintln(char stringIn[]){ Serial1.println(stringIn); } void Xprintln(int in){ Serial1.println(in); } void Xprintln(float in){ Serial1.println(in); } void Xprintln(double in){ Serial1.println(in); } void Xprintln(float in, int intIn){ Serial1.println(in, intIn); } void Xprintln(double in, int intIn){ Serial1.println(in, intIn); }