Skip to content

Instantly share code, notes, and snippets.

@kylefritz
Last active December 29, 2015 18:59
Show Gist options
  • Save kylefritz/7714494 to your computer and use it in GitHub Desktop.
Save kylefritz/7714494 to your computer and use it in GitHub Desktop.
Arduino control of two relay shields
const int buttonPin = 8;
int buttonState = 0;
int relay_control_pins[] = {
2, //white (office)
3, //house
4, //downstairs building 2
5, //downstairs building 1
6 //work
};
void setup(){
for(int i = 0; i < 5; i++){
pinMode(relay_control_pins[i], OUTPUT);
digitalWrite(relay_control_pins[i], HIGH);
}
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
digitalWrite(13, LOW);//turn off light
}
void loop(){
buttonState = digitalRead(buttonPin);
if(buttonState == LOW){
//needs to be held down for 250 ms
delay(250);
buttonState = digitalRead(buttonPin);
}
if(buttonState == LOW){
for(int i = 0; i < 5; i++){
toggle(relay_control_pins[i]);
}
delay(500);
}
}
void toggle(int pin){
digitalWrite(pin, LOW);
delay(1400);
digitalWrite(pin, HIGH);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment