feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
/**
* TaskScheduler Test sketch - Showing how to use std::function
* to get acces to variables from within the task callback function
*
* Support for std::function is only available for ESP8266 architecture
*/
#define _TASK_SLEEP_ON_IDLE_RUN
#define _TASK_STD_FUNCTION // Compile with support for std::function
#include <TaskScheduler.h>
Scheduler ts;
int counter = 0;
class Calculator {
public:
int cumSum = 0; // cumulative sum
Calculator(int b) {
// Pass the this pointer, so that we get access to this->cumSum
// Also pass a copy of b
calculateTask.set(TASK_SECOND, TASK_FOREVER, [this, b]() {
counter++;
Serial.printf("%u. %u: cumSum = %u + %u\t", counter, millis(), cumSum, b);
cumSum += b;
Serial.printf("Resulting cumulative sum: %u\n", cumSum);
});
ts.addTask(calculateTask);
calculateTask.enable();
}
Task calculateTask;
};
Calculator calc1(2);
Calculator calc2(4);
Calculator calc3(8);
// Disable tasks after 10 seconds
Task tWrapper(10*TASK_SECOND, TASK_ONCE, []() {
ts.disableAll();
}, &ts);
/**
* Standard Arduino setup and loop methods
*/
void setup() {
Serial.begin(74880);
Serial.println("std::function test");
tWrapper.enableDelayed();
}
void loop() {
ts.execute();
}