neopixel.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * neopixel.cpp
  24. */
  25. #include "MarlinConfig.h"
  26. #if ENABLED(NEOPIXEL_LED)
  27. #include "neopixel.h"
  28. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  29. #include "utility.h"
  30. #endif
  31. Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
  32. void set_neopixel_color(const uint32_t color) {
  33. for (uint16_t i = 0; i < pixels.numPixels(); ++i)
  34. pixels.setPixelColor(i, color);
  35. pixels.show();
  36. }
  37. void setup_neopixel() {
  38. SET_OUTPUT(NEOPIXEL_PIN);
  39. pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
  40. pixels.begin();
  41. pixels.show(); // initialize to all off
  42. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  43. safe_delay(1000);
  44. set_neopixel_color(pixels.Color(255, 0, 0, 0)); // red
  45. safe_delay(1000);
  46. set_neopixel_color(pixels.Color(0, 255, 0, 0)); // green
  47. safe_delay(1000);
  48. set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
  49. safe_delay(1000);
  50. #endif
  51. set_neopixel_color(pixels.Color(NEO_WHITE)); // white
  52. }
  53. #endif // NEOPIXEL_LED