ESP32 Native version of Blinky, featureful controller code for WS2811/WS2812/NeoPixels
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

119 行
2.1KB

  1. #include "presets.hpp"
  2. namespace Gradients {
  3. #define GRADIENT(name, len, ...) \
  4. constexpr Gradient name = { \
  5. .n_colors = len, \
  6. .colors = __VA_ARGS__, \
  7. }
  8. GRADIENT(rainbow, 6, {
  9. Colors::red,
  10. Colors::orange,
  11. Colors::yellow,
  12. Colors::green,
  13. Colors::blue,
  14. Colors::purple,
  15. });
  16. GRADIENT(dark_rainbow, 6, {
  17. Colors::dark_red,
  18. Colors::dark_orange,
  19. Colors::dark_yellow,
  20. Colors::dark_green,
  21. Colors::dark_blue,
  22. Colors::dark_purple,
  23. });
  24. GRADIENT(pale_rainbow, 6, {
  25. Colors::pale_red,
  26. Colors::pale_orange,
  27. Colors::pale_yellow,
  28. Colors::pale_green,
  29. Colors::pale_blue,
  30. Colors::pale_purple,
  31. });
  32. GRADIENT(peacock, 4, {
  33. Colors::teal,
  34. Colors::black,
  35. Colors::purple,
  36. Colors::blue,
  37. });
  38. // Guaranteed to be random. https://xkcd.com/221/
  39. GRADIENT(random, 20, {
  40. {223, 241, 107},
  41. Colors::black,
  42. {34, 170, 82},
  43. Colors::black,
  44. {98, 222, 224},
  45. Colors::black,
  46. {230, 114, 8},
  47. Colors::black,
  48. {226, 215, 213},
  49. Colors::black,
  50. {94, 187, 179},
  51. Colors::black,
  52. {76, 185, 214},
  53. Colors::black,
  54. {40, 115, 111},
  55. Colors::black,
  56. {230, 234, 120},
  57. Colors::black,
  58. {157, 128, 68},
  59. Colors::black,
  60. });
  61. } // Gradients
  62. namespace Patterns {
  63. #define PATTERN(x) \
  64. static const Pattern x = { \
  65. .cycle_length = 20, \
  66. .cycle_time_ms = 10000, \
  67. .reverse = false, \
  68. .march = false, \
  69. .gradient = Gradients::x, \
  70. }
  71. PATTERN(rainbow);
  72. PATTERN(dark_rainbow);
  73. PATTERN(pale_rainbow);
  74. PATTERN(peacock);
  75. static const Pattern random = {
  76. .cycle_length = 20,
  77. .cycle_time_ms = 10000,
  78. .reverse = false,
  79. .march = true,
  80. .gradient = Gradients::random
  81. };
  82. } // Patterns
  83. namespace Presets {
  84. #define PRESET(x) {#x, &Patterns::x}
  85. const std::map <std::string, const Pattern*> map = {
  86. PRESET(rainbow),
  87. PRESET(dark_rainbow),
  88. PRESET(pale_rainbow),
  89. PRESET(peacock),
  90. PRESET(random),
  91. };
  92. const Pattern* find(const std::string &name) {
  93. auto e = map.find(name);
  94. return e == map.end() ? NULL : e->second;
  95. }
  96. } // Presets