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!



Fastled NoisePlusPa...
 
Share:
Notifications
Clear all

[Solved] Fastled NoisePlusPalette help needed !

6 Posts
2 Users
0 Reactions
3,515 Views
(@perolalars)
Active Member
Joined: 7 years ago
Posts: 5
Topic starter  

Hi
I hope that someone could help me with this cause I am totally stuck!
I have used the example off NoisePlusPalette from the Fastled library examples.
I am (almost) a total newbie at this so plz bare with me!

What I want is:
1. Get rid off the partycolor palette that starts the code, but when I just are commenting out that code, it dont work anymore.
2. I am just interested in using the CloudColors palette, so I probably can just delete all the rest of the palettes, or?
3. I would like to extend the number of colors in the CloudColors palette but I dont know how to edit that and get it to work.
4. And I would like to slow down the color-changing speed and I havent been able to find where to do that. Or is it just not possible?

I would be very happy for any help to how to adress this issues!!
Per

The code:

#include <FastLED.h>

#define LED_PIN     6
#define BRIGHTNESS  96
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB

const uint8_t kMatrixWidth  = 16;
const uint8_t kMatrixHeight = 16;
const bool    kMatrixSerpentineLayout = true;


// This example combines two features of FastLED to produce a remarkable range of
// effects from a relatively small amount of code.  This example combines FastLED's
// color palette lookup functions with FastLED's Perlin/simplex noise generator, and
// the combination is extremely powerful.
//
// You might want to look at the "ColorPalette" and "Noise" examples separately
// if this example code seems daunting.
//
//
// The basic setup here is that for each frame, we generate a new array of
// 'noise' data, and then map it onto the LED matrix through a color palette.
//
// Periodically, the color palette is changed, and new noise-generation parameters
// are chosen at the same time.  In this example, specific noise-generation
// values have been selected to match the given color palettes; some are faster,
// or slower, or larger, or smaller than others, but there's no reason these
// parameters can't be freely mixed-and-matched.
//
// In addition, this example includes some fast automatic 'data smoothing' at
// lower noise speeds to help produce smoother animations in those cases.
//
// The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
// used, as well as some 'hand-defined' ones, and some proceedurally generated
// palettes.


#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)

// The leds
CRGB leds[kMatrixWidth * kMatrixHeight];

// The 16 bit version of our coordinates
static uint16_t x;
static uint16_t y;
static uint16_t z;

// We're using the x/y dimensions to map to the x/y pixels on the matrix.  We'll
// use the z-axis for "time".  speed determines how fast time moves forward.  Try
// 1 for a very slow moving effect, or 60 for something that ends up looking like
// water.
uint16_t speed = 20; // speed is set dynamically once we've started up

// Scale determines how far apart the pixels in our noise matrix are.  Try
// changing these values around to see how it affects the motion of the display.  The
// higher the value of scale, the more "zoomed out" the noise iwll be.  A value
// of 1 will be so zoomed in, you'll mostly see solid colors.
uint16_t scale = 30; // scale is set dynamically once we've started up

// This is the array that we keep our computed noise values in
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];

CRGBPalette16 currentPalette( PartyColors_p );
uint8_t       colorLoop = 1;

void setup() {
  delay(3000);
  LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS);
  LEDS.setBrightness(BRIGHTNESS);

  // Initialize our coordinates to some random values
  x = random16();
  y = random16();
  z = random16();
}



// Fill the x/y array of 8-bit noise values using the inoise8 function.
void fillnoise8() {
  // If we're runing at a low "speed", some 8-bit artifacts become visible
  // from frame-to-frame.  In order to reduce this, we can do some fast data-smoothing.
  // The amount of data smoothing we're doing depends on "speed".
  uint8_t dataSmoothing = 0;
  if( speed < 50) {
    dataSmoothing = 200 - (speed * 4);
  }
 
  for(int i = 0; i < MAX_DIMENSION; i++) {
    int ioffset = scale * i;
    for(int j = 0; j < MAX_DIMENSION; j++) {
      int joffset = scale * j;
     
      uint8_t data = inoise8(x + ioffset,y + joffset,z);

      // The range of the inoise8 function is roughly 16-238.
      // These two operations expand those values out to roughly 0..255
      // You can comment them out if you want the raw noise data.
      data = qsub8(data,16);
      data = qadd8(data,scale8(data,39));

      if( dataSmoothing ) {
        uint8_t olddata = noise[j];
        uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
        data = newdata;
      }
     
      noise[j] = data;
    }
  }
 
  z += speed;
 
  // apply slow drift to X and Y, just for visual variation.
  x += speed / 8;
  y -= speed / 16;
}

