const int Button1 = 2; // Input from Button 1, Purge
const int Button2 = 4; // Input from Button 2, Flow Vairable
const int Button3 = 7; // Input from Button 3, Flow 100%
const int Bank1 = 3; // Output to Bank 1
const int Bank2 = 11; // Output to Bank 2
int Purge; // Set vairable for Purge button
int FlowCyc; // Set vairable for Flow Cycle
int Flow100; // Set vairable for Flow 100%
void setup() {
// put your setup code here, to run once:
pinMode(Button1, INPUT_PULLUP); // Read ground signal from button
pinMode(Button2, INPUT_PULLUP); // Read ground signal from button
pinMode(Button3, INPUT_PULLUP); // Read ground signal from button
TCCR2B = TCCR2B & B11111000 | B00000111; //Set pin 3 and 11 PWM frequency to 31hz
}
void loop() {
// put your main code here, to run repeatedly:
Purge = digitalRead(Button1); // Set Purge to read signal from Button1
FlowCyc = digitalRead(Button2); // Set FlowCyc to read signal from Button2
Flow100 = digitalRead(Button3); // Set Flow100 to read signal from Button3
// If Purge (Button 1) is pushed, pulse both banks at 50% duty cycle for 1 second
if (Purge == 0) {
analogWrite(Bank1, 127);
analogWrite(Bank2, 127);
delay(1000);
}
// If Flow Cycle (Button 2) is pressed, pulse each bank at each duty cycle for 2 seconds
if (FlowCyc == 0) {
// 50% dutycycle for 2 seconds
// Pulse bank 1
analogWrite(Bank1, 127);
analogWrite(Bank2, 0);
delay(2000);
// Pulse bank 2
analogWrite(Bank1, 0);
analogWrite(Bank2, 127);
delay(2000);
// 60% dutycycle for 2 seconds
// Pulse bank 1
analogWrite(Bank1, 153);
analogWrite(Bank2, 0);
delay(2000);
// Pulse bank 2
analogWrite(Bank1, 0);
analogWrite(Bank2, 153);
delay(2000);
// 75% dutycycle for 2 seconds
// Pulse bank 1
analogWrite(Bank1, 191);
analogWrite(Bank2, 0);
delay(2000);
// Pulse bank 2
analogWrite(Bank1, 0);
analogWrite(Bank2, 191);
delay(2000);
// 85% dutycycle for 2 seconds
// Pulse bank 1
analogWrite(Bank1, 217);
analogWrite(Bank2, 0);
delay(2000);
// Pulse bank 2
analogWrite(Bank1, 0);
analogWrite(Bank2, 217);
delay(2000);
// 100% dutycycle for 2 seconds
// Pulse bank 1
analogWrite(Bank1, 255);
analogWrite(Bank2, 0);
delay(2000);
// Pulse bank 2
analogWrite(Bank1, 0);
analogWrite(Bank2, 255);
delay(2000);
}
// If Flow 100% (Button 3) is pushed, flow each bank at 100% duty cycle for 10 seconds
if (Flow100 == 0) {
analogWrite(Bank1, 255);
analogWrite(Bank2, 0);
delay(10000);
analogWrite(Bank1, 0);
analogWrite(Bank2, 255);
delay(10000);
}
// If no button is pressed, both banks remain inactive
else {
analogWrite(Bank1, 0);
analogWrite(Bank2, 0);
}
}