mirror of
https://github.com/bbulkow/FastLED-idf.git
synced 2026-01-26 17:02:19 +01:00
80 lines
2.7 KiB
C++
80 lines
2.7 KiB
C++
/* Hello World Example
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
#include <stdio.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_system.h"
|
|
#include "esp_spi_flash.h"
|
|
#include "FastLED.h"
|
|
CRGBPalette16 currentPalette;
|
|
TBlendType currentBlending;
|
|
|
|
extern CRGBPalette16 myRedWhiteBluePalette;
|
|
extern const TProgmemPalette16 IRAM_ATTR myRedWhiteBluePalette_p;
|
|
|
|
#include "palettes.h"
|
|
|
|
#define NUM_LEDS 400
|
|
#define DATA_PIN 15
|
|
#define BRIGHTNESS 64
|
|
#define LED_TYPE WS2811
|
|
#define COLOR_ORDER GRB
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
|
|
extern "C" {
|
|
void app_main();
|
|
}
|
|
|
|
void ChangePalettePeriodically(){
|
|
|
|
uint8_t secondHand = (millis() / 1000) % 60;
|
|
static uint8_t lastSecond = 99;
|
|
|
|
if( lastSecond != secondHand) {
|
|
lastSecond = secondHand;
|
|
if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
|
|
if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
|
|
if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; }
|
|
if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; }
|
|
if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; }
|
|
if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
|
|
if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
|
|
if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
|
|
if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; }
|
|
if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
|
|
if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
|
|
}
|
|
|
|
}
|
|
void blinkLeds(void *pvParameters){
|
|
while(1){
|
|
ChangePalettePeriodically();
|
|
|
|
static uint8_t startIndex = 0;
|
|
startIndex = startIndex + 1; /* motion speed */
|
|
|
|
for( int i = 0; i < NUM_LEDS; i++) {
|
|
leds[i] = ColorFromPalette( currentPalette, startIndex, 64, currentBlending);
|
|
startIndex += 3;
|
|
}
|
|
|
|
FastLED.show();
|
|
delay(40);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void app_main() {
|
|
FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
|
|
FastLED.setMaxPowerInVoltsAndMilliamps(5,1000);
|
|
xTaskCreatePinnedToCore(&blinkLeds, "blinkLeds", 4000, NULL, 5, NULL, 0);
|
|
}
|