NeoPixelRingTopologyTest.ino 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. protected:
  33. const uint16_t Rings[7] = {0, 1, 7, 19, 35, 59, PixelCount};
  34. uint8_t _ringCount() const
  35. {
  36. return sizeof(Rings) / sizeof(Rings[0]);
  37. }
  38. };
  39. // use the MyRingsLayout to declare the topo object
  40. //
  41. NeoRingTopology<MyRingsLayout> topo;
  42. // declare our strip
  43. //
  44. NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  45. // define some handy colors
  46. //
  47. RgbColor red(128, 0, 0);
  48. RgbColor green(0, 128, 0);
  49. RgbColor blue(0, 0, 128);
  50. RgbColor black(0);
  51. void setup()
  52. {
  53. Serial.begin(115200);
  54. while (!Serial); // wait for serial attach
  55. Serial.println();
  56. Serial.println("Initializing...");
  57. strip.Begin();
  58. strip.Show();
  59. Serial.println();
  60. Serial.println("Running...");
  61. }
  62. void loop()
  63. {
  64. delay(2500);
  65. Serial.println();
  66. Serial.println("If your panel is correctly defined, you should see ...");
  67. Serial.println("First pixel in each ring is Red.");
  68. Serial.println("Middle pixel in each ring is Green.");
  69. Serial.println("Last Pixel in each ring is Blue.");
  70. // use the topo to map the 2d polar cordinate to the pixel
  71. // and use that to SetPixelColor
  72. for (uint16_t ring = 0; ring < topo.getCountOfRings(); ring++)
  73. {
  74. // first pixel in each ring is red
  75. strip.SetPixelColor(topo.Map(ring, 0), red);
  76. // last pixel in each ring is blue
  77. strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) - 1), blue);
  78. // middle pixel in each ring is green
  79. strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) / 2), green);
  80. }
  81. strip.Show();
  82. delay(5000);
  83. Serial.println();
  84. Serial.println("Cleared to black ...");
  85. strip.ClearTo(black);
  86. strip.Show();
  87. }