Sending an integer with xbee

Hello,

For my project i am trying to send the value of a variable from one arduino to another with 2 xbee's series 1.

To be more specific i have made a circuit where the sending arduino is connected to a pushbutton (pin2) and a LED (pin13). The receiving arduino also has a LED on pin 13.
I am trying to make the LED on the receiving arduino go on by pushing the button on de sending arduino.

This is my code:
(sending arduino)

const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop(){

buttonState = digitalRead(buttonPin);

if (buttonState == 1) {
digitalWrite(ledPin, HIGH);
}
if (buttonState == 0) {
digitalWrite(ledPin, LOW);
}

Serial.print(buttonState);
delay(100);

}

(receiving arduino)

int buttonState = 0;
const int ledPin = 13;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {

if (Serial.available() > 0){

buttonState = Serial.write(Serial.read());
Serial.println(buttonState);
}

if (buttonState == 1) {
digitalWrite(ledPin, HIGH);
}
if (buttonState == 0) {
digitalWrite(ledPin, LOW);
}

}

The data i receive on the serial monitor of my receiving arduino is the state of the button with a 1 on the end. So i am either getting 01 if the button isn't pushed or 11 if the button is pushed.

Is the 1 on the end the stop bit? I have no idea what else it could be.

And how do i get rid of this 1?

You are not reading what is sent. Serial.write returns the number of bytes sent.

buttonState = Serial.write(Serial.read());

well if i change Serial.write into Serial.print i get the value 248 if the button is not pressed and 249 if the button is pressed.

If i keep that part away and only say: ButtonState = Serial.read(); i get 48 if not pressed and 49 if pressed.

Why do i get these numbers?

I just found out 48 means 0 and 49 means 1. But how do i map this to the correct form?

But how do i map this to the correct form?

What do you consider "the correct form"? Isn't it obvious that the numeric value of a character that represent a digit is the character value - '0'?

That was quite obvious to me, but i didn’t know how to write my code so that i would receive a ‘0’ instead of ‘48’.

Now i do now:

buttonState = Serial.read();
c = char(buttonState);
Serial.print("ButtonState is: ");
Serial.println(c);