123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/gpio.h"
- #define LED_RED GPIO_NUM_5
- #define LED_GREEN GPIO_NUM_2
- #define LED_BLUE GPIO_NUM_4
- static TimerHandle_t led1 , led2 ,led3= NULL ;
- void TimerLedControlRed(TimerHandle_t xtimer){
- // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
- //red led
- gpio_set_level(LED_RED,!gpio_get_level(LED_RED));
- printf(" from RED %d\n",ESP.getFreeHeap());
- //printf("inside timer\n");
- }
- void TimerLedControlGreen(TimerHandle_t xtimer){
- // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
- gpio_set_level(LED_GREEN,!gpio_get_level(LED_GREEN));
- printf(" from GREEN %d\n",ESP.getFreeHeap());
- //printf("inside timer\n");
- }
- void TimerLedControlBlue(TimerHandle_t xtimer){
- // uint32_t led_timer_id = (uint32_t) pvTimerGetTimerID(xtimer) ;
- //red led
- gpio_set_level(LED_BLUE,!gpio_get_level(LED_BLUE));
- printf(" from BLUE %d\n",ESP.getFreeHeap());
- //printf("inside timer\n");
- }
- extern "C" void app_main()
- {
- //setting GPIO Direction (INPUT , OUTPUT)
- printf(" from main 1 %d\n",ESP.getFreeHeap());
- gpio_set_direction(LED_RED, GPIO_MODE_OUTPUT);
- gpio_set_direction(LED_GREEN, GPIO_MODE_OUTPUT);
- gpio_set_direction(LED_BLUE, GPIO_MODE_OUTPUT);
-
- //timer tasks
- printf(" from main 2 %d\n",ESP.getFreeHeap());
- led1 = xTimerCreate("LED Red", pdMS_TO_TICKS(100),pdTRUE,(void *) 0,TimerLedControlRed);
- led2 = xTimerCreate("LED Green", pdMS_TO_TICKS(100),pdTRUE,(void *) 1,TimerLedControlGreen);
- led3 = xTimerCreate("LED Blue", pdMS_TO_TICKS(100),pdTRUE,(void *) 2,TimerLedControlBlue);
- xTimerStart(led1,0);
- xTimerStart(led2,0);
- xTimerStart(led3,0);
- printf(" from main 3 %d\n",ESP.getFreeHeap());
- }
|