#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
typedef struct {
int priority;
int pin;
int loops;
TickType_t period;
} task_param_t;
const task_param_t task_params[] = {
{tskIDLE_PRIORITY + 10, 27, 1, pdMS_TO_TICKS(240)},
{tskIDLE_PRIORITY + 4, 14, 117*10, pdMS_TO_TICKS(40)},
{tskIDLE_PRIORITY + 3, 12, 117*20, pdMS_TO_TICKS(80)},
{tskIDLE_PRIORITY + 2, 13, 117*30, pdMS_TO_TICKS(120)},
};
void toggleTask(void *pvParameter) {
task_param_t *params =(task_param_t *)pvParameter;
pinMode(params->pin, OUTPUT);
TickType_t xNextWakeTime = pdMS_TO_TICKS(2000); // xTaskGetTickCount();
while (true) {
for (int i = 0; i < params->loops; i++) {
digitalWrite(params->pin, HIGH);
digitalWrite(params->pin, LOW);
}
vTaskDelayUntil(&xNextWakeTime, params->period);
}
}
void setup() { //loopBack , Priority 1, Core 1
Serial.begin(115200);
Serial.printf("\n\n");
Serial.printf("Application " __FILE__ " compiled " __DATE__ " at " __TIME__ "\n");
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(15, 10, "Hello world !"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
for (int i = 0; i < sizeof(task_params)/sizeof(task_params[0]); i++) {
Serial.printf("Create task %d\n", i);
xTaskCreatePinnedToCore(toggleTask, "Task", 1024 * 6,
(void *)&task_params[i], task_params[i].priority, NULL, 1);
}
}
void loop() {
}
Loading
ssd1306
ssd1306