hello all i have now been playing about for what feel likes ages and

hello all i have now been playing about for what feel likes ages and dont seem to be getting any where, I have been play around the “cylon example”. i have stripped the code back and played around, What i am trying to do is get at sweep of lights from each end of the strip to the middle, My code seems to run one side one dot at a time, each time the loop runs (all leds) on one side the other side only moves once. (i dont want the back and forward motion) i have shorted total leds used for speed, can some please cast a eye over my code and point me in the right direction (still new to coding)

#include “FastLED.h”
#define NUM_LEDS 300
#define DATA_PIN 6
#define BRIGHTEST 100
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);

}

void loop() {
FastLED.setBrightness(BRIGHTEST);

for (int i = 0; i<13; i++){
for (int e = 24; e>12; e--){
    
  leds[i].setRGB( 255, 0, 0);
  leds[e].setRGB( 255, 0, 0);
   FastLED.show();
delay (500);

leds[i].setRGB( 0, 0, 0);
leds[e].setRGB( 0, 0, 0);
delay (1000);

}}}

Remove the inner loop : for (int e = 24; e>12; e–)

and just add the line : int e = 24 - i;

@JP_Roy thanks for you help 3 nights i have spent on this. now i have some this the work with many thanks

wayne

Here’s a 4 liner that does away with the for loop and delay statement:

void loop() {

fadeToBlackBy(leds, NUM_LEDS, 4);
leds[beat8(10,0)/16].setRGB(255,0,0);
leds[30-beat8(10,0)/16].setRGB(255,0,0);
FastLED.show();

}

Still been playing with my code, What i am now trying to do is as the dot fills once to the center i want all leds to turn off i have been trying to use
if (i>149);
set[Num_LED] (0,0,0) **or somthing like this
My full code so far
*************************************

#include “FastLED.h”
#define NUM_LEDS 300
#define DATA_PIN 6
#define BRIGHTEST 100
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);

}

void loop() {
FastLED.setBrightness(BRIGHTEST);

for (int i = 0; i<149; i++){
 int e = 299 - i;
leds[i].setRGB( 255,0,0);
leds[e].setRGB( 255,0,0);
  
   FastLED.show();
delay (20);

//leds[i].setRGB( 0, 0, 0); fills the strip as i want if not used
//leds[e].setRGB( 0, 0, 0); fills the Strip as i want if not used

// stuck here to clear all leds**

}}

@wayne_hemmings You could duplicate the loop but set all leds off in the 2nd loop like this :

for (int i = 0; i<149; i++){
int e = 299 - i;
leds[i].setRGB( 255,0,0);
leds[e].setRGB( 255,0,0);

   FastLED.show();
delay (20);

//leds[i].setRGB( 0, 0, 0); fills the strip as i want if not used
//leds[e].setRGB( 0, 0, 0); fills the Strip as i want if not used

// stuck here to clear all leds**

}

for (int i = 0; i<149; i++){
int e = 299 - i;
leds[i].setRGB( 0,0,0);
leds[e].setRGB( 0,0,0);

   FastLED.show();
delay (20);

//leds[i].setRGB( 0, 0, 0); fills the strip as i want if not used
//leds[e].setRGB( 0, 0, 0); fills the Strip as i want if not used

// stuck here to clear all leds**

}}

Thanks JP Roy, code is coming together and I getting a much better understanding on what I am doing, one thing I was thinking (I don’t want the answer yet) is it possible to increase the delay mid loop, what I was thinking how can I get the dot the speed up each time the loop is repeated till the end of the strip, dose this make since I want a dot starts slow and ends fast. Can you point me where to start so I can learn
Many thanks Wayne

@wayne_hemmings yes of course it is possible. Instead of using a constant integer in the line…

delay (20);

you should use a variable such as…

delay (myDelay);

First declare that variable near the top of your sketch, before the setup(). Since you do not want that variable to ever be a negative number I would suggest…

unsigned int myDelay = 20; // or any other number

Then, somewhere inside your… for (int i = 0; i<149; i++) loop , you increase or decrease that variable as you want.

My best advice would be to go through some Arduino tutorial that can be found on YouTube, there are many !!

Also go through the example sketches that come with Arduino and the FastLED library and play, modify them to understand how they work.

If you get stuck, just come back here with a clear problem description, I or someone else within this forum may help.

Good luck !!