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!



Christmas project ....
 
Share:
Notifications
Clear all

[Solved] Christmas project ..

20 Posts
2 Users
0 Reactions
6,282 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

This is a continuation of a comment Philip placed under the "All LED Effects in one".

Quote:

Hi Hans,

Brilliant sequence and explanation and I’m really impressed. Its also answered a future problem (for me), as I needed to add a button to 2 x 2.5m strips of 2812b to both my kids bedrooms (one per child) and wanted them to be able to switch between patterns. Thank you!

I took the plunge about 8 months ago and have installed strips round the outside of my house ready for Christmas (took it slow as the leds are cheap but the infrastructure to run the 500 leds I have installed is substantial. (PSUs, buck converters, conduit, cable etc)), I’ll definitely be looking to add a few of your sequences to my (ever extending) list .

I’ve tried to write a few (very unsuccessful) sequences myself but just don’t seem to be mathematically capable YET!  

I have a question though. I really want to modify the code so that the fire and bouncing ball sequences will run within my 500led outside lights. Try as I might I cannot get the sequences to work as I need the first 75 leds to work then miss out the next 142 then run again (but upside down) in the next 75 leds (I do hope you can follow). Can you see a way of doing it as I’ve been scratching my head so much its starting to bleed. LOL 

The leds are arranged (outside) in one continuous loop. A vertical strip (going up) up the side of the house (75leds), a horizonal strip under the guttering (142 leds), another 75leds going down the opposite side, then a final horizontal set (208) linking back around a porch.

I’ve set used the #define NUM_LEDS 500 and both look very silly when you try to run them round the house….

Hope you can help.

Philip


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Alrighty then - another awesome Christmas project ... 

I'll admit that I'm not the best math person either - but that's the fun part of LED strips: Playing with them to get what you want. 

So if I understand this right; left and right of the house each a vertical strip of 75 LEDs, one on top of 142 LEDs and 208 on the back porch? 

I assume that you'd want the strips left and right to run similar - for this we could set those in parallel.

This leaves us with the top part (142 LEDs) and the porch (208 LEDs).

Can you tell me what kind of effects you had in mind and how they should work?
This way we can see if we can modify the wiring accordingly and/or modify the sketch. 


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Oh I am SOOOOOOO fed up right now... Ive tried to upload a video of my leds 6 times now and every time it fails meaning I have to re-write this reply AGAIN! it gets to 70% then fails... ANNOYINGLY! (I'm sure its my laptop )

Sorry Hans, not your fault and I really do appreciate the offer of help. Thank you!

I agree it would be easier to have the verticals wired in parallel, but unfortunately their all in series. all 499leds 

IF the video uploads (I may try separately this time) it'll make it easier to understand. My configuration is in an anti-clockwise direction from right to left then (almost) linking back to the start (there's about 2.5m of no leds as the only people who would see them would be low flying aircraft and UFOs ). I played before with the code and managed to get 2 duplicate fire/ball sequences running with about 10 blank leds between them, but this doesn't help as it'll mean the right vertical display would be upside down (not good) lol. Again this is where the video would help... (fingers crossed for a few mins time). I tried all the maths I could think of but got nowhere... 

leds are as follows:-

  • Left side(up) 66leds
  • Top (right to left) 142 leds
  • Right (down) 71leds
  • Bottom (left to right) 218 leds

My biggest issue (at the moment) is lack of leds I can test it against (as mine are now firmly attached to the outside). Keep it a secret from my wife but theres another 5m of leds coming this week ready for the kids (button project( did I tell you how BLOODY AMAZING your code is BTW? )) so thats our little secret LOL!

Any ideas and help would be grateful. 

Philip (hopefully the video will follow)


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

No video still... I'll try again later tonight on my sons PC (hopefully that will work). 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Sorry for the frustration ... how big is the video file? Do you get a Warning (when the file is too big, the forum just rejects it)?
I'll read your reply later on ... 


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Yeah just not working for me at all today. Even on my sons PC. (Admin: removed link and uploaded the video in one of the following replies)


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

I think I see the problem with your video ... it's 101 Mb haha ... yeah that's a little too much for the forum.
I managed to recompress it to 6Mb and uploaded ...
Looks like a good start! 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Haha, so far I have been laughing about your text - let me know when you see those low flying UFO's coming by 
And no worries; I won't tell your wife ...

Yeah the lack of LEDs to test with (thanks for the great compliment by the way) is usually my problem as well, right after the lack of "working space". 

A few things I notice is that with some of the effects;
- Motion could be a little faster (especially with the first effect, since it took me a while to even see it moving.
- Some effects would be better if we'd cluster LEDs (say group them in 2's or 3's)

As for setting them in parallel; not sure how you attached the strips, but usually it's as simple as cutting the strand and running 3 extra wires from one side to the other. Trying to put the effects with a strand like this will be challenging. Maybe we could work around it by making a "translation" function that converts any setPixel() call to a proper location.

For this we probably should define some logic. Let's start simple and focus on the front of the house first, and keep it simple (so you can later expand on this in your own way with 500 LEDs). Let's assume we have this (assuming your strand start in the lower right corner and we have 28 LEDs in total);

14 13 12 11 10  9  8  7
15                    6
16                    5
17                    4
18                    3
19                    2 
20                    1
21 22 23 24 25 26 27  0

If we would have only the first 7 LEDs then we could change the setPixel function as such (assuming you're using FastLED, since that may perform better than NeoPixel, especially with this many LEDs):

void setNewPixel(int Pixel, byte red, byte green, byte blue) {
   // Regular (right side) Position
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
   // Translate to the left side
   leds[21-Pixel].r = red; // 21 is the lower left corner
   leds[21-Pixel].g = green; // subtract since we want to go the opposite direction
   leds[21-Pixel].b = blue;
}

Not sure how we want to continue with the effects, but this could be a "fix" for the fire effect. I've given it a new name, since setPixel would be needed possibly in a different way for other effects. Because I've given it a new name, we could also write this function as:

void setNewPixel(int Pixel, byte red, byte green, byte blue) {
   // Regular (right side) Position
   setPixel(Pixel,red,green,blue);
   // Translate to the left side
   setPixel(21-Pixel,red,green,blue);
}

With the fire effect we'd probably want to fill the bottom with red, since that would make things look more coherent. So before calling the fire effect, we could add

for(int i=21; i++; i<28) {
  setPixel(i,0xff,0x00,0x00); }  

For this we should need to slightly modify the setPixelHeatColor() function, used by the Fire effect, as well so it uses the new setPixel function:

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);
 
  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
 
  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) { // hottest
    setNewPixel(Pixel, 255, 255, heatramp); // use the new function instead of setPixel()
  } else if( t192 > 0x40 ) { // middle
    setNewPixel(Pixel, 255, heatramp, 0); // use the new function instead of setPixel()
  } else { // coolest
    setNewPixel(Pixel, heatramp, 0, 0); // use the new function instead of setPixel()
  }
}

There is more too it (of course ), we need to limit how many LEDs the fire effect will be using.
In our example, we only use 7 LEDs for the fire effect (more in your setup of course). Somewhere in the beginning of the code you have

#define NUM_LEDS 500 

Naturally we do NOT want to change this number, as it initializes the full array of LEDs.
So for our new Fire Effect we could add:

#define NUM_FIRE_LEDS 7 

So we can easily adapt the fire effect function, by replacing NUM_LEDS with NUM_FIRE_LEDS in the function:

void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_FIRE_LEDS];
  int cooldown;
  
  // Step 1. Cool down every cell a little
  for( int i = 0; i < NUM_FIRE_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_FIRE_LEDS) + 2);
    
    if(cooldown>heat) {
      heat=0;
    } else {
      heat=heat-cooldown;
    }
  }
  
  // Step 2. Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_FIRE_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }
    
  // Step 3. Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }
  // Step 4. Convert heat to LED colors
  for( int j = 0; j < NUM_FIRE_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }
  showStrip();
  delay(SpeedDelay);
}

Ok, now I need coffee hahah ... I just woke up, so I hope I didn't make too many typos.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Forgot to mention;

I used HandBrake to recompress your video, it's a fast and free tool to recompress videos. With it's default setting I brought your file back to 46Mb. Increasing the compression (RF - more details on optimizing can be found here, it's my go-to tool for video conversion) to 30 brought the file back to 6 Mb! 
Could be useful for future posting of videos. 


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Hi Hans, once again thanks for you help on this 

The way the entire system is wired it'll be difficult (at best) to parallel any of the strip in any way. I had a test (bell) wire linking from (using your pattern here) led 1 to under the ground (a distance of about 3m), this was ok but any further meant I lost the data signal to the leds. If I was to parallel opposing strips the cable length would almost definitely cause issues.
An added problem is, to reduce the risk of volt drop/power issues with each strip, I've used system of wiring (don't think its practiced in Europe) called a "ring main". Its as simple as it sounds but it also means that I can reduce the size of the power cables, reducing cost, and distributing the leds load across the entire circuit. So that's why changing the code would be better. Also as an added bonus I can use any random code I find. Like yours  

