/*
LED blink example from TaskScheduler.
Source: https://github.com/arkhipenko/TaskScheduler/tree/master/examples/Scheduler_example00_Blink
*/
#include <AceButton.h>
using namespace ace_button;
// The pin number attached to the button.
const int BUTTON_LORA_PIN = 2;
const int BUTTON_WIFI_PIN = 7;
const int PIN_LED_VERDE = 8;
// LED states. Some microcontrollers wire their built-in LED the reverse.
const int LED_ON = HIGH;
const int LED_OFF = LOW;
// One button wired to the pin at BUTTON_PIN. Automatically uses the default
// ButtonConfig. The alternative is to call the AceButton::init() method in
// setup() below.
AceButton button_lora(BUTTON_LORA_PIN, LOW);
AceButton button_wifi(BUTTON_WIFI_PIN, LOW);
// Forward reference to prevent Arduino compiler becoming confused.
void handleEvent_lora(AceButton*, uint8_t, uint8_t);
void handleEvent_wifi(AceButton*, uint8_t, uint8_t);
// #define _TASK_TIMECRITICAL // Enable monitoring scheduling overruns
// #define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
// #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
// #define _TASK_WDT_IDS // Compile with support for wdt control points and task ids
// #define _TASK_LTS_POINTER // Compile with support for local task storage pointer
// #define _TASK_PRIORITY // Support for layered scheduling priority
// #define _TASK_MICRO_RES // Support for microsecond resolution
// #define _TASK_STD_FUNCTION // Support for std::function (ESP8266 and ESP32 ONLY)
// #define _TASK_DEBUG // Make all methods and variables public for debug purposes
// #define _TASK_INLINE // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
// #define _TASK_TIMEOUT // Support for overall task timeout
// #define _TASK_OO_CALLBACKS // Support for dynamic callback method binding
#include <TaskScheduler.h>
// Debug and Test options
#define _DEBUG_
//#define _TEST_
#ifdef _DEBUG_
#define _PP(a) Serial.print(a);
#define _PL(a) Serial.println(a);
#else
#define _PP(a)
#define _PL(a)
#endif
// Scheduler
Scheduler loop_Tasks_Scheduler;
void print_function();
Task print_task(5 * TASK_SECOND, 3, &print_function, &loop_Tasks_Scheduler, false);
void setup() {
// put your setup code here, to run once:
#if defined(_DEBUG_) || defined(_TEST_)
Serial.begin(115200);
delay(TASK_SECOND);
_PL("TaskScheduler Blink example");
_PL("Blinking for 10 seconds using various techniques\n");
delay(2 * TASK_SECOND);
#endif
ButtonConfig* buttonConfig_lora = button_lora.getButtonConfig();
buttonConfig_lora->setEventHandler(handleEvent_lora);
buttonConfig_lora->setFeature(ButtonConfig::kFeatureClick);
buttonConfig_lora->setDebounceDelay(20);
ButtonConfig* buttonConfig_wifi = button_wifi.getButtonConfig();
buttonConfig_wifi->setEventHandler(handleEvent_wifi);
buttonConfig_wifi->setFeature(ButtonConfig::kFeatureClick);
buttonConfig_wifi->setDebounceDelay(20);
}
void loop() {
loop_Tasks_Scheduler.execute();
button_lora.check();
button_wifi.check();
}
void print_function(){
Serial.print(">>>>>>> Status Task: ");
Serial.print(" - millis: ");
Serial.println(millis());
};
void handleEvent_lora(AceButton* /* button */, uint8_t eventType,
uint8_t buttonState) {
// Print out a message for all events.
Serial.print(F("handleEvent(): eventType: "));
Serial.print(eventType);
Serial.print(F("; buttonState: "));
Serial.println(buttonState);
switch (eventType) {
case AceButton::kEventPressed:
//blink_task.enable();
//blink_task.disable();
//blink_task.cancel(); //Chama OnDisable no final
//blink_task.abort(); //NÃO chama OnDisable no final
//blink_task.enableDelayed(5000);
//print_task.restart();
//blink_task.enableDelayed(10);
//blink_task.restart();
// Serial.print("+ kEventPressed");
// Serial.print(" millis: ");
// Serial.println(millis());
// String txt = "10";
// uint8_t teste = 10;
// if(txt.toInt() == teste) {
// Serial.println("FUNCIONOU!!!");
// } else {
// Serial.println("ERRO no IF: String != uint_8!!!");
// Serial.print("txt.toInt(): ");
// Serial.print(txt.toInt());
// }
break;
case AceButton::kEventReleased:
// Serial.print("- kEventReleased");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
case AceButton::kEventClicked:
print_task.restart();
Serial.print("+ kEventClicked");
Serial.print(" millis: ");
Serial.println(millis());
break;
case AceButton::kEventDoubleClicked:
break;
case AceButton::kEventLongPressed:
// Serial.print("+++ kEventLongPressed");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
case AceButton::kEventRepeatPressed:
break;
case AceButton::kEventLongReleased:
// Serial.print("--- kEventLongReleased");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
}
}
void handleEvent_wifi(AceButton* /* button */, uint8_t eventType,
uint8_t buttonState) {
// Print out a message for all events.
Serial.print(F("handleEvent(): eventType: "));
Serial.print(eventType);
Serial.print(F("; buttonState: "));
Serial.println(buttonState);
switch (eventType) {
case AceButton::kEventPressed:
//blink_task.enable();
//blink_task.disable();
//blink_task.cancel(); //Chama OnDisable no final
//blink_task.abort(); //NÃO chama OnDisable no final
//blink_task.enableDelayed(5000);
// print_task.set(2 * TASK_SECOND, 2, &print_function);
// print_task.forceNextIteration();
//blink_task.enableDelayed(10);
//blink_task.restart();
// Serial.print("+ kEventPressed");
// Serial.print(" millis: ");
// Serial.println(millis());
// String txt = "10";
// uint8_t teste = 10;
// if(txt.toInt() == teste) {
// Serial.println("FUNCIONOU!!!");
// } else {
// Serial.println("ERRO no IF: String != uint_8!!!");
// Serial.print("txt.toInt(): ");
// Serial.print(txt.toInt());
// }
break;
case AceButton::kEventReleased:
// Serial.print("- kEventReleased");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
case AceButton::kEventClicked:
print_task.set(2 * TASK_SECOND, 2, &print_function);
print_task.forceNextIteration();
Serial.print("+ kEventClicked");
Serial.print(" millis: ");
Serial.println(millis());
break;
case AceButton::kEventDoubleClicked:
break;
case AceButton::kEventLongPressed:
// Serial.print("+++ kEventLongPressed");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
case AceButton::kEventRepeatPressed:
break;
case AceButton::kEventLongReleased:
// Serial.print("--- kEventLongReleased");
// Serial.print(" millis: ");
// Serial.println(millis());
break;
}
}