#include <Preferences.h>
Preferences prefs;
enum CommandType {
CMD_SET_PIN,
CMD_WAIT,
CMD_PRINT
};
struct Command {
CommandType type;
int arg1;
int arg2;
char text[32];
};
struct Task {
uint8_t id;
uint8_t enabled;
uint32_t lastRun;
uint32_t interval;
Command commands[10];
uint8_t commandCount;
};
Task tasks[10];
int taskCount = 0;
void runCommand(Command &cmd) {
switch (cmd.type) {
case CMD_SET_PIN:
digitalWrite(cmd.arg1, cmd.arg2);
break;
case CMD_WAIT:
delay(cmd.arg1); // később nem blokkolóra cseréljük
break;
case CMD_PRINT:
Serial.println(cmd.text);
break;
}
}
void runTask(Task &t) {
uint32_t now = millis();
if (now - t.lastRun < t.interval) return;
t.lastRun = now;
for (int i = 0; i < t.commandCount; i++) {
runCommand(t.commands[i]);
}
}
void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
// Példa: létrehozunk egy taskot
Task &t = tasks[taskCount++];
t.id = 0;
t.enabled = 1;
t.interval = 500;
t.commandCount = 4;
t.commands[0] = {CMD_SET_PIN, 2, HIGH, ""};
t.commands[1] = {CMD_WAIT, 100, 0, ""};
t.commands[2] = {CMD_SET_PIN, 2, LOW, ""};
t.commands[3] = {CMD_PRINT, 0, 0, "Villogtam!"};
}
void loop() {
for (int i = 0; i < taskCount; i++) {
if (tasks[i].enabled) {
runTask(tasks[i]);
}
}
}