fjrg76

one_code_multiple_tasks

Jan 16th, 2021
1,472
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void led_task( void* pvParameters )
  2. {
  3.     uint8_t* pin = (uint8_t*) pvParameters;
  4.  
  5.     pinMode( *pin, OUTPUT );
  6.  
  7.     while( 1 )
  8.     {
  9.         digitalWrite( *pin, HIGH );
  10.  
  11.         vTaskDelay( pdMS_TO_TICKS( 497 ) );
  12.    
  13.         digitalWrite( *pin, LOW );
  14.  
  15.         vTaskDelay( pdMS_TO_TICKS( 497 ) );
  16.     }
  17. }
  18.  
  19. void setup()
  20. {
  21.    static uint8_t pin_led_1 = 13;
  22.    xTaskCreate(
  23.       led_task,
  24.       "LD1",
  25.       128,
  26.       (void*) &pin_led_1,
  27.       tskIDLE_PRIORITY,
  28.       NULL );
  29.  
  30.    static uint8_t pin_led_2 = 12;
  31.    xTaskCreate( led_task, "LD2", 128, (void*) &pin_led_2, tskIDLE_PRIORITY, NULL );
  32.  
  33.    vTaskStartScheduler();
  34. }
  35.  
RAW Paste Data