void mapNoiseToLEDsUsingPalette()
{
  static uint8_t ihue=0;
 
  for(int i = 0; i < kMatrixWidth; i++) {
    for(int j = 0; j < kMatrixHeight; j++) {
      // We use the value at the (i,j) coordinate in the noise
      // array for our brightness, and the flipped value from (j,i)
      // for our pixel's index into the color palette.

      uint8_t index = noise[j];
      uint8_t bri =   noise[j];

      // if this palette is a 'loop', add a slowly-changing base value
      if( colorLoop) {
        index += ihue;
      }

      // brighten up, as the color palette itself often contains the
      // light/dark dynamic range desired
      if( bri > 127 ) {
        bri = 255;
      } else {
        bri = dim8_raw( bri * 2);
      }

      CRGB color = ColorFromPalette( currentPalette, index, bri);
      leds[XY(i,j)] = color;
    }
  }
 
  ihue+=1;
}

void loop() {
  // Periodically choose a new palette, speed, and scale
  ChangePaletteAndSettingsPeriodically();

  // generate noise data
  fillnoise8();
 
  // convert the noise data to colors in the LED array
  // using the current palette
  mapNoiseToLEDsUsingPalette();

  LEDS.show();
  // delay(10);
}



// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.

// 1 = 5 sec per palette
// 2 = 10 sec per palette
// etc
#define HOLD_PALETTES_X_TIMES_AS_LONG 1

void ChangePaletteAndSettingsPeriodically()
{
  uint8_t secondHand = ((millis() / 1000) / HOLD_PALETTES_X_TIMES_AS_LONG) % 60;
  static uint8_t lastSecond = 99;
 
  if( lastSecond != secondHand) {
    lastSecond = secondHand;
    // if( secondHand ==  0)  { currentPalette = RainbowColors_p;         speed = 20; scale = 30; colorLoop = 1; }
    // if( secondHand ==  5)  { SetupPurpleAndGreenPalette();             speed = 1; scale = 40; colorLoop = 1; }
    // if( secondHand == 15)  { currentPalette = ForestColors_p;          speed =  8; scale =120; colorLoop = 0; }
    if( secondHand == 20)  { currentPalette = CloudColors_p;           speed =  3; scale = 30; colorLoop = 0; }
    // if( secondHand == 25)  { currentPalette = LavaColors_p;            speed =  8; scale = 50; colorLoop = 0; }
    // if( secondHand == 30)  { currentPalette = OceanColors_p;           speed = 20; scale = 90; colorLoop = 0; }
    // if( secondHand == 35)  { currentPalette = PartyColors_p;           speed = 20; scale = 30; colorLoop = 1; }
    // if( secondHand == 40)  { SetupRandomPalette();                     speed = 20; scale = 20; colorLoop = 1; }
    // if( secondHand == 45)  { SetupRandomPalette();                     speed = 50; scale = 50; colorLoop = 1; }
    // if( secondHand == 50)  { SetupRandomPalette();                     speed = 90; scale = 90; colorLoop = 1; }
    // if( secondHand == 55)  { currentPalette = RainbowStripeColors_p;   speed = 30; scale = 20; colorLoop = 1; }
  }
}

