ESP32 Native version of Blinky, featureful controller code for WS2811/WS2812/NeoPixels
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1003B

  1. #pragma once
  2. #include <cstdint>
  3. #include <string>
  4. struct Color {
  5. uint8_t r, g, b;
  6. };
  7. typedef uint16_t Fixed;
  8. constexpr int factor = 65536;
  9. constexpr int shift = 16;
  10. struct Gradient {
  11. Color at(Fixed x) const;
  12. unsigned int n_colors;
  13. Color colors[];
  14. };
  15. struct Pattern {
  16. void step(Color[], int, int64_t &last_us, Fixed &offset) const;
  17. int cycle_length;
  18. int cycle_time_ms;
  19. bool reverse;
  20. bool march;
  21. Gradient gradient;
  22. };
  23. class LEDStrip {
  24. public:
  25. LEDStrip(int length);
  26. void step();
  27. virtual void show() const = 0;
  28. void setPattern(const Pattern* _pattern) { pattern = _pattern; }
  29. const Pattern* getPattern() const { return pattern; }
  30. int getLength() const { return length; }
  31. protected:
  32. const int length;
  33. const Pattern *pattern;
  34. Color *pixels;
  35. private:
  36. int64_t last_us;
  37. Fixed offset;
  38. };
  39. class TerminalLEDs : public LEDStrip {
  40. public:
  41. TerminalLEDs(int length) : LEDStrip(length) {}
  42. void show() const;
  43. };