I posted a while back about controlling multiple relays simultaneously, and with some great advice and help with the code, I understand it more and have a program that works well for what I need.
Here is what I'm working with
// Adapted from: Example of fading multiple LEDs at different rates without delays
// Author: Nick Gammon
// Date: 27 December 2012
#include <LedFlasher.h>
// set up some Relays
LedFlasher Relay1 (8, 34566, 22432);
LedFlasher Relay2 (12, 16632, 15366);
LedFlasher Relay3 (13, 30132, 21866);
void setup()
{
Relay1.begin ();
Relay2.begin ();
Relay3.begin ();
} // end of setup
void loop()
{
// update Relays
Relay1.update ();
Relay2.update ();
Relay3.update ();
// do other useful stuff here ...
} // end of loop
I'm now interested in generating a conditional that begins a new temporary pattern after the void loop repeats it self say, 3 times after...
I'd like all relays to then delay 15 seconds, cut on for 30 seconds, then cut off for 15 seconds. Then I need the loop to resume from the beginning with the Relay1.update (); etc...
I've tried many things from if/else statements, counting, and state change detection, but everything I have tried impedes upon the relay transitions of the original code or doesn't work at all. I feel like I'm close to understanding, but I'm still too new to writing code to understand what to use and how to write it to work properly. Can anyone help me out? Thanks.
I'm not exactly sure I understand the problem, but why couldn't you use something like:
void loop()
{
// update Relays
Relay1.update ();
Relay2.update ();
Relay3.update ();
delay(15000); // Delay 15 seconds...
Relay1.activate(); // Turn relays on...I'm assuming there's an activate() method for this
Relay2.activate();
Relay3.activate();
delay(30000); // Leave the relays on for 30 seconds...
Relay1.shutdown(); // Turn relays off...assume a shutdown() method for this
Relay2.shutdown();
Relay3.shutdown();
delay(15000); // Keep 'em off for 15 seconds, then repeat...
} // end of loop
the delay() function may not be the best routine to use, depending on your needs, but it should give you the delays you need. (See BlinkWithoutDelay in IDE examples.)
Thanks @econjack. That will help for sure, but what I'm also having trouble with is allowing the first Relay.update() pattern in the loop to occur uninterrupted multiple times, before the delay and the addition you posted begins.
I'm assuming I can do this with a counter function and a if/else conditional statement, but I'm having trouble setting this up to work. How do I let the first pattern of relays in the loop...