when i push a button its supposed to send a 1 to my cordinator xbee and drive a motor forward allthough the data comes across as 49 instead of the 1 that the router sends or is supposed to send....does xbee convert to this for some reason?
suppose i should show my code as well router first...
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 12); // RX, TX
//BUTTON PINS
const int SW1 = 8; //forward
const int SW2 = 9; //backward
const int SW3 = 3; //left
const int SW4 = 2; //right
void setup()
{
//SET BUTTON AS PULLUP
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)
{
unsigned char i = 0;
//Forward
if (digitalRead(SW1) == HIGH)
{
i += 1;
}
//Backward
if (digitalRead(SW2) == HIGH)
{
i += 2;
}
//left
if (digitalRead(SW3) == HIGH)
{
i += 4;
}
//right
if (digitalRead(SW4) == HIGH)
{
i += 8;
}
if(i > 0)
{
mySerial.print(i);
Serial.print(i);
}
}
#include <MotorDriver.h>
int data = 0;
const int rx_led = 42;
void setup()
{
//MOTOR SHIELD SET MOTOR SPEEDS
motordriver.init();
motordriver.setSpeed(400, MOTORB);
motordriver.setSpeed(200, MOTORA); // steering motor
//DATA RECIEVE INDICATOR LIGHT
pinMode(rx_led, OUTPUT);
digitalWrite(rx_led, LOW);
//RECIEVER PINS
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
//BEGIN SERIAL COMMUNICATION
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
}
//DATA FROM TRANSMITTER TO DETERMINE MOVE FUNCTION
// move forward
if (data == 1)
{
motordriver.goForward();
}
//move backward
else if (data == 2)
{
motordriver.goBackward();
}
//straight left turn
else if (data == 5)
{
motordriver.goForward();
motordriver.goLeft();
}
//straight right turn
else if (data == 9)
{
motordriver.goForward();
motordriver.goRight();
}
//back left turn
else if (data == 6)
{
motordriver.goBackward();
motordriver.goLeft();
}
//back right turn
else if (data == 10)
{
motordriver.goBackward();
motordriver.goRight();
}
else
{
motordriver.stop();
}
//SERIAL PRINT DATA RECIEVED
delay(50);
Serial.print("data=");
Serial.println(data, DEC);
}
unsigned char i = 0;
The char type is normally signed. Why are you using unsigned?
int data = 0;
Why are you sending a char, and receiving an int? They are not even the same size.