Files
Arduino_Projects/LED_Helmet/LED_Helmet.ino
2025-02-28 17:08:32 +01:00

87 lines
2.9 KiB
C++

#define Blinker_Right 17
#define Blinker_Left 16
#define BRT 15
#define BR_LED_PIN 12
#define BL_LED_PIN 13
#define BRK_LED_PIN 14
#define Blinker_Pixels 8
#define BRK_Pixels 12
#define Pixel_SPD 100
#define BRIGHT 150
#define DIM 25
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel BL_LED(Blinker_Pixels, BL_LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel BR_LED(Blinker_Pixels, BR_LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel BRK_LED(BRK_Pixels, BRK_LED_PIN, NEO_GRB + NEO_KHZ800);
void clearLEDs(){
BL_LED.clear();
BR_LED.clear();
BRK_LED.clear();
}
void setup() {
Serial.begin(57600);
// put your setup code here, to run once:
pinMode(Blinker_Right,INPUT);
pinMode(Blinker_Left,INPUT);
pinMode(BRT,INPUT);
BL_LED.begin();
BR_LED.begin();
BRK_LED.begin();
}
int BR_LED_State = 0;
int BL_LED_State = 0;
int BRK_LED_State = 0;
int BR_State = 0;
int BR_active = 0;
int BL_State = 0;
int BL_active = 0;
int BRT_State = 0;
int BRT_active = 0;
int old_BR_state = 0;
int old_BL_state = 0;
int old_BRT_state = 0;
int Brightness = 0;
void loop() {
old_BR_state = BR_State; //Right Blinker Input Debouncing and Sticky Function
BR_State = digitalRead(Blinker_Right);
if(BR_State != old_BR_state && !old_BR_state ) BR_active = !BR_active;
old_BL_state = BL_State; //Left Blinker Input Debouncing and Sticky Function
BL_State = digitalRead(Blinker_Left);
if(BL_State != old_BL_state && !old_BL_state) BL_active = !BL_active;
old_BRT_state = BRT_State; //Brightness Toggle Input Debouncing and Sticky Function
BRT_State = digitalRead(BRT);
if(BRT_State != old_BRT_state && !old_BRT_state) BRT_active = !BRT_active;
Brightness = BRT_active ? BRIGHT:DIM; //Set Brightness according to Bright or dim setting
BR_LED_State = BR_active ? (BR_LED_State+1)%(Blinker_Pixels+1) : 0; //Set Active LEDs of Right Blinker
BL_LED_State = BL_active ? (BR_active ? BR_LED_State :(BL_LED_State+1)%(Blinker_Pixels+1)) : 0; //Set Active LEDs of Left Blinker. Warn Function synchronizes Left and Right Blinker
clearLEDs();
if(BR_active){
for(int pixel = 0;pixel<BR_LED_State;pixel++){
BR_LED.setPixelColor(pixel, BR_LED.Color(255, 30, 0));
}
}
if(BL_active){
for(int pixel = 0;pixel<BL_LED_State;pixel++){
BL_LED.setPixelColor(pixel, BL_LED.Color(255, 30, 0));
}
}
BRK_LED_State = (BRK_LED_State+1)%(BRK_Pixels/2+1); //Back Light is on regardless
for(int pixel = 0;pixel<BRK_LED_State;pixel++){
BRK_LED.setPixelColor(pixel, BRK_LED.Color(255, 0, 0));
BRK_LED.setPixelColor(BRK_Pixels-1-pixel, BRK_LED.Color(255, 0, 0));
}
BR_LED.setBrightness(Brightness);
BL_LED.setBrightness(Brightness);
BRK_LED.setBrightness(Brightness);
BR_LED.show();
BL_LED.show();
BRK_LED.show();
delay(Pixel_SPD);
}