Update LED_Helmet

This commit is contained in:
MindCreeper03
2025-02-28 17:08:32 +01:00
parent 5345d21d29
commit 52f7ce5fc7
2441 changed files with 47 additions and 1320410 deletions

View File

@@ -1,12 +1,14 @@
#define Blinker_Right 17
#define Blinker_Left 16
#define Brightness_Toggle 15
#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>
@@ -23,7 +25,7 @@ void setup() {
// put your setup code here, to run once:
pinMode(Blinker_Right,INPUT);
pinMode(Blinker_Left,INPUT);
pinMode(Brightness_Toggle,INPUT);
pinMode(BRT,INPUT);
BL_LED.begin();
BR_LED.begin();
BRK_LED.begin();
@@ -37,59 +39,46 @@ 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;
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_state = BR_State;
old_BR_state = BR_State; //Right Blinker Input Debouncing and Sticky Function
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);
}
if(BR_State != old_BR_state && !old_BR_state ) BR_active = !BR_active;
// 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));
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));
}
}
for(int pixel = 0;pixel<BL_LED_State;pixel++){
BL_LED.setPixelColor(pixel, BL_LED.Color(255, 255, 0));
if(BL_active){
for(int pixel = 0;pixel<BL_LED_State;pixel++){
BL_LED.setPixelColor(pixel, BL_LED.Color(255, 30, 0));
}
}
for(int pixel = 0;pixel<(BRK_LED_State-BRK_LED_State%2)/2;pixel++){
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(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.setBrightness(Brightness);
BL_LED.setBrightness(Brightness);
BRK_LED.setBrightness(Brightness);
BR_LED.show();
BL_LED.show();
BRK_LED.show();