#include <TaskScheduler.h>

#define BLEND_TIME 5000 // milliseconds
#define BLEND_STEPS 255

void bufferBlend();
void bufferBlendDone();
void startBufferBlend();

uint8_t _bufferBlendAmount = 0; // blending between buffers

Scheduler _runner;
Task _taskBufferBlend(19 * TASK_MILLISECOND, BLEND_STEPS, &bufferBlend);
Task _taskStartBufferBlend(15 * TASK_SECOND,TASK_FOREVER, &startBufferBlend);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

    _runner.init();
    _runner.addTask(_taskBufferBlend);
    _taskBufferBlend.setOnDisable(&bufferBlendDone);
    _taskBufferBlend.enable();

    _runner.addTask(_taskStartBufferBlend);
    _taskStartBufferBlend.enable();
}

void loop() {
    _runner.execute(); 
    // delay(1);
}

void startBufferBlend() {
  _taskBufferBlend.enableIfNot();
    Serial.printf("Start blending: %u\n", _bufferBlendAmount );
}

void bufferBlend() {
    constexpr const char* SGN = "bufferBlend()";
    _bufferBlendAmount = _taskBufferBlend.getRunCounter();
     Serial.printf("Blending: %u\n", _bufferBlendAmount );
}

void bufferBlendDone() {
    constexpr const char* SGN = "bufferBlendDone()";
    Serial.printf("%s: Blending done: %u\n", SGN, _bufferBlendAmount );
}