NeoPixelRingTopologyTest.ino 2.8 KB

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