chipKIT® Development Platform

Inspired by Arduino™

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


  1. Synopsis

  2. Parameter

  3. Description

  4. Return Value

  5. Conforming To

  6. Example

  7. See Also


 void * getTaskVar(int id)  


task : Pointer to the task function


This function returns the current value of the task user variable. Note that the return value is typed to be a void pointer. This means that the return value must be cast to some specific type and stored into a variable of that type in order to be used.

Return Value

The current value of the task variable

Conforming To

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


  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);
       case 1:
          for (uint8_t i=0; i<8; i++){
            setTaskPeriod(blink_id[i], (200+i*10));
 void setup() {
    for (uint8_t i=0; i<8; i++){
       pinMode(nP[LEFT][i], OUTPUT);
      blink_id[i] = createTask(blink_task, 200, TASK_ENABLE, &blink_var[i]);
      setTaskVar(blink_id[i], (void *)nP[LEFT][i]);
 void loop() {

See Also

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