NeoPixelTest.ino 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. //NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
  24. //
  25. // NeoEsp8266Uart800KbpsMethod uses GPI02 instead
  26. // You can also use one of these for Esp8266,
  27. // each having their own restrictions
  28. //
  29. // These two are the same as above as the DMA method is the default
  30. // NOTE: These will ignore the PIN and use GPI03 pin
  31. //NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);
  32. //NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> strip(PixelCount, PixelPin);
  33. // Uart method is good for the Esp-01 or other pin restricted modules
  34. // NOTE: These will ignore the PIN and use GPI02 pin
  35. //NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
  36. //NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin);
  37. // The bitbang method is really only good if you are not using WiFi features of the ESP
  38. // It works with all but pin 16
  39. //NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
  40. //NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang400KbpsMethod> strip(PixelCount, PixelPin);
  41. // four element pixels, RGBW
  42. //NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  43. RgbColor red(colorSaturation, 0, 0);
  44. RgbColor green(0, colorSaturation, 0);
  45. RgbColor blue(0, 0, colorSaturation);
  46. RgbColor white(colorSaturation);
  47. RgbColor black(0);
  48. HslColor hslRed(red);
  49. HslColor hslGreen(green);
  50. HslColor hslBlue(blue);
  51. HslColor hslWhite(white);
  52. HslColor hslBlack(black);
  53. void setup()
  54. {
  55. Serial.begin(115200);
  56. while (!Serial); // wait for serial attach
  57. Serial.println();
  58. Serial.println("Initializing...");
  59. Serial.flush();
  60. // this resets all the neopixels to an off state
  61. strip.Begin();
  62. strip.Show();
  63. Serial.println();
  64. Serial.println("Running...");
  65. }
  66. void loop()
  67. {
  68. delay(5000);
  69. Serial.println("Colors R, G, B, W...");
  70. // set the colors,
  71. // if they don't match in order, you need to use NeoGrbFeature feature
  72. strip.SetPixelColor(0, red);
  73. strip.SetPixelColor(1, green);
  74. strip.SetPixelColor(2, blue);
  75. strip.SetPixelColor(3, white);
  76. // the following line demonstrates rgbw color support
  77. // if the NeoPixels are rgbw types the following line will compile
  78. // if the NeoPixels are anything else, the following line will give an error
  79. //strip.SetPixelColor(3, RgbwColor(colorSaturation));
  80. strip.Show();
  81. delay(5000);
  82. Serial.println("Off ...");
  83. // turn off the pixels
  84. strip.SetPixelColor(0, black);
  85. strip.SetPixelColor(1, black);
  86. strip.SetPixelColor(2, black);
  87. strip.SetPixelColor(3, black);
  88. strip.Show();
  89. delay(5000);
  90. Serial.println("HSL Colors R, G, B, W...");
  91. // set the colors,
  92. // if they don't match in order, you may need to use NeoGrbFeature feature
  93. strip.SetPixelColor(0, hslRed);
  94. strip.SetPixelColor(1, hslGreen);
  95. strip.SetPixelColor(2, hslBlue);
  96. strip.SetPixelColor(3, hslWhite);
  97. strip.Show();
  98. delay(5000);
  99. Serial.println("Off again...");
  100. // turn off the pixels
  101. strip.SetPixelColor(0, hslBlack);
  102. strip.SetPixelColor(1, hslBlack);
  103. strip.SetPixelColor(2, hslBlack);
  104. strip.SetPixelColor(3, hslBlack);
  105. strip.Show();
  106. }