// Estoy tratando de usar un único timer con varios tasks que se pueden borrar y resetear con otro valor.
// Pero no me está saliendo por el scope del handle al task (que no puede ser global).
#include <arduino-timer.h>
// https://deepbluembedded.com/arduino-timer-library/#google_vignette
// https://github.com/contrem/arduino-timer
#define LED_TENSION_PIN 13
#define LED_BLUETOOTH_PIN 11
#define LED_LOW_BATTERY_PIN 12
int timeGap2 = 1000;
Timer<2, millis> MyTimer; // 2 concurrent tasks, using millis as resolution.
void setup() {
// put your setup code here, to run once:
auto Task1Handle = MyTimer.every(500, Task_Led_tension_Handler);
auto Task2Handle = MyTimer.every(timeGap2, Task_Led_tension_Handler2);
pinMode(LED_TENSION_PIN, OUTPUT); // set LED pin to OUTPUT
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
MyTimer.tick();
}
void interesting_function()
{
d
}
void set_timer_2()
{
static auto Task2Handle = MyTimer.every(timeGap2, Task_Led_tension_Handler2);
}
bool Task_Led_tension_Handler(void *)
{
digitalWrite(LED_TENSION_PIN, !digitalRead(LED_TENSION_PIN)); // Toggle LED1
Serial.println("First Task.");
return true; // true: repeat the action, false: to stop the task.
}
bool Task_Led_tension_Handler2(void *)
{
digitalWrite(LED_TENSION_PIN, !digitalRead(LED_TENSION_PIN)); // Toggle LED1
Serial.println("Second Task.");
timeGap2 = 2*timeGap2;
MyTimer.cancel(Task2Handle);
MyTimer.every(timeGap2, Task_Led_tension_Handler2);
return true; // true: repeat the action, false: to stop the task.
}