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 bring you to the same post, in Dutch, as there is no translation for that post!



Art installation pr...
 
Share:
Notifications
Clear all

[Solved] Art installation project.

6 Posts
2 Users
0 Likes
2,031 Views
(@simba)
New Member
Joined: 4 years ago
Posts: 2
Topic starter  

Hello Hans!

Firs of all i want to thank you a lot for this forum. It’s so helpful. Its been over a month that i am working on my project and i am having a hard time to make the code.
So i have 32 different LED strips each with 300 LEDs and arduino mega which has 32 digital outputs (pin 22 – pin 53.)
I will try to explain the diagram that i have:
16L       16R 
15L       15R 
14L       14R 
13L       13R 
12L       12R 
11L       11R 
10L       10R 
9L          9R 
8L          8R 
7L          7R 
6L          6R 
5L          5R 
4L          4R 
3L          3R 
2L          2R
1L          1R
All my LED strips are connected to power supplies. All the power supplies have same ground which is also connected to arduino.I am trying to make it as a light show. If you take a look on this video you will see on 1:30 which effect i want to make.
Pretty much a strobe light that goes fro 1 to 16 from right side than from left side.Now, instead of writing down individually all 32 outputs, is there any way i can make it nicer maybe by using digitalwrite and pinMode?So this is what i have so far and i stoped on strobe1:
_________________________________________________________________________________
#include “FastLED.h”
#define NUM_LEDS 300
#define NUM_STRIPS 32
CRGB leds[NUM_LEDS];
uint8_t gBrightness = 1;
void setup()
{
FastLED.addLeds<WS2812B, 22>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 23>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 24>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 25>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 26>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 27>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 28>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 29>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 30>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 31>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 32>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 33>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 34>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 35>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 36>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 37>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 38>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 39>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 40>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 41>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 42>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 43>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 44>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 45>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 46>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 47>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 48>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 49>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 50>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 51>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 52>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 53>(leds, NUM_LEDS);
}
void loop() {
  Strobe(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe1(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe2(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe3(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe4(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe5(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe6(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe7(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe8(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe9(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe10(0xff, 0xff, 0x00, 1, 50, 500);          
  Strobe11(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe12(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe13(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe14(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe15(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe16(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe17(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe18(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe19(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe20(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe21(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe22(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe23(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe24(0xff, 0xff, 0x00, 1, 50, 500); 
  Strobe25(0xff, 0xff, 0x00, 1, 50, 500); 
  Strobe26(0xff, 0xff, 0x00, 1, 50, 500); 
  Strobe27(0xff, 0xff, 0x00, 1, 50, 500); 
  Strobe28(0xff, 0xff, 0x00, 1, 50, 500); 
  Strobe29(0xff, 0xff, 0x00, 1, 50, 500);                          
  Strobe30(0xff, 0xff, 0x00, 1, 50, 500);
  Strobe31(0xff, 0xff, 0x00, 1, 50, 500);  
  
}  
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip1();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip1();
    delay(FlashDelay);
     }
 delay(EndPause);
 }
void Strobe1(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip2();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip2();
    delay(FlashDelay);
  }
 delay(EndPause);
 }
void showStrip1() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED[0].showLeds(gBrightness);
 #endif
}
void showStrip2() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED[1].showLeds(gBrightness);
 #endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
}
_________________________________________________________________________
//This is how i tried to make the code smaller:
#include “FastLED.h”
#define NUM_LEDS 300
CRGB leds[NUM_LEDS];
uint8_t gBrightness = 1;
void setup() {
 for(int z=22; z<=53; z++) {
    pinMode(z, OUTPUT);
    
    FastLED.addLeds<WS2812B, z>(leds, NUM_LEDS); // <- Right here i am getting and error stating that the value z is not  
                                                                                                                // is not usable in a constant expression
 }                                                                                                             
}
void loop() {
Strobe(0xff, 0x00, 0x00, 1, 50, 100);
for(int z=22; z<=53; z++) {
  digitalWrite(z, HIGH);
  delay(10);
  digitalWrite(z, LOW);
  }
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }
delay(EndPause);
}
void showStrip() {
  for(int z=22; z<=53; z++) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED[z].showLeds(gBrightness);
 #endif
 }   
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
}
I would much appreciate you help!

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

Hi Simba! 

That looks like a very cool project! 

To shorten your code you can use for-loops.
Any time you see code repeat in your sketch: think about using loops, for-loop being one of them. See also: Arduino Programming for Beginners – Part 5: Going in Loops.

For example:

FastLED.addLeds<WS2812B, 22>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 23>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 24>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 25>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 26>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 27>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 28>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 29>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 30>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 31>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 32>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 33>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 34>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 35>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 36>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 37>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 38>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 39>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 40>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 41>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 42>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 43>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 44>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 45>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 46>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 47>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 48>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 49>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 50>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 51>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 52>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, 53>(leds, NUM_LEDS);

Could be written as:

for(int PinForStrip = 22; PinForStrip <= 53; PinForStrip ++) {
  FastLED.addLeds<WS2812B, PinForStrip>(leds, NUM_LEDS);
}

Note that in your code ALL LEDs are added to the "leds" array. I'm not sure if that was intentional or not.
If it is, then your LEDs array has 32x300 LEDs in it, and separately calling an effect for each strand should not really work.
Just calling Strobe once would affect all 9600 LEDs (as far as I understand the documentation - I do not have that many LED strips available).

Also note, that since you're using FastLED, you could optimize and simplify the code some more.

You can replace showStrip() function by calling the FastLED's show() function directly instead.
If you do so, the showStrip function can be removed from the code.

Setting all colors to one given color (black) can be done faster in FastLED as well.
Either by using "showColor(CRGB(Red,Green,Blue))" or in case all LEDs should be off, we could use "Clear()" as well.

On that note: if all strands should show the exact same effect, you can just connect all Data-in pins of the strands to one and the same pin on the Arduino.
But seeing the effect in the example video, I can imagine this is not what you have in mind.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

p.s. I noticed a double post of this, so I removed one of them. 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

For Reference:

FastLED.clear()

FastLed.showColor()


   
ReplyQuote
(@simba)
New Member
Joined: 4 years ago
Posts: 2
Topic starter  

Wow such a fast reply. Thank you so much for your help. I will try testing the modified code  a little bit later. 
Been researching all night, now need some sleep. I will share end results as i am done.

And yes i accidentally created the topic twice, my pc glitched.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

No worries - the website seems to glitch every now and then as well 


   
ReplyQuote
Share: