NeoPixelTest.ino 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // NeoPixelTest
  2. // This example will cycle between showing four pixels as Red, Green, Blue, White
  3. // and then showing those pixels as Black.
  4. //
  5. // Included but commented out are examples of configuring a NeoPixelBus for
  6. // different color order including an extra white channel, different data speeds, and
  7. // for Esp8266 different methods to send the data.
  8. // NOTE: You will need to make sure to pick the one for your platform
  9. //
  10. //
  11. // There is serial output of the current state so you can confirm and follow along
  12. //
  13. #include <NeoPixelBus.h>
  14. const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure
  15. const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
  16. #define colorSaturation 128
  17. // three element pixels, in different order and speeds
  18. NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  19. //NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin);
  20. // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
  21. // There are other Esp8266 alternative methods that provide more pin options, but also have
  22. // other side effects.
  23. // for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
  24. // You can also use one of these for Esp8266,
  25. // each having their own restrictions
  26. //
  27. // These two are the same as above as the DMA method is the default
  28. // NOTE: These will ignore the PIN and use GPI03 pin
  29. //NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);
  30. //NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> strip(PixelCount, PixelPin);
  31. // Uart method is good for the Esp-01 or other pin restricted modules
  32. // for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods
  33. // NOTE: These will ignore the PIN and use GPI02 pin
  34. //NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart1800KbpsMethod> strip(PixelCount, PixelPin);
  35. //NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart1400KbpsMethod> strip(PixelCount, PixelPin);
  36. // The bitbang method is really only good if you are not using WiFi features of the ESP
  37. // It works with all but pin 16
  38. //NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
  39. //NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang400KbpsMethod> strip(PixelCount, PixelPin);
  40. // four element pixels, RGBW
  41. //NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  42. RgbColor red(colorSaturation, 0, 0);
  43. RgbColor green(0, colorSaturation, 0);
  44. RgbColor blue(0, 0, colorSaturation);
  45. RgbColor white(colorSaturation);
  46. RgbColor black(0);
  47. HslColor hslRed(red);
  48. HslColor hslGreen(green);
  49. HslColor hslBlue(blue);
  50. HslColor hslWhite(white);
  51. HslColor hslBlack(black);
  52. void setup()
  53. {
  54. Serial.begin(115200);
  55. while (!Serial); // wait for serial attach
  56. Serial.println();
  57. Serial.println("Initializing...");
  58. Serial.flush();
  59. // this resets all the neopixels to an off state
  60. strip.Begin();
  61. strip.Show();
  62. Serial.println();
  63. Serial.println("Running...");
  64. }
  65. void loop()
  66. {
  67. delay(5000);
  68. Serial.println("Colors R, G, B, W...");
  69. // set the colors,
  70. // if they don't match in order, you need to use NeoGrbFeature feature
  71. strip.SetPixelColor(0, red);
  72. strip.SetPixelColor(1, green);
  73. strip.SetPixelColor(2, blue);
  74. strip.SetPixelColor(3, white);
  75. // the following line demonstrates rgbw color support
  76. // if the NeoPixels are rgbw types the following line will compile
  77. // if the NeoPixels are anything else, the following line will give an error
  78. //strip.SetPixelColor(3, RgbwColor(colorSaturation));
  79. strip.Show();
  80. delay(5000);
  81. Serial.println("Off ...");
  82. // turn off the pixels
  83. strip.SetPixelColor(0, black);
  84. strip.SetPixelColor(1, black);
  85. strip.SetPixelColor(2, black);
  86. strip.SetPixelColor(3, black);
  87. strip.Show();
  88. delay(5000);
  89. Serial.println("HSL Colors R, G, B, W...");
  90. // set the colors,
  91. // if they don't match in order, you may need to use NeoGrbFeature feature
  92. strip.SetPixelColor(0, hslRed);
  93. strip.SetPixelColor(1, hslGreen);
  94. strip.SetPixelColor(2, hslBlue);
  95. strip.SetPixelColor(3, hslWhite);
  96. strip.Show();
  97. delay(5000);
  98. Serial.println("Off again...");
  99. // turn off the pixels
  100. strip.SetPixelColor(0, hslBlack);
  101. strip.SetPixelColor(1, hslBlack);
  102. strip.SetPixelColor(2, hslBlack);
  103. strip.SetPixelColor(3, hslBlack);
  104. strip.Show();
  105. }