1

I'm trying to control a pellet stove auger motor in such a way that I can use a toggle switch to do High/Low (H/L) - so the way that I have it now is:

 void setup() {
   // initialize digital pin 13 as an output.
   pinMode(13, OUTPUT);
   pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2850);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(11250);  

Which is just LED on/off but it also controls another relay that controls the blower motor - what I'm trying to set up is a H setting that would be the 2850 delay-ON - and then have say: pin 11 have a delay-OFF of 7000, and have pin 13 still resetting to the delay-ON of 2850.

What I mean is:

  • loop A: pin12 on -delay 2850 pin12 off -delay 11250
  • loop B: pin13 on -delay 2850 pin13 off -delay 7000

I saw and tried the code for 'multi-blink' - as the one I use is pretty much modified 'blink'.

Any assistance would be awesome - I run the one I show above now, on my pellet stove and it was recently -31.4 and worked like a charm, but I'd like to be able to have a high/low option.

PS: I also have a coffee roaster control project as well... help on that one is always appreciated as well.

  • Just out of interest... -31.4°C or -31.4°F? Although they are pretty much close, and damned cold either way! – Greenonline Feb 17 '16 at 8:06
2

This seems to be the perfect example for the simple scheduler:

#include <Scheduler.h>

const int pinA = 12;
const int pinB = 13;

void setup()
{
  Serial.begin(9600);
  while (!Serial);
  Scheduler.start(setupA, loopA);
  Scheduler.start(setupB, loopB);
}

void loop()
{
  Serial.print(millis());
  Serial.print(F(":pinA="));
  Serial.print(digitalRead(pinA));
  Serial.print(F(",pinB="));
  Serial.println(digitalRead(pinB));
  delay(1000);
}

void setupA()
{
  pinMode(pinA, OUTPUT);
}

void loopA()
{
  digitalWrite(pinA, HIGH);
  delay(2850);
  digitalWrite(pinA, LOW);
  delay(11250);
}

void setupB()
{
  pinMode(pinB, OUTPUT);
}

void loopB()
{
  digitalWrite(pinB, HIGH);
  delay(2850);
  digitalWrite(pinB, LOW);
  delay(7000);
}

Cheers!

  • Pretty amazing that only a couple of hours ago and now I have a written variant to try, which I tried something similar on the uno before, the code available at arduino for "multi-blink" but it wouldn't compile, but then i saw it said you needed a due, but not an uno to run it, but so didn't mess with it all that much, it made sense, but wouldn't run, and I failed to copy the error, but i'll def try running this, with pins of course, is there any reason it wouldn't run on a mega as well? The uno is busy keeping me warm, but I have a mega here, so I'll try that first – Polartransit Feb 16 '16 at 0:54
  • The Scheduler library above (lhttps://github.com/mikaelpatel/Arduino-Scheduler) can be used with more or less all Arduino boards. It gives the illusion of running multiple sketches in the same sketch. – Mikael Patel Feb 16 '16 at 6:38
  • I'm sorry man, i'm pretty sure i'm a dunce at this point - i tried all the ways i could find to include that and a different one as well, library, but still was unable to compile it = i don't get it, my understanding is that the code you posted would work with the library listed added - i'm certainly feeling shame in admitting I clearly don't know how to add a library to a sketch - help please. – Polartransit Feb 18 '16 at 0:39
  • Installing a library in Arduino is hard (at least the first time). Start by downloading the ZIP file from github.com/mikaelpatel/Arduino-Scheduler. Locate the "libraries" folder in the Sketchbook (or Arduino folder). Unzip the Arduino-Scheduler-master into the "libraries" folder and rename the folder Scheduler. Restart the Arduino IDE and you are ready to go. – Mikael Patel Feb 18 '16 at 8:17
  • It definitely doesn't help that the pc i'm using to code/try to code with is a 2012 hp $250 laptop that, as someone that has used computers since 1986+/- , is the WORST computer ever - tried upgrading to win10 from 7 - which was working fine, but i suppose i'm a bit of an early adopter , then, no touch pad at all, ditched the thing for a bit and just used phone, then needed to program the A unit to make the pellet stove work, so tried again, now, my touch pad does work, but, if you use the keyboard there is a oh, one to 1.5 sec delay before the touchpad works again - not stellar equpiment, – Polartransit Feb 18 '16 at 23:47
2

The Arduino Simple Timer library (and other similar timer libraries) are made for exactly this kind of application. Your setup() routine calls the SimpleTimer library, naming a callback-function and how often it should get called. Your loop function must then call timer.run() reasonably frequently (where reasonably frequently" depends on the timing accuracy and jitter tolerance of your application). timer.run() will call each of your callback-functions at its appropriate time. You write the callback-functions to do whatever you need them to do when the timer calls them.

There are one-shot timers and repeating timers - it sounds like your application could one of each per LED: One that fires periodically, to to call a turn-on-LED12 function every (ON_TIME_12+OFF_TIME_12) ms, and a one-shot that calls a turn-off-LED12 function, started by the turn-on-LED_12 function for (ON_TIME_12) msec. Same for LED13, ( ..., etc.)

Your loop function is free to do whatever else, as long as it calls timer.run() frequently enough that your application can meet its timing requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.