Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Modern turn lights v.6.1.0 with arduino or attiny85 and ws2812b - individual strips easy to embed - tail, reverse, brake and turn signal - by Fedaceag Ionut ( Youtube - Think small, build big! )
- #include <FastLED.h> //FastLed library version 3.2.1 - https://github.com/FastLED/FastLED/wiki/Overview or http://fastled.io/ with NEOPIXEL or WS2812B
- //#define NUM_STRIPS 1 //number of led strips
- #define NUM_LEDS_PER_STRIP 288 //number of leds per each strip
- #define LED_PIN 2 //LED Strip Signal Connection
- CRGB leds[NUM_LEDS_PER_STRIP];
- unsigned long turnColor = 0xff6a00; //turn signal color
- unsigned long startupcolordim = 0x5a0000;
- unsigned long startupcolorbright = 0xff0000;
- unsigned long black = 0x000000;
- //input pins for arduino
- const int buttonPinTS = 6; // turn signal pin for arduino
- const int buttonPinTailLights = 3; // night / tail lights for arduino
- const int buttonPinBreak = 4; // brake lights for arduino
- const int buttonPinReverseLights = 5; // reverse lights for arduino
- const int buttonPinStartup = 9;
- int Startup = 0;
- int TailLights = 0;
- int ReverseLights = 0;
- int Break = 0;
- int TailState = 0;
- int stateTS = 0;
- int stateTSRuns = 0;
- int ReverseState = 0;
- int BrakeState = 0;
- int StartupState = 0;
- int buttonStateTS = 0;
- int buttonstartupstate = 0;
- int maxBrtBreak = 254; // maxim brightness Break lights - from 0 to 254
- int maxBrtTailLights = 70; // maxim brightness tail lights - from 0 to 254
- int maxBrtReverseLights = 254;
- int tailLightModel[]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,
- 145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,
- 259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288};
- int reverseLightModel[] = {20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, 248,249,250,251,252,253,254,255,256,257,258,
- 259,260,261,262,263,264,265,266,267,268};
- int turnsignalmodel[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
- int delayTurnLedAnim = 1; //delay of each led in turn light animation
- int delayTurnLedOff = 70; //delay from animation to black (is used twice)
- int delayLedToDayLight = 500; // delay from animation to day light on
- int nrAnimAfterOff = 3; // number of animations for a single impulse
- int StartupSpeed = 6;
- unsigned long currentMillis = 0;
- unsigned long previousMillis = 0;
- void setup() {
- //Serial.begin(115200);
- FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS_PER_STRIP);
- pinMode(buttonPinTS, INPUT);
- pinMode(buttonPinBreak, INPUT);
- pinMode(buttonPinTailLights, INPUT);
- pinMode(buttonPinReverseLights, INPUT);
- pinMode(buttonPinStartup, INPUT);
- for (int i = 0; i < (NUM_LEDS_PER_STRIP/2); i++) { //beggining of Startup Sweep loop
- leds[i] = startupcolordim;
- leds[i-1] = black;
- leds[(NUM_LEDS_PER_STRIP-1)-i] = startupcolordim;
- leds[(NUM_LEDS_PER_STRIP)-i] = black;
- FastLED.show();
- delay (StartupSpeed);
- }
- for (int j = ((NUM_LEDS_PER_STRIP/2)-1); j >= 0; j--)
- {
- leds[j] = startupcolordim;
- leds[(NUM_LEDS_PER_STRIP/2-1)+((NUM_LEDS_PER_STRIP/2)-j)] = startupcolordim;
- FastLED.show();
- delay (StartupSpeed);
- }
- for (int j = ((NUM_LEDS_PER_STRIP/2)-1); j >= 0; j--)
- {
- leds[j] = startupcolorbright;
- leds[(NUM_LEDS_PER_STRIP/2-1)+((NUM_LEDS_PER_STRIP)/2-j)] = startupcolorbright;
- FastLED.show();
- delay (StartupSpeed);
- }
- for (int j = 255; j >= 60; j--)
- {
- for (int i = 0; i < NUM_LEDS_PER_STRIP; i++)
- {
- leds[i] = CRGB(j, 0, 0);
- }
- FastLED.show();
- delay (5);
- }
- //led strip front left for arduino
- //FastLED.addLeds<NEOPIXEL, 0>(leds[0], NUM_LEDS_PER_STRIP); //led strip front left for attiny85
- fill_solid(leds, NUM_LEDS_PER_STRIP, CRGB::Red); // some led strips are all on at power on, so let's power them off at boot
- FastLED.show();
- }
- void loop() {
- // read the input state
- buttonStateTS = digitalRead(buttonPinTS);
- if(buttonStateTS == HIGH){
- stateTS = 1;
- }
- // turn signal function
- if(stateTS != 0){
- for(int dot = 0; dot < turnsignalmodel; dot++) {
- leds[dot] = turnColor;
- //delay(delayTurnLedAnim);
- currentMillis = previousMillis = millis();
- while(previousMillis + delayTurnLedAnim >= currentMillis){
- stateTSRuns = 1;
- TailAndBrake();
- FastLED.show();
- currentMillis = millis();
- }
- }
- //delay(delayTurnLedOff);
- currentMillis = previousMillis = millis();
- while(previousMillis + delayTurnLedOff >= currentMillis){
- stateTSRuns = 1;
- TailAndBrake();
- FastLED.show();
- currentMillis = millis();
- }
- fill_solid(leds, NUM_LEDS_PER_STRIP, CRGB::Black);
- stateTSRuns = 1;
- TailAndBrake();
- FastLED.show();
- //delay(delayTurnLedOff);
- currentMillis = previousMillis = millis();
- while(previousMillis + delayTurnLedOff >= currentMillis){
- stateTSRuns = 1;
- TailAndBrake();
- FastLED.show();
- currentMillis = millis();
- }
- buttonStateTS = digitalRead(buttonPinTS);
- if(buttonStateTS == HIGH){
- stateTS = 1;
- }
- stateTS++;
- if(stateTS >= nrAnimAfterOff && buttonStateTS != HIGH){
- stateTS = 0;
- //delay(delayLedToDayLight);
- currentMillis = previousMillis = millis();
- while(previousMillis + delayLedToDayLight >= currentMillis){
- stateTSRuns = 1;
- TailAndBrake();
- FastLED.show();
- currentMillis = millis();
- }
- }
- }else{
- fill_solid(leds, NUM_LEDS_PER_STRIP, CRGB::Black);
- TailAndBrake();
- FastLED.show();
- }
- }
- //function for Brake lights, tail lights and reverse lights
- void TailAndBrake(){
- Break = digitalRead(buttonPinBreak);
- TailLights = digitalRead(buttonPinTailLights);
- ReverseLights = digitalRead(buttonPinReverseLights);
- Startup = digitalRead(buttonPinStartup);
- if(TailLights == HIGH && Break == LOW && stateTSRuns == 0){
- for(int i = 0; i <= sizeof(tailLightModel) / sizeof(tailLightModel[0]); i++){
- leds[tailLightModel[i]]=CHSV(0,254,maxBrtTailLights);
- }
- }else if(Break == HIGH && stateTSRuns == 0){
- fill_solid( leds, NUM_LEDS_PER_STRIP, CHSV(0,255,maxBrtBreak));
- }else if(TailLights == HIGH && Break == LOW && stateTSRuns == 1){
- int nrLedsTail = NUM_LEDS_PER_STRIP / 4;
- for(int i = 0; i <= nrLedsTail; i++){
- leds[i]=CHSV(0,254,maxBrtTailLights);
- }
- }else if(Break == HIGH && stateTSRuns == 1){
- int nrLedsBrake = NUM_LEDS_PER_STRIP / 4;
- for(int i = 0; i <= nrLedsBrake; i++){
- leds[i]=CHSV(0,254,maxBrtBreak);
- }
- }
- if(ReverseLights == HIGH){
- for(int i = 0; i < sizeof(reverseLightModel) / sizeof(reverseLightModel[0]); i++){
- leds[reverseLightModel[i]]=CHSV(0,0,maxBrtReverseLights);
- }
- }
- stateTSRuns = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment