Colour cycle on a ring of LED's using FastLED library. Help Needed

I am trying to create a colour cycle on a ring of LED's, this is my first time using FastLED library can anyone help because currently when I switch t the cycle case, all the led's go static blue

#include "FastLED.h"

#define NUM_LEDS 7
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
const int buttonPin = 2;
int currentcolour = 0;


void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<WS2812, DATA_PIN>(leds, NUM_LEDS);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW){
    currentcolour ++;
    if (currentcolour > 7){
      currentcolour = 0;
    }
  }
 for (int i = 0; i < 8; i++) {
    switch (currentcolour) {
      case 0:
      //off
      leds[0] = CRGB::Black;
      leds[1] = CRGB::Black;
      leds[2] = CRGB::Black;
      leds[3] = CRGB::Black;
      leds[4] = CRGB::Black;
      leds[5] = CRGB::Black;
      leds[6] = CRGB::Black;
      break;
      case 1:
      //cycle
      leds[0] = RainbowColors_p;
      leds[1] = RainbowColors_p;
      leds[2] = RainbowColors_p;
      leds[3] = RainbowColors_p;
      leds[4] = RainbowColors_p;
      leds[5] = RainbowColors_p;
      leds[6] = RainbowColors_p;
      FastLED.show();
      break;
      case 2:
      //red
      leds[0] = CRGB::Red;
      leds[1] = CRGB::Red;
      leds[2] = CRGB::Red;
      leds[3] = CRGB::Red;
      leds[4] = CRGB::Red;
      leds[5] = CRGB::Red;
      leds[6] = CRGB::Red;
      break;
      case 3:
      leds[0] = CRGB::Green;
      leds[1] = CRGB::Green;
      leds[2] = CRGB::Green;
      leds[3] = CRGB::Green;
      leds[4] = CRGB::Green;
      leds[5] = CRGB::Green;
      leds[6] = CRGB::Green;
      break;
      case 4:
      leds[0] = CRGB::Blue;
      leds[1] = CRGB::Blue;
      leds[2] = CRGB::Blue;
      leds[3] = CRGB::Blue;
      leds[4] = CRGB::Blue;
      leds[5] = CRGB::Blue;
      leds[6] = CRGB::Blue;
      break;
      case 5:
      leds[0] = CRGB::Yellow;
      leds[1] = CRGB::Yellow;
      leds[2] = CRGB::Yellow;
      leds[3] = CRGB::Yellow;
      leds[4] = CRGB::Yellow;
      leds[5] = CRGB::Yellow;
      leds[6] = CRGB::Yellow;
      break;
      case 6:
      leds[0] = CRGB::Magenta;
      leds[1] = CRGB::Magenta;
      leds[2] = CRGB::Magenta;
      leds[3] = CRGB::Magenta;
      leds[4] = CRGB::Magenta;
      leds[5] = CRGB::Magenta;
      leds[6] = CRGB::Magenta;
      break;
      case 7:
      leds[0] = CRGB::Cyan;
      leds[1] = CRGB::Cyan;
      leds[2] = CRGB::Cyan;
      leds[3] = CRGB::Cyan;
      leds[4] = CRGB::Cyan;
      leds[5] = CRGB::Cyan;
      leds[6] = CRGB::Cyan;
      break;
    }
 }
 FastLED.show();
 delay(250);
}

why you using for loop?

I change the mode with a button, each time i press the button it changes the case. to me that seemed the easiest way to do it

yes, i see and this works perfect, but why you using for loop?

Why not. Unless you want a beginner to dive into state machine programming.

That means your LEDs are not working. Have you tried running one of the examples to check the hardware is working first.
What sort of Arduino are you using.

i uploaded to UNO - works fine, except of if button is hold - colors changes without waiting

I am using a nano and on this example it works just fine

because it's useless. isn't that reason enough?

The for loop would be better employed in a function to set the colours.

That is because the code only uses the level of the push button, what he needs to do is to use the edge. That is detect when the state of the level changes.
Look in the Examples in the IDE for the State Change Detector example.

Also it will depend on how the push button is wired. I assume from the code it is wired from input to ground.

That wiring is correct, would you suggest i wire it differently?
Also i'm not using an led strip, i'm using this LED, could this have an effect?

Given we haven't seen how you have wired it up in the first place it is hard to tell if it is correct. But given that the examples work there can not be much wrong with it. It is only the push button that this different.

Here are images of my wiring, if they help


Sorry they don't.
They look like a tangle of wires, nothing like a schematic.
Surely in order to build anything you need a schematic. I can't build anything without one and I have been doing electronics for over 50 years.


My overall circuit is here

Thanks. That looks fine.
I would just add a bit of decoupling to make it all more reliable.
Put a 220uF or so large capacitor across the power and ground of the ring. Also add one between the Vin and Ground of the Arduino.
Add a 220 to 510R resistor in series with the data line.

Check the data line is going to the data input of the ring and not the data output of the ring.

arduino produce not enough power for other device.
make so

Come off it, what other devices, a push button with an internal pull up resistor! We are only talking about 7 LEDs. And the code only has two colours on at any one time. That is 280mA max. I can get that from the 5V from a Nano but it is not coming from the Nano anyway. It is coming direct from the power supply and not going through the Arduino at all.

his schematic say something other

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.