FastLed colour changing HELP Pls

can anyone tell me where im going wrong. i just cant seem to make the colour change
\

#include "FastLED.h"
#define TOTAL_LEDS 20
#define PIN 9
CRGB leds[TOTAL_LEDS];

byte COLOUR[6]= { 0x00ff00, 0xff0000, 0x0000ff, 0xFFFF00, 0xFF00FF , 0x00ffff}; //green , red , blue , yellow , pink , paleblue

 

void setup() {
delay(2000);     
FastLED.addLeds<WS2812B, PIN, GRB>(leds, TOTAL_LEDS);

      
}

void loop() {
   // Move led 
   for(int i = 0; i < TOTAL_LEDS; i = i + 1) {
      
      leds[i] = COLOUR[2];  //[2]this will be changed to a number variable later through a menu
      FastLED.show();
      delay(100);  
      leds[i] = CRGB::Black ;
   }
}

You seem to use only one colour for the LEDs in your sketch. So you need to do more explaining on what exactly you do, the result you expect, and the result you get.

byte COLOUR[6]= { 0x00ff00, 0xff0000,

0x00ff00 and the rest will not fit in a byte data type. They will fit in a long (4 byte data type).

I fixed the data type and added an index to iterate through the colour array. Does this do what you want?

#include "FastLED.h"
#define TOTAL_LEDS 20
#define PIN 9
CRGB leds[TOTAL_LEDS];

long COLOUR[6]= { 0x00ff00, 0xff0000, 0x0000ff, 0xFFFF00, 0xFF00FF , 0x00ffff}; //green , red , blue , yellow , pink , paleblue

 

void setup() {
delay(2000);     
FastLED.addLeds<WS2812B, PIN, GRB>(leds, TOTAL_LEDS);

     
}

void loop() {
   // Move led
   byte colourIndex = 0;
   for(int i = 0; i < TOTAL_LEDS; i = i + 1) {
     
      leds[i] = COLOUR[colourIndex];  //[2]this will be changed to a number variable later through a menu
      colourIndex++;
      if(colourIndex > 5)
      {
        colourIndex = 0;
      }
      FastLED.show();
      delay(100); 
      leds[i] = CRGB::Black ;
   }
}

Thanks

i was trying to set up 9 basic colour's and be able to change the colour based on a select button which also changes a sound file in another program i have written

this was a test example and i just set up the first 6 colours so i could test x

i.e
where x is 0
x makes sound file 0 and blue leds
when x is changed to 1
x makes sound file 2 and red leds

OK, post the code that you tried. Describe what the code does and how that differs from what you ant to do and we can try to help you make it work the way you want.

For the push button to select an action, have a look at the state change detection example. You can use the buttonPushCounter variable and a switch case or if/else to select which colour/sound is used.

what i needed was an array for LED_COLOUR (not sure exactly how to make one)and assign a number to each colour
1 blue
2 red
3 green
4 yellow
5 purple
etc..

when my select button returns X which is selectable between 1-9

set the led colour to LED_COLOUR X
set the sound file AUDIO X

what i needed was an array for LED_COLOUR (not sure exactly how to make one)and assign a number to each colour

That is, in effect, what your COLOUR array does. Blue (0x00ff00) is COLOUR[0], red (0xff0000) is COLOUR[1], etc.

So if you use the state change detection code, the buttonPushCounter variable returns x and you use it to set the array index of COLOUR like COLOUR[buttonPushCounter]. Each button push will select the next color. When the buttonPushCounter reaches the last color, reset the buttonPushCounter to 0 to start over.

I can't help with the audio part yet as I know nothing about what you are using for audio or how to play a specific sound.

so far i have everything else working - the colour change
thats the bit i was struggling with.
i just couldn't see what i was doing wrong
but as in the corrected code you did , i realized if i changed byte to long it sorted it out .
very much appreciate'd.
as for the index you added , that gives me another idea :slight_smile:

you have helped me understand arrays a lot better

and thanks a lot for your help

Glad to be of assistance.