Reverse / change direction of LEDs

Hi,

Thank you taking a look at my question.

I’m very new to all of this but am trying to learn through doing.

I have a simple question - I’d like to change the LED flow direction in this Knightrider script using FastLED:

// Knight Rider Type Patterns by Chemdoc77
// Based on the DemoReel100 example of the FastLED library.
// Goes either back and forth with a tail or goes only forward with a tail.

#include “FastLED.h”
#define NUM_LEDS 29
#define chipset NEOPIXEL //use WS2812B if not using NEOPIXEL products.
#define Data_pin 6

#define BRIGHTEST 40 // the BRIGHTEST range is from 0 to 255.

CRGB leds[NUM_LEDS];

//pre-declaration of functions
void cd77_sinelon_oneway();
void cd77_sinelon();

void setup() {
delay(2000); // power-up safety delay
FastLED.addLeds<chipset, Data_pin/,GRB/>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // uncomment “,GRB” if you use the WS2812B chipset.
FastLED.setBrightness(BRIGHTEST);

}

void loop () {

cd77_sinelon_oneway(30, CRGB::Red);

}

// Functions ======================

void cd77_sinelon_oneway(uint8_t BPM, CRGB color)
{
// a colored dot going in one direction with fading tail
fadeToBlackBy( leds, NUM_LEDS, 10); //change 10 to smaller or larger number to adjust the length of the tail.
uint8_t u= beat8(BPM,0); //BPM will allow you to adjust the speed the dot is moving.
uint8_t pos=map(u,0,255,0,NUM_LEDS);
leds[pos] = color;
FastLED.show();
}

void cd77_sinelon(uint8_t BPM, CRGB color )
{
// a colored dot sweeping back and forth, with fading tail
fadeToBlackBy( leds, NUM_LEDS, 20); //change 20 to smaller or larger number to adjust the length of the tail.
uint8_t pos = beatsin16(BPM,0,NUM_LEDS); //BPM will allow you to adjust the speed the dot is moving.
leds[pos] = color;
FastLED.show();
}

Do you just want a solution, or do you want to understand how to do it?

Please read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

Hi, thank you for getting back to me.

I was hoping you'd be able to suggest a amendment or addition to the code. Any advice to help me understand the process would also be greatly received.

Thanks again

Apologies, here’s the code auto-formatted:

// Knight Rider Type Patterns by Chemdoc77
// Based on the DemoReel100 example of the FastLED library.
// Goes either back and forth with a tail or goes only forward with a tail.

#include "FastLED.h"
#define NUM_LEDS 29
#define chipset NEOPIXEL //use WS2812B if not using NEOPIXEL products.
#define Data_pin 6

#define BRIGHTEST 40  // the BRIGHTEST range is from 0 to 255.

CRGB leds[NUM_LEDS];

//pre-declaration of functions
void cd77_sinelon_oneway();
void cd77_sinelon();


void setup() {
 delay(2000); // power-up safety delay
 FastLED.addLeds<chipset, Data_pin/*,GRB*/>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // uncomment ",GRB" if you use the WS2812B chipset.
 FastLED.setBrightness(BRIGHTEST);

}

void loop () {

 cd77_sinelon_oneway(30, CRGB::Red);

}

// Functions ======================

void cd77_sinelon_oneway(uint8_t BPM, CRGB color)
{
 // a colored dot going in one direction with fading tail
 fadeToBlackBy( leds, NUM_LEDS, 10);  //change 10 to smaller or larger number to adjust the length of the tail.
 uint8_t u = beat8(BPM, 0); //BPM will allow you to adjust the speed the dot is moving.
 uint8_t pos = map(u, 0, 255, 0, NUM_LEDS);
 leds[pos] = color;
 FastLED.show();
}

void cd77_sinelon(uint8_t BPM, CRGB color )
{
 // a colored dot sweeping back and forth, with fading tail
 fadeToBlackBy( leds, NUM_LEDS, 20); //change 20 to smaller or larger number to adjust the length of the tail.
 uint8_t pos = beatsin16(BPM, 0, NUM_LEDS); //BPM will allow you to adjust the speed the dot is moving.
 leds[pos] = color;
 FastLED.show();
}
// Knight Rider Type Patterns by Chemdoc77
// Based on the DemoReel100 example of the FastLED library.
// Goes either back and forth with a tail or goes only forward with a tail.

#include "FastLED.h"
#define NUM_LEDS 29
#define chipset NEOPIXEL //use WS2812B if not using NEOPIXEL products.
#define Data_pin 6

#define BRIGHTEST 40  // the BRIGHTEST range is from 0 to 255.

CRGB leds[NUM_LEDS];

//pre-declaration of functions
void cd77_sinelon_oneway();
void cd77_sinelon();


void setup() {
  delay(2000); // power-up safety delay
  FastLED.addLeds<chipset, Data_pin/*,GRB*/>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // uncomment ",GRB" if you use the WS2812B chipset.
  FastLED.setBrightness(BRIGHTEST);

}

void loop () {

  cd77_sinelon_oneway(30, CRGB::Red);

}

// Functions ======================

void cd77_sinelon_oneway(uint8_t BPM, CRGB color)
{
  // a colored dot going in one direction with fading tail
  fadeToBlackBy( leds, NUM_LEDS, 10);  //change 10 to smaller or larger number to adjust the length of the tail.
  uint8_t u = beat8(BPM, 0); //BPM will allow you to adjust the speed the dot is moving.
  uint8_t pos = map(u, 0, 255, 0, NUM_LEDS);
  leds[pos] = color;
  FastLED.show();
}

void cd77_sinelon(uint8_t BPM, CRGB color )
{
  // a colored dot sweeping back and forth, with fading tail
  fadeToBlackBy( leds, NUM_LEDS, 20); //change 20 to smaller or larger number to adjust the length of the tail.
  uint8_t pos = beatsin16(BPM, 0, NUM_LEDS); //BPM will allow you to adjust the speed the dot is moving.
  leds[pos] = color;
  FastLED.show();
}

In code tags like described in para #7 of the how to use this forum sticky.

You didn’t use code tags to post your code. It’s important that you use them - if you don’t, the forum software sometimes interprets sequences of characters in the code as directives to format text in some way. It won’t display those sequences, and it will unexpectedly reformat the rest of the text. When that happens, and someone tries to copy your code and paste it into the IDE, it often throws an error, and readers will complain that the code fails to compile. Using code tags also makes it easier to read, and can be copied with a single mouse click.


The code tags make the code look

like this

when posting source code files.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the [code] and [/code] metatags.

try changing:

uint8_t pos = map(u, 0, 255, 0, NUM_LEDS);

to

uint8_t pos = map(u, 255, 0, 0, NUM_LEDS);

Amazing!!!!

Aarg, hank you for your patience.

Massively appreciated!