DotStarTest.ino 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // DotStarTest
  2. // This example will cycle between showing four pixels as Red, Green, Blue, White
  3. // and then showing those pixels as Black.
  4. //
  5. // There is serial output of the current state so you can confirm and follow along
  6. //
  7. #include <NeoPixelBus.h>
  8. const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure
  9. // make sure to set this to the correct pins
  10. const uint8_t DotClockPin = 2;
  11. const uint8_t DotDataPin = 3;
  12. #define colorSaturation 128
  13. // for software bit bang
  14. NeoPixelBus<DotStarBgrFeature, DotStarMethod> strip(PixelCount, DotClockPin, DotDataPin);
  15. // for hardware SPI (best performance but must use hardware pins)
  16. //NeoPixelBus<DotStarBgrFeature, DotStarSpiMethod> strip(PixelCount);
  17. // DotStars that support RGB color and a overall luminance/brightness value
  18. // NeoPixelBus<DotStarLbgrFeature, DotStarMethod> strip(PixelCount, DotClockPin, DotDataPin);
  19. // DotStars that support RGBW color with a seperate white element
  20. //NeoPixelBus<DotStarWbgrFeature, DotStarMethod> strip(PixelCount, DotClockPin, DotDataPin);
  21. RgbColor red(colorSaturation, 0, 0);
  22. RgbColor green(0, colorSaturation, 0);
  23. RgbColor blue(0, 0, colorSaturation);
  24. RgbColor white(colorSaturation);
  25. RgbColor black(0);
  26. // for use with RGB DotStars when using the luminance/brightness global value
  27. // note that its range is only 0 - 31 (31 is full bright) and
  28. // also note that it is not useful for POV displays as it will cause more flicker
  29. RgbwColor redL(colorSaturation, 0, 0, 31); // use white value to store luminance
  30. RgbwColor greenL(0, colorSaturation, 0, 31); // use white value to store luminance
  31. RgbwColor blueL(0, 0, colorSaturation, 31); // use white value to store luminance
  32. RgbwColor whiteL(255, 255, 255, colorSaturation / 8); // luminance is only 0-31
  33. void setup()
  34. {
  35. Serial.begin(115200);
  36. while (!Serial); // wait for serial attach
  37. Serial.println();
  38. Serial.println("Initializing...");
  39. Serial.flush();
  40. // this resets all the neopixels to an off state
  41. strip.Begin();
  42. strip.ClearTo(black);
  43. strip.Show();
  44. Serial.println();
  45. Serial.println("Running...");
  46. }
  47. void loop()
  48. {
  49. delay(5000);
  50. Serial.println("Colors R, G, B, W...");
  51. // set the colors,
  52. strip.SetPixelColor(0, red);
  53. strip.SetPixelColor(1, green);
  54. strip.SetPixelColor(2, blue);
  55. strip.SetPixelColor(3, white);
  56. strip.Show();
  57. delay(5000);
  58. Serial.println("Off ...");
  59. // turn off the pixels
  60. strip.SetPixelColor(0, black);
  61. strip.SetPixelColor(1, black);
  62. strip.SetPixelColor(2, black);
  63. strip.SetPixelColor(3, black);
  64. strip.Show();
  65. }