Question about the cylon fastled example

ok, so heres the cylon fast led example, with some slight modifications on my part to make it non rainbow anymore.

what do i have to change/add to make groupings of the LED's different colors? i want the moving led to change colors after it has passed so many, like the first 59 are green, second red, etc.

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 259 

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 7
#define COLOR_ORDER GRB

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
	Serial.begin(57600);
	Serial.println("resetting");
	FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
	FastLED.setBrightness(60);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
	static uint8_t;
	Serial.print("x");
	// First slide the led in one direction
	for(int i = 0; i < NUM_LEDS; i++) {
		// Set the i'th led to red 
		leds[i] = CRGB(255,0,0);
		// Show the leds
		FastLED.show(); 
		// now that we've shown the leds, reset the i'th led to black
		 leds[i] = CRGB(0,0,0);
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	}
	Serial.print("x");

	// Now go in the other direction.  
	for(int i = (NUM_LEDS)-1; i >= 0; i--) {
		// Set the i'th led to red 
		leds[i] = CRGB(255,0,0);
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		leds[i] = CRGB(255,0,0);
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	}
}

Here you assign the colour red to an LED. You want to make the colour dependent on the LED index if I understand you correctly.

One way of doing this, would be something like:

if (i < 59) {
  leds[i] = CRGB(0, 255, 0);
}
else {
  if (i < 118) {
    leds[i] = CRGB(255, 255, 0);
  }
  else {
    leds[i] = CRGB(255, 0, 0);
  }
}

i dont know what im doing right, or wrong, this sketch makes the entire strip turn off, then the first led turns blue, then a green "cylon" starts at the end and goes forward, once it reaches the start the first led turns off, then it starts over, but on the second pass the second led turns off, then the third pass the third led, so on and so forth.

why is this so complicated

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 259
#define MAX_AMPS 500
#define BRIGHTNESS 60
#define VOLTS 5
#define DATA_PIN 7
#define COLOR_ORDER GRB


// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
	Serial.begin(57600);
	Serial.println("resetting");
	FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
	FastLED.setBrightness(BRIGHTNESS);
  FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
	static uint8_t ;
	Serial.print("x");
	for(int i = 0; i < NUM_LEDS; i++) {
	
	if (i < 58) {
  leds[i] = CRGB(0, 255, 0);
  }
  if (i < 116) {leds[i] = CRGB(255, 0, 0);
  }
  if (i < 175) {leds[i] = CRGB(0, 0,255);
  }
  if (i < 234) {leds[i] = CRGB(128, 0, 128);
  }
   if (i > 234) {leds[i] = CRGB(85,85,85);
  }



		FastLED.show(); 
		// now that we've shown the leds, reset the i'th led to black
		 leds[i] = CRGB(0,0,0);
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	
	

	// Now go in the other direction.  
	for(int i = (NUM_LEDS)-1; i >= 0; i--) {
		// Set the i'th led to red 
		leds[i] = CHSV(0, 255, 255);
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		// leds[i] = CRGB::Black;
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	 }
}
}

When i is smaller than 58, it is also smaller than 175 and 234. The result is that an LED is set to CRGB(128, 0, 128) whenever i is smaller than 234.

The following will probably do something closer to what you want.

if (i < 58) {
  leds[i] = CRGB(0, 255, 0);
}
else if (i < 116) {
  leds[i] = CRGB(255, 0, 0);
}
else if (i < 175) {
  leds[i] = CRGB(0, 0, 255);
}
else if (i < 234) {
  leds[i] = CRGB(128, 0, 128);
}
else {
  leds[i] = CRGB(85, 85, 85);
}

thank you!! that is what i was looking for, i only have one last question, when the led's fade to black how would i make them not fade all the way? like, only fade to half brightness?

i had originally wanted them to fade all the way to black, and you helped me acheive that, but now looking at it i think it would look better if it didnt fade all the way out.

I am not familiar with this library, but the fadeToBlackBy function looks promising.

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