Weird, because I modified someone's code to sweep a servo back and forth every 10 seconds to wake up a device by shaking it, and blinks led 13 at the same time. He was using delay() before.
void loop(){
timer(10000, tipper);
timer(500, blinking);
}
Works perfectly. But, I didn't have the second function with the extra parameter.
You could create a timer object that keeps a separate "prev" for each timer.
How to do?
If I use my library with seperate classes, will it work?
/*Multitasking
Original by Daniel Liang
This example lets you blink an LED on pin 13, and fade an LED on
pin 9 at the same time! It uses the Routine class of the Easy
library. This class uses millis() to run functions at intervals,
effectively not stopping the program, and can be used to replace
delay().
*/
#include <Easy.h> //include the Easy library
//instantiante two Routine objects
Routine routine1;
Routine routine2;
//function for fading LED on pin 9
void fading(){
static byte brightness = 0;
static byte fadeAmount = 1;
analogWrite(9, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
}
//function for blinking LED on pin 13
void blinking(){
static boolean output = 1; //output HIGH or LOW variable
digitalWrite(13, output);
output = !output;
}
void setup(){
pinMode(13, OUTPUT);
}
void loop(){
//begin fading and blinking at the same time!
routine1.begin(30, fading);
routine2.begin(500, blinking);
}