I'm trying to practice a bit more with XBees, and I wanted to try to use 2 potentiometers connected to one arduino to control 2 servo motors connected to another arduino via xbee. I'm using XBee series 1.
I saw the EasyTransfer library and thought that maybe this is the best way to go for a beginner like me.
For the sender part:
#include <EasyTransfer.h>
EasyTransfer ET;
int potpin1 = 0;
int potpin2 = 1;
struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};
SEND_DATA_STRUCTURE txdata;
void setup(){
Serial.begin(115200);
ET.begin(details(txdata), &Serial);
pinMode(potpin1, INPUT);
pinMode(potpin2, INPUT);
}
void loop(){
txdata.servo1val = analogRead(potpin1);
txdata.servo2val = analogRead(potpin2);
ET.sendData();
}
For the receiving side:
#include <Servo.h>
#include <EasyTransfer.h>
EasyTransfer ET;
Servo myservo1;
Servo myservo2;
struct RECEIVE_DATA_STRUCTURE{
int servo1val;
int servo2val;
};
RECEIVE_DATA_STRUCTURE txdata;
void setup(){
Serial.begin(115200);
ET.begin(details(txdata), &Serial);
myservo1.attach(9);
myservo2.attach(10);
}
void loop(){
if(ET.receiveData()){
myservo1.write(map(txdata.servo1val, 0, 1023, 0, 179));
myservo2.write(map(txdata.servo2val, 0, 1023, 0, 179));
}
}
I tried the code but nothing happens :S
Can you guys please tell me what I'm doing wrong? Thanks in advance