software-timer-different-callback.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #define LED_RED GPIO_NUM_5
  6. #define LED_GREEN GPIO_NUM_2
  7. #define LED_BLUE GPIO_NUM_4
  8. static TimerHandle_t led1 , led2 ,led3= NULL ;
  9. void TimerLedControlRed(TimerHandle_t xtimer){
  10. // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
  11. //red led
  12. gpio_set_level(LED_RED,!gpio_get_level(LED_RED));
  13. printf(" from RED %d\n",ESP.getFreeHeap());
  14. //printf("inside timer\n");
  15. }
  16. void TimerLedControlGreen(TimerHandle_t xtimer){
  17. // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
  18. gpio_set_level(LED_GREEN,!gpio_get_level(LED_GREEN));
  19. printf(" from GREEN %d\n",ESP.getFreeHeap());
  20. //printf("inside timer\n");
  21. }
  22. void TimerLedControlBlue(TimerHandle_t xtimer){
  23. // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
  24. //red led
  25. gpio_set_level(LED_BLUE,!gpio_get_level(LED_BLUE));
  26. printf(" from BLUE %d\n",ESP.getFreeHeap());
  27. //printf("inside timer\n");
  28. }
  29. extern "C" void app_main()
  30. {
  31. //setting GPIO Direction (INPUT , OUTPUT)
  32. printf(" from main 1 %d\n",ESP.getFreeHeap());
  33. gpio_set_direction(LED_RED, GPIO_MODE_OUTPUT);
  34. gpio_set_direction(LED_GREEN, GPIO_MODE_OUTPUT);
  35. gpio_set_direction(LED_BLUE, GPIO_MODE_OUTPUT);
  36. //timer tasks
  37. printf(" from main 2 %d\n",ESP.getFreeHeap());
  38. led1 = xTimerCreate("LED Red", pdMS_TO_TICKS(100),pdTRUE,(void *) 0,TimerLedControlRed);
  39. led2 = xTimerCreate("LED Green", pdMS_TO_TICKS(100),pdTRUE,(void *) 1,TimerLedControlGreen);
  40. led3 = xTimerCreate("LED Blue", pdMS_TO_TICKS(100),pdTRUE,(void *) 2,TimerLedControlBlue);
  41. xTimerStart(led1,0);
  42. xTimerStart(led2,0);
  43. xTimerStart(led3,0);
  44. printf(" from main 3 %d\n",ESP.getFreeHeap());
  45. }