diff --git a/main/ledstrip.c b/main/ledstrip.c --- a/main/ledstrip.c +++ b/main/ledstrip.c @@ -11,19 +11,19 @@ // Settings #define LED_STRIP_GPIO 11 -#define LED_STRIP_NUM_LEDS 150 +#define LED_STRIP_NUM_LEDS 250 #define LED_STRIP_RMT_FREQ_HZ (10 * 1000 * 1000) static const char *TAG = "ledstrip"; - // Private Prototypes -static uint8_t process_effect_rainbow(); -static uint8_t process_effect_singlechase(); - +static uint8_t process_effect_rainbow(void); +static uint8_t process_effect_singlechase(void); +static uint8_t process_effect_cauldron(void); // Private variables static led_strip_handle_t led_strip; static effect_t current_effect = EFFECT_NONE; +static led_mode_t mode = LEDMODE_AUTO; // Initialize WS2812 strip void ledstrip_init(void) @@ -60,6 +60,7 @@ void ledstrip_set_modifier(float frac) void ledstrip_set_effect(effect_t effect) { + mode = LEDMODE_AUTO; current_effect = effect; } @@ -67,8 +68,9 @@ void ledstrip_set_effect(effect_t effect // Set entire strip to RGB value void ledstrip_set(uint32_t r, uint32_t g, uint32_t b) { + mode = LEDMODE_MANUAL; for (int i = 0; i < LED_STRIP_NUM_LEDS; i++) { - ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, r, g, b)); + ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, g, r, b)); } led_strip_refresh(led_strip); } @@ -76,27 +78,47 @@ void ledstrip_set(uint32_t r, uint32_t g // Run effect and refresh strip void ledstrip_refresh(void) { - switch(current_effect) + for(;;) { - - case EFFECT_RAINBOW: + if(mode == LEDMODE_MANUAL) { - if(process_effect_rainbow() & 0x01) - led_strip_refresh(led_strip); - } break; - - case EFFECT_SINGLECHASE: + // do nothing + } + + else { - if(process_effect_singlechase() & 0x01) - led_strip_refresh(led_strip); - } break; + switch(current_effect) + { + + case EFFECT_RAINBOW: + { + if(process_effect_rainbow() & 0x01) + led_strip_refresh(led_strip); + } break; + + case EFFECT_SINGLECHASE: + { + if(process_effect_singlechase() & 0x01) + led_strip_refresh(led_strip); + } break; - case EFFECT_NONE: - default: - { - ledstrip_set(10,10,10); - led_strip_refresh(led_strip); - } break; + case EFFECT_CAULDRON: + { + if(process_effect_cauldron() & 0x01) + led_strip_refresh(led_strip); + } break; + + case EFFECT_NONE: + default: + { + ledstrip_set(10,10,10); + led_strip_refresh(led_strip); + } break; + } + } + + // TODO: DelayUntil + vTaskDelay(pdMS_TO_TICKS(10)); } } @@ -122,7 +144,7 @@ static void __reset(void) -static uint8_t process_effect_rainbow() { +static uint8_t process_effect_rainbow(void) { // Strip ID: 0 - Effect: Rainbow - LEDS: 120 // Steps: 60 - Delay: 20 // Colors: 3 (255.0.0, 0.255.0, 0.0.255) @@ -157,7 +179,7 @@ static uint8_t process_effect_rainbow() static uint32_t countloc = 0; -static uint8_t process_effect_singlechase() { +static uint8_t process_effect_singlechase(void) { if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00; float intensity = (float)countloc / (float)LED_STRIP_NUM_LEDS; @@ -165,7 +187,6 @@ static uint8_t process_effect_singlechas if(j == countloc) { ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 255, 255 * (1.0-intensity), 255 * (1.0-intensity))); - ESP_LOGI(TAG, "Friggn intensity %f", intensity); } else ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 0,0,0)); @@ -175,3 +196,53 @@ static uint8_t process_effect_singlechas return 0x01; } + + + +//127, 122 + +// static uint32_t countloc = 0; +float intensity = 1.0f; +uint8_t intensity_up = 0; +uint8_t modmod = 0; +uint32_t last_modmod = 0; + +static uint8_t process_effect_cauldron(void) { + if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00; + + if(intensity_up) + { + intensity += 0.01f; + if(intensity > 0.98f) + intensity_up = 0; + } + else + { + intensity -= 0.01f; + if(intensity < 0.7f) + intensity_up = 1; + } + // ESP_LOGI(TAG, "Friggn intensity %f", intensity); + + if((xTaskGetTickCount() * portTICK_PERIOD_MS) - last_modmod > 25) + { + last_modmod = (xTaskGetTickCount() * portTICK_PERIOD_MS); + modmod +=1; + } + + for(uint16_t j=0;j