Hello--
I think I am so close, but there must be an error in my code. I have two Arduino Uno's, two xbee's and two xbee shields.
The goal is to get one full revolution of the motor (hooked up to one arduino) when the button (hooked up to the other arduino) is pushed.
I have set up the xbees to talk to each other. In fact if I connect one xbee to my computer via a dongle explorer, I can see the output from my other xbee (since it is connected to a button, it returns values of 0 when the button is NOT pressed, and 1's when the button is pressed). So communication is not the issue.
Once I take the Xbee off the dongleExplorer and put it on the other xbee shield (connected to the Arduino) is when I get trouble. Here is the code I have loaded on the arduino controlling my stepper motor:
I realize that the button arduino is constantly sending data (either 0's or 1's). I would have expected that this would mean that Serial.available() would always be > 0, but this is not the case. This code sends the printed line "I got here 1", and then "Backward" over and over. What I would LIKE for it to do is to turn on the motor one full revolution when the button is pushed.
Any help would be so great! Thank you!
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
It can be useful to send the data regularly - say 5 times per second - so that the receiver can tell if the flow of data is interrupted. However sending the data more frequently will probably be counter productive.
PaulS:
Why? It should send a value ONCE when the switch becomes pressed and ONCE when the switch becomes released.
Make that happen, and I'll bet a box of donuts that the receiver starts working properly.
You make a great point, I said that it was continuously sending...I guess I am not sure if it is 'sending' it continuously, but I had lines in my code to print out a line saying send the value, and THAT was continuous.
The code is here:
int switchPin = 8;
void setup()
{
pinMode(switchPin, INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(switchPin) == HIGH)
{
int val = HIGH;
Serial.println(val);
}
else
{
int val = LOW;
Serial.println(val);
}
}
You need to look at the state change detection example. Send a value when the switch BECOMES pressed. Send a value when the switch BECOMES released. Send nothing when no change takes place.