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(" ");
}