본문 바로가기

Arduino

NeoPixel 테스트

네오픽셀하나에 평균 20mA이고 최대 60mA까지 사용합니다. 8개짜리 네오픽셀이라고 해도 최대 480mA나 사용 가능하기 때문에 USB의 최대 허용 500mA 를 고려하면 아래 그림처럼 네오픽셀 전원 공급은 따로 하는게 좋겠지요. 테스트해보니 엄청 화려하긴 하네요. 어떤 용도로 사용할지 고민이 필요하네요.



  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN 6
  3. // Parameter 1 = number of pixels in strip
  4. // Parameter 2 = Arduino pin number (most are valid)
  5. // Parameter 3 = pixel type flags, add together as needed:
  6. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  7. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  8. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  9. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  10. // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  11. Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
  12. void setup() {
  13. strip.begin();
  14. strip.setBrightness(50);
  15. strip.show(); // Initialize all pixels to 'off'
  16. }
  17. void loop() {
  18. // Some example procedures showing how to display to the pixels:
  19. colorWipe(strip.Color(255, 0, 0), 50); // Red
  20. colorWipe(strip.Color(0, 255, 0), 50); // Green
  21. colorWipe(strip.Color(0, 0, 255), 50); // Blue
  22. //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  23. // Send a theater pixel chase in...
  24. theaterChase(strip.Color(127, 127, 127), 50); // White
  25. theaterChase(strip.Color(127, 0, 0), 50); // Red
  26. theaterChase(strip.Color(0, 0, 127), 50); // Blue
  27. rainbow(20);
  28. rainbowCycle(20);
  29. theaterChaseRainbow(50);
  30. }
  31. // Fill the dots one after the other with a color
  32. void colorWipe(uint32_t c, uint8_t wait) {
  33. for(uint16_t i=0; i<strip.numPixels(); i++) {
  34. strip.setPixelColor(i, c);
  35. strip.show();
  36. delay(wait);
  37. }
  38. }
  39. void rainbow(uint8_t wait) {
  40. uint16_t i, j;
  41. for(j=0; j<256; j++) {
  42. for(i=0; i<strip.numPixels(); i++) {
  43. strip.setPixelColor(i, Wheel((i+j) & 255));
  44. }
  45. strip.show();
  46. delay(wait);
  47. }
  48. }
  49. // Slightly different, this makes the rainbow equally distributed throughout
  50. void rainbowCycle(uint8_t wait) {
  51. uint16_t i, j;
  52. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  53. for(i=0; i< strip.numPixels(); i++) {
  54. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  55. }
  56. strip.show();
  57. delay(wait);
  58. }
  59. }
  60. //Theatre-style crawling lights.
  61. void theaterChase(uint32_t c, uint8_t wait) {
  62. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  63. for (int q=0; q < 3; q++) {
  64. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  65. strip.setPixelColor(i+q, c); //turn every third pixel on
  66. }
  67. strip.show();
  68. delay(wait);
  69. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  70. strip.setPixelColor(i+q, 0); //turn every third pixel off
  71. }
  72. }
  73. }
  74. }
  75. //Theatre-style crawling lights with rainbow effect
  76. void theaterChaseRainbow(uint8_t wait) {
  77. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  78. for (int q=0; q < 3; q++) {
  79. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  80. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  81. }
  82. strip.show();
  83. delay(wait);
  84. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  85. strip.setPixelColor(i+q, 0); //turn every third pixel off
  86. }
  87. }
  88. }
  89. }
  90. // Input a value 0 to 255 to get a color value.
  91. // The colours are a transition r - g - b - back to r.
  92. uint32_t Wheel(byte WheelPos) {
  93. WheelPos = 255 - WheelPos;
  94. if(WheelPos < 85) {
  95. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  96. }
  97. if(WheelPos < 170) {
  98. WheelPos -= 85;
  99. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  100. }
  101. WheelPos -= 170;
  102. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  103. }


'Arduino' 카테고리의 다른 글

APDS-9960 센서  (0) 2019.03.13
Pro Micro 시간과 날짜 PCB  (0) 2019.03.06
아두이노 Pro Micro 시계 - 듀얼 모드  (0) 2019.03.04
아두이노 시계 PCB 제작  (0) 2019.03.03
Arduino Pro Micro 시계 셋업 테스트  (0) 2019.02.28