I use:
Arduino Leonardo
Arduino Wireless SD Shield
XBEE USB Adapter
Two XBEE S1
Receive from Button State was OK, but no sending (LED turn on/off). What's wrong with code?
#include <SoftwareSerial.h>
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
SoftwareSerial xbee (0,1);
void setup() {
xbee.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
if (xbee.available() >0 )
{
char ch = xbee.read();
if (ch == '1')
{
digitalWrite(ledPin, HIGH);
}
else if (ch == '0')
{
digitalWrite(ledPin, LOW);
}
}
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
xbee.println("Button pressed!");
delay(500);
}
}