First Commit

This commit is contained in:
Christian Langer
2025-02-27 17:24:38 +01:00
parent 8e43a0fcbd
commit 70f7979811

97
LED_Helmet.ino Normal file
View File

@@ -0,0 +1,97 @@
#define Blinker_Right 17
#define Blinker_Left 16
#define Brightness_Toggle 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
#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(Brightness_Toggle,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 Brightness_toggle_state = 0;
int Brightness_toggle_active = 0;
int old_state = 0;
void loop() {
old_state = BR_State;
BR_State = digitalRead(Blinker_Right);
if(BR_State != old_state && old_state ==0) BR_active = !BR_active;
old_state = BL_State;
BL_State = digitalRead(Blinker_Left);
if(BL_State != old_state && old_state ==0) BL_active = !BL_active;
old_state = Brightness_toggle_state;
Brightness_toggle_state = digitalRead(Brightness_Toggle);
if(Brightness_toggle_state != old_state && old_state ==0) Brightness_toggle_active = !Brightness_toggle_active;
if(!BR_active){ //Right Blinker Active
BR_LED_State = 0;
}
else{
BR_LED_State = (BR_LED_State+1)%(Blinker_Pixels+1);
}
if(!BL_active){ //Left Blinker Active
BL_LED_State = 0;
}
else{
BL_LED_State = (BL_LED_State+1)%(Blinker_Pixels+1);
}
if(!Brightness_toggle_active){ //Break Lights Active
BRK_LED_State = 0;
}
else{
BRK_LED_State = (BRK_LED_State+1)%(BRK_Pixels+1);
}
// put your main code here, to run repeatedly:
BR_LED.clear();
BL_LED.clear();
BRK_LED.clear();
for(int pixel = 0;pixel<BR_LED_State;pixel++){
BR_LED.setPixelColor(pixel, BR_LED.Color(255, 255, 0));
}
for(int pixel = 0;pixel<BL_LED_State;pixel++){
BL_LED.setPixelColor(pixel, BL_LED.Color(255, 255, 0));
}
for(int pixel = 0;pixel<(BRK_LED_State-BRK_LED_State%2)/2;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(255);
BL_LED.setBrightness(255);
BRK_LED.setBrightness(255);
if(!BR_active)BR_LED.clear();
if(!BL_active)BL_LED.clear();
if(!Brightness_toggle_active) BRK_LED.clear();
BR_LED.show();
BL_LED.show();
BRK_LED.show();
delay(Pixel_SPD);
}