Replicating Sim Hubs Rev Bar with Fast LED

So I came across this little project on youtube,

which is pretty simple if I was using SimHub but my project does not so I am trying to figure out how to replicate something similar. So far I have got as far as dicovering the FastLED libary and have the basic programs up and running on my Arduino with a 30 WS2812 Led strip. What i would like to do is use a variable pot to simulate the "speed" input. Based off this i would like the bar to fill a gradient of blue green through orange into red and then back fill from the red end with more red as an over run condition is reached. Pulling this off is beyond my current understanding of FastLED tho and any help of direction would be greatly appreciated

I got this far where an input of 800 from A1 is considered full throttle. My main question is how would I back fill the strip with red for the readings up to 1023?

#include <FastLED.h>

#define NUM_LEDS  30
#define LED_PIN   2

CRGB leds[NUM_LEDS];
uint8_t paletteIndex = 0;

DEFINE_GRADIENT_PALETTE( RPM_gp ) { 
0,0, 255 ,0,
63 ,18,157,4, 
 127, 17, 174,242,
 179, 107, 15, 221,
 200, 235, 63, 196,
238, 255, 0, 0, 
255, 255, 0, 0,
};

const byte POTH            = A1;
int throttle     = 0;
int rpm         = 0;

CRGBPalette16 myPAL = RPM_gp;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(5);
  FastLED.clear();
  Serial.begin(115200);
  Serial.println (" ");
  Serial.println ("Throttle Test");
  }

void loop() {
  fadeToBlackBy(leds, NUM_LEDS, 5);
  throttle = analogRead(POTH); //0 to 1023
  rpm = map(throttle, 0, 800, 0, NUM_LEDS);
  rpm = constrain(rpm, 0, NUM_LEDS);
  fill_palette (leds, rpm, paletteIndex, 255 / NUM_LEDS, myPAL, 255, LINEARBLEND);
  FastLED.show();
  Serial.print(throttle);
  Serial.print("- throttle       rpm - ");
  Serial.println(rpm);
}

I have my code basically working how i want except for the part of my IF loop, I would like it to fill from the last LED back down the strip in the reverse direction. Im sure theres a simple way to do it i'm just not sure how.....

#include <FastLED.h>

#define NUM_LEDS  30
#define LED_PIN   2

CRGB leds[NUM_LEDS];
uint8_t paletteIndex = 0;

DEFINE_GRADIENT_PALETTE( RPM_gp ) { 
0,0, 255 ,0,
63 ,18,157,4, 
 127, 17, 174,242,
 179, 107, 15, 221,
 200, 235, 63, 196,
// 238, 255, 0, 0, 
255, 255, 0, 0,
};

DEFINE_GRADIENT_PALETTE( OVERDRIVE_gp ) {
  0, 255, 0, 0,
  122, 255, 0, 0,
  200, 10, 0, 255,
  255, 10, 0, 255, 
};

const byte POTH   = A1;
int throttle     = 0;
int rpm         = 0;

CRGBPalette16 RPMPAL = RPM_gp;
CRGBPalette16 OVERDRIVEPAL = OVERDRIVE_gp;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(200);
  FastLED.clear();
  Serial.begin(115200);
  Serial.println (" ");
  Serial.println ("Throttle Test");
  }

void loop() {
  fadeToBlackBy(leds, NUM_LEDS, 5);
  throttle = analogRead(POTH); //0 to 1023
  rpm = map(throttle, 0, 800, 0, NUM_LEDS);
  rpm = constrain(rpm, 0, NUM_LEDS);
  fill_palette (leds, rpm, paletteIndex, 255 / NUM_LEDS, RPMPAL, 255, LINEARBLEND);
  
  if (throttle > 800) {
    rpm = map(throttle, 800, 1023, 0, NUM_LEDS);
    rpm = constrain(rpm, 0, NUM_LEDS);
    fill_palette (leds, rpm, paletteIndex, 255 / NUM_LEDS, OVERDRIVEPAL, 255, LINEARBLEND);
    }
  
  FastLED.show();
  Serial.print(throttle);
  Serial.print("- throttle       rpm - ");
  Serial.print(rpm);
  Serial.print("    ");
  if (throttle > 800) {
    Serial.print("OVERDRIVE");
  }
  Serial.println(" ");
}

I have merged your topics due to them having too much overlap on the same subject matter @sugakane.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

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