Hello,
Thank you for the support thus far.
It truly means the world to me.
Okay I have got both PaulPaulSon code and gcjr code to work,
But I am currently working with Paulpaulson's code as I was able to implement a 4th relay in the mix by adding TwoC (a 4th relay) and this code..
case 4: digitalWrite ( Relays[One] , HIGH); break;
case 5: digitalWrite ( Relays[TwoC] , HIGH); break;
I am hoping I can get some further assistance to configure some additional code,
I am wanting to advance the circuit system to be able to:
Detect Input Signal.
Depend on how slow or quick the pulse goes, to be able to run 3(all) (TwoA, TwoB, TwoC) at the same time.
The INPUT pulse rate can vary from (once every 2 seconds), up to 10 times per second.
When the Pulse is SLOW (like every 2 Seconds) I would like all Relays (TwoA, B & C) same time
When the Pulse is faster (every 1 second) to have cycle between TwoA,B then TwoB,C
When the Pulse is Fastest (faster than 1 second) Standard Cycle TwoA, then TwoB, then TwoC.
Thanks again so much for the support you guys have given.
Code as it stands Now..
//BLOCK COMMENT
//https://forum.arduino.cc/t/cyclic-relay2a-2b/889080/10
#define ProjectName "Cyclic Relay2A & 2B"
// CONSTANT DEFINITION
// you need to change these constants to your hardware
const byte Relays[] {3, 7, 8, 4};
const byte Buttons[] {2};
// VARIABLE DECLARATION
enum {One, TwoA, TwoB, TwoC};
struct BUTTON {
byte pin;
bool state;
int counter;
unsigned long stamp;
unsigned long duration;
} button {Buttons[One], 1, 0, 0, 20};
void setup() {
Serial.begin(9600);
Serial.println(F("."));
Serial.print(F("File : ")), Serial.println(__FILE__);
Serial.print(F("Date : ")), Serial.println(__DATE__);
Serial.print(F("Project: ")), Serial.println(ProjectName);
pinMode (LED_BUILTIN, OUTPUT);
for (auto Relay : Relays) pinMode ( Relay, OUTPUT);
for (auto Button : Buttons) pinMode ( Button, INPUT_PULLUP);
}
void loop () {
unsigned long currentTime = millis();
digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
if (currentTime - button.stamp >= button.duration) {
button.stamp = currentTime;
bool stateNew = digitalRead(button.pin);
if (button.state != stateNew) {
button.state = stateNew;
for (auto Relay : Relays) digitalWrite ( Relay, LOW);
switch (button.counter) {
case 0: digitalWrite ( Relays[One] , HIGH); break;
case 1: digitalWrite ( Relays[TwoA] , HIGH); break;
case 2: digitalWrite ( Relays[One] , HIGH); break;
case 3: digitalWrite ( Relays[TwoB] , HIGH); break;
case 4: digitalWrite ( Relays[One] , HIGH); break;
case 5: digitalWrite ( Relays[TwoC] , HIGH); break;
}
button.counter++;
button.counter = button.counter % 6;
}
}
}