chipKIT® Development Platform

Inspired by Arduino™

Last edit: 2021-03-21 22:34 by Majenko

SetTaskPeriod

  1. Synopsis

  2. Parameter

  3. Description

  4. Return Value

  5. Conforming To

  6. Example

  7. See Also

Synopsis

 void setTaskPeriod(int id, unsigned long period)

Parameter

id : Task identifier of task to modify
period : New scheduling interval in milliseconds for the task

Description

This function is used to modify the scheduling interval for the specified task. The task will be run the specified number of milliseconds after the function is called, and each time thereafter, depending on the task enable state. If the task is disabled, the scheduling interval is modified, but it remains disabled.

Return Value

None.

Conforming To

The Task Management Functions are specific to ChipKit and exceed the Arduino 1.6.x specification.

Example

 /*
  Blink Task (tested in UECIDE version 0.8.7)
  Utlizing the chipKIT task manager rather than delay functions.
  The use of the delay() function in loop() is done on purpose to demonstrate that the delay() call is not blocking the task
  This example code is in the public domain.
 */
 #include "System_Defs.h"
 
 const uint8_t LEFT=0;
 const uint8_t RIGHT=1;
 uint8_t nP[2][8] = {
    {
       0,17, 9,10,11,12,13,14   }
    ,{
       18,17, 1, 2, 3, 6, 7, 8   }
 }; 
 
 volatile int blink_id[8];
 unsigned long blink_var[8];
 int toggle_id;
 unsigned long toggle_var;
 volatile int state = 0; 
 
 void blink_task(int id, void * tptr) {
   int led_pin;
   unsigned long period;
   period = getTaskPeriod(id);
   led_pin = (int)getTaskVar(id);
   digitalWrite(led_pin, !digitalRead(led_pin)); // Toggle pin state
 } 
 
 void toggle_task() {
    switch (state){
       case 0:
          for (uint8_t i=0; i<8; i++){
            setTaskPeriod(blink_id[i], 100);
          }
         state++;
          break;
       case 1:
          for (uint8_t i=0; i<8; i++){
            setTaskPeriod(blink_id[i], (200+i*10));
          }
         state=0;
          break;
    }
 }
 
 void setup() {
    for (uint8_t i=0; i<8; i++){
       pinMode(nP[LEFT][i], OUTPUT);
       digitalWrite(nP[LEFT][i],LOW);
      blink_id[i] = createTask(blink_task, 200, TASK_ENABLE, &blink_var[i]);
      setTaskVar(blink_id[i], (void *)nP[LEFT][i]);
    }
 }
 
 void loop() {
    toggle_task();
    delay(2000);
 }

See Also

createTask(), destroyTask(), getTaskId(), getTaskNextExec(), getTaskPeriod(), getTaskState(), getTaskVar(), setTaskPeriod(), setTaskState(), setTaskVar(), startTaskAt(),