Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tamHow do I add new animations to PixelAnim?
Direct answer to the question
Detailed problem analysis
Current information and trends
Supporting explanations and details
Minimal function-pointer pattern (Arduino/FastLED style)
// Globals (example)
CRGB leds[NUM_LEDS];
using AnimationFn = void (*)();
// Example animation: blue wipe (non-blocking) void blueWipe() { static uint16_t i = 0; static uint32_t t0 = 0; const uint16_t step_ms = 40; uint32_t now = millis(); if (now - t0 < step_ms) return; t0 = now;
if (i < NUM_LEDS) { leds[i++] = CRGB::Blue; } else { i = 0; fill_solid(leds, NUM_LEDS, CRGB::Black); } }
// Another example: rainbow march void rainbow() { static uint8_t hue = 0; fill_rainbow(leds, NUM_LEDS, hue, 7); hue++; }
AnimationFn animations[] = { rainbow, blueWipe }; const uint8_t animCount = sizeof(animations)/sizeof(animations[0]); uint8_t current = 0;
void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); FastLED.setBrightness(64); }
void loop() { static uint32_t lastSwitch = 0; uint32_t now = millis(); if (now - lastSwitch > 10000) { // switch every 10 s lastSwitch = now; current = (current + 1) % animCount; fill_solid(leds, NUM_LEDS, CRGB::Black); }
animations[current](); // run current animation FastLED.show(); // push pixels once per loop }
Object-oriented pattern (sketch) struct IAnimation { virtual void reset() = 0; virtual void step(uint32_t now) = 0; virtual ~IAnimation(){} };
struct TheaterChase : IAnimation { uint16_t phase=0; uint32_t t0=0; uint8_t hue=0; void reset() override { phase=0; t0=0; } void step(uint32_t now) override { if (now - t0 < 50) return; t0 = now; fill_solid(leds, NUM_LEDS, CRGB::Black); for (uint16_t i = phase; i < NUM_LEDS; i += 3) leds[i] = CHSV(hue,255,255); hue++; phase = (phase+1)%3; } };
// Registry of objects allows per-instance parameters, e.g., color/speed.
Data-driven sprite import (matrix example)
{ "name": "flame", "w": 16, "h": 16, "fps": 12, "loop": true, "sheet": "/flame.png", "frames": 20, "order": "row-major" }
Matrix mapping helper inline uint16_t XY(uint8_t x, uint8_t y, bool serp=true, uint8_t W=16) { return serp ? (y%2 ? yW + (W-1 - x) : yW + x) : (y*W + x); }
Ethical and legal aspects
Practical guidelines
Possible disclaimers or additional notes
Suggestions for further research
Brief summary