Its quite ironic (but typical) that after writing my reply to you I did a little digging and found this Fire Mirror code ... It needs "tweaking" (lol ) but I think that its workable. I will play with your code to as it may be better.  
I really do need to start learing C++... Although I "sort of" understand the byte and round function you used 
byte t192 = round((temperature/255.0)*191);
can you explain the t192??  is it a variable (as I suspect) or a memory address?
I came up with a similar idea to your about defining the led strips in number form too (and I'll be playing with the code later tonight). 
#define STRING1 66
#define STRING2 144
#define STRING3 71
#define STRING4 90
#define STRING5 128
I like this idea as it will make things easier to do later if (as I plan) I do something really basic for Halloween (plus add the fire).
That said I do like the idea of speeding it all up a bit. Its a shame but the video doesn't really show the effects very well. If you look at the code of DemoReel100 it actually runs the rainbow pattern then adds a sparkle effect(rainbowwithglitter). It works quite well but in the video it does seem to drag on a bit. Obviously I used the DemoReel just to get things working but as I think we both agree some effects just wont work in such a long string of leds.
Totally off topic now- 
Can I also point out that any typos will be totally ignored by me. In fact I'll compliment you on your English skills as it amazes me how you all manage to do it so well. My wife's first language isn't English (she actually talks 4 languages inc English) and I'm always in awe with the way she (and I image yourself) can work and translate so well both verbally (as shes doing right now talking to her family) and in written form. And I'm not being patronizing I'm a really lazy typical English speaker who only know a few words in a couple of languages.
Lastly the video...
So much for "Your account has the ability to upload any attachment regardless of size and type."
 <span style="text-align: initial;">I first tried to upload the original 1.1 GIG video, my phone converted it to 100meg... not a bad conversion but it has lost a lot of the detail (glitter flash) of the original file. I have though downloaded the HandBrake tool and will use it if I need to upload any more videos (as I'm sure I will. </span>
Now I need food and sleep as I've been up since 3am 
Phil

   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Now look at the typos in that... 


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Hi Hans,

After sorting out the fire routine, I was wondering if you could look at this...

Its something I've been playing with this week, I got it working (sort of) but for some reason It just wont work anymore when I upload the sketch. I added the serial prints to see where it gets up to but it actually locks up regulary reporting "Startup r" and not "Startup running..."

My idea was to make the leds look like dumb leds for a few seconds, fizzle out, then have your Meteor rain sequence to look like a fuse before igniting the Fire sequence (not added yet)

I managed to get it to work about 3 times then it locks up... I can run any other code over the leds (DemoReel) but mine just locks up. Last night the leds just went nuts and very random even though I changed nothing major.

Its not tidy so if you can look at it and suggest whats going on it would be great.

I added the serial.println routines just so I could see where it was locking up.

#include "FastLED.h"
#include "SoftwareSerial.h"
#define NUM_LEDS 75 
CRGB leds[NUM_LEDS];
#define PIN 3 
#define Brightness 40
// strip lengths
#define S1 10 //66
#define S2 15 //142
#define S3 15 //71
#define S4 5 //91
#define S5 25 //128
int RunOnce = true ; 
void setup()
{
  FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(Brightness);
int S2a = S1+S2 ;
int S3a = S2a+S3 ;
int S4a = S3a+S4 ;
// mySoftwareSerial.begin(9600);
  Serial.begin(115200);
  Serial.println("Startup running...");
//randomSeed(analogRead(0));
}
// REPLACE FROM HERE
void loop() { 
  Serial.println(("Main code running"));
  if (RunOnce == true ){
    RunOnce = false ;
// rgb(1st colour), delay, rgb (2nd Colour), how many times (3000x3)
    SolidFill( 255 , 0, 0, 3000, 0, 255, 0 , 3 );
    Serial.println(F("SolidFill Complete...")); 
// Fizzle (red, green, blue), count, speed delay, only one twinkle (true/false) 
    Fizzle(0xff, 0xff, 0xff, 300, 1, true);
    Serial.println(("Fizzle Complete..."));
// Fuse(); //fade in Fuse
// FastLED.setBrightness(Brightness);
  }
// Move MeteorRain to below fuse in real life
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay 
     MeteorRain(0xff,0xff,0xff,2, 200, true, 50);
     Serial.println(("MeteorRain Complete..."));    
  
}
void SolidFill (int r, int g, int b, int Wait, int r1, int g1, int b1, int Times){
Serial.println(("Start SolidFill..."));
 for (int x = 0 ; x <= 10 ; x++){
  if (Wait >=2)
   for ( int i = 0 ; i <= Times; i++){
    fill_solid (leds, S1, CRGB( r, g, b));
    fill_solid (leds+S1, S2, CRGB( r1, g1, b1));
    fill_solid (leds+(S1+S2), S3, CRGB( r, g,b));
    fill_solid (leds+(S1+S2+S3), S4, CRGB( r1, g1, b1));
    fill_solid (leds+(S1+S2+S3+S4), NUM_LEDS, CRGB( r, g, b));
    showStrip();
    delay (Wait);
    fill_solid (leds, S1, CRGB( r1, g1, b1));
    fill_solid (leds+S1, S2, CRGB( r, g, b));
    fill_solid (leds+(S1+S2), S3, CRGB( r1, g1, b1));
    fill_solid (leds+(S1+S2+S3), S4, CRGB( r, g, b));
    fill_solid (leds+(S1+S2+S3+S4), NUM_LEDS, CRGB( r1, g1, b1));
    showStrip();
    delay (Wait);
    }
 if (Wait <=1000)
// Wait1 = Wait/2;
Wait = Wait/2;
  else
  Wait = Wait - 1000;
  }
}
void MeteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
// setAll(0,0,0);
  Serial.println(("MeteorRain Started..."));
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
    
    
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
    
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      } 
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}
// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
   leds[ledNo].fadeToBlackBy( fadeValue );
}
void Fizzle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
 /* setAll (0,0,0);
  delay (1000);
  setAll(255,255,255);
  delay (1000);
  setAll(0,0,0);
 */ 
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) { 
       setAll(0,0,0); 
     }
   }
}
  
