diff --git a/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino b/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino new file mode 100644 index 0000000..57aa6e4 --- /dev/null +++ b/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino @@ -0,0 +1,122 @@ +//---------------------------------------------------------------------- +// NeoPixelRingTopologyTest +// This will display specific colors in specific locations on the led rings +// +// This is useful in confirming the layout of your rings +// +// It does require that you have the actual series of rings connected +//---------------------------------------------------------------------- + +#include + +const uint8_t PixelCount = 119; +const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 + +// define the layout of your series of rings +// +// This example is using all of Adafruits rings and a Jewel in the center. +// The center is the input and all the rings are connected in series going outward +// +// Rings: +// 0 - 1 (virtual ring, the center of the jewel) +// 1 - 6 (virtual ring, the outer ring of the jewel) +// 2 - 12 count ring +// 3 - 16 count ring +// 4 - 24 count ring +// 5 - 60 count ring comprised of four arc segments +// +// The values below in Rings[] are the index of the first pixel in each ring. +// An extra value is appended for a virtual ring start that also +// represents the total count of pixels in the complete series and this extra +// value is required. +// +class MyRingsLayout +{ +public: + void Begin() { + // this is where you load your dynamic rings layout and init Rings and RingCount + // this example will just set these to static numbers to simulate a dynamic layout + RingCount = 6; + Rings = new uint16_t[RingCount]; + + Rings[0] = 1; + Rings[1] = 6; + Rings[2] = 12; + Rings[3] = 16; + Rings[4] = 24; + Rings[5] = 60; // don't forget the final count of pixels as the last item + } + +protected: + uint16_t* Rings; + uint8_t RingCount; + + uint8_t _ringCount() const + { + return RingCount; + } +}; + +// use the MyRingsLayout to declare the topo object +// +NeoRingTopology topo; + +// declare our strip +// +NeoPixelBus strip(PixelCount, PixelPin); + +// define some handy colors +// +RgbColor red(128, 0, 0); +RgbColor green(0, 128, 0); +RgbColor blue(0, 0, 128); +RgbColor black(0); + +void setup() +{ + Serial.begin(115200); + while (!Serial); // wait for serial attach + + Serial.println(); + Serial.println("Initializing..."); + + topo.Begin(); + + strip.Begin(); + strip.Show(); + + Serial.println(); + Serial.println("Running..."); +} + +void loop() +{ + delay(2500); + + Serial.println(); + Serial.println("If your panel is correctly defined, you should see ..."); + Serial.println("First pixel in each ring is Red."); + Serial.println("Middle pixel in each ring is Green."); + Serial.println("Last Pixel in each ring is Blue."); + + + // use the topo to map the 2d polar cordinate to the pixel + // and use that to SetPixelColor + for (uint16_t ring = 0; ring < topo.getCountOfRings(); ring++) + { + // first pixel in each ring is red + strip.SetPixelColor(topo.Map(ring, 0), red); + // last pixel in each ring is blue + strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) - 1), blue); + // middle pixel in each ring is green + strip.SetPixelColor(topo.Map(ring, topo.getPixelCountAtRing(ring) / 2), green); + } + strip.Show(); + + delay(5000); + + Serial.println(); + Serial.println("Cleared to black ..."); + strip.ClearTo(black); + strip.Show(); +} diff --git a/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino b/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino index 64a1bcd..26d526f 100644 --- a/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino +++ b/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino @@ -34,6 +34,11 @@ class MyRingsLayout { protected: const uint16_t Rings[7] = {0, 1, 7, 19, 35, 59, PixelCount}; + + uint8_t _ringCount() const + { + return sizeof(Rings) / sizeof(Rings[0]); + } }; // use the MyRingsLayout to declare the topo object @@ -97,4 +102,3 @@ void loop() strip.ClearTo(black); strip.Show(); } - diff --git a/src/internal/NeoRingTopology.h b/src/internal/NeoRingTopology.h index e598fa4..7255a97 100644 --- a/src/internal/NeoRingTopology.h +++ b/src/internal/NeoRingTopology.h @@ -29,7 +29,7 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -template class NeoRingTopology : protected T_LAYOUT +template class NeoRingTopology : public T_LAYOUT { public: NeoRingTopology() @@ -85,7 +85,7 @@ public: uint8_t getCountOfRings() const { - return _ringCount() - 1; // minus one as the Rings includes the extra value + return T_LAYOUT::_ringCount() - 1; // minus one as the Rings includes the extra value } uint16_t getPixelCountAtRing(uint8_t ring) const @@ -100,7 +100,7 @@ public: uint16_t getPixelCount() const { - return T_LAYOUT::Rings[_ringCount() - 1]; // the last entry is the total count + return T_LAYOUT::Rings[T_LAYOUT::_ringCount() - 1]; // the last entry is the total count } private: @@ -109,8 +109,4 @@ private: return T_LAYOUT::Rings[ring] + pixel; } - uint8_t _ringCount() const - { - return sizeof(T_LAYOUT::Rings) / sizeof(T_LAYOUT::Rings[0]); - } };