im looking to simply send my pot. data over xbee to control my servo on the other side without interfering with my other controls heres my tx side
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12); // RX, TX
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
void setup()
{
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(SW3, INPUT_PULLUP);
pinMode(SW4, INPUT_PULLUP);
//pinMode(Light, INPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop(void)
{
byte data = 0;
if (digitalRead(SW1) == HIGH)
{
data += 1;
}
if (digitalRead(SW2) == HIGH)
{
data += 2;
}
if (digitalRead(SW3) == HIGH)
{
data += 4;
}
if (digitalRead(SW4) == HIGH)
{
data += 8;
}
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180);
if(data > 0)
{
delay(50);
mySerial.write(data);
Serial.print(data);
}
}
#include <MotorDriver.h>
#include <Servo.h>
Servo myservo;
byte data = 0;
void setup()
{
motordriver.init();
motordriver.setSpeed(250, MOTORB);
motordriver.setSpeed(250, MOTORA); // steering motor
myservo.attach(4);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0)
{
data = Serial.read();
}
if (data == 1)
{
motordriver.goForward();
}
else if (data == 2)
{
motordriver.goBackward();
}
else if (data == 4)
{
motordriver.goLeft();
}
else if (data == 8)
{
motordriver.goRight();
}
else if (data == 5)
{
motordriver.goForward();
motordriver.goLeft();
}
else if (data == 9)
{
motordriver.goForward();
motordriver.goRight();
}
else if (data == 6)
{
motordriver.goBackward();
motordriver.goLeft();
}
else if (data == 10)
{
motordriver.goBackward();
motordriver.goRight();
}
else
{
motordriver.stop();
}
delay(50);
if (data > 0)
{
Serial.print("data=");
Serial.println(data, DEC);
}
data -= data;
}