Working on an arduinoless joystick to control a snow plow robot using direct IO. I have the x axis of the code working but am not used to serial, can someone help me refine the code to work with the second axis as well. I am not sure how to pull the data from the D1 pin. I have been referencing the Xbee S2 Quick reference Guide: http://www.tunnelsup.com/xbee-s2-quick-reference-guide-cheat-sheet. The code i have thus far is a derivative of code found in the Arduino Cook book by Michael Margolis.
The Setup:
Controller - 2 axis joystick
Series 2 xbee in Router AT mode
X axis D0 - Set to ADC output
Y axis D1 - Set to ADC output
Receiver - Arduino Uno + series 2 xbee in Coordinator API mode
pin 9 led emulates x axis control
pin 12 led will emulate y axis control
The code which is working for the X axis:
#define LEDPINX 9
#define LEDPINY 12
void setup() {
Serial.begin(9600);
pinMode(LEDPINX, OUTPUT);
pinMode(LEDPINY, OUTPUT);
}
void loop() {
if (Serial.available() >= 21) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 18; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();
int analogValue = analogLow + (analogHigh * 256);
// Scale the brightness to the Arduino PWM range
int brightness = map(analogValue, 0, 1023, 0, 255);
Serial.print("Analog High");
Serial.println(analogHigh);
Serial.print("Analog Low");
Serial.println(analogLow);
Serial.print("Analog");
Serial.println(analogValue);
Serial.print("Brightness");
Serial.println(brightness);
Serial.println(" ");
//delay(1000);
// Light the LED
analogWrite(LEDPINX, brightness);
}
}
}


