MCPcopy Create free account
hub / github.com/arkhipenko/TaskScheduler / setup

Function setup

examples/Scheduler_example30_THREAD_SAFE/src/main.cpp:237–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235// ============================================
236
237void setup() {
238 Serial.begin(115200);
239 delay(500);
240
241 Serial.println("\n\n===========================================");
242 Serial.println("TaskScheduler Example 30: _TASK_THREAD_SAFE");
243 Serial.println("===========================================\n");
244
245 // Initialize LED
246 pinMode(LED_PIN, OUTPUT);
247 digitalWrite(LED_PIN, LOW);
248
249 // Initialize button with pull-up
250 pinMode(BUTTON_PIN, INPUT_PULLUP);
251
252 // Create the task request queue
253 tsQueue = xQueueCreateStatic(
254 TS_QUEUE_LEN,
255 sizeof(_task_request_t),
256 tsQueueData,
257 &tsQueueBuffer
258 );
259
260 if (tsQueue == NULL) {
261 Serial.println("ERROR: Failed to create task queue!");
262 while (1) delay(1000);
263 }
264
265 Serial.printf("Task request queue created (size: %d)\n", TS_QUEUE_LEN);
266
267 // Set up button watch task to wait for button press signal
268 tButtonWatch.waitFor(&buttonPressed);
269
270 // Attach button interrupt
271 attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonISR, FALLING);
272 Serial.println("Button interrupt attached (press boot button)");
273
274 // Create timer for periodic ISR (every 7 seconds)
275 hw_timer_t* timer = timerBegin(0, 80, true); // Timer 0, prescaler 80 (1MHz), count up
276 timerAttachInterrupt(timer, &timerISR, true);
277 timerAlarmWrite(timer, 7000000, true); // 7 seconds in microseconds, auto-reload
278 timerAlarmEnable(timer);
279 Serial.println("Hardware timer started (triggers every 7 seconds)");
280
281 // Create worker thread
282 xTaskCreate(
283 workerThread,
284 "WorkerThread",
285 4096,
286 NULL,
287 1, // Priority
288 NULL
289 );
290 Serial.println("Worker thread created");
291
292 Serial.println("\n--- System initialized ---");
293 Serial.println("Expected behavior:");
294 Serial.println("1. LED blinks at variable rate");

Callers

nothing calls this directly

Calls 5

delayFunction · 0.85
pinModeFunction · 0.85
digitalWriteFunction · 0.85
waitForMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected