I have the Arduino Ethernet Shield R3. I'm not where I can test this again but I believe this was the last version of the code that I had working with the xbee radios & shields.
Serial Catchers Relay shield side
unsigned char relayPin[4] = {4,5,6,7};
#define LED 13 // the pin for the LED
#define Input1 8 // the input pin where the
// pushbutton is connected
int valIn = 0; // val will be used to store the state
// of the input pin
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(Input1, INPUT);
pinMode(relayPin[0],OUTPUT);
pinMode(relayPin[1],OUTPUT);
pinMode(relayPin[2],OUTPUT);
pinMode(relayPin[3],OUTPUT);
}
void loop() {
if (Serial.available()) {
byte val = Serial.read(); // this will read from the xbee
if (val == 'x') {
digitalWrite(relayPin[3],HIGH);
delay(1000);
digitalWrite(relayPin[3],LOW);
}
if (val == 'c') {
digitalWrite(relayPin[2],HIGH);
delay(1000);
digitalWrite(relayPin[2],LOW);
}
if (val == 'v') {
digitalWrite(relayPin[1],HIGH);
digitalWrite(relayPin[0],HIGH);
delay(1000);
digitalWrite(relayPin[1],LOW);
digitalWrite(relayPin[0],LOW);
}
}
valIn = digitalRead(Input1); // read input value and store it
// check whether the input is HIGH (button pressed)
if (valIn == HIGH) {
digitalWrite(LED, HIGH); // turn LED ON
Serial.print('l'); //send back to the Pitcher
} else {
digitalWrite(LED, LOW);
Serial.print('k'); //send back to the Pitcher
}
}
Serial Pitcher Push Button
#define LED1 12 // the pin for the open LED
#define LED2 11 // the pin for the closed LED
#define BUTTON1 7 // the input pin where the
// pushbutton is connected
#define BUTTON2 8 // the input pin where the
// pushbutton is connected
#define BUTTON3 9 // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
void setup() {
Serial.begin(9600);
pinMode(LED1, OUTPUT); // tell Arduino LED is an output
pinMode(LED2, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON1, INPUT); // and BUTTON is an input
pinMode(BUTTON2, INPUT); // and BUTTON is an input
pinMode(BUTTON3, INPUT); // and BUTTON is an input
}
void loop() {
if (Serial.available()) {
byte valR = Serial.read(); // this will read from the xbee
if (valR == 'l') {
digitalWrite(LED1, HIGH); // turn LED ON
digitalWrite(LED2, LOW); // turn LED OFF
}
if (valR == 'k') {
digitalWrite(LED2, HIGH); // turn LED ON
digitalWrite(LED1, LOW); // turn LED OFF
}
}
val = digitalRead(BUTTON1); // read input value and store it
// check whether the input is HIGH (button pressed)
if (val == HIGH) {
Serial.print('x'); // send the value x to catcher
delay(500);
}
val = digitalRead(BUTTON2); // read input value and store it
// check whether the input is HIGH (button pressed)
if (val == HIGH) {
Serial.print('c'); // send the value c to catcher
delay(500);
}
val = digitalRead(BUTTON3); // read input value and store it
// check whether the input is HIGH (button pressed)
if (val == HIGH) {
Serial.print('v'); // send the value v to catcher
delay(500);
}
}