FastLED-Library
1. http://fastled.io/ Klick auf "Releases" im Menü herunterscrollen zu "Downloads" Source code (zip) Source code (tar.gz) 2. auspacken, ins arduino_sketch-Unter-Verzeichnis "libraries" 3. Verzeichnis umbenennnen in "FastLED" 4. Ggf. Arduino neustarten
C-Kenntnisse - Struct
typedef struct { uint8_t r; uint8_t g; uint8_t b; } my_RGB; my_RGB px; px.r=255; my_RGB pxs[3]; pxs[0].r=255;
Das erste Programm mit WS2812b LED-Streifen
#include <FastLED.h> const int LEDPin = 4; const int NPixels = 9; CRGB leds[NPixels]; int pos=0; void setup() { FastLED.addLeds<NEOPIXEL, LEDPin>(leds, NPixels); } void loop() { for (int i=0; i<NPixels; i++) { leds[i].setRGB(0,0,0); } //leds[pos].setRGB(32,16,0); leds[pos].r=32; leds[pos].g=16; FastLED.show(); pos++; if (pos >= NPixels) pos=0; delay(200); } /* Ungefähr (aus FastLEDpixeltypes.h) struct CRGB { union { struct { union { uint8_t r; uint8_t red; }; union { uint8_t g; uint8_t green; }; union { uint8_t b; uint8_t blue; }; }; uint8_t raw[3]; }; ... }; struct CRGB { uint8_t r; uint8_t g; uint8_t b; }; */
Experimental..temporär:
#include <FastLED.h> const int LEDPin = 4; const int NPixels = 18; CRGB leds[NPixels]; typedef struct { uint8_t r,g,b; int pos; } PUNKT; const int NPunkte = 6; PUNKT punkte[NPunkte]; int pos=0; void setup() { FastLED.addLeds<NEOPIXEL, LEDPin>(leds, NPixels+2); // +2 zur Sicherheit für Effekte for (int j=0; j<NPunkte; j++) punkte[j]={random(256),random(256),random(256), random(NPixels)}; } void loop() { for (int i=0; i<NPixels; i++) { leds[i].setRGB(0,0,0); } for (int j=0; j<NPunkte; j++) { leds[ punkte[j].pos ].setRGB(punkte[j].r, punkte[j].g, punkte[j].b); } /* typedef struct { uint8_t r,g,b; int pos; } PUNKT; */ /* //leds[pos].setRGB(32,16,0); //leds[pos].r=32; //leds[pos].g=16; for (int i=0; i<NPixels; i++) { leds[(i+pos)%NPixels].r= i* (int)255 /(NPixels-1); leds[(i+pos)%NPixels].g= (NPixels-i-1)* (int)255 /(NPixels-1); }*/ FastLED.show(); // Alternative zu untenstehendem: pos = (pos+1)%NPixels; pos++; if (pos >= NPixels-1) pos=0; delay(200); } /* Ungefähr (aus FastLEDpixeltypes.h) struct CRGB { union { struct { union { uint8_t r; uint8_t red; }; union { uint8_t g; uint8_t green; }; union { uint8_t b; uint8_t blue; }; }; uint8_t raw[3]; }; ... }; struct CRGB { uint8_t r; uint8_t g; uint8_t b; }; a[1] = {60,0,0}; */ }