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!





LED Strip Effects -...
 
Share:
Notifications
Clear all

LED Strip Effects - Two fire effects  

  RSS

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

This is the continuation of a comment posted by Steve:

Hi Guys
Looking for major help, I have made an intinity mirror which is using 205 ws2812B what I would like to do is use the fire sketch (which i can of course) but what i cannot do or maybe its not possiable is to have 2 starting point with the flames using 100 leds.
starting point (1) leds 1 to 100
starting point (2) leds 205 to 105
The idea is that it looks like the flames are starting at the same point and lapping round the mirror
I really enjoy working with the arduino and leds but sometimes its so bloody frustating :)
If you think its not possiable let me know as i will then give up on that idea, on a postive note if it is any help would be much appreciated
Fantastic page by the way 

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

I wouldn't think of it as impossible, would it be OK if both sets behave the same with the fire effect? Or should they be different?


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

OK, let me post the original Fire Effect here:

void loop() {
  Fire(55,120,15);
}
void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;
  
  // Step 1. Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_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_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_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }
  showStrip();
  delay(SpeedDelay);
}
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
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) { // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else { // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

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

Sine you want two sets:

Set 1: leds 1 - 100
Set 2: leds 105 - 205

We could "cheat" a little with minimal modifications.
In "Step 4" we set the LED color, for each LED. So we could cheat by copying the color from set1 to set2:

for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
    setPixelHeatColor(j + 104, heat[j] );
  }

Now this will work but we'd run into trouble with the use of NUM_LEDS, so we define a new define for that.

#define SET_NUM_LEDS 100

and modify the previous code as such:

#define SET_NUM_LEDS 100  // might need to tweak this number
...
void loop() {
  Fire(55,120,15);
}
void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[SET_NUM_LEDS];
  int cooldown;
  
  // Step 1. Cool down every cell a little
  for( int i = 0; i < SET_NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / SET_NUM_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= SET_NUM_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 < SET_NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
    setPixelHeatColor(j + 105, heat[j] ); // might need to tweak the number 105
  }
  showStrip();
  delay(SpeedDelay);
}
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
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) { // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else { // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

The number 100 and 105 might need some tweaking, since you counted from 1-100, where as the procedure starts counting at zero.


ReplyQuote
Hans
 Hans
(@hans)
Noble Member Admin
Joined: 7 years ago
Posts: 1266
July 30, 2016 12:16 AM  

Since you reported it counting from 0-99 instead of 1-100, modify this (see the 3 lines with “// <– here”).

Hope this works … 

#define SET_NUM_LEDS 100  // might need to tweak this number
...
void loop() {
  Fire(55,120,15);
}
void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[SET_NUM_LEDS];
  int cooldown;
  
  // Step 1. Cool down every cell a little
  for( int i = 1; i < SET_NUM_LEDS; i++) { // <-- here, start counting at 1
    cooldown = random(0, ((Cooling * 10) / SET_NUM_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= SET_NUM_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);
  }
  // Step 4. Convert heat to LED colors
  for( int j = 1; j < SET_NUM_LEDS; j++) { // <-- here
    setPixelHeatColor(j, heat[j] );
    setPixelHeatColor(j + 104, heat[j] ); // <-- here 105 became 104
  }
  showStrip();
  delay(SpeedDelay);
}
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
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) { // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else { // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

ReplyQuote



ap0ll0
(@ap0ll0)
New Member
Joined: 4 years ago
Posts: 0
July 30, 2016 1:24 AM  

Hans

You may have misunderstood what I typed as the problem

Set 1: leds 0 – 99 ( starting point for the flame is at 99 were I was after it starting at 0)

Set 2: leds 104 – 204 this one is spot on

This is a mirror and 0 and 204 are at the bottom(south)  set2 runs up the right side of the mirror perfect

Set1 starts at the top (north)  of the mirror runs down (south) the left side

I have had a play with the code but seem unable to reposition the starting point of set 1

               > >>>  end  (99, 104 <<<

           set1   >    (    )     < set2

               >>>>  start(0, 204)   <<<

The devil ment to be the fire

I will post a pic or video for all your hard work


ReplyQuote
ap0ll0
(@ap0ll0)
New Member
Joined: 4 years ago
Posts: 0
July 30, 2016 6:56 AM  

Hans

The confusion  im causing is because i was thinking the flames were clockwise on the orginal but ive just uploaded the orginal and the flames go counter clockwise ie starting at 204 around my mirror


ReplyQuote
ap0ll0
(@ap0ll0)
New Member
Joined: 4 years ago
Posts: 0
July 30, 2016 7:30 AM  

once you start working the correct way round 

  // Step 4.  Convert heat to LED colors

  for( int j = 1; j < SET_NUM_LEDS; j++) {  //**** here
     setPixelHeatColor(j, heat[j] );
     setPixelHeatColor(NUM_LEDS - j, heat[j] ); // **** here
  }

I dont like asking for help but sometimes its pays

Thank you for your time and instruction because it wouldnt have happen without it


ReplyQuote
ap0ll0
(@ap0ll0)
New Member
Joined: 4 years ago
Posts: 0
July 30, 2016 11:10 AM  

Fire effect after Hans gave it a makeover for a infinity mirror


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

Hi Ap0ll0!

Man that looks awesome!!! I love it!!! 
Asking for help is never wrong, and it got you started in the right direction, didn't it? 
I'm glad to see that you've got it to work - it really looks great!

For those who'd like to see a preview of Ap0ll0's great effect, see the movie or this preview screenshot ...
It looks awesome!


ReplyQuote



Share: