Files
Last update 1 year 3 months
by
Darren Winter
FilesFirmwaremain | |
---|---|
.. | |
CMakeLists.txt | |
LEDLightDriver.h | |
LED_Light_Driver.c | |
main.c |
main.c#include <stdio.h> #include <stdbool.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/adc.h" #include "LEDLightDriver.h" #include "freertos/semphr.h" #define Brightness_Pin GPIO_NUM_39 #define Mode_Pin GPIO_NUM_38 int Brightness_Level = 1; int Mode_Select = 2; //1 = RGBW Mode, 2 = Warm LED Mode SemaphoreHandle_t mutexBus; //Allows to only let one write at a time before another starts void Brightness_Pin_Config() { gpio_reset_pin(Brightness_Pin); gpio_set_direction(Brightness_Pin, GPIO_MODE_INPUT); gpio_pullup_en(Brightness_Pin); gpio_pulldown_dis(Brightness_Pin); } void Mode_Pin_Config() { gpio_reset_pin(Mode_Pin); gpio_set_direction(Mode_Pin, GPIO_MODE_INPUT); gpio_pullup_en(Mode_Pin); gpio_pulldown_dis(Mode_Pin); } //Configure mode and brightness setting void Brightness_Pin_Input() //input button for brightness { while(true) { if(gpio_get_level(Brightness_Pin) == 0) { Brightness_Level++; printf("brightness level is %d\n", Brightness_Level); vTaskDelay(1000/portTICK_PERIOD_MS); printf("brightness level is %d\n", Brightness_Level); } vTaskDelay(1000/portTICK_PERIOD_MS); //added to notify watch dog. } } void Mode_Pin_Input() //input button for brightness { while(true) { if(gpio_get_level(Mode_Pin) == 0) { Mode_Select++; printf("mode select is %d\n", Mode_Select); vTaskDelay(1000/portTICK_PERIOD_MS); printf("mode select level is %d\n", Mode_Select); if(Mode_Select == 3) { Mode_Select = 1; printf("mode select level is %d\n", Mode_Select); } } vTaskDelay(1000/portTICK_PERIOD_MS); //added to notify watch dog. } } void Brightness_Level_Increase_Warm_LED() //cycle through brightness levels for warm leds { while(true) { if(Mode_Select == 2) { if (xSemaphoreTake(mutexBus, 1000 / portTICK_PERIOD_MS)) { Stop_RGBW_LEDs(); //disables rgbw LEDC_Config_Set_Warm_LED(); //enables warm leds xSemaphoreGive(mutexBus); if(Brightness_Level == 1) { WARM_WHITE_BRIGHTNESS_25(); } else if(Brightness_Level == 2) { WARM_WHITE_BRIGHTNESS_50(); } else if(Brightness_Level == 3) { WARM_WHITE_BRIGHTNESS_75(); } else if(Brightness_Level == 4) { WARM_WHITE_BRIGHTNESS_100(); } else if(Brightness_Level == 5) { Brightness_Level = 1; } } else { printf("Failed \n"); vTaskDelay(1000/portTICK_PERIOD_MS); } vTaskDelay(1000/portTICK_PERIOD_MS); } vTaskDelay(1000/portTICK_PERIOD_MS); } } void Brightness_Level_Increase() //cycle through brightness levels for rgbw { while(true) { if(Mode_Select == 1) { if (xSemaphoreTake(mutexBus, 1000 / portTICK_PERIOD_MS)) { Stop_Warm_LEDs(); //disables warm light leds LEDC_Config_Set_RGBW(); xSemaphoreGive(mutexBus); if(Brightness_Level == 1) { RED_BRIGHTNESS_25(); GREEN_BRIGHTNESS_25(); BLUE_BRIGHTNESS_25(); WHITE_BRIGHTNESS_25(); } else if(Brightness_Level == 2) { RED_BRIGHTNESS_50(); GREEN_BRIGHTNESS_50(); BLUE_BRIGHTNESS_50(); WHITE_BRIGHTNESS_50(); } else if(Brightness_Level == 3) { RED_BRIGHTNESS_75(); GREEN_BRIGHTNESS_75(); BLUE_BRIGHTNESS_75(); WHITE_BRIGHTNESS_75(); } else if(Brightness_Level == 4) { RED_BRIGHTNESS_100(); GREEN_BRIGHTNESS_100(); BLUE_BRIGHTNESS_100(); WHITE_BRIGHTNESS_100(); } else if(Brightness_Level == 5) { Brightness_Level = 1; } } vTaskDelay(1000/portTICK_PERIOD_MS); } vTaskDelay(1000/portTICK_PERIOD_MS); } } void app_main(void) { mutexBus = xSemaphoreCreateMutex(); LEDC_Config_Set_Warm_LED(); Brightness_Pin_Config(); Mode_Pin_Config(); xTaskCreate(&Mode_Pin_Input, "Reading mode selectinput pin", 2048, NULL, 2, NULL); xTaskCreate(&Brightness_Pin_Input, "Reading brightness input pin", 2048, NULL, 2, NULL); xTaskCreate(&Brightness_Level_Increase, "Cycle through brightness", 2048, NULL, 1, NULL); xTaskCreate(&Brightness_Level_Increase_Warm_LED, "Cycle through brightness warm leds", 2048, NULL, 1, NULL); }