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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_LED)
  27. #include "neopixel.h"
  28. Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + 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. SET_OUTPUT(NEOPIXEL_PIN);
  36. pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
  37. pixels.begin();
  38. pixels.show(); // initialize to all off
  39. #if ENABLED(NEOPIXEL_STARTUP_TEST)
  40. safe_delay(1000);
  41. set_neopixel_color(pixels.Color(255, 0, 0, 0)); // red
  42. safe_delay(1000);
  43. set_neopixel_color(pixels.Color(0, 255, 0, 0)); // green
  44. safe_delay(1000);
  45. set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
  46. safe_delay(1000);
  47. #endif
  48. #if ENABLED(LED_USER_PRESET_STARTUP)
  49. set_neopixel_color(pixels.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
  50. #else
  51. set_neopixel_color(pixels.Color(0, 0, 0, 0));
  52. #endif
  53. }
  54. #if 0
  55. bool neopixel_set_led_color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w, const uint8_t p) {
  56. const uint32_t color = pixels.Color(r, g, b, w);
  57. pixels.setBrightness(p);
  58. #if !ENABLED(NEOPIXEL_IS_SEQUENTIAL)
  59. set_neopixel_color(color);
  60. return false;
  61. #else
  62. static uint16_t nextLed = 0;
  63. pixels.setPixelColor(nextLed, color);
  64. pixels.show();
  65. if (++nextLed >= pixels.numPixels()) nextLed = 0;
  66. return true;
  67. #endif
  68. }
  69. #endif
  70. #endif // NEOPIXEL_LED