AmpDelay Arduino Code

/*
* Amp Delay circuit, based on ‘button’ by DojoDave <http://www.0j0.org&gt;
*
* Control relays turning on power amps when input is detected on pin 2
* When input is gone (receiver off) the relays will turn off
*
*/

int relayPin1 = 6;             // choose the pin for the RELAY
int relayPin2 = 12;             // choose the pin for the RELAY
int relayPin3 = 11;             // choose the pin for the RELAY
int relayPin4 = 10;             // choose the pin for the RELAY
int relayPin5 = 9;             // choose the pin for the RELAY
int relayPin6 = 8;             // choose the pin for the RELAY
int inputPin = 7;               // choose the input pin for receiver
int val = 0;
int val2 = 0;                   // variable for reading the pin status
int onToggle = 0;               // variable so delays don’t occur every cycle
int offToggle = 0;              // variable so delays don’t occur every cycle
int buttonState;

void setup() {
pinMode(relayPin1, OUTPUT);   // declare relay as output
pinMode(relayPin2, OUTPUT);   // declare relay as output
pinMode(relayPin3, OUTPUT);   // declare relay as output
pinMode(relayPin4, OUTPUT);   // declare relay as output
pinMode(relayPin5, OUTPUT);   // declare relay as output
pinMode(relayPin6, OUTPUT);   // declare relay as output
pinMode(inputPin, INPUT);     // declare receiver as input
buttonState = digitalRead(inputPin);   // read the initial state
}

void loop(){
val = digitalRead(inputPin);  // read input value
delay(10);
val2 = digitalRead(inputPin);  // read input value
if (val == val2) {
if (val !=buttonState) {
if (val == HIGH) {            // check if the input is HIGH
if (onToggle == 0) {
onToggle = 1;
delay(200);
digitalWrite(relayPin1, HIGH);  // turn relay ON
delay(200);
digitalWrite(relayPin2, HIGH);  // turn relay ON
delay(200);
digitalWrite(relayPin3, HIGH);  // turn relay ON
delay(200);
digitalWrite(relayPin4, HIGH);  // turn relay ON
delay(200);
digitalWrite(relayPin5, HIGH);  // turn relay ON
delay(200);
digitalWrite(relayPin6, HIGH);  // turn relay ON
}
offToggle = 0;
}
else {
if (offToggle == 0) {
offToggle = 1;
delay(200);
digitalWrite(relayPin6, LOW);  // turn relay OFF
delay(200);
digitalWrite(relayPin5, LOW);  // turn relay OFF
delay(200);
digitalWrite(relayPin4, LOW);  // turn relay OFF
delay(200);
digitalWrite(relayPin3, LOW);  // turn relay OFF
delay(200);
digitalWrite(relayPin2, LOW);  // turn relay OFF
delay(200);
digitalWrite(relayPin1, LOW);  // turn relay OFF
}
onToggle = 0;
}
}
buttonState=val;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s