Hi,
I'm a full noob. I'm trying to run 4 relays, each on their own time loop. I've gotten the thing to work by way of BlinkWithoutDelay sort of sketch. The problem is that some of my intervals are long and I'm driving some big solenoids that get hot. Since the high interval is the same length as the low.
I tried to download the Event Fuse library but the link gave me a Ping folder without EventFuze.h. Is there a way to make a BinkWithoutDelay interval that would make a pin Low for say 6 seconds and High for only 1? Keeping in mind that I'll have 4 of these loops running simultaneously at different intervals.
Or is there a way to get the EventFuze.h library and utilize that?
Sorry for all the words and the bother. this is the Sketch I'm using now.
/* Blink Multiple LEDs without Delay
*
Turns on and off several light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
*/
const int NUMLEDS = 18;
byte pin[NUMLEDS] = {10, 11, 12, 13};
byte state[NUMLEDS] = {LOW, LOW, LOW, LOW};
unsigned long interval[NUMLEDS] = {3000, 5000, 7000, 42500};
unsigned long time[NUMLEDS];
void setup()
{
for (int i=0; i<NUMLEDS; ++i)
pinMode(pin*, OUTPUT);* } void loop() { unsigned long m = millis(); for (int i=0; i<NUMLEDS; ++i) if (m - time > interval*)* * {* _ time = m; state = state == LOW ? HIGH : LOW; digitalWrite(pin, state*); } }* Thanks for any help! Jake._
This might be a silly question, but why, when you are only supply 4 values for each array, is NUMLEDS 18?
Since you have not set values for the array positions beyond 3, but you are taking actions on the values in those positions, that might be causing some problems.
I'd try setting NUMLEDS to 4 and see if that makes a difference.
I just copied and pasted this sketch and didn't change the 18 value, I'll fix that, but I still have a problem changing the ratio of the blink. I want it to be High for only 1 second then Low for 6, for example. I don't know how to write that. I started out using a sketch like this, which my feeble mind understands better than the first one I posted (note: I haven't added the 2 other pins yet to this)
int led1 = 13; // LED connected to digital pin 13
int led2 = 12;
int value1 = LOW; // previous value of the LED
int value2 = LOW; // previous value of the LED
long time1 = millis();
long time2 = millis();
long interval1 = 6000; // interval at which to blink (milliseconds)
long interval2 = 14000;
void setup()
{
pinMode(led1, OUTPUT); // sets the digital pin as output
pinMode(led2, OUTPUT);
}
If you want and LED to be on and off (or a relay, as you originally said), for different intervals (on for 1 second, off for 6 seconds), you need two intervals per LED (or relay).
long onInterval = 1000;
long offInterval = 6000;
long onTime = 0;
long offTime = 0;
int ledState = LOW;
int ledPin = 13;
void loop()
{
if(ledState == LOW)
{
// See if it's time to turn it on
if(millis() - offTime > offInterval)
{
offTime = millis();
onTime = offTime + offInterval;
ledState != ledState;
digitalWrite(ledPin, ledState);
}
}
else
{
// See if it's time to turn it off
if(millis() - onTime > onInterval)
{
onTime = millis();
offTime = onTime + onInterval;
ledState != ledState;
digitalWrite(ledPin, ledState);
}
}
}
Hi Paul,
That makes a lot of sense, but I can't seem to get that to work. I tried to interpret that into the sketch I've been working with but All I got was one cycle and then the pin went high permanently.
I'm sorry to be such a bother, I'm super new to coding and a pretty dumb guy. I'm not sure what part of the code isn't working. If I could figure out how to make this, on, off interval work it would be awesome. The code seems to make sense to me.
Also, I tried TimedAction, but I had the same problem getting the on, off, interval to be different.
the real problem is that I'm still learning the code, and far from understanding it.
thanks for the help, you guys are waaaay, smarter than me.