Wemos D1 Mini Frimware zur Steuerung einer RGBW-LED-Lampe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * LEDStripManager.cpp
  3. *
  4. * Created on: 19.06.2026
  5. * Author: FSmilari
  6. */
  7. #include "LEDStripManager.h"
  8. /*
  9. * Constructor
  10. */
  11. LEDStripManager::LEDStripManager(uint16_t numLeds, uint8_t pin) : strip(numLeds, pin, NEO_GRBW + NEO_KHZ800) {
  12. }
  13. /*
  14. * Destructor
  15. */
  16. LEDStripManager::~LEDStripManager() {
  17. }
  18. void LEDStripManager::begin() {
  19. pinMode(LED_STRIP_POWER_PIN, OUTPUT);
  20. pinMode(LED_STRIP_DATA_PIN, OUTPUT);
  21. digitalWrite(LED_STRIP_POWER_PIN, HIGH); // LED zunächst EIN
  22. strip.begin(); // Initialisiert den NeoPixel-Streifen
  23. strip.clear();
  24. strip.show(); // Setzt alle LEDs auf "aus"
  25. strip.setBrightness(255); // Helligkeit (0 bis 255)
  26. // Setzt die erste LED (Index 0) auf rotes Licht (Rot, Grün, Blau, Weiss)
  27. strip.setPixelColor(0, strip.Color(255, 0, 0, 0));
  28. // Setzt die zweite LED auf grün
  29. strip.setPixelColor(1, strip.Color(0, 255, 0, 0));
  30. strip.setPixelColor(2, strip.Color(0, 0, 255, 0));
  31. strip.setPixelColor(3, strip.Color(0, 0, 0, 255));
  32. // Schickt die Farbinformationen zum LED-Streifen
  33. show();
  34. }
  35. void LEDStripManager::clear() {
  36. strip.clear();
  37. }
  38. void LEDStripManager::show() {
  39. strip.show();
  40. }
  41. void LEDStripManager::on() {
  42. Serial.println("LEDStripManager LED ON");
  43. digitalWrite(LED_STRIP_POWER_PIN, HIGH);
  44. delay(50);
  45. digitalWrite(LED_STRIP_DATA_PIN, HIGH);
  46. delay(50);
  47. strip.begin();
  48. strip.show();
  49. // TODO: Load the state from the eeprom
  50. strip.setPixelColor(0, strip.Color(255, 0, 0, 0));
  51. strip.setPixelColor(1, strip.Color(0, 255, 0, 0));
  52. strip.setPixelColor(2, strip.Color(0, 0, 255, 0));
  53. strip.setPixelColor(3, strip.Color(0, 0, 0, 255));
  54. strip.show();
  55. }
  56. void LEDStripManager::off() {
  57. Serial.println("LEDStripManager LED OFF");
  58. clear();
  59. show();
  60. delay(50);
  61. digitalWrite(LED_STRIP_POWER_PIN, LOW); // LED zunächst AUS
  62. digitalWrite(LED_STRIP_DATA_PIN, LOW);
  63. }
  64. void LEDStripManager::setBrightness(uint8_t brightness) {
  65. strip.setBrightness(brightness);
  66. }
  67. void LEDStripManager::setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) {
  68. if (index >= strip.numPixels()) {
  69. return;
  70. }
  71. strip.setPixelColor(index, strip.Color(red, green, blue));
  72. }
  73. void LEDStripManager::setAll(uint8_t red, uint8_t green, uint8_t blue) {
  74. for (uint16_t i = 0; i < strip.numPixels(); i++) {
  75. strip.setPixelColor(i, strip.Color(red, green, blue));
  76. }
  77. strip.show();
  78. }
  79. uint32_t
  80. LEDStripManager::wheel(uint8_t pos) {
  81. pos = 255 - pos;
  82. if (pos < 85) {
  83. return strip.Color(255 - pos * 3, 0, pos * 3);
  84. }
  85. if (pos < 170) {
  86. pos -= 85;
  87. return strip.Color(0, pos * 3, 255 - pos * 3);
  88. }
  89. pos -= 170;
  90. return strip.Color(pos * 3, 255 - pos * 3, 0);
  91. }
  92. void LEDStripManager::rainbow(uint8_t wait) {
  93. for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
  94. for (uint16_t i = 0; i < strip.numPixels(); i++) {
  95. uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  96. strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  97. }
  98. strip.show();
  99. delay(wait);
  100. }
  101. }