void Fuse() {
  for ( int r = 0 ; r <= 10 ; r++){
    FastLED.setBrightness(r);
      fill_solid (leds, NUM_LEDS, CRGB( 155 , 57, 15));
    showStrip();
  delay (200);
  }
  delay (3000);
}
// FastLED main sequences
// REPLACE TO HERE
void showStrip() {
   FastLED.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}

Many thanks 

Phil


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Hey Phil!

Sorry for the radio silence the past few days - I've been working on a project. If I only could make a living out of running my website .

First thing I noticed, is that you include "SoftwareSerial.h" - I have no idea what this library does, but maybe that's locking up your sketch. It seems to be a library for serial communication, which may interfere with the standard serial functions?


   
ReplyQuote
(@philipking)
Active Member
Joined: 7 years ago
Posts: 9
 

Hi Hans,

Hehehe I fully understand what you mean, in my (lot) younger days I used to run a BBS system (Pre-Internet) on a dial-up system and the HOURS I used to spend updating the scripts, ANSI code for the screens, routing and all the other rubbish... Then along came internet gateways and finally email and the WWW and well... Here we are today! 

I still appreciate being able to talk to someone as all I get at work in blank looks whenever I discuss my little project and (especially) the coding issues I have  

I removed the extra serial library (I thought I had to use it but obviously not), it actually made no difference. 

I remembered seeing a guy saying that he had to run an old version of the IDE otherwise the sketch he wrote hangs...(YouTube) and I've now installed 2 versions, (1.8.6 and 1.6.5) and its quite interesting (I will ask the question on the Arduino forum later)  but the code I wrote  compiles slightly bigger (21% compared to 18% of memory) and also appears to work "better".

1.8.6 - code still seems to hang and it freezes at "Starting r"

1.6.5 - code runs reporting "Startup running" but then seems to print garbage and not what I've asked of it... 

I've yet to test the code with LEDs as the wife is hanging about today but is due to go out very soon so I should be able to test if there is a difference if I run the same code on BOTH IDEs (before I go to work). I'll report back (ASAP) what the result is.

Phil


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Hi Phil,

that's awesome! Me and a buddy used to run a BBS (FidoNet) as well ... back in the day on an Atari ST, with 2 9600 baud modems hahah. When a 20Mb hardisk cost $1400 hahah ... not to mention mind blowing phone bills ... Those where the days!

I agree; it's more fun to chat with like minded folks - at least they understand the frustrations and the kick one gets out of getting it to work anyway .
Back in the day we used to have computer clubs, every 2nd Saturday, hauling our computers to an event, where we'd meet folks that were like minded. These events have become extinct unfortunately. Good thing with the Internet though; you get to chat with folks that are thousands of miles apart that share a similar interest.

Back to the issue at hand;
Sounds like you found a bug in the most recent IDE. Or beter said: the most recent compiler.
Curious what your findings will be ...


   
ReplyQuote
Page 1 / 2
Share: