Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not work!





3D printed Star wit...
 
Share:
Notifications
Clear all

3D printed Star with 2D array  

  RSS

Spike
(@spike)
New Member
Joined: 4 years ago
Posts: 0
July 22, 2016 6:01 AM  

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);
}

ReplyQuote
Spike
(@spike)
New Member
Joined: 4 years ago
Posts: 0
July 22, 2016 10:34 PM  

It appears that my code didn't paste well, sorry.

So I have attached the .ino here if you need it.


ReplyQuote
Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1266
July 22, 2016 10:54 PM  

Thanks Spike! 
I'll see if I can clean it up, but having an attachment helps as well ...


ReplyQuote
Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1266
July 22, 2016 11:06 PM  

Looked at your YouTube clip; nice!!! 


ReplyQuote
Spike
(@spike)
New Member
Joined: 4 years ago
Posts: 0
July 22, 2016 11:11 PM  

Thank you Hans,


ReplyQuote



Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1266
July 22, 2016 11:13 PM  

Oh no, thank you for posting all that is needed to make this cool Christmas star! 


ReplyQuote
Spike
(@spike)
New Member
Joined: 4 years ago
Posts: 0
July 25, 2016 10:06 PM  

Here is the layout that I used to determine which LEDs should be address for each arm of the array. It's nothing special, but it did the job for me.

I hope this will help anyone that is having a hard time getting their head around the arrays and how they relate to this project. I know I had a hard time getting to grips with arrays, until I found all the info that Hans gave us.

ReplyQuote
Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1266
July 25, 2016 10:47 PM  

Thanks Spike for posting the layout!

I think I might build this one too ... but I'll probably just work with wood (MDF)
Love it! 


ReplyQuote
Spike
(@spike)
New Member
Joined: 4 years ago
Posts: 0
July 25, 2016 11:35 PM  

Thats would be great to see Hans.

I don't have a workshop so can't really work with wood or metal etc. Though I do love my 3D printers, one of which I built myself and I do love to use and tweak them.


ReplyQuote
Share: