Hi
Everyone, Further to my previous post on Multi Dimensional arrays, I have finally got my head around them.
Or to be more accurate, Hans has given me the ability to get my head around them. Huge thanks Hans.
Anyway, now that I've got it working, I thought I would share it in the hope that it may help others, and also give you all something to build on.
I have commented the code liberally to help with guidance for anyone that needs it. I've uploaded a video so you can see what it looks like in practice on YouTube.
This is where the 3D design and files came from
Thingiverse And here is the code for you to do with as you wish.
#include <Adafruit_NeoPixel.h>
#define arms 5 // Number of arms on star
#define lightPerArm 30 // Max number of pixels per arm
#define PIN 6 // Data pin
#define NUM_LEDS 144 // Total number of pixels
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Array to define the pixels in each arm
uint16_t Star[arms][lightPerArm] = { { 0,1,6,7,8,9,26,27,28,29,30,31,56,57,58,59,60,61,62,63,96,97,98,99,100,101,102,103,104,105}, // Arm 1
{ 2,10,11,12,13,32,33,34,35,36,37,64,65,66,67,68,69,70,71,106,107,108,109,110,111,112,113,114,115}, // Arm 2
{ 3,14,15,16,17,38,39,40,41,42,43,72,73,74,75,76,77,78,79,116,117,118,119,120,121,122,123,124,125}, // Arm 3
{ 4,18,19,20,21,44,45,46,47,48,49,80,81,82,83,84,85,86,87,126,127,128,129,130,131,132,133,134,135}, // Arm 4
{ 5,22,23,24,25,50,51,52,53,54,55,88,89,90,91,92,93,94,95,136,137,138,139,140,141,142,143,144} }; // Arm 5
void setup() {
strip.begin();
strip.setBrightness(40); //adjust brightness here
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
for(int i=0; i<10; i++) { // Number of times the loop repeats
ArmSpin (random(255), random(255), random(255), 100, 100); // Function parameters (Red, Green, Blue, StepDelay, LoopDelay)
delay(100); //Delay before loop repeats
}
for(int i=0; i<25; i++) {
SnowSparkle(0x10, 0x10, 0x10, 20, random(100,500));
}
}
//Light each arm sequentially clockwise with a random colour, then radialy wipe colour to black (off).
void ArmSpin (byte red, byte green, byte blue, int StepDelay, int LoopDelay) {
for(int arm=0; arm<arms; arm++) { // Count ARMS
strip.setPixelColor(Star[arm][lightPerArm], strip.Color(0,0,0)); // Background pixel colour
for(int light=0; light<lightPerArm; light++) { // Count LIGHTS per ARM
strip.setPixelColor(Star[arm][light], strip.Color(red, green, blue)); //change RGB color value here
}
strip.show();
delay(StepDelay);
}
for(int x=0; x<=NUM_LEDS-1; x++) {
strip.setPixelColor(x,0,0,0);
strip.show();
//delay(LoopDelay);
}
delay(LoopDelay);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void showStrip() {
strip.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
setAll(red,green,blue);
int Pixel = random(NUM_LEDS);
setPixel(Pixel,0xff,0xff,0xff);
showStrip();
delay(SparkleDelay);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
}