#include "FastLED.h"// How many leds in your strip?#define NUM_LEDS 8// For led chips like Neopixels, which have a data line, ground, and power, you just// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN#define DATA_PIN 6#define BRIGHTNESS 30// Define the array of ledsCRGB leds[NUM_LEDS];void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN, RGB>(leds, NUM_LEDS); FastLED.setBrightness( BRIGHTNESS ); }void loop(){ // Turn the LED off, then pause leds[0].setRGB(0,0,0); leds[1].setRGB(0,0,0); leds[2].setRGB(0,0,0); leds[3].setRGB(0,0,0); leds[4].setRGB(0,0,0); leds[5].setRGB(0,0,0); leds[6].setRGB(0,0,0); leds[7].setRGB(0,0,0); FastLED.show(); delay(2000); // Turn the LED on, then pause leds[0].setRGB(60,0,20); leds[1].setRGB(60,0,20); leds[2].setRGB(60,0,20); leds[3].setRGB(60,0,20); leds[4].setRGB(60,0,20); leds[5].setRGB(60,0,20); leds[6].setRGB(60,0,20); leds[7].setRGB(60,0,20); FastLED.show(); delay(5000); // Turn the LED on, then pause leds[0].setRGB(120,0,40); leds[1].setRGB(120,0,40); leds[2].setRGB(120,0,40); leds[3].setRGB(120,0,40); leds[4].setRGB(120,0,40); leds[5].setRGB(120,0,40); leds[6].setRGB(120,0,40); leds[7].setRGB(120,0,40); FastLED.show(); delay(5000); // Turn the LED on, then pause leds[0].setRGB(180,0,60); leds[1].setRGB(180,0,60); leds[2].setRGB(180,0,60); leds[3].setRGB(180,0,60); leds[4].setRGB(180,0,60); leds[5].setRGB(180,0,60); leds[6].setRGB(180,0,60); leds[7].setRGB(180,0,60); FastLED.show(); delay(5000); // Turn the LED on, then pause leds[0].setRGB(240,0,80); leds[1].setRGB(240,0,80); leds[2].setRGB(240,0,80); leds[3].setRGB(240,0,80); leds[4].setRGB(240,0,80); leds[5].setRGB(240,0,80); leds[6].setRGB(240,0,80); leds[7].setRGB(240,0,80); FastLED.show(); delay(5000); }
#include "FastLED.h"/********** Color and timing *************/typedef struct{ unsigned int fadeIn; unsigned int ontime; CRGB color;} preset_map;//map of {fadeIn time = transition time (in ms), on time (in ms), CRGB color}//You can add more colors (and times) for more transitions//transitions happen in chronological order order starting at 0 at bootconst preset_map Presets[] = { {10000, 5000, CRGB(240, 0, 80)}, {10000, 5000, CRGB(255, 255, 255)}};#define NUM_PRESETS sizeof(Presets)/sizeof(Presets[0])/********** FastLED definitions **********/// How many leds in your strip?#define NUM_LEDS 8// For led chips like Neopixels, which have a data line, ground, and power, you just// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN#define DATA_PIN 6#define BRIGHTNESS 30// Define the array of ledsCRGB leds[NUM_LEDS];void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); FastLED.setBrightness( BRIGHTNESS );}void loop(){ ledsUpdate(); }void ledsUpdate(){ static bool inTransition; static unsigned long millisLast; static byte presetCounter; static unsigned int interval; static byte transitionCounter; byte r, g, b, lastPreset; if(millis() - millisLast > interval){ millisLast = millis(); if(inTransition){ //It's a new transition, calculate transition interval //transition in 256 steps //Full transition will be 256 * (fadeIn / 256) as int so there can be a significant error if(transitionCounter == 0){ interval = Presets[presetCounter].fadeIn / 256; transitionCounter++; } //What was the last preset? lastPreset = (presetCounter == 0 ? NUM_PRESETS - 1 : presetCounter - 1); //calculate in between color for RGB r = lerp8by8(Presets[lastPreset].color.r, Presets[presetCounter].color.r, transitionCounter); g = lerp8by8(Presets[lastPreset].color.g, Presets[presetCounter].color.g, transitionCounter); b = lerp8by8(Presets[lastPreset].color.b, Presets[presetCounter].color.b, transitionCounter); //set al the colors for(byte i = 0; i < NUM_LEDS; i++){ leds[i].setRGB(r, g, b); } //if it was the last transition if(transitionCounter == 255){ inTransition = false; } transitionCounter++; } //we are at the new preset else{ //turn all leds to preset color for(byte i = 0; i < NUM_LEDS; i++){ leds[i] = Presets[presetCounter].color; } //start waiting for next transition interval = Presets[presetCounter].ontime; presetCounter++; inTransition = true; } FastLED.show(); }}/code]Ik hoop dat je hier iets mee kan.Timo
Orgineel:for(byte i = 0; i < NUM_LEDS; i++){ leds[i].setRGB(r, g, b); }Nieuw:for(byte i = 0; i < NUM_LEDS; i++){ leds[i].setRGB(r, g, b); delay(10); }