int cycles = 5;
int rate1 = 5;
int rate2 = 3;
int rate3 = 2;
int rate4 = 1;
int rate5 = 3;
#include <Servo.h>
Servo gate1;
Servo gate2;
Servo gate3;
Servo gate4;
Servo gate5;
int open = 90;
int close = 0;
int window = 500;
int wait = 200;
void setup() {
gate1.attach(8);
gate2.attach(9);
gate3.attach(10);
gate4.attach(11);
gate5.attach(12);
gate1.write(close);
gate2.write(close);
gate3.write(close);
gate4.write(close);
gate5.write(close);
Serial.begin(9600);
delay(1000);
}
void loop() {
Serial.print("System has begun to run ");
Serial.print (cycles);
Serial.println(" x cycles.");
for (int i=0; i < cycles; i++) {
gate1.write(open);
delay(window*rate1);
gate1.write(close);
delay(wait);
gate2.write(open);
delay(window*rate2);
gate2.write(close);
delay(wait);
gate3.write(open);
delay(window*rate3);
gate3.write(close);
delay(wait);
gate4.write(open);
delay(window*rate4);
gate4.write(close);
delay(wait);
gate5.write(open);
delay(window*rate5);
gate5.write(close);
delay(wait);
Serial.print(i+1);
Serial.println(" x cycles completed.");
}
Serial.println("All cycles complete.");
Serial.println("System will automatically restart in 30 secounds unless switched off.");
Serial.println();
delay(30000);
}