#include <FastLED.h>
//////// Cluster Visuals
//----------------------MODES---------------------
// 1-OEM
// 2-OEM+
// 3-Point bouncing by
// 4-Breathing color
// 5-Roling Rainbow
// 6-RPM Reactive procedural (NOT FINISHED)
// 7-Color1 to Color2 RPM reactive
// 8-Color1 to Color2 SPEED reactive
// 9-RAINBOW RPM REACTIVE
// 10-comet bouncing
int cluster_leds_mode = 2;
// Mode 1 - OEM
uint8_t Clstr1_HUE = 255; //HUE
uint8_t Clstr1_SAT = 0; //Saturation
uint8_t Clstr1_VAL = 255; //Brightness
// Mode 2 - OEM+
uint8_t Clstr2_HUE = 0; //HUE (0-255)
uint8_t Clstr2_SAT = 0; //Saturation (0-255)
uint8_t Clstr2_VAL = 255; //Brightness (0-255)
int Clstr2_Fade_Speed = 3; //Speed (ms per brightness +1, until 255)
// Mode 3 - Point bouncing by
uint8_t Clstr3_HUE = 255; //HUE (0-255)
uint8_t Clstr3_SAT = 0; //Saturation (0-255)
int Clstr3_Speed = 20; //BPMS (waves per minute)
//COMET BOUNCING BY 10
// Mode 4 - Breathing color
uint8_t Clstr4_HUE = 255; //HUE (0-255)
uint8_t Clstr4_SAT = 0; //Saturation (0-255)
int Clstr4_Speed= 20; //BPMS (waves per minute)
// Mode 5 - Roling rainbow
uint8_t Clstr5_HUE = 0; //not a config
uint8_t Clstr5_SAT = 255; //Saturation
uint8_t Clstr5_VAL = 255; //Brightness
int Clstr5_Speed = 20; //Speed (ms per hue +1)
// Mode 7 - Color1 to Color2 RPM reactive
CRGBPalette256 Clstr7_palette;
CHSV Clstr7_palette_hsv1;
CRGB Clstr7_palette_rgb1;
CHSV Clstr7_palette_hsv2;
CRGB Clstr7_palette_rgb2;
uint8_t prev_color2_hue = 0;
uint8_t temp_color2_hue = 0;
boolean colorHSV2_rainbow = true; //Color 2 Rainbow Mode
int color2_hue_speed = 10; //ms per hue value up
//Color1
uint8_t Clstr7_palette_HUE1 = 255; //HUE (0-255)
uint8_t Clstr7_palette_SAT1 = 0; //Saturation (0-255)
uint8_t Clstr7_palette_VAL1 = 255; //Brightness (0-255)
//Color2
uint8_t Clstr7_palette_HUE2 = 255; //HUE (0-255)
uint8_t Clstr7_palette_SAT2 = 255; //Saturation (0-255)
uint8_t Clstr7_palette_VAL2 = 255; //Brightness (0-255)
int Clstr7_RPMmin = 2500; //Change color starting point (0-7000)
int Clstr7_RPMmax = 2600; //Change color ending point (0-7000)
//Mode 8 - Color1 to Color2 SPEED reactive
CRGBPalette256 Clstr8_palette;
CHSV Clstr8_palette_hsv1;
CRGB Clstr8_palette_rgb1;
CHSV Clstr8_palette_hsv2;
CRGB Clstr8_palette_rgb2;
//Color1
uint8_t Clstr8_palette_HUE1 = 255; //HUE (0-255)
uint8_t Clstr8_palette_SAT1 = 0; //Saturation (0-255)
uint8_t Clstr8_palette_VAL1 = 255; //Brightness (0-255)
//Color2
uint8_t Clstr8_palette_HUE2 = 255; //HUE (0-255)
uint8_t Clstr8_palette_SAT2 = 255; //Saturation (0-255)
uint8_t Clstr8_palette_VAL2 = 255; //Brightness (0-255)
int Clstr8_SPEEDmin = 120; //Change color starting point (0-7000)
int Clstr8_SPEEDmax = 130; //Change color ending point (0-7000)
//Mode 9 - RAINBOW RPM REACTIVE
uint8_t Clstr9calcAdd = 0; //not a config
boolean Clstr9autoRoll = true; //Activate autoroll mode
int Clstr9autoRollSpeed = 20; //Speed (ms per hue +1)
//TO ADD SETTINGS
//Extra 1 - Ignition cut Reaction
boolean ClstrLdsXtra1 = false;
uint8_t ClstrXtra1_CutHUE = 255; //Color
uint8_t ClstrXtra1_CutSAT = 255; //Saturation
uint8_t ClstrXtra1_CutVAL = 255; //Brightness
#define cluster_main_NUM_LEDS 32
#define cluster_screen_NUM_LEDS 6 //screen strip total leds
#define cluster_shift_light_NUM_LEDS 1 //shift light strip total leds
#define LED_PIN 5
#define NUM_LEDS 32
#define BRIGHTNESS 64
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB cluster_leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
CRGBPalette16 currentPalette;
TBlendType currentBlending;
float mapfloat(long x, long in_min, long in_max, long out_min, long out_max) {
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
}
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
float cluster_leds_brightness = 0.9;
/*
CRGB ColorFraction(CRGB colorIn, float fraction, int iPos) {
//fraction = min(1.0f, fraction);
colorIn.r = colorIn.r * (1.0f - fraction);
colorIn.g = colorIn.g * (1.0f - fraction);
colorIn.b = colorIn.b * (1.0f - fraction);
CRGB lastcolor = cluster_leds[iPos];
int test = lastcolor.r + colorIn.r - 255;
if (test > 0){
lastcolor.r =- test;
lastcolor.g =- test;
lastcolor.b =- test;
lastcolor.r =+ colorIn.r;
lastcolor.g =+ colorIn.g;
lastcolor.b =+ colorIn.b;
}
return lastcolor;
}
*/
CRGB ColorFraction(CRGB colorIn, float fraction, int iPos)
{
fraction = min(1.0f, fraction);
CRGB baseColor = cluster_leds[iPos];
//CRGB finalColor = CRGB(colorIn).fadeToBlackBy(255 * (1.0f - fraction));
colorIn.r = colorIn.r * fraction;
colorIn.g = colorIn.g * fraction;
colorIn.b = colorIn.b * fraction;
int test1 = baseColor.r + colorIn.r - 255;
int test2 = baseColor.g + colorIn.g - 255;
int test3 = baseColor.b + colorIn.b - 255;
if (test1 > 0){
baseColor.r = baseColor.r - test1;
baseColor.g = baseColor.g - test1;
baseColor.b = baseColor.b - test1;
baseColor.r = baseColor.r + colorIn.r;
}
if (test2 > 0){
baseColor.r = baseColor.r - test2;
baseColor.g = baseColor.g - test2;
baseColor.b = baseColor.b - test2;
baseColor.g = baseColor.g + colorIn.g;
}
if (test3 > 0){
baseColor.r = baseColor.r - test3;
baseColor.g = baseColor.g - test3;
baseColor.b = baseColor.b - test3;
baseColor.b = baseColor.b + colorIn.b;
}
return baseColor;
}
void DrawPixels(float fPos, float count, CRGB color) {
// Calculate how much the first pixel will hold
float availFirstPixel = 1.0f - (fPos - (long)(fPos));
float amtFirstPixel = min(availFirstPixel, count);
float remaining = min(count, cluster_main_NUM_LEDS-fPos);
int iPos = fPos;
// Blend (add) in the color of the first partial pixel
if (remaining > 0.0f) {
cluster_leds[iPos++] = ColorFraction(color, amtFirstPixel, iPos);
remaining -= amtFirstPixel;
}
// Now draw any full pixels in the middle
while (remaining > 1.0f) {
cluster_leds[iPos++] = color; remaining--;
}
// Draw tail pixel, up to a single full pixel
if (remaining > 0.0f) {
cluster_leds[iPos] = ColorFraction(color, remaining, iPos);
}
}
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(cluster_leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void loop()
{
uint8_t current_RPM = beatsin8(5,0,255,0,0);
uint8_t current_SPEED = beatsin8(5,0,255,0,0);
EVERY_N_MILLISECONDS(4){
float mode5Speed = mapfloat(current_SPEED,0,255,0,10);
float mode5rpm = mapfloat(current_RPM,0,255,0,15);
fill_solid( cluster_leds, cluster_main_NUM_LEDS, CRGB::White);
DrawPixels(4, mode5Speed, CHSV(255, 255, 255*cluster_leds_brightness));
DrawPixels(15, mode5rpm, CHSV(255, 255, 255*cluster_leds_brightness));
}
FastLED.show();
FastLED.delay(500 / UPDATES_PER_SECOND);
}