ArduinoCandleEffectNeoPixel icon indicating copy to clipboard operation
ArduinoCandleEffectNeoPixel copied to clipboard

More leds

Open henrikl2000 opened this issue 7 years ago • 3 comments

Hi Alain,

Thank you for sharing. Looks really good. What do I have to change in order to use a neopixel ring or strip with more leds? I tried with a 60 led neostrip, but when I change NUM_LEDS to 60 I get an error : not enough memory

Best regards, Henrik

henrikl2000 avatar Jul 04 '18 10:07 henrikl2000

Hi Henrik,

What board are you using?

The code is not really optimized for a larger number of LEDs due to the bunch of variables being created. In order to get that working for i.e. 60 I'd suggest to reduce the resolution of the values by bringing all 'state and color' vars back to 'byte' types and optimize the code for that.

The various arduino series do have a lot of memory. Either 2K RAM for UNO, Uno Ethernet, Menta and Boarduino. 2.5K for Leonardo, Micro, Teensy, etc... and 8K for the MEGA.

Cheers, Alain

avanhanegem avatar Jul 04 '18 11:07 avanhanegem

Hi Alain,

Thank you for your fast reply.

I am using an Arduino Nano. OK I will try to look into optimizing the code.

Thanks again,

Henrik

Fra: Alain van Hanegem [email protected] Sendt: Wednesday, July 4, 2018 13:23 Til: avanhanegem/ArduinoCandleEffectNeoPixel [email protected] Cc: henrikl2000 [email protected]; Author [email protected] Emne: Re: [avanhanegem/ArduinoCandleEffectNeoPixel] More leds (#1)

Hi Henrik,

What board are you using?

The code is not really optimized for a larger number of LEDs due to the bunch of variables being created. In order to get that working for i.e. 60 I'd suggest to reduce the resolution of the values by bringing all 'state and color' vars back to 'byte' types and optimize the code for that.

The various arduino series do have a lot of memory. Either 2K RAM for UNO, Uno Ethernet, Menta and Boarduino. 2.5K for Leonardo, Micro, Teensy, etc... and 8K for the MEGA.

Cheers, Alain

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/avanhanegem/ArduinoCandleEffectNeoPixel/issues/1#issuecomment-402449981 , or mute the thread https://github.com/notifications/unsubscribe-auth/AIi901KfESqxgFz2JRpACWeF3mZqpzf2ks5uDKWdgaJpZM4VCYJS . https://github.com/notifications/beacon/AIi90zOlXm2Q3tsMdpY31cnRKxfgeYYQks5uDKWdgaJpZM4VCYJS.gif

henrikl2000 avatar Jul 04 '18 13:07 henrikl2000

Just for inspiration (not worth a pull-request), here's my way of solving the memory issue on an Arduino running a lot of LED's (12 Neopixel rings with each 12 led's = 144 Neopixels):

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6
#define NUM_RINGS 12
#define NUM_LEDS_PER_RING 12
#define BRIGHTNESS 55

#define NUM_LEDS NUM_RINGS*NUM_LEDS_PER_RING

//We need to prevent overflow of memory
//On an Arduino Uno we have a max of 2000bytes available. 
#define Z_VALUES_DUPLICATES 4 //The higher the value, the less memory is consumed

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

// the original levels for the leds (mix of yellow and red) that we define in setup()
const uint8_t base[3][3] = {
    {140, 0, 0},//Org: 70,0,0
    {60, 30, 0},//Org: 60,30,0
    {100, 70, 8}//Org: 100,70,0     
};

uint8_t count = 0;
int diffIndex = 0;
double z;

// the levels to approach the new levels by tweaning (these we use to set the neopixels)
int valR[NUM_LEDS];//replaced 'double' by 'int' to save memory
int valG[NUM_LEDS];
int valB[NUM_LEDS];

//The diff holds values for groups of 3 leds
int diff[NUM_LEDS/Z_VALUES_DUPLICATES][3];

void setup() 
{
  strip.setBrightness(BRIGHTNESS);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() 
{
//delay(100);
  //Loop over each led
  for (int i=0; i<NUM_LEDS; i++)
  {
    diffIndex = map(i, 0, NUM_LEDS, 0, NUM_LEDS/Z_VALUES_DUPLICATES);
    
    //Each 10th loop() execution we update the diff value for each LED
    if(count>9){
      //Set a new z value for each group of 3 leds.
      if( i%3 )
      {
        z = 10.0/random(5.5, 11);
      }
      
      //Calculate a new value, based on the Z value
      diff[diffIndex][0] = ( (base[i%3][0] * z) - valR[i])/10;
      diff[diffIndex][1] = ( (base[i%3][1] * z) - valG[i])/10;
      diff[diffIndex][2] = ( (base[i%3][2] * z) - valB[i])/10;
      
      
    }//End if count>9
    
    valR[i] += diff[diffIndex][0];
    valG[i] += diff[diffIndex][1];
    valB[i] += diff[diffIndex][2];
    
    // to guard from overflow or accidental unwanted flickering
    if (valR[i]<0) valR[i] = 0;
    if (valR[i]>255) valR[i] = 255;
    if (valG[i]<0) valG[i] = 0;
    if (valG[i]>255) valG[i] = 255;
    if (valB[i]<0) valB[i] = 0;
    if (valB[i]>255) valB[i] = 255;
    
    strip.setPixelColor(i, valR[i], valG[i], valB[i] );
  }
  
  strip.show();

  if(count>9) count = 0;
  count++;
  
  delay(10);    // run our loop at approx 100Hz; so new LED levels reach every ~100 ms (~10Hz)
}

dhunink avatar Jul 05 '18 17:07 dhunink