My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

neopixel.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * Marlin RGB LED general support
  24. */
  25. #include "../../inc/MarlinConfig.h"
  26. #if ENABLED(NEOPIXEL_RGBW_LED)
  27. #include "neopixel.h"
  28. Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEO_GRBW + NEO_KHZ800);
  29. void set_neopixel_color(const uint32_t color) {
  30. for (uint16_t i = 0; i < pixels.numPixels(); ++i)
  31. pixels.setPixelColor(i, color);
  32. pixels.show();
  33. }
  34. void setup_neopixel() {
  35. pixels.setBrightness(255); // 0 - 255 range
  36. pixels.begin();
  37. pixels.show(); // initialize to all off
  38. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  39. delay(2000);
  40. set_neopixel_color(pixels.Color(255, 0, 0, 0)); // red
  41. delay(2000);
  42. set_neopixel_color(pixels.Color(0, 255, 0, 0)); // green
  43. delay(2000);
  44. set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
  45. delay(2000);
  46. #endif
  47. set_neopixel_color(pixels.Color(0, 0, 0, 255)); // white
  48. }
  49. bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const bool isSequence) {
  50. const uint32_t color = pixels.Color(r, g, b, w);
  51. static uint16_t nextLed = 0;
  52. if (!isSequence)
  53. set_neopixel_color(color);
  54. else {
  55. pixels.setPixelColor(nextLed, color);
  56. pixels.show();
  57. if (++nextLed >= pixels.numPixels()) nextLed = 0;
  58. return true;
  59. }
  60. return false;
  61. }
  62. #endif // NEOPIXEL_RGBW_LED