[Solved] Value returning to 255 after some time

Hey all,

I’m busy programming a LEDstrip to do some animations. I have a simple control pannel consisting of 2 buttons (on pins 12 and 13) and a potentiometer (on pin A0). the “select_pin” button scrolls through a selection of menus, in each menu a certain parameter changes according to the potentiometer value, this value can then be ignored (by pressing the “select_pin” button) or accepted (by pressing the other button, “confirm_pin”), then the menu continues to the next one.
Thus far I’ve got everything working, I can set the hue, saturation and brightness to a certain variable.

However, I was working on a scrolling animation which just won’t work.
What I want to happen is that all values in an array, say array, get copied 1 over so that array[0] becomes array[1] and array[1] becomes array[2], just shifting everything over by one. Then a new value gets calculated for array[0] and the thing repeats. the length of this array is “NUM_LEDS”, the amount of leds on my strip.

I want this to happen to three arrays: “hue_pixel”, “saturation_pixel” and “brightness_pixel”.

This is the piece of my code causing me problems:

for (int i = NUM_LEDS - 1; i >= 0; i--){
            hue_pixel[(i+1)] = hue_pixel[i];
            saturation_pixel[(i+1)] = saturation_pixel[i];
            brightness_pixel[i] = 0; //brightness_pixel[i];
            }


        hue_pixel[0] = hue;
        saturation_pixel[0] = saturation;
        brightness_pixel[0] = brightness_new;


        Serial.print("      hue:");
        Serial.print(hue_pixel[1]);
        Serial.print("      saturation:");
        Serial.print(saturation_pixel[1]);
        Serial.print("      brightness:");
        Serial.println(brightness_pixel[1]);



        for (int i = 0; i < NUM_LEDS; i ++){
            leds[i].setHSV(  hue_pixel[i]  ,  saturation_pixel[i]  ,  //brightness_pixel[i]  );
                                                                      255);      
        }



        FastLED.show();

LED_Noise_test_new.ino (5.62 KB)

What I want to happen is that all values in an array, say array, get copied 1 over so that array[0] becomes array[1] and array[1] becomes array[2], just shifting everything over by one. Then a new value gets calculated for array[0] and the thing repeats. the length of this array is "NUM_LEDS", the amount of leds on my strip.

That sounds very clumsy. No need to copy anything, just update a variable to point to the index of the array with the current or next value

     for (int i = NUM_LEDS - 1; i >= 0; i--){
            hue_pixel[(i+1)] = hue_pixel[i];

in the code above and assuming hue_pixel has NUM_LEDS elements, an index of NUM_LEDS or above is out of range. so when i == NUM_LEDS-1, hue_pixel [i+1] is out of range

consider ... if NUM_LEDS is 1, hue_pixel only has a single element at hue_pixel [0].

gcjr:

     for (int i = NUM_LEDS - 1; i >= 0; i--){

hue_pixel[(i+1)] = hue_pixel[i];




in the code above and assuming hue_pixel has NUM_LEDS elements, an index of NUM_LEDS or above is out of range. so when i == NUM_LEDS-1, hue_pixel [i+1] is out of range

Thanks, I thought I had done this correctly, for some reason in my mind I thought this was correct, thanks for pointing it out.
This also seemed to have fixed the issue.
Thank you!