#include "Arduino.h"
#include <FastLED.h>
#define NUM_LEDS 32
#define DATA_PIN_L 2
#define DATA_PIN_R 3
#define TurnRight 5
#define TurnLeft 7
#define DRLsignal 10
CRGB leds[NUM_LEDS];
int BlinkerSpeed = 20; //Turn Signal Running LED Speed. Adjust this to match with your vehicle turn signal speed.
int BlinkerOffDelay = 250; //Turn Signal Off time. Adjust this to match with your vehicle turn signal speed.
int HazardDelay = 700;
void setup() {
FastLED.addLeds<WS2812, DATA_PIN_L, GRB>(leds, 0, 16);
FastLED.addLeds<WS2812, DATA_PIN_R, GRB>(leds, 16, 16);
pinMode(TurnRight, INPUT); //1KΩ PULLDOWN στο GND.
pinMode(TurnLeft, INPUT); //1KΩ PULLDOWN στο GND.
pinMode(DRLsignal, INPUT); //1KΩ PULLDOWN στο GND.
}
void loop()
{
// Turn on tail lights
if((digitalRead(DRLsignal)==1))
{ DRLOn();
}
else
{ DRLOff();
}
// Blink right blinker
if((digitalRead(TurnRight)==1)&&(digitalRead(TurnLeft)==0))
{ RightBlinker();
delay (BlinkerOffDelay);
}
// Blink left blinker
if((digitalRead(TurnLeft)==1)&&(digitalRead(TurnRight)==0))
{ LeftBlinker();
delay (BlinkerOffDelay);
}
// Hazards (Blink all 90 leds)
if(((digitalRead(TurnRight)==1)&&(digitalRead(TurnLeft)==1))&&(digitalRead(DRLsignal)==1))
{ HazLghts();
}
if(((digitalRead(TurnRight)==1)&&(digitalRead(TurnLeft)==1))&&(digitalRead(DRLsignal)==0))
{ Haz();
}
}
void LeftBlinker()
{
for (int l = 32; l >= 016; l--)
{
leds[l] = CRGB(255, 192, 0);
FastLED.show(l);
delay (BlinkerSpeed);
}
}
void RightBlinker()
{
for (int r = 0; r < 16; r++)
{
leds[r] = CRGB(255, 192, 0);
FastLED.show(r);
delay (BlinkerSpeed);
}
}
void HazLghts()
{ fill_solid(&leds[0], 32, CRGB(255,192,0));
FastLED.show();
delay(HazardDelay);
fill_solid(&leds[0], 32, CRGB::Red);
FastLED.show();
delay(HazardDelay);
}
void Haz()
{ fill_solid(&leds[0],32, CRGB(255,192,0));
FastLED.show();
delay(HazardDelay);
fill_solid(&leds[0], 32, CRGB(0,0,0));
FastLED.show();
delay(HazardDelay);
}
void DRLOn()
{ fill_solid(&leds[0], 32, CRGB (255,0,0));
FastLED.show();
}
void DRLOff()
{ fill_solid(&leds[0], 32, CRGB (0,0,0));
FastLED.show();
}