Hello again, after some serious keyboard pounding, a lot of reading, and much forum chatter, here is the arduino sketch that actually works. I share this in the hopes that others can benefit form my trials.
// single-tasking sketch: switch relay ON for certain time
const byte NUMRELAYS = 4;
const byte RELAYACTIVE = LOW; // many mechanical relay boards are "active LOW" switching
const byte relayPins[] = {2, 3, 4, 5};
const byte buttonPin = 8; // connect button pins to D8 and GND
const long relayTimes[] = {1000L, 1000L, 1000L, 1000L}; // task duration in milliseconds (long)
void setup() {
for (int i = 0; i < NUMRELAYS; i++)
{
digitalWrite(relayPins, !RELAYACTIVE);
pinMode(relayPins, OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP); // connect button pins to D8 and GND
}
boolean buttonPressed() // reading button presses of a button with
{
static unsigned long lastTime;
static byte lastState = digitalRead(buttonPin);
if (millis() - lastTime < 10) return false; // debounce 10 milliseconds
byte currentState = digitalRead(buttonPin);
if (currentState == lastState) return false;
lastState=currentState;
if (currentState==LOW) return true;
else return false;
}
byte currentRelay = 0;
void loop() {
if (buttonPressed())
{
digitalWrite(relayPins[currentRelay], RELAYACTIVE);
delay(relayTimes[currentRelay]);
digitalWrite(relayPins[currentRelay], !RELAYACTIVE);
currentRelay++;
if (currentRelay >= NUMRELAYS) currentRelay = 0;
}
}