//||||||||||||||||||||PINs
//Pinos 10 ,11 mortos
//---------------LIGHTS---------------------
#define PIN_mosfet_AE_RIGHT 4 //Right angel eye mosfet
#define PIN_mosfet_AE_LEFT 5 //Left angel eye mosfet
//---------------ENGINE---------------------
#define PIN_ignition_CUT 6 //Ignition cut mosfet
#define PIN_minimos_in_signal 7 //Low Beam on signal
//--------------"INPUTS"--------------------
#define PIN_remote_in_signal_lock 8 //Remote close signal
#define PIN_remote_in_signal_unlock 19 //Remote open signal
#define PIN_ignitionON_in_signal 24 //Ignition on signal
#define PIN_driver_door_sensor 25 //Driver door open signal
#define PIN_passenger_door_sensor 26 //Passenger door open signal
#define in_PIN_fuel_changer 11 //change fuel
//--------------"OUTPUTS"-------------------
#define PIN_out_signal_lock 12 //Lock mosfet
#define PIN_set_fuel 10
#define PIN_out_signal_unlock 14 //Unlock mosfet
//---------------"DATA"--------------------
#define PIN_screen4digit_clock 23 //Cluster 4digit Clock
#define PIN_screen4digit_DI 22 //Cluster 4digit Data
//||||||||||||||||||||Libraries
#include <Arduino.h> //main arduino
#include <avr/sleep.h> //sleep functions
#include "TM1637.h" //4 digit screens
#include <Servo.h> //Servos
#include <FastLED.h> //FastLED
//||||||||||||||||||||Lib Actions
TM1637 disp(PIN_screen4digit_clock, PIN_screen4digit_DI); //create and name an 4DigitDisplay object
//||||||||||||||||||||Led Strips
//ceiling
//tens de dividir os ceiling leds como fizeste no cluster, por parte e chamar todas juntas depois
#define inside_NUM_LEDS 26 //stip total leds
#define inside_LED_PIN 33 //stip pin number
CRGB inside_leds[inside_NUM_LEDS];
//foot driver
#define foot_NUM_LEDS 21 //stip total leds
#define foot_LED_PIN 34 //strip pin number
CRGB foot_leds[foot_NUM_LEDS];
//cluster
#define cluster_main_NUM_LEDS 32 //main strip total leds
#define cluster_screen_NUM_LEDS 6 //screen strip total leds
#define cluster_shift_light_NUM_LEDS 1 //shift light strip total leds
#define cluster_LED_PIN 35 //strip pin number
CRGB cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS + cluster_shift_light_NUM_LEDS];
//||||||||||||||||||||Software Controled Variables
boolean ignitionCutted = false;
boolean final_pulse_RPM = false;
boolean final_pulse_SPEED = false;
//DEBUG
//serial
int codeLPSs = 0;
//wokwi
boolean wokwi_debug = true;
//Acomulatives
float distance_traveled = 0;
//Run Onces
boolean first_time_after_lock_runned = true;
boolean ignitionON_runned = false;
boolean ignitionOFF_runned = false;
boolean after_open_driver_door_runned = false;
boolean after_open_passenger_door_runned = false;
boolean driver_door_open_runned = false;
boolean driver_door_close_runned = false;
boolean passenger_door_open_runned = false;
boolean passenger_door_close_runned = false;
boolean prev_mode_defined;
int prev_mode_num;
//Other
long largenumber = 2000000000;
//Various on triggers
boolean AE_on = false;
boolean AE_on_by_unlock = false;
boolean AE_on_by_switch = false;
boolean AE_on_by_car_on = false;
boolean AE_on_by_door_open = false;
int AEx_subtr = 0;
boolean inside_leds_on = false;
boolean inside_leds_on_by_unlock = false;
boolean inside_leds_on_by_doors = false;
boolean foot_leds_on = false;
boolean cluster_leds_on = false;
boolean cluster_led_on_by_switch = false;
boolean cluster_leds_on_by_unlock = false;
int cluster_leds_x_subtr = 255;
//Door States
boolean passenger_door_open = false;
boolean driver_door_open = false;
//Lock/Unlock States
boolean car_open = true;
boolean lock_runned = false;
boolean unlock_runned = false;
boolean to_be_closed = false;
boolean to_be_opened = false;
//Interrupts
boolean _4digit_bottom_left_interrupt1 = false;
boolean _4digit_bottom_left_interrupt2 = false;
boolean _4digit_bottom_left_interrupt3 = false;
boolean _4digit_bottom_left_interrupt = false;
boolean interrupt_angel_eyes = false;
boolean interrupt_angel_eyes1 = false;
boolean interrupt_inside_LEDs = false;
//Other
int delay_stop_4dgt_for_N_millis = 0;
int disaServoAngle = 175;
boolean shift_light_ON = false;
uint8_t AE1_current_AE_brightness = 0;
uint8_t insideLds1_current_brightness = 0;
uint8_t insideLds2_current_brightness = 0;
uint8_t brightness_cluster_normal = 0;
uint8_t brightness_foot_normal = 0;
uint8_t onpix_foot_normal = 0;
unsigned long prev_timeRPM = 0;
unsigned long current_RPM_RAW;
unsigned long current_RPM_RAW_final;
int current_RPM;
unsigned long prev_timeSPEED = 0;
unsigned long current_SPEED_RAW;
int current_SPEED;
//Timers
unsigned long time_RPM_changing_intreval = 0;
unsigned long time_SPEED_changing_intreval = 0;
unsigned long time_ignition_cut = 0;
unsigned long time_ignition_cut_2 = 0;
unsigned long time_ignition_cut_3 = 0;
unsigned long first_time_after_unlock = 0;
unsigned long second_time_after_unlock = 0;
unsigned long first_time_after_lock = 0;
unsigned long time_hold_lock = 0;
unsigned long time_hold_unlock = 0;
unsigned long off_modules_time_after_lock = 0;
unsigned long time_animation1 = 0;
unsigned long time_stop_4dgt_for_N_millis = 0;
unsigned long time_after_open_driver_door = 0;
unsigned long time_after_open_passenger_door = 0;
//Animation Delays
int animation1 = 1;
int delay_animation1 = 0;
//||||||||||||||||||||Praticamente n��o se mechem
//Hold Locking/Unlocking delays
int long delay_hold_lock = 1000; //ms
int long delay_hold_unlock = 1000; //ms
//LOW RPM and SPEED cleaning
int long SPEED_changing_intreval = 40; // more means shows more low range of speed , currently 40 is like 12kms/h
int long RPM_changing_intreval = 55; // no mecher senhor
//||||||||||||||||||||Default Config
//||||||||||Screens
boolean serialDebug = true; // OG Serial through usb, SLOWS LPS
boolean LPSDebug = false; // SERIAL SHOW LPS
int long delay_SERIAL_SHOW = 100; //ms
int long delay_LPS = 1000; //ms
//||||||||||Delays
//unlock delays
int long first_delay_after_unlock = 1000000; //ms
int long second_delay_after_unlock = 340000; //ms
//lock delays
int long first_delay_after_lock = 10000; //ms
//off modules
int long off_modules_delay_after_lock = 60000; //ms
int long delay_after_open_driver_door = 50000;
int long delay_after_open_passenger_door = 50000;
//||||||||||ENGINE
//////// Launch Control
int launch_control_mode = 1;
//Mode 1 - Normal ignition cut on RPMs
int LchCtrl1_RPM = 4000; //Launch control RPM limit
int LchCtrl1_ignition_cut_delay = 30; //Delay after cutting ignition in millis
//Mode 2 - Diesel like ignition cut
int LchCtrl2_RPM = 2800; //Launch control RPM limit
int LchCtrl2_delay_ignition_cut_2 = 23; //How much time it stays cut
int LchCtrl2_delay_ignition_cut_3 = 32; //How much time its on after cut
//Disa
int disaOpen1RPM = 4200;
int disaOpen2RPM = 4800;
//||||||||||Visuals
//Shift Light Mode 1
int shift_light_blink_intreval = 0;
int shift_light_RPM = 2500;
//Shift Light Mode 2
int shift_light_RPM_Good = 5600;
int shift_light_RPM_Perfect = 5900;
int shift_light_RPM_Over = 6400;
//||||||||||Sounds
//||||||||||Modes
//////// Foot Light
int foot_leds_mode = 1;
//smooth
int foot_leds_x_subtr = 0;
//Mode 1 - Smooth on
int foot_lds1_on_fade_speed = 4;
int foot_lds1_off_fade_speed = 9;
// Extra 1 - Ignition cut Reaction
boolean footLdsXtra1 = false;
uint8_t footLdsXtra1_CutHUE = 255; //Color
uint8_t footLdsXtra1_CutSAT = 255; //Saturation
uint8_t footLdsXtra1_CutVAL = 255; //Brightness
//////// Angel Eyes
int AE_mode = 1;
int AE_mode_w_unlocked = 3;
// Mode changers:
// Define a variable to store the previous mode value
int previous_AE_mode = 1; // Set an initial default mode
bool AE_mode_changed1 = false; // Flag to track if the mode has been changed
unsigned long AE_mode_change1_start_time = 0; // Timestamp when mode change started
unsigned long AE_mode_change1_duration = 30000; // Duration in milliseconds (30 seconds)
//Mode Smooth
bool smooth_AE_mode = true;
int AEx_on_fade_speed = 2;
int AEx_off_fade_speed = 3;
//Mode 1 - Basic On
//Mode 2 - Sideways Wave
int AE2_speed = 120;
//Mode 3 - Sparkle
// Set the interval between sparkle updates (in milliseconds)
int AE_sparkle_interval = 20;
// Custom probability (0-255), higher values mean LEDs turn on less frequently
int AE_sparkle_probability = 50;
bool AE_applyFade = true; // Set this to false if you don't want the fading effect
int AE_FADE_AMOUNT = 8;
//////// Inside Lights
int inside_leds_mode = 1;
int inside_leds_mode_w_unlocked = 3;
//smooth
boolean smooth_inside_leds_mode = true;
int insd_leds_x_subtr = 255;
// Mode changers:
// Define a variable to store the previous mode value
int previous_inside_leds_mode = 1; // Set an initial default mode
bool inside_leds_mode_changed = false; // Flag to track if the mode has been changed
unsigned long inside_leds_mode_change_start_time = 0; // Timestamp when mode change started
unsigned long inside_leds_mode_change_duration = 30000; // Duration in milliseconds (30 seconds)
// Mode 1 - OEM
int insideLds1_HUE = 255; //HUE
int insideLds1_SAT = 0; //Saturation
int insideLds1_on_fade_speed = 4; //ms
int insideLds1_off_fade_speed = 6; //ms
// Mode 2 - Rainbow
uint8_t insideLds2_HUE = 0;
int insideLds2_SAT = 255; //Saturation
int insideLds2_Speed = 20; //ms
int insideLds2_on_fade_speed = 20; //ms
int insideLds2_off_fade_speed = 20; //ms
// Mode 3 - Sparkle
// Set whether LEDs fade slowly to black instead of an instant blackout
bool insideLds3_fadeSlowly = true; // Set to true for a fade effect
// Set the default mode to blink in groups
bool insideLds3_blinkInGroups = true;
// Define the number of groups and LEDs per group
int insideLds3_numGroups = 3;
int insideLds3_ledsPerGroup[] = {16, 5, 5}; // Define the number of LEDs for each group
int insideLds3_fadeAmount = 15; //0-255
int insideLds3_fadeSpeed = 1; //ms
// Extra 1 - Ignition cut Reaction
boolean insideLdsXtra1 = false;
uint8_t insideLdsXtra1_CutHUE = 255; //Color
uint8_t insideLdsXtra1_CutSAT = 255; //Saturation
uint8_t insideLdsXtra1_CutVAL = 255; //Brightness
//////// 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 = 6;
int cluster_leds_mode_w_unlocked = 11;
float cluster_leds_brightness = 0.4; // multyplier 0 to 1
//smooth code
boolean smooth_cluster_leds_mode = true;
int cluster_leds_on_fade_speed = 3;
int cluster_leds_off_fade_speed = 3;
// Mode Changers:
// Define a variable to store the previous mode value
int previous_cluster_leds_mode = cluster_leds_mode; // Set an initial default mode
bool cluster_leds_mode_changed1 = false; // Flag to track if the mode has been changed
unsigned long cluster_leds_mode_change1_start_time = 0; // Timestamp when mode change started
unsigned long cluster_leds_mode_change1_duration = 30000; // Duration in milliseconds (30 seconds)
// 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 = 168; //HUE (0-255)
uint8_t Clstr2_SAT = 0; //Saturation (0-255)
uint8_t Clstr2_VAL = 210; //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 6 - RPM and Speed reactive gradual
int Clstr6_RPM_offset = 16;
int Clstr6_SPEED_offset = 4;
int Clstr6_RPM_num_Leds = 14;
int Clstr6_SPEED_num_Leds = 14;
//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;
//color 2 rainbow mode
boolean colorHSV2_rainbow = false; //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 = 3000; //Change color intercection starting point (0-7000)
int Clstr7_RPMmax = 4500; //Change color intercection 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)
//Mode 10 - Sparkle
boolean Clstr10_fadeSlowly = true;
//TO ADD and review 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
//Extra 1 - Ignition cut Reaction
boolean ClstrLdsXtra2 = false;
boolean ClstrLdsXtra2AllwaysOn = false;
/////////////TESTE
CRGBPalette256 currentPalette;
CHSV hsv;
CRGB rgb;
//////// Shift Light
int shift_light_mode = 2;
//Mode 1 - Only Blinking at defined RPMs
int ShftL1_shift_light_blink_over_intreval = 60; //Blink interval in millis
CRGB ShftL1OverClr = CRGB::Red; //Color to blink when over
CRGB ShftL1OverBlankClr = CRGB::Black; //Second Color to blink when over
//Mode 2 - Full arcade game style with 3 levels of lights
int ShftL2_shift_light_blink_over_intreval = 60; //Blink interval in millis
CRGB ShftL2GoodClr = CRGB::Blue; //Color to light when goood
CRGB ShftL2PerfClr = CRGB::Green; //Color to light when perfect
CRGB ShftL2OverClr = CRGB::Red; //Color to blink when over
CRGB ShftL2OverBlankClr = CRGB::Black; //Second Color to blink when over
//||||||||||||||||||||VOIDS
CRGB ColorFraction(CRGB colorIn, float fraction, int iPos) {
CRGB baseColor = cluster_leds[iPos];
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);
}
}
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;
}
void putin_sleep_mode() {
sleep_enable();
//TRIGGERS to wake up with void wakeUp
detachInterrupt(digitalPinToInterrupt(2));
detachInterrupt(digitalPinToInterrupt(3));
attachInterrupt(digitalPinToInterrupt(2), wakeUp, CHANGE);
attachInterrupt(digitalPinToInterrupt(3), wakeUp, CHANGE);
attachInterrupt(digitalPinToInterrupt(PIN_remote_in_signal_unlock), wakeUp, RISING);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
//ACOES MESMO ANTES DE LIGAR O SLEEPMODE
//disp disp.displayByte(_empty, __G, __P, __S);
sleep_cpu();
//codigo a fazer depois de acordar
}
void wakeUp() {
sleep_disable();
//restore previous atachInterrupts
detachInterrupt(digitalPinToInterrupt(PIN_remote_in_signal_unlock));
pinMode(PIN_remote_in_signal_unlock, INPUT);
attachInterrupt(digitalPinToInterrupt(2), risingRPM, RISING);
attachInterrupt(digitalPinToInterrupt(3), risingSPEED, RISING);
//disp disp.displayByte(__h, __O, __q, __E);
}
void risingRPM() {
//timer caso o codigo nao passe por aqui por x tempo
time_RPM_changing_intreval = millis();
//if its the 1st pulse start counting, else calculate
if (final_pulse_RPM == false) {
prev_timeRPM = micros();
final_pulse_RPM = true;
} else {
current_RPM_RAW = micros() - prev_timeRPM;
current_RPM_RAW = 28000000 / current_RPM_RAW;
//final rpm
if (current_RPM_RAW > 7000) {
current_RPM_RAW = 0;
}
current_RPM_RAW_final = current_RPM_RAW;
current_RPM = current_RPM_RAW;
final_pulse_RPM = false;
}
}
void risingSPEEDold() {
if (final_pulse_SPEED == false) {
prev_timeSPEED = micros();
final_pulse_SPEED = true;
} else {
EVERY_N_MILLIS(40) {
current_SPEED_RAW = micros() - prev_timeSPEED;
if (current_SPEED_RAW > 900) {
current_SPEED_RAW = 6313 * 63L / current_SPEED_RAW;
if (current_SPEED_RAW < 300 && current_SPEED_RAW > 0) {
//final speed
current_SPEED = current_SPEED_RAW;
}
}
}
final_pulse_SPEED = false;
}
}
unsigned long time_SPEED_changing_interval = 0;
const unsigned long speedTimeout = 2000; // Time limit (in milliseconds) between pulses
const int speedThreshold = 10; // Threshold speed below which the final speed will be set to 0
void risingSPEED() {
if (final_pulse_SPEED == false) {
prev_timeSPEED = micros();
final_pulse_SPEED = true;
} else {
EVERY_N_MILLIS(40) {
current_SPEED_RAW = micros() - prev_timeSPEED;
if (current_SPEED_RAW > 900) {
current_SPEED_RAW = 6313 * 63L / current_SPEED_RAW;
if (current_SPEED_RAW < 300 && current_SPEED_RAW > 0) {
// Set the final speed
current_SPEED = current_SPEED_RAW;
}
}
}
final_pulse_SPEED = false;
// Update the interval time
time_SPEED_changing_interval = millis();
// Check if there has been a long enough time since the last pulse
if (millis() - time_SPEED_changing_interval > speedTimeout) {
// Check if the current speed is below the threshold and set it to 0 if so
if (current_SPEED < speedThreshold) {
current_SPEED = 0;
}
}
}
}
void closeCar(boolean changeState) {
if (lock_runned == false) {
digitalWrite(PIN_out_signal_lock, HIGH);
time_hold_lock = millis();
lock_runned = true;
to_be_closed = true;
}
if (millis() >= time_hold_lock + delay_hold_lock) {
digitalWrite(PIN_out_signal_lock, LOW);
car_open = false;
to_be_closed = false;
lock_runned = false;
}
}
void openCar(boolean changeState) {
if (unlock_runned == false) {
digitalWrite(PIN_out_signal_unlock, HIGH);
time_hold_unlock = millis();
unlock_runned = true;
to_be_opened = true;
}
if (millis() >= time_hold_unlock + delay_hold_unlock) {
digitalWrite(PIN_out_signal_unlock, LOW);
car_open = true;
to_be_opened = false;
unlock_runned = false;
}
}
void cutIgnition(boolean value) {
if (value == true) {
ignitionCutted = true;
analogWrite(PIN_ignition_CUT, 0);
} else {
ignitionCutted = false;
analogWrite(PIN_ignition_CUT, 255);
}
}
void stop_4dgt_for_N_millis(int delay_time) {
time_stop_4dgt_for_N_millis = millis();
delay_stop_4dgt_for_N_millis = delay_time;
}
byte increment;
void setup() {
//DEBUG
if (wokwi_debug == true) {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}
//||||||||||Serial Comunications
Serial.begin(19200);
//||||||||||INTERRUPTS
attachInterrupt(digitalPinToInterrupt(2), risingRPM, RISING);
attachInterrupt(digitalPinToInterrupt(3), risingSPEED, RISING);
//||||||||||FASTELEDS LEDS
FastLED.addLeds<WS2812, inside_LED_PIN, GRB>(inside_leds, inside_NUM_LEDS);
FastLED.addLeds<WS2812, foot_LED_PIN, GRB>(foot_leds, foot_NUM_LEDS);
FastLED.addLeds<WS2812, cluster_LED_PIN, GRB>(cluster_leds, cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS + cluster_shift_light_NUM_LEDS);
FastLED.setBrightness(255);
//FastLED.setCorrection(TypicalLEDStrip);
//||||||||||OBJECTS
randomSeed(analogRead(14));
//4 Digit - leftDown
//disp disp.init(); // iniciar
//disp disp.set(3); // brilho 0 - 7
//||||||||||PINMODES
//out
pinMode(PIN_set_fuel, OUTPUT);
pinMode(PIN_ignition_CUT, OUTPUT);
pinMode(PIN_mosfet_AE_LEFT, OUTPUT);
pinMode(PIN_mosfet_AE_RIGHT, OUTPUT);
pinMode(PIN_out_signal_lock, OUTPUT);
pinMode(PIN_out_signal_unlock, OUTPUT);
//in
pinMode(PIN_minimos_in_signal, INPUT);
pinMode(PIN_remote_in_signal_unlock, INPUT);
pinMode(PIN_remote_in_signal_lock, INPUT);
pinMode(PIN_ignitionON_in_signal, INPUT);
pinMode(PIN_passenger_door_sensor, INPUT_PULLUP);
pinMode(PIN_driver_door_sensor, INPUT_PULLUP);
pinMode(in_PIN_fuel_changer, INPUT_PULLUP);
//set states
analogWrite(PIN_ignition_CUT, 255);
digitalWrite(PIN_out_signal_unlock, LOW);
digitalWrite(PIN_out_signal_lock, LOW);
}
void loop() {
//CHECK IF IS RUNNING
if (millis() - time_RPM_changing_intreval > RPM_changing_intreval) {
time_RPM_changing_intreval = millis();
current_RPM = 0;
final_pulse_RPM = false;
}
//DEBUG
if (wokwi_debug == true) {
int current_RPM_wat = analogRead(A0);
current_RPM = map(current_RPM_wat, 0, 1020, 0, 7000);
int current_SPEED_wat = analogRead(A1);
current_SPEED = map(current_SPEED_wat, 0, 1020, 0, 230);
}
//Check Inputs
if (digitalRead(PIN_minimos_in_signal) == HIGH) {
AE_on_by_switch = true;
cluster_led_on_by_switch = true;
} else {
AE_on_by_switch = false;
cluster_led_on_by_switch = false;
}
EVERY_N_MILLIS(200) {
//fuel changer
if (digitalRead(in_PIN_fuel_changer) == HIGH) {
analogWrite(PIN_set_fuel, HIGH);
} else {
analogWrite(PIN_set_fuel, LOW);
}
}
//EVERY_N_MILLIS(400){
// if (Serial.available() > 0){
// String dataserial = Serial.readStringUntil("\n");
// LchCtrl1_RPM = dataserial.toInt();
// Serial.println(dataserial.toInt());
// }
// }
if (
_4digit_bottom_left_interrupt1 == true || _4digit_bottom_left_interrupt2 == true || _4digit_bottom_left_interrupt3 == true) {
_4digit_bottom_left_interrupt = true;
} else {
_4digit_bottom_left_interrupt = false;
}
//4 DIGIT SCREEN
if (digitalRead(PIN_ignitionON_in_signal) == HIGH) {
if (digitalRead(PIN_minimos_in_signal) == HIGH) {
//DISPLAY VRIGHTNESS CHANGE
} else {
//DISPLAY VRIGHTNESS CHANGE
}
} else {
//DO TIMER TO DO THIS AFTER A WHILE
//DISPLAY VRIGHTNESS CHANGE
}
//on cluster screen on
if (digitalRead(PIN_ignitionON_in_signal) == HIGH) {
if (digitalRead(PIN_minimos_in_signal) == HIGH) {
fill_solid(cluster_leds + cluster_main_NUM_LEDS, cluster_screen_NUM_LEDS, CHSV(225, 0, 160));
} else {
fill_solid(cluster_leds + cluster_main_NUM_LEDS, cluster_screen_NUM_LEDS, CHSV(225, 0, 255));
}
} else {
//DO TIMER TO DO THIS AFTER A WHILE
fill_solid(cluster_leds + cluster_main_NUM_LEDS, cluster_screen_NUM_LEDS, CHSV(255, 0, 0));
}
//When engine is running
if (current_RPM > 100) {
//turn off the bottom side of the cluster OEM screen
fill_solid(cluster_leds + cluster_main_NUM_LEDS + 3, cluster_screen_NUM_LEDS - 3, CHSV(255, 0, 0));
//Turn on Angle Eyes
AE_on_by_car_on = true;
} else {
//Turn off Angle Eyes
AE_on_by_car_on = false;
}
//Check GPL state
/*
EVERY_N_MILLISECONDS(200) {
if (digitalRead(PIN_GPL_l1) == LOW) {
int GPL_amount = 1;
} else {
}
if (digitalRead(PIN_GPL_l2) == LOW) {
int GPL_amount = 2;
} else {
}
if (digitalRead(PIN_GPL_l3) == LOW) {
int GPL_amount = 3;
} else {
}
if (digitalRead(PIN_GPL_l4) == LOW) {
int GPL_amount = 4;
} else {
}
}
*/
//Quando ignicao estiver on
if (digitalRead(PIN_ignitionON_in_signal) == HIGH) {
//Current Trip distance calculator
EVERY_N_MILLISECONDS(250) {
//passar de kms/h para m/s e adicionar a variavel de distancia pecorrida na viagem.
float slave_calc = current_SPEED * 100;
slave_calc = slave_calc / 60;
slave_calc = slave_calc / 60;
slave_calc = slave_calc / 4;
slave_calc = slave_calc / 100;
distance_traveled += slave_calc;
}
//Launch Control
switch (launch_control_mode) {
case 1:
if (current_RPM_RAW_final > LchCtrl1_RPM && current_SPEED < 20) {
cutIgnition(true);
} else if (millis() - time_ignition_cut > LchCtrl1_ignition_cut_delay) {
time_ignition_cut = millis();
cutIgnition(false);
}
break;
}
//SHIFT LIGHT
switch (shift_light_mode) {
case 1:
if (current_RPM > shift_light_RPM) {
EVERY_N_MILLISECONDS(ShftL1_shift_light_blink_over_intreval) {
if (shift_light_ON == false) {
fill_solid(cluster_leds + cluster_main_NUM_LEDS, cluster_screen_NUM_LEDS, CHSV(225, 0, 160));
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = ShftL1OverClr;
shift_light_ON = true;
} else {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = ShftL1OverBlankClr;
shift_light_ON = false;
}
}
} else {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = CRGB::Black;
shift_light_ON = false;
}
break;
case 2:
if (current_RPM >= shift_light_RPM_Good && current_RPM <= shift_light_RPM_Perfect) {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = ShftL2GoodClr;
} else if (current_RPM > shift_light_RPM_Perfect && current_RPM <= shift_light_RPM_Over) {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = ShftL2PerfClr;
} else if (current_RPM >= shift_light_RPM_Over) {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = ShftL2OverClr;
} else {
cluster_leds[cluster_main_NUM_LEDS + cluster_screen_NUM_LEDS] = CRGB::Black;
}
break;
}
//4 DIGIT LEFT Bottom
if (_4digit_bottom_left_interrupt == false) {
EVERY_N_MILLISECONDS(50) {
//disp disp.displayIntZero(current_SPEED);
}
}
if (ignitionON_runned == false) {
ignitionOFF_runned = false;
//variables to change when ignition on
AE_on_by_unlock = false;
inside_leds_on_by_unlock = false;
cluster_leds_on_by_unlock = false;
foot_leds_on = false;
//disp disp.point(0);
distance_traveled = 0;
//disp disp.displayByte(__r, __S, __t, __d);
stop_4dgt_for_N_millis(3000);
//disp disp.set(4);
ignitionON_runned = true;
}
} else {
//////Quando ignição estiver off
if (ignitionOFF_runned == false) {
ignitionON_runned = false;
//disp disp.displayInt(distance_traveled);
ignitionOFF_runned = true;
}
}
///Serial Debug
if (serialDebug == true) {
//Serial Monitor
EVERY_N_MILLISECONDS(delay_SERIAL_SHOW) {
// Serial.println("SPEED IS:");
// Serial.println(current_SPEED);
// Serial.println("RPM IS:");
// Serial.println(current_RPM_RAW_final);
}
}
if (LPSDebug == true) {
EVERY_N_MILLISECONDS(delay_LPS) {
Serial.println("LPS:");
Serial.println(codeLPSs);
codeLPSs = 0;
}
codeLPSs++;
}
//DISA Valve state
if (current_RPM > disaOpen2RPM) {
disaServoAngle = 175;
} else if (current_RPM < disaOpen1RPM) {
disaServoAngle = 105;
} else {
disaServoAngle = map(current_RPM, disaOpen1RPM, disaOpen2RPM, 105, 175);
}
//CHECK IF IS MOVING now on the void itself
//part of stop 4digit for N millis
EVERY_N_MILLISECONDS(20) {
if (millis() - time_stop_4dgt_for_N_millis < delay_stop_4dgt_for_N_millis) {
_4digit_bottom_left_interrupt3 = true;
} else {
_4digit_bottom_left_interrupt3 = false;
}
}
// Quando porta do condutor abre
if (digitalRead(PIN_driver_door_sensor) == LOW) {
driver_door_open = true;
} else {
driver_door_open = false;
}
//Quando porta do pendura abre
if (digitalRead(PIN_passenger_door_sensor) == LOW) {
passenger_door_open = true;
} else {
passenger_door_open = false;
}
if (millis() - time_after_open_driver_door > delay_after_open_driver_door && after_open_driver_door_runned == false) {
inside_leds_on_by_doors = false;
AE_on_by_door_open = false;
foot_leds_on = false;
after_open_driver_door_runned = true;
}
if (millis() - time_after_open_passenger_door > delay_after_open_passenger_door && after_open_passenger_door_runned == false) {
inside_leds_on_by_doors = false;
AE_on_by_door_open = false;
after_open_passenger_door_runned = true;
}
//run once open/close driver door
if (driver_door_open == true) {
if (driver_door_open_runned == false) {
//codigo quando abrir
inside_leds_on_by_doors = true;
foot_leds_on = true;
AE_on_by_door_open = true;
car_open = true;
after_open_driver_door_runned = false;
time_after_open_driver_door = millis();
driver_door_close_runned = false;
driver_door_open_runned = true;
}
} else if (driver_door_close_runned == false) {
//codigo quando fechar
inside_leds_on_by_doors = false;
AE_on_by_door_open = false;
foot_leds_on = false;
after_open_driver_door_runned = true;
driver_door_close_runned = true;
driver_door_open_runned = false;
}
//run once open/close passenger door
if (passenger_door_open == true) {
if (passenger_door_open_runned == false) {
passenger_door_open_runned = true;
//codigo quando abrir
inside_leds_on_by_doors = true;
AE_on_by_door_open = true;
car_open = true;
after_open_passenger_door_runned = false;
time_after_open_passenger_door = millis();
passenger_door_close_runned = false;
}
} else {
if (passenger_door_close_runned == false) {
//codigo quando fechar
inside_leds_on_by_doors = false;
AE_on_by_door_open = false;
after_open_passenger_door_runned = true;
passenger_door_close_runned = true;
passenger_door_open_runned = false;
}
}
//AVISO SE UMA DAS PORTAS ESTIVER ABERTA EM ANDAMENTO
if (passenger_door_open == true && current_SPEED > 1) {
_4digit_bottom_left_interrupt1 = true;
//disp disp.displayByte(__S, __t, __O, __P);
} else {
_4digit_bottom_left_interrupt1 = false;
}
if (driver_door_open == true && current_SPEED > 1) {
_4digit_bottom_left_interrupt2 = true;
//disp disp.displayByte(__S, __t, __O, __P);
} else {
_4digit_bottom_left_interrupt2 = false;
}
if (to_be_closed == true) {
closeCar(true);
}
if (to_be_opened == true) {
openCar(true);
}
//Quando o carro é aberto remotamente
if (digitalRead(PIN_remote_in_signal_unlock) == HIGH) {
openCar(true);
AE_on_by_unlock = true;
inside_leds_on_by_unlock = true;
cluster_leds_on_by_unlock = true;
foot_leds_on = true;
first_time_after_unlock = millis();
second_time_after_unlock = millis();
}
//Quando o carro é fechado remotamente
if (digitalRead(PIN_remote_in_signal_lock) == HIGH) {
closeCar(true);
AE_on_by_unlock = false;
inside_leds_on_by_unlock = false;
cluster_leds_on_by_unlock = false;
foot_leds_on = false;
first_time_after_lock = millis();
first_time_after_lock_runned = false;
}
//Fechar carro em movimento
if (car_open == true && current_SPEED > 20) {
closeCar(false);
stop_4dgt_for_N_millis(1200);
//disp disp.displayByte(__C, __L, __S, __D);
}
//acões depois de x tempo de ter sido aberto remotamente
if (car_open == true) {
if (millis() >= first_time_after_unlock + first_delay_after_unlock) {
first_time_after_unlock += largenumber;
AE_on_by_unlock = false;
inside_leds_on_by_unlock = false;
cluster_leds_on_by_unlock = false;
foot_leds_on = false;
}
if (millis() >= second_time_after_unlock + first_delay_after_unlock + second_delay_after_unlock) {
second_time_after_unlock += largenumber;
}
}
//acões depois de x tempo de ter sido fechado remotamente
if (car_open == false) {
if (millis() >= first_time_after_lock + first_delay_after_lock && first_time_after_lock_runned == false) {
first_time_after_lock_runned = true;
putin_sleep_mode();
}
if (millis() >= off_modules_time_after_lock + off_modules_delay_after_lock) {
off_modules_time_after_lock += largenumber;
}
}
if (interrupt_angel_eyes1 == true) {
interrupt_angel_eyes = true;
} else {
interrupt_angel_eyes = false;
}
/*
if (inside_leds_on == true) {
for (int i = 0; i < inside_NUM_LEDS; i++) {
inside_leds[i] = CHSV(255, 0, 255);
}
} else {
for (int i ; i < inside_NUM_LEDS; i++) {
inside_leds[i] = CHSV(255, 255, 0);
}
}
*/
//CLUSTER SHITTTTTTTTTTTTTTTTTT
if (
cluster_led_on_by_switch == true || cluster_leds_on_by_unlock == true) {
cluster_leds_on = true;
} else {
cluster_leds_on = false;
}
//Mode Changers
//mode changer with timer
if (digitalRead(PIN_remote_in_signal_unlock) == HIGH) {
// If XXXXX is true and the mode hasn't been changed yet, change the mode
if (!cluster_leds_mode_changed1) {
// Store the current mode as the previous mode
previous_cluster_leds_mode = cluster_leds_mode;
// Set the mode to a specific value
cluster_leds_mode = cluster_leds_mode_w_unlocked; // cluster_leds_mode_w_unlocked is the new mode to change to
cluster_leds_mode_changed1 = true;
cluster_leds_mode_change1_start_time = millis(); // Record the start time
}
} else {
// If open_by_door is false and the mode has been changed, check if it's time to return to normal mode
if (cluster_leds_mode_changed1 && (millis() - cluster_leds_mode_change1_start_time >= cluster_leds_mode_change1_duration) || digitalRead(PIN_remote_in_signal_lock) == HIGH) {
cluster_leds_mode = previous_cluster_leds_mode; // Return to normal mode
cluster_leds_mode_changed1 = false; // Reset the AE_mode_change1 flag
}
}
/*
//normal mode changer
if (open_by_door) {
// Store the current mode as the previous mode
previous_AE_mode = AE_mode;
// Set the mode to a specific value when open_by_door is true
AE_mode = NEW_MODE_VALUE; // Replace NEW_MODE_VALUE with the desired mode
}
*/
//smooth code
//set a value to subtract to the actual value set by the mode, resulting in a fade
if (cluster_leds_on == true) {
if (smooth_cluster_leds_mode == true) {
EVERY_N_MILLISECONDS(cluster_leds_on_fade_speed) {
if (cluster_leds_x_subtr >= 1) {
cluster_leds_x_subtr = cluster_leds_x_subtr - 1;
}
}
} else {
cluster_leds_x_subtr = 0;
}
} else {
if (smooth_cluster_leds_mode == true) {
EVERY_N_MILLISECONDS(cluster_leds_off_fade_speed) {
if (cluster_leds_x_subtr <= 254) {
cluster_leds_x_subtr = cluster_leds_x_subtr + 1;
}
}
} else {
cluster_leds_x_subtr = 255;
}
}
//Serial.println(current_RPM);
switch (cluster_leds_mode) {
case 1:
//OEM and OEM+
if (cluster_leds_x_subtr < 255) {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(Clstr1_HUE, Clstr1_SAT, (Clstr1_VAL * cluster_leds_brightness) - cluster_leds_x_subtr));
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//Point bouncing by
case 3:
if (cluster_leds_x_subtr < 255) {
EVERY_N_MILLISECONDS(16) {
uint8_t sinBeat = beatsin8(Clstr3_Speed, 0, cluster_main_NUM_LEDS - 1, 0, 0);
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
cluster_leds[sinBeat] = CHSV(Clstr3_HUE, Clstr3_SAT, 255 * cluster_leds_brightness - cluster_leds_x_subtr);
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//Breathing white
case 4:
if (cluster_leds_x_subtr < 255) {
EVERY_N_MILLISECONDS(30) {
uint8_t sinBeat = beatsin8(Clstr4_Speed, 0, 255, 0, 0);
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(Clstr4_HUE, Clstr4_SAT, sinBeat * cluster_leds_brightness - cluster_leds_x_subtr));
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//Roling rainbow
case 5:
if (cluster_leds_x_subtr < 255) {
EVERY_N_MILLISECONDS(Clstr5_Speed) {
Clstr5_HUE++;
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(Clstr5_HUE, Clstr5_SAT, Clstr5_VAL * cluster_leds_brightness - cluster_leds_x_subtr));
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//RPM Reactive procedural
case 6:
if (cluster_leds_x_subtr < 255) {
EVERY_N_MILLISECONDS(4) {
float mode5Speed = mapfloat(current_SPEED, 0, 240, 0, Clstr6_SPEED_num_Leds);
float mode5rpm = mapfloat(current_RPM, 0, 5000, 0, Clstr6_RPM_num_Leds);
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(0, 0, 255 - cluster_leds_x_subtr));
DrawPixels(Clstr6_SPEED_offset, mode5Speed, CHSV(255, 255, 255 - cluster_leds_x_subtr));
DrawPixels(Clstr6_RPM_offset, mode5rpm, CHSV(255, 255, 255 - cluster_leds_x_subtr));
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//Color1 with rpms transitioning to Color2
//With rainbow mode
case 7:
if (cluster_leds_on) {
EVERY_N_MILLISECONDS(20) {
if (colorHSV2_rainbow == true) {
prev_color2_hue = Clstr7_palette_HUE2;
temp_color2_hue = temp_color2_hue + 8;
Clstr7_palette_HUE2 = temp_color2_hue;
}
uint8_t xyz[8]; // Needs to be 4 times however many colors are being used.
Clstr7_palette_hsv1 = CHSV(Clstr7_palette_HUE1, Clstr7_palette_SAT1, Clstr7_palette_VAL1 * cluster_leds_brightness); //variavel de config
Clstr7_palette_hsv2 = CHSV(Clstr7_palette_HUE2, Clstr7_palette_SAT2, Clstr7_palette_VAL2 * cluster_leds_brightness); //variavel de config
hsv2rgb_rainbow(Clstr7_palette_hsv1, Clstr7_palette_rgb1); // convert to R,G,B
hsv2rgb_rainbow(Clstr7_palette_hsv2, Clstr7_palette_rgb2); // convert to R,G,B
xyz[0] = 0; // first palette point - must be zero
xyz[1] = Clstr7_palette_rgb1.r;
xyz[2] = Clstr7_palette_rgb1.g;
xyz[3] = Clstr7_palette_rgb1.b;
xyz[4] = 255; // second palette point
xyz[5] = Clstr7_palette_rgb2.r;
xyz[6] = Clstr7_palette_rgb2.g;
xyz[7] = Clstr7_palette_rgb2.b;
Clstr7_palette.loadDynamicGradientPalette(xyz); // update the palette with the new defined array
}
if (colorHSV2_rainbow == true) {
Clstr7_palette_HUE2 = prev_color2_hue;
}
EVERY_N_MILLISECONDS(30) {
int Clstr7calc = map(current_RPM, Clstr7_RPMmin, Clstr7_RPMmax, 0, 255);
if (current_RPM >= Clstr7_RPMmin) {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, Clstr7calc, 0, Clstr7_palette, 255, LINEARBLEND);
} else {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, 0, 0, Clstr7_palette, 255, LINEARBLEND);
}
if (current_RPM >= Clstr7_RPMmax) {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, 255, 0, Clstr7_palette, 255, LINEARBLEND);
}
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//Color1 with speed transitioning to Color2
case 8:
if (cluster_leds_on) {
EVERY_N_MILLISECONDS(2200) {
uint8_t xyz[8]; // Needs to be 4 times however many colors are being used.
Clstr8_palette_hsv1 = CHSV(Clstr8_palette_HUE1, Clstr8_palette_SAT1, Clstr8_palette_VAL1 * cluster_leds_brightness); //variavel de config
Clstr8_palette_hsv2 = CHSV(Clstr8_palette_HUE2, Clstr8_palette_SAT2, Clstr8_palette_VAL2 * cluster_leds_brightness); //variavel de config
hsv2rgb_rainbow(Clstr8_palette_hsv1, Clstr8_palette_rgb1); // convert to R,G,B
hsv2rgb_rainbow(Clstr8_palette_hsv2, Clstr8_palette_rgb2); // convert to R,G,B
xyz[0] = 0; // first palette point - must be zero
xyz[1] = Clstr8_palette_rgb1.r;
xyz[2] = Clstr8_palette_rgb1.g;
xyz[3] = Clstr8_palette_rgb1.b;
xyz[4] = 255; // second palette point
xyz[5] = Clstr8_palette_rgb2.r;
xyz[6] = Clstr8_palette_rgb2.g;
xyz[7] = Clstr8_palette_rgb2.b;
Clstr8_palette.loadDynamicGradientPalette(xyz); // update the palette with the new defined array
}
EVERY_N_MILLISECONDS(30) {
int Clstr8calc = map(current_RPM, Clstr8_SPEEDmin, Clstr8_SPEEDmax, 0, 255);
if (current_RPM >= Clstr8_SPEEDmin) {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, Clstr8calc, 0, Clstr8_palette, 255, LINEARBLEND);
} else {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, 0, 0, Clstr8_palette, 255, LINEARBLEND);
}
if (current_RPM >= Clstr8_SPEEDmax) {
fill_palette(cluster_leds, cluster_main_NUM_LEDS, 255, 0, Clstr8_palette, 255, LINEARBLEND);
}
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
//RAINBOW RPM REACTIVE
case 9:
if (cluster_leds_on) {
//if autoroll is activated
if (Clstr9autoRoll == true) {
EVERY_N_MILLIS(Clstr9autoRollSpeed) {
Clstr9calcAdd++;
}
} else {
Clstr9calcAdd = 0;
}
EVERY_N_MILLIS(30) {
uint8_t Clstr9calc = map(current_RPM, 0, 7000, 0, 255); //calculate hue based on the whole rpm range
Clstr9calc = Clstr9calc + Clstr9calcAdd; //add the autoroll amount
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(Clstr9calc, 255, 255 * cluster_leds_brightness)); //color all the pixels with the hue calculated
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black); //set all black
}
break;
//comet bouncing by
case 10:
if (cluster_leds_on) {
EVERY_N_MILLISECONDS(16) {
uint8_t sinBeat = beatsin8(Clstr3_Speed, 0, cluster_main_NUM_LEDS - 1, 0, 0);
cluster_leds[sinBeat] = CHSV(Clstr3_HUE, Clstr3_SAT, 255 * cluster_leds_brightness);
fadeToBlackBy(cluster_leds, cluster_main_NUM_LEDS, 29);
}
} else {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CRGB::Black);
}
break;
case 11:
//sparkles
// Set the interval between sparkle updates (in milliseconds)
#define SPARKLE_INTERVAL 30
// Custom probability (0-255), higher values mean LEDs turn on less frequently
#define CUSTOM_PROBABILITY 15
EVERY_N_MILLISECONDS(SPARKLE_INTERVAL) {
// Loop through each LED
for (int i = 0; i < cluster_main_NUM_LEDS; i++) {
// Generate a random number between 0 and 255
int randomValue = random8(255);
// Check if the random value is less than CUSTOM_PROBABILITY
// If true, turn on the LED, otherwise, turn it off
if (randomValue < CUSTOM_PROBABILITY) {
cluster_leds[i] = CHSV(255, 0, 255 - cluster_leds_x_subtr);
; // LED is on
} else if (!Clstr10_fadeSlowly) {
cluster_leds[i] = CRGB::Black; // LED is off
}
}
}
EVERY_N_MILLIS(8) {
if (Clstr10_fadeSlowly) {
fadeToBlackBy(cluster_leds, cluster_main_NUM_LEDS, 4);
}
}
break;
}
//Ignition cut Reactive
if (ClstrLdsXtra1 == true) {
EVERY_N_MILLIS(10) {
if (ignitionCutted == true) {
fill_solid(cluster_leds, cluster_main_NUM_LEDS, CHSV(ClstrXtra1_CutHUE, ClstrXtra1_CutSAT, ClstrXtra1_CutVAL));
}
}
}
uint8_t current_RPM = beatsin8(5, 0, 255, 0, 0);
uint8_t current_SPEED = beatsin8(5, 0, 250, 0, 0);
if (
cluster_led_on_by_switch == true && ClstrLdsXtra2 == true || ClstrLdsXtra2AllwaysOn == true
// and ignition on
) {
/* NON FRACTIONAL THING ------- EVERY_N_MILLISECONDS(4){
int mode5rpm = map(current_RPM,0,5000,15,28);
int mode5Speed = map(current_SPEED,0,240,3,14);
fill_solid( cluster_leds, cluster_main_NUM_LEDS, CRGB::White);
for (int i = 4; i < mode5Speed; i++) {
cluster_leds[i] = CHSV(255, 255, 255*cluster_leds_brightness);
}
for (int i = 15; i < mode5rpm; i++) {
cluster_leds[i] = CHSV(255, 255, 255*cluster_leds_brightness);
}
}
*/
EVERY_N_MILLISECONDS(1) {
float mode5rpm = mapfloat(current_RPM, 0, 255, 1, 15);
float mode5Speed = mapfloat(current_SPEED, 0, 255, 1, 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));
}
}
if (
AE_on_by_switch == true || AE_on_by_unlock == true || AE_on_by_car_on == true) {
AE_on = true;
} else {
AE_on = false;
}
//Mode Changers
//mode changer with timer
if (digitalRead(PIN_remote_in_signal_unlock) == HIGH) {
// If XXXXX is true and the mode hasn't been changed yet, change the mode
if (!AE_mode_changed1) {
// Store the current mode as the previous mode
previous_AE_mode = AE_mode;
// Set the mode to a specific value
AE_mode = AE_mode_w_unlocked; // AE_mode_w_unlocked is the new mode to change to
AE_mode_changed1 = true;
AE_mode_change1_start_time = millis(); // Record the start time
}
} else {
// If open_by_door is false and the mode has been changed, check if it's time to return to normal mode
if (AE_mode_changed1 && (millis() - AE_mode_change1_start_time >= AE_mode_change1_duration) || digitalRead(PIN_remote_in_signal_lock) == HIGH) {
AE_mode = previous_AE_mode; // Return to normal mode
AE_mode_changed1 = false; // Reset the AE_mode_change1 flag
}
}
/*
//normal mode changer
if (open_by_door) {
// Store the current mode as the previous mode
previous_AE_mode = AE_mode;
// Set the mode to a specific value when open_by_door is true
AE_mode = NEW_MODE_VALUE; // Replace NEW_MODE_VALUE with the desired mode
}
*/
//smooth code
//set a value to subtract to the actual value set by the mode, resulting in a fade
if (AE_on == true) {
if (smooth_AE_mode == true) {
EVERY_N_MILLISECONDS(AEx_on_fade_speed) {
if (AEx_subtr >= 1) {
AEx_subtr = AEx_subtr - 1;
}
}
} else {
AEx_subtr = 0;
}
} else {
if (smooth_AE_mode == true) {
EVERY_N_MILLISECONDS(AEx_off_fade_speed) {
if (AEx_subtr <= 254) {
AEx_subtr = AEx_subtr + 1;
}
}
} else {
AEx_subtr = 255;
}
}
switch (AE_mode) {
case 1:
//on angel eyes
if (AEx_subtr != 255) {
AE1_current_AE_brightness = (255 - AEx_subtr);
}
analogWrite(PIN_mosfet_AE_RIGHT, AE1_current_AE_brightness);
analogWrite(PIN_mosfet_AE_LEFT, AE1_current_AE_brightness);
break;
case 2:
if (AEx_subtr != 255) {
//Sideways wave
uint8_t AE2_sinBeat = beatsin8(AE2_speed, 0, 255, 0, 0);
uint8_t AE2_sinBeat2 = beatsin8(AE2_speed, 0, 255, 0, 70);
AE2_sinBeat = (AE2_sinBeat - AEx_subtr);
AE2_sinBeat2 = (AE2_sinBeat2 - AEx_subtr);
EVERY_N_MILLISECONDS(32) {
analogWrite(PIN_mosfet_AE_RIGHT, AE2_sinBeat);
analogWrite(PIN_mosfet_AE_LEFT, AE2_sinBeat2);
}
}
break;
case 3:
//sparkles
EVERY_N_MILLISECONDS(AE_sparkle_interval) {
// Loop through each LED
for (int i = 0; i < 2; i++) {
// Generate a random number between 0 and 255
int randomValue = random8(255);
// Check if the random value is less than CUSTOM_PROBABILITY
// If true, turn on the LED, otherwise, turn it off
int final_value = 255 - AEx_subtr;
if (randomValue < AE_sparkle_probability) {
if (i == 0) {
analogWrite(PIN_mosfet_AE_RIGHT, final_value);
} else {
analogWrite(PIN_mosfet_AE_LEFT, final_value);
}
} else if (!AE_applyFade) {
if (i == 0) {
analogWrite(PIN_mosfet_AE_RIGHT, 0);
} else {
analogWrite(PIN_mosfet_AE_LEFT, 0);
}
}
}
}
// Fade to black logic (if AE_applyFade is true)
if (AE_applyFade) {
EVERY_N_MILLIS(20) { // Adjust the timing here as needed
analogWrite(PIN_mosfet_AE_RIGHT, max(0, analogRead(PIN_mosfet_AE_RIGHT) - AE_FADE_AMOUNT));
analogWrite(PIN_mosfet_AE_LEFT, max(0, analogRead(PIN_mosfet_AE_LEFT) - AE_FADE_AMOUNT));
}
}
break;
}
//INSIDE LEDS
if (
inside_leds_on_by_doors == true || inside_leds_on_by_unlock == true) {
inside_leds_on = true;
} else {
inside_leds_on = false;
}
//Mode Changers
//mode changer with timer
if (digitalRead(PIN_remote_in_signal_unlock) == HIGH) {
// If open_by_door is true and the mode hasn't been changed yet, change the mode
if (!inside_leds_mode_changed) {
// Store the current mode as the previous mode
previous_inside_leds_mode = inside_leds_mode;
// Set the mode to a specific value when open_by_door is true
inside_leds_mode = inside_leds_mode_w_unlocked; // Replace NEW_MODE_VALUE with the desired mode
inside_leds_mode_changed = true;
inside_leds_mode_change_start_time = millis(); // Record the start time
}
} else {
// If open_by_door is false and the mode has been changed, check if it's time to return to normal mode
if (inside_leds_mode_changed && (millis() - inside_leds_mode_change_start_time >= inside_leds_mode_change_duration) || digitalRead(PIN_remote_in_signal_lock) == HIGH) {
inside_leds_mode = previous_inside_leds_mode; // Return to normal mode
inside_leds_mode_changed = false; // Reset the mode_changed flag
}
}
/*
//normal mode changer
if (open_by_door) {
// Store the current mode as the previous mode
previous_inside_leds_mode = inside_leds_mode;
// Set the mode to a specific value when open_by_door is true
inside_leds_mode = NEW_MODE_VALUE; // Replace NEW_MODE_VALUE with the desired mode
}
*/
//Smooth code
//set a value to subtract to the actual value set by the mode, resulting in a fade
if (inside_leds_on == true) {
if (smooth_inside_leds_mode == true) {
EVERY_N_MILLISECONDS(4) {
if (insd_leds_x_subtr >= 1) {
insd_leds_x_subtr = insd_leds_x_subtr - 1;
}
}
} else {
insd_leds_x_subtr = 0;
}
} else {
if (smooth_inside_leds_mode == true) {
EVERY_N_MILLISECONDS(4) {
if (insd_leds_x_subtr <= 254) {
insd_leds_x_subtr = insd_leds_x_subtr + 1;
}
}
} else {
insd_leds_x_subtr = 255;
}
}
//Inside Leds
switch (inside_leds_mode) {
case 1:
//OEM
if (insd_leds_x_subtr < 255) {
fill_solid(inside_leds, inside_NUM_LEDS, CHSV(insideLds1_HUE, insideLds1_SAT, 255 - insd_leds_x_subtr));
}
break;
case 2:
//Rainbow
if (insd_leds_x_subtr < 255) {
EVERY_N_MILLISECONDS(insideLds2_Speed) {
insideLds2_HUE++;
}
insideLds2_current_brightness = insideLds2_current_brightness - insd_leds_x_subtr;
fill_solid(inside_leds, inside_NUM_LEDS, CHSV(insideLds2_HUE, insideLds2_SAT, insideLds2_current_brightness));
}
break;
// Sparkles
case 3:
if (insd_leds_x_subtr < 255) {
// Set the interval between sparkle updates (in milliseconds)
#define sparkle_interval 30
// Custom probability (0-255), higher values mean LEDs turn on less frequently
#define custom_probability 15
EVERY_N_MILLISECONDS(sparkle_interval) {
if (insideLds3_blinkInGroups) {
int currentIndex = 0;
for (int group = 0; group < insideLds3_numGroups; group++) {
// Generate a random number for the group
int randomValue = random8(255);
bool groupLightUp = randomValue < custom_probability;
// Set LEDs for the current group based on the group's random value
int numLEDsInGroup = insideLds3_ledsPerGroup[group];
for (int i = currentIndex; i < currentIndex + numLEDsInGroup; i++) {
if (i < inside_NUM_LEDS) {
if (groupLightUp) {
inside_leds[i] = CHSV(255, 0, 255 - insd_leds_x_subtr); // LED is on
} else {
if (insideLds3_fadeSlowly) {
// Do nothing so we can fade latter
} else {
inside_leds[i] = CRGB::Black; // LED is off
}
}
}
}
currentIndex += numLEDsInGroup; // Move to the next group's LEDs
}
} else {
// Original code to blink all LEDs randomly
for (int i = 0; i < inside_NUM_LEDS; i++) {
int randomValue = random8(255);
if (randomValue < custom_probability) {
inside_leds[i] = CHSV(255, 0, 255 - insd_leds_x_subtr); // LED is on
} else {
if (insideLds3_fadeSlowly) {
// Do nothing so we can fade latter
} else {
inside_leds[i] = CRGB::Black; // LED is off
}
}
}
}
if (insideLds3_fadeSlowly) {
EVERY_N_MILLIS(insideLds3_fadeSpeed) {
fadeToBlackBy(inside_leds, inside_NUM_LEDS, insideLds3_fadeAmount);
}
}
}
}
break;
}
//INTERIOR OVERLAYS
//Ignition cut Reactive
if (insideLdsXtra1 == true) {
if (ignitionCutted == true) {
fill_solid(inside_leds, inside_NUM_LEDS, CHSV(insideLdsXtra1_CutHUE, insideLdsXtra1_CutSAT, insideLdsXtra1_CutVAL));
}
}
//Foot Leds activation logic
if (
foot_leds_on == true) {
foot_leds_on = true;
} else {
foot_leds_on = false;
}
//Smooth code
//set a value to subtract to the actual value set by the mode, resulting in a fade
if (foot_leds_on == true) {
if (foot_leds_mode == true) {
EVERY_N_MILLISECONDS(4) {
if (foot_leds_x_subtr >= 1) {
foot_leds_x_subtr = foot_leds_x_subtr - 1;
}
}
} else {
foot_leds_x_subtr = 0;
}
} else {
if (foot_leds_mode == true) {
EVERY_N_MILLISECONDS(4) {
if (foot_leds_x_subtr <= 254) {
foot_leds_x_subtr = foot_leds_x_subtr + 1;
}
}
} else {
foot_leds_x_subtr = 255;
}
}
//Foot Leds
switch (foot_leds_mode) {
case 1:
if (foot_leds_on == true) {
EVERY_N_MILLISECONDS(foot_lds1_on_fade_speed) {
if (brightness_foot_normal <= 254) {
brightness_foot_normal = brightness_foot_normal + 1;
fill_solid(foot_leds, foot_NUM_LEDS, CHSV(255, 0, brightness_foot_normal));
}
}
} else {
EVERY_N_MILLISECONDS(foot_lds1_off_fade_speed) {
if (brightness_foot_normal >= 1) {
brightness_foot_normal = brightness_foot_normal - 1;
fill_solid(foot_leds, foot_NUM_LEDS, CHSV(255, 0, brightness_foot_normal));
}
}
}
break;
//wave lado a lado
case 2:
if (foot_leds_on == true) {
EVERY_N_MILLISECONDS(20) {
if (onpix_foot_normal >= 1) {
fill_solid(foot_leds, foot_NUM_LEDS, CRGB::White);
onpix_foot_normal = onpix_foot_normal - 1;
}
for (int i = 0; i < onpix_foot_normal; i++) {
foot_leds[i] = CRGB::Black;
}
}
} else {
EVERY_N_MILLISECONDS(20) {
if (onpix_foot_normal <= foot_NUM_LEDS) {
onpix_foot_normal = onpix_foot_normal + 1;
fill_solid(foot_leds, foot_NUM_LEDS, CRGB::White);
for (int i = 0; i < onpix_foot_normal; i++) {
foot_leds[i] = CRGB::Black;
}
}
}
}
break;
case 3:
if (foot_leds_on == true) {
EVERY_N_MILLIS(1000) {
uint8_t xyz[16]; // Needs to be 4 times however many colors are being used.
// 3 colors = 12, 4 colors = 16, etc.
hsv = CHSV(255, 255, 255); // pick random hue
hsv2rgb_rainbow(hsv, rgb); // convert to R,G,B
xyz[0] = 0; // anchor of first color - must be zero
xyz[1] = rgb.r;
xyz[2] = rgb.g;
xyz[3] = rgb.b;
xyz[4] = random8(48, 118); // random anchor point for second color
xyz[5] = 255;
xyz[6] = 0;
xyz[7] = 0;
xyz[8] = random8(138, 225); // random anchor point for third color
xyz[9] = 0,
xyz[10] = 255;
xyz[11] = 0;
xyz[12] = 255; // anchor of last color - must be 255
xyz[13] = rgb.r;
xyz[14] = rgb.g;
xyz[15] = rgb.b;
currentPalette.loadDynamicGradientPalette(xyz);
for (int p = 0; p < foot_NUM_LEDS; p++) {
foot_leds[p] = ColorFromPalette(currentPalette, p * 255 / (foot_NUM_LEDS - 1), 255, NOBLEND);
}
}
} else {
EVERY_N_MILLISECONDS(20) {
for (int i = 0; i < foot_NUM_LEDS; i++) {
foot_leds[i] = CHSV(255, 0, brightness_foot_normal);
}
}
}
break;
}
//FOOT OVERLAYS
//Ignition cut Reactive
if (footLdsXtra1 == true) {
if (ignitionCutted == true) {
fill_solid(foot_leds, foot_NUM_LEDS, CHSV(footLdsXtra1_CutHUE, footLdsXtra1_CutSAT, footLdsXtra1_CutVAL));
}
}
//send data to all pins with leds
EVERY_N_MILLIS(32) {
FastLED.show();
}
}
This is an example of
Text Labels for Wokwi.
Luzes teto
Foot Leds
Cluster Leds
Minimos in
Remote Lock
Remote Unlock
Ign On
RPM
SPEED