Hello,
After being abandoned on another forum, I come here with my head held low… I need help…
The best I can describe this project is:
I have a time period of 240 seconds (cycle)
I have 24 relays driven by outputs 22-45 (LOW on active)
I wish to be able to have the relays come on at different intervals thru out the “cycle”… IE: relay 1 on for 10 seconds, off for 180 seconds and back on for 15 seconds, off till the end of the cycle…
I need this functionality for all 24 relays
I hope this gives you enough insight as to my project…
ALSO… :oops: Can someone teach this old dog how to get the CODE to work so I can at least present my work…
//CONSTANTS
//SETTING UP THE OUTPUT PINS
byte outputPins[24] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
//SETTING UP THE INTERVAL CONSTANTS Ie: How long You want the output to go HIGH
//…//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18 //19 //20 //21 //22 //23 //24
unsigned long outputIntervals[24] = {5000UL, 3000UL, 4000UL, 4000UL, 20000UL, 5000UL, 60000UL, 20000UL, 20000UL, 20000UL, 5000UL, 40000UL, 20000UL, 20000UL, 20000UL, 10000UL, 10000UL, 10000UL, 30000UL, 30000UL, 20000UL, 20000UL, 500UL, 550UL};
//SETTING THE “ON” TIME Ie: How Often You Want It To Happen
//…//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 /17 //18 //19 //20 //21 //22 //23 //24
unsigned long blinkDurations[24] = {240000UL, 245000UL, 247500UL, 248500UL, 249000UL, 269500UL, 245000UL, 295000UL, 245000UL, 245000UL, 275000UL, 245000UL, 275000UL, 265000UL, 280000UL, 290000UL, 290000UL, 290000, 180000, 180000UL, 170000UL, 160000UL, 240000UL, 200000UL};
//SETTING THE OUTPUT PINS LOW
byte outputStates[24] = {0}; // initialize all elements to 0 == LOW
//SETTING THE MILLIS TO 0 TO START FRESH
unsigned long currentMillis = 0; // stores the value of millis() in each iteration of loop()
unsigned long previousMillis[24] = {0};
//SETUP AREA
//SETTING THE MONITOR FUNCTION TO 9600 AND PRINT THE LED_A_STATE
void setup() {
Serial.begin(9600);
// SETTING THE OUTPUT PINS TO OUTPUT MODE
for (int i = 0; i < 24; i++) {
pinMode(outputPins, OUTPUT);
}
}
//LOOP AREA
void loop() {
currentMillis = millis(); // capture the latest value of millis()
for (int i = 0; i < 24; i++) {
updateOutputState(i);
}
switchOutputs();
}
//SETTING LED n IN ACTION
void updateOutputState(int n) {
if (outputStates[n] == LOW) {
if (currentMillis - previousMillis[n] >= outputIntervals[n]) {
outputStates[n] = HIGH;
previousMillis[n] += outputIntervals[n];
}
}
else {
if (currentMillis - previousMillis[n] >= blinkDurations[n]) {
outputStates[n] = LOW;
previousMillis[n] += blinkDurations[n];
}
}
}
//SWITCH THE LED STATE
void switchOutputs() {
// this is the code that actually switches the LEDs on and off
for (int i = 0; i < 24; i++) {
digitalWrite(outputPins, outputStates);
Serial.println(outputStates[21]);
}
}
//=====END