// This function generates a random palette that's a gradient
// between four different colors.  The first is a dim hue, the second is
// a bright hue, the third is a bright pastel, and the last is
// another bright hue.  This gives some visual bright/dark variation
// which is more interesting than just a gradient of different hues.
void SetupRandomPalette()
{
  currentPalette = CRGBPalette16(
                      CHSV( random8(), 255, 32),
                      CHSV( random8(), 255, 255),
                      CHSV( random8(), 128, 255),
                      CHSV( random8(), 255, 255));
}

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
  // 'black out' all 16 palette entries...
  fill_solid( currentPalette, 16, CRGB::Black);
  // and set every fourth one to white.
  currentPalette[0] = CRGB::White;
  currentPalette[4] = CRGB::White;
  currentPalette[8] = CRGB::White;
  currentPalette[12] = CRGB::White;

}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
  CRGB purple = CHSV( HUE_PURPLE, 255, 255);
  CRGB green  = CHSV( HUE_GREEN, 255, 255);
  CRGB black  = CRGB::Black;
 
  currentPalette = CRGBPalette16(
    green,  green,  black,  black,
    purple, purple, black,  black,
    green,  green,  black,  black,
    purple, purple, black,  black );
}


//
// Mark's xy coordinate mapping code.  See the XYMatrix for more information on it.
//
uint16_t XY( uint8_t x, uint8_t y)
{
  uint16_t i;
  if( kMatrixSerpentineLayout == false) {
    i = (y * kMatrixWidth) + x;
  }
  if( kMatrixSerpentineLayout == true) {
    if( y & 0x01) {
      // Odd rows run backwards
      uint8_t reverseX = (kMatrixWidth - 1) - x;
      i = (y * kMatrixWidth) + reverseX;
    } else {
      // Even rows run forwards
      i = (y * kMatrixWidth) + x;
    }
  }
  return i;
}

   
ReplyQuote
(@perolalars)
Active Member
Joined: 7 years ago
Posts: 5
Topic starter  

Now I am working with this code instead since it seams easier...
I still want to get rid off the red and yellows and just have a blue/green/white color palette and to bee able to slow down the speed of the color changing
Any help would be greatly appreciated!

/* Title: inoise8_pal_demo.ino
 *
 * By: Andrew Tuline
 *
 * Date: August, 2016
 *
 * This short sketch demonstrates some of the functions of FastLED, including:
 *
 * Perlin noise
 * Palettes
 * Palette blending
 * Alternatives to blocking delays
 * Beats (and not the Dr. Dre kind, but rather the sinewave kind)
 *
 * Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions.
 *
 *
 * Recommendations for high performance routines:
 *
 * Don't use blocking delays, especially if you plan to use buttons for input.
 * Keep loops to a minimum, and don't use nested loops.
 * Don't use floating point math. It's slow. Use 8 bit where possible.
 * Let high school and not elementary school math do the work for you, i.e. don't just count pixels; use sine waves or other math functions instead.
 * FastLED math functions are faster than built in math functions.
 *  
 */
 
 
#include "FastLED.h"
 
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
 
#define LED_PIN 6
// #define CLK_PIN 11
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
 
#define NUM_LEDS 36
 
struct CRGB leds[NUM_LEDS];
 
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(OceanColors_p);
 

void setup() {
  
  Serial.begin(115200);
  delay(1000);
 
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); // WS2812
// LEDS.addLeds<LED_TYPE,LED_PIN,CLK_PIN, COLOR_ORDER>(leds,NUM_LEDS); // APA102, WS8201
 
  LEDS.setBrightness(BRIGHTNESS);
  
} // setup()


void loop() {
  
  EVERY_N_MILLIS(10) {
    nblendPaletteTowardPalette(currentPalette, targetPalette, 48); // Blend towards the target palette over 48 iterations
    fillnoise8(); // Update the LED array with noise at the new location. You can put this in its own EVERY_N_MILLIS() function to speed up/slow down.
  }
 
  EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
  targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
  }
  
  LEDS.show(); // Display the LED's at every loop cycle.
  
} // loop()
 

void fillnoise8() {
  #define scale 30 // Don't change this programmatically or everything shakes.
  static uint16_t dist; // A random number for our noise generator.
  
  for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
    uint8_t index = inoise8(i*scale, dist+i*scale); // Get a value from the noise function. I'm using both x and y axis.
    leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
  }
  dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
                                                                            // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()/* Title: inoise8_pal_demo.ino
 *
 * By: Andrew Tuline
 *
 * Date: August, 2016
 *
 * This short sketch demonstrates some of the functions of FastLED, including:
 *
 * Perlin noise
 * Palettes
 * Palette blending
 * Alternatives to blocking delays
 * Beats (and not the Dr. Dre kind, but rather the sinewave kind)
 *
 * Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions.
 *
 *
 * Recommendations for high performance routines:
 *
 * Don't use blocking delays, especially if you plan to use buttons for input.
 * Keep loops to a minimum, and don't use nested loops.
 * Don't use floating point math. It's slow. Use 8 bit where possible.
 * Let high school and not elementary school math do the work for you, i.e. don't just count pixels; use sine waves or other math functions instead.
 * FastLED math functions are faster than built in math functions.
 *  
 */
 
 
#include "FastLED.h"
 
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
 
#define LED_PIN 6
// #define CLK_PIN 11
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
 
#define NUM_LEDS 36
 
struct CRGB leds[NUM_LEDS];
 
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(OceanColors_p);
 

void setup() {
  
  Serial.begin(115200);
  delay(1000);
 
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); // WS2812
// LEDS.addLeds<LED_TYPE,LED_PIN,CLK_PIN, COLOR_ORDER>(leds,NUM_LEDS); // APA102, WS8201
 
  LEDS.setBrightness(BRIGHTNESS);
  
} // setup()


void loop() {
  
  EVERY_N_MILLIS(10) {
    nblendPaletteTowardPalette(currentPalette, targetPalette, 48); // Blend towards the target palette over 48 iterations
    fillnoise8(); // Update the LED array with noise at the new location. You can put this in its own EVERY_N_MILLIS() function to speed up/slow down.
  }
 
  EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
  targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
  }
  
  LEDS.show(); // Display the LED's at every loop cycle.
  
} // loop()
 

void fillnoise8() {
  #define scale 30 // Don't change this programmatically or everything shakes.
  static uint16_t dist; // A random number for our noise generator.
  
  for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
    uint8_t index = inoise8(i*scale, dist+i*scale); // Get a value from the noise function. I'm using both x and y axis.
    leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
  }
  dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
                                                                            // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()/* Title: inoise8_pal_demo.ino
 *
 * By: Andrew Tuline
 *
 * Date: August, 2016
 *
 * This short sketch demonstrates some of the functions of FastLED, including:
 *
 * Perlin noise
 * Palettes
 * Palette blending
 * Alternatives to blocking delays
 * Beats (and not the Dr. Dre kind, but rather the sinewave kind)
 *
 * Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions.
 *
 *
 * Recommendations for high performance routines:
 *
 * Don't use blocking delays, especially if you plan to use buttons for input.
 * Keep loops to a minimum, and don't use nested loops.
 * Don't use floating point math. It's slow. Use 8 bit where possible.
 * Let high school and not elementary school math do the work for you, i.e. don't just count pixels; use sine waves or other math functions instead.
 * FastLED math functions are faster than built in math functions.
 *  
 */
 
 
#include "FastLED.h"
 
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
 
#define LED_PIN 6
// #define CLK_PIN 11
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
 
#define NUM_LEDS 36
 
struct CRGB leds[NUM_LEDS];
 
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(OceanColors_p);
 

void setup() {
  
  Serial.begin(115200);
  delay(1000);
 
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); // WS2812
// LEDS.addLeds<LED_TYPE,LED_PIN,CLK_PIN, COLOR_ORDER>(leds,NUM_LEDS); // APA102, WS8201
 
  LEDS.setBrightness(BRIGHTNESS);
  
} // setup()


void loop() {
  
  EVERY_N_MILLIS(10) {
    nblendPaletteTowardPalette(currentPalette, targetPalette, 48); // Blend towards the target palette over 48 iterations
    fillnoise8(); // Update the LED array with noise at the new location. You can put this in its own EVERY_N_MILLIS() function to speed up/slow down.
  }
 
  EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
  targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
  }
  
  LEDS.show(); // Display the LED's at every loop cycle.
  
} // loop()
 

void fillnoise8() {
  #define scale 30 // Don't change this programmatically or everything shakes.
  static uint16_t dist; // A random number for our noise generator.
  
  for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
    uint8_t index = inoise8(i*scale, dist+i*scale); // Get a value from the noise function. I'm using both x and y axis.
    leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
  }
  dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
                                                                            // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()/* Title: inoise8_pal_demo.ino
 *
 * By: Andrew Tuline
 *
 * Date: August, 2016
 *
 * This short sketch demonstrates some of the functions of FastLED, including:
 *
 * Perlin noise
 * Palettes
 * Palette blending
 * Alternatives to blocking delays
 * Beats (and not the Dr. Dre kind, but rather the sinewave kind)
 *
 * Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions.
 *
 *
 * Recommendations for high performance routines:
 *
 * Don't use blocking delays, especially if you plan to use buttons for input.
 * Keep loops to a minimum, and don't use nested loops.
 * Don't use floating point math. It's slow. Use 8 bit where possible.
 * Let high school and not elementary school math do the work for you, i.e. don't just count pixels; use sine waves or other math functions instead.
 * FastLED math functions are faster than built in math functions.
 *  
 */
 
 
#include "FastLED.h"
 
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
 
#define LED_PIN 6
// #define CLK_PIN 11
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
 
#define NUM_LEDS 36
 
struct CRGB leds[NUM_LEDS];
 
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(OceanColors_p);
 

void setup() {
  
  Serial.begin(115200);
  delay(1000);
 
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); // WS2812
// LEDS.addLeds<LED_TYPE,LED_PIN,CLK_PIN, COLOR_ORDER>(leds,NUM_LEDS); // APA102, WS8201
 
  LEDS.setBrightness(BRIGHTNESS);
  
} // setup()


void loop() {
  
  EVERY_N_MILLIS(10) {
    nblendPaletteTowardPalette(currentPalette, targetPalette, 48); // Blend towards the target palette over 48 iterations
    fillnoise8(); // Update the LED array with noise at the new location. You can put this in its own EVERY_N_MILLIS() function to speed up/slow down.
  }
 
  EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
  targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
  }
  
  LEDS.show(); // Display the LED's at every loop cycle.
  
} // loop()
 

void fillnoise8() {
  #define scale 30 // Don't change this programmatically or everything shakes.
  static uint16_t dist; // A random number for our noise generator.
  
  for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
    uint8_t index = inoise8(i*scale, dist+i*scale); // Get a value from the noise function. I'm using both x and y axis.
    leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
  }
  dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
                                                                            // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()

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

In your last post, I see 4 sketches in 1, I'm not sure if this was intentional of by mistake.
Either way, the last 3 parts will not do anything, if all these would be in the same sketch (I don't even think it would compile).

So I'll assume this is the code you're using:

#include "FastLED.h"
 
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
 
#define LED_PIN 6
// #define CLK_PIN 11
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER BRG
 
#define NUM_LEDS 36
 
struct CRGB leds[NUM_LEDS];
 
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette(OceanColors_p);
 
void setup() {
  Serial.begin(115200);
  delay(1000);
 
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); // WS2812
  LEDS.setBrightness(BRIGHTNESS);
  
} // setup()

void loop() {
  
  EVERY_N_MILLIS(10) {
    nblendPaletteTowardPalette(currentPalette, targetPalette, 48); // Blend towards the target palette over 48 iterations
    fillnoise8(); // Update the LED array with noise at the new location. You can put this in its own EVERY_N_MILLIS() function to speed up/slow down.
  }
 
  EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
  targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));
  }
  
  LEDS.show(); // Display the LED's at every loop cycle.
  
} // loop()
 
void fillnoise8() {
  #define scale 30 // Don't change this programmatically or everything shakes.
  static uint16_t dist; // A random number for our noise generator.
  
  for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
    uint8_t index = inoise8(i*scale, dist+i*scale); // Get a value from the noise function. I'm using both x and y axis.
    leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
  }
  dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
                                                                            // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()/* Title: inoise8_pal_demo.ino

Since your question is: "I still want to get rid off the red and yellows and just have a blue/green/white color palette and to bee able to slow down the speed of the color changing", I'd start with this:

The line in setup() with 

nblendPaletteTowardPalette(currentPalette, targetPalette, 48);

change it to something like this:

nblendPaletteTowardPalette(currentPalette, targetPalette, 5);

From what I'm reading here:

Each time that nblendPaletteTowardPalette is called, small changes

are made to currentPalette to bring it closer to matching targetPalette.

You can control how many changes are made in each call:

 - the default of 24 is a good balance

 - meaningful values are 1-48. 1=veeeeeeeery slow, 48=quickest

 - "0" means do not change the currentPalette at all; freeze

For getting rid of red's and yellows, we'd need to eliminate any red items in colors.
So when looking at this line:

targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255)));

we should set anything red to zero. Now you've used CHSV, which does not (by my knowledge) allow you to select "red" as such, so I would try changing it tp CRGB functions.
Change something like this:

CHSV(random8(), 255, random8(128,255))

to

CRGB(0, random8(), 255, random8(128,255))

So your line would look something like this:

targetPalette = CRGBPalette16( CRGB(0, random8(), 255, random8(128,255)), 
                CRGB(0, random8(), 255, random8(128,255)), CRGB(0, random8(), 255, random8(128,255)), CRGB(0, random8(), 255, random8(128,255)) );

Since I'm unable to test this, we'll have to see what results you will have after testing this.


   
ReplyQuote
(@perolalars)
Active Member
Joined: 7 years ago
Posts: 5
Topic starter  

Hi Hans

And thank you so much for your reply! I was thinking that it was alot of code that I did not need, but since I am still a newbie I didnt know what to get rid off.
When making your suggested changes I get a lot of error messages and I dont even know where to start...

Arduino:1.8.10 (Windows 10), Kort:"Arduino/Genuino Uno"
In file included from E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino:1:0:
E:\Dokument\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.002
 # pragma message "FastLED version 3.003.002"
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino: In function 'void loop()':
NoisePlusPalette_03:37:74: error: no matching function for call to 'CRGB::CRGB(int, uint8_t, int, uint8_t)'
   targetPalette = CRGBPalette16( CRGB(0, random8(), 255, random8(128,255)),
                                                                          ^
In file included from E:\Dokument\Arduino\libraries\FastLED/controller.h:9:0,
                 from E:\Dokument\Arduino\libraries\FastLED/FastLED.h:47,
                 from E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino:1:
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate: CRGB::CRGB(const CHSV&)
  inline CRGB(const CHSV& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate: CRGB::CRGB(const CRGB&)
  inline CRGB(const CRGB& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate: CRGB::CRGB(ColorTemperature)
     inline CRGB( ColorTemperature colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate: CRGB::CRGB(LEDColorCorrection)
     inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate: CRGB::CRGB(uint32_t)
     inline CRGB( uint32_t colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate: CRGB::CRGB(uint8_t, uint8_t, uint8_t)
     inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate expects 3 arguments, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate: CRGB::CRGB()
  inline CRGB() __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate expects 0 arguments, 4 provided
NoisePlusPalette_03:38:72: error: no matching function for call to 'CRGB::CRGB(int, uint8_t, int, uint8_t)'
                                CRGB(0, random8(), 255, random8(128,255)),
                                                                        ^
In file included from E:\Dokument\Arduino\libraries\FastLED/controller.h:9:0,
                 from E:\Dokument\Arduino\libraries\FastLED/FastLED.h:47,
                 from E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino:1:
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate: CRGB::CRGB(const CHSV&)
  inline CRGB(const CHSV& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate: CRGB::CRGB(const CRGB&)
  inline CRGB(const CRGB& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate: CRGB::CRGB(ColorTemperature)
     inline CRGB( ColorTemperature colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate: CRGB::CRGB(LEDColorCorrection)
     inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate: CRGB::CRGB(uint32_t)
     inline CRGB( uint32_t colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate: CRGB::CRGB(uint8_t, uint8_t, uint8_t)
     inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate expects 3 arguments, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate: CRGB::CRGB()
  inline CRGB() __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate expects 0 arguments, 4 provided
NoisePlusPalette_03:39:72: error: no matching function for call to 'CRGB::CRGB(int, uint8_t, int, uint8_t)'
                                CRGB(0, random8(), 255, random8(128,255)),
                                                                        ^
In file included from E:\Dokument\Arduino\libraries\FastLED/controller.h:9:0,
                 from E:\Dokument\Arduino\libraries\FastLED/FastLED.h:47,
                 from E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino:1:
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate: CRGB::CRGB(const CHSV&)
  inline CRGB(const CHSV& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate: CRGB::CRGB(const CRGB&)
  inline CRGB(const CRGB& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate: CRGB::CRGB(ColorTemperature)
     inline CRGB( ColorTemperature colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate: CRGB::CRGB(LEDColorCorrection)
     inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate: CRGB::CRGB(uint32_t)
     inline CRGB( uint32_t colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate: CRGB::CRGB(uint8_t, uint8_t, uint8_t)
     inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate expects 3 arguments, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate: CRGB::CRGB()
  inline CRGB() __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate expects 0 arguments, 4 provided
NoisePlusPalette_03:40:72: error: no matching function for call to 'CRGB::CRGB(int, uint8_t, int, uint8_t)'
                                CRGB(0, random8(), 255, random8(128,255)) );
                                                                        ^
In file included from E:\Dokument\Arduino\libraries\FastLED/controller.h:9:0,
                 from E:\Dokument\Arduino\libraries\FastLED/FastLED.h:47,
                 from E:\Dokument\Arduino\NoisePlusPalette_03\NoisePlusPalette_03.ino:1:
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate: CRGB::CRGB(const CHSV&)
  inline CRGB(const CHSV& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:161:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate: CRGB::CRGB(const CRGB&)
  inline CRGB(const CRGB& rhs) __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:153:9: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate: CRGB::CRGB(ColorTemperature)
     inline CRGB( ColorTemperature colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:146:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate: CRGB::CRGB(LEDColorCorrection)
     inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:139:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate: CRGB::CRGB(uint32_t)
     inline CRGB( uint32_t colorcode) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:133:12: note: candidate expects 1 argument, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate: CRGB::CRGB(uint8_t, uint8_t, uint8_t)
     inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
            ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:127:12: note: candidate expects 3 arguments, 4 provided
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate: CRGB::CRGB()
  inline CRGB() __attribute__((always_inline))
         ^~~~
E:\Dokument\Arduino\libraries\FastLED/pixeltypes.h:122:9: note: candidate expects 0 arguments, 4 provided
Multiple libraries were found for "FastLED.h"
 Använd: E:\Dokument\Arduino\libraries\FastLED
exit status 1
no matching function for call to 'CRGB::CRGB(int, uint8_t, int, uint8_t)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


   
ReplyQuote
(@perolalars)
Active Member
Joined: 7 years ago
Posts: 5
Topic starter  

Since it talks about something from "pixeltypes.h" I tried to uninstall the fastled library and reinstall it again but that didnt solve anything.
Really out of my depth here...


   
ReplyQuote
(@perolalars)
Active Member
Joined: 7 years ago
Posts: 5
Topic starter  

Hi again!
And sorry Hans, I did give the PaletteCrossFade from Kriegsman a go, and discover that changing the:

nblendPaletteTowardPalette(currentPalette, targetPalette, 5);

value only seams to change the speed of transitions between different pixel colors, not the actual color changing speed. So back at square 1, except that it showed me a different way of handling color palettes.
But is it possible to make use of my second sketch and get rid of the error messages and change the speed?

Sorry to be a pain but really need assistance! 


   
ReplyQuote
Share: