NeoPixelRingDynamicTopologyTest.ino 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //----------------------------------------------------------------------
  2. // NeoPixelRingTopologyTest
  3. // This will display specific colors in specific locations on the led rings
  4. //
  5. // This is useful in confirming the layout of your rings
  6. //
  7. // It does require that you have the actual series of rings connected
  8. //----------------------------------------------------------------------
  9. #include <NeoPixelBus.h>
  10. const uint8_t PixelCount = 119;
  11. const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
  12. // define the layout of your series of rings
  13. //
  14. // This example is using all of Adafruits rings and a Jewel in the center.
  15. // The center is the input and all the rings are connected in series going outward
  16. //
  17. // Rings:
  18. // 0 - 1 (virtual ring, the center of the jewel)
  19. // 1 - 6 (virtual ring, the outer ring of the jewel)
  20. // 2 - 12 count ring
  21. // 3 - 16 count ring
  22. // 4 - 24 count ring
  23. // 5 - 60 count ring comprised of four arc segments
  24. //
  25. // The values below in Rings[] are the index of the first pixel in each ring.
  26. // An extra value is appended for a virtual ring start that also
  27. // represents the total count of pixels in the complete series and this extra
  28. // value is required.
  29. //
  30. class MyRingsLayout
  31. {
  32. public:
  33. void Begin() {
  34. // this is where you load your dynamic rings layout and init Rings and RingCount
  35. // this example will just set these to static numbers to simulate a dynamic layout
  36. RingCount = 6;
  37. Rings = new uint16_t[RingCount];
  38. Rings[0] = 1;
  39. Rings[1] = 6;
  40. Rings[2] = 12;
  41. Rings[3] = 16;
  42. Rings[4] = 24;
  43. Rings[5] = 60; // don't forget the final count of pixels as the last item
  44. }
  45. protected:
  46. uint16_t* Rings;
  47. uint8_t RingCount;
  48. uint8_t _ringCount() const
  49. {
  50. return RingCount;
  51. }
  52. };
  53. // use the MyRingsLayout to declare the topo object
  54. //
  55. NeoRingTopology<MyRingsLayout> topo;
  56. // declare our strip
  57. //
  58. NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  59. // define some handy colors
  60. //
  61. RgbColor red(128, 0, 0);
  62. RgbColor green(0, 128, 0);
  63. RgbColor blue(0, 0, 128);
  64. RgbColor black(0);
  65. void setup()
  66. {
  67. Serial.begin(115200);
  68. while (!Serial); // wait for serial attach
  69. Serial.println();
  70. Serial.println("Initializing...");
  71. topo.Begin();
  72. strip.Begin();
  73. strip.Show();
  74. Serial.println();
  75. Serial.println("Running...");
  76. }
  77. void loop()
  78. {
  79. delay(2500);
  80. Serial.println();
  81. Serial.println("If your panel is correctly defined, you should see ...");
  82. Serial.println("First pixel in each ring is Red.");
  83. Serial.println("Middle pixel in each ring is Green.");
  84. Serial.println("Last Pixel in each ring is Blue.");
  85. // use the topo to map the 2d polar cordinate to the pixel
  86. // and use that to SetPixelColor
  87. for (uint16_t ring = 0; ring < topo.getCountOfRings(); ring++)
  88. {
  89. // first pixel in each ring is red
  90. strip.SetPixelColor(topo.Map(ring, 0), red);
  91. // last pixel in each ring is blue
  92. strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) - 1), blue);
  93. // middle pixel in each ring is green
  94. strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) / 2), green);
  95. }
  96. strip.Show();
  97. delay(5000);
  98. Serial.println();
  99. Serial.println("Cleared to black ...");
  100. strip.ClearTo(black);
  101. strip.Show();
  102. }