#include <Adafruit_NeoPixel.h>
// Pin definíciók
#define LED_PIN_1 9
#define LED_PIN_2 10
#define LED_PIN_3 11
#define LED_PIN_4 12
#define BUTTON_PIN_1 3
#define BUTTON_PIN_2 2
#define BUTTON_PIN_3 6
#define BUTTON_PIN_4 13
#define SWITCH_PIN_1 7
#define SWITCH_PIN_2 4
#define SWITCH_PIN_3 5
// LED szalagok inicializálása
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(50, LED_PIN_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(50, LED_PIN_2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(50, LED_PIN_3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(50, LED_PIN_4, NEO_GRB + NEO_KHZ800);
// Változók
bool runningLights = false;
bool hazardLights = false;
bool knightRider = false;
bool brakeLights = false;
bool reverseLights = false;
void setup() {
// LED szalagok inicializálása
strip1.begin();
strip2.begin();
strip3.begin();
strip4.begin();
strip1.show();
strip2.show();
strip3.show();
strip4.show();
// Bemeneti pinmódok beállítása
pinMode(BUTTON_PIN_1, INPUT_PULLUP);
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
pinMode(BUTTON_PIN_3, INPUT_PULLUP);
pinMode(BUTTON_PIN_4, INPUT_PULLUP);
pinMode(SWITCH_PIN_1, INPUT_PULLUP);
pinMode(SWITCH_PIN_2, INPUT_PULLUP);
pinMode(SWITCH_PIN_3, INPUT_PULLUP);
}
void loop() {
// Kapcsolók állapotának ellenőrzése
if (digitalRead(SWITCH_PIN_1) == LOW) {
runningLights = !runningLights;
delay(200); // Debounce
}
if (digitalRead(SWITCH_PIN_2) == LOW) {
hazardLights = !hazardLights;
delay(200); // Debounce
}
if (digitalRead(SWITCH_PIN_3) == LOW) {
knightRider = !knightRider;
delay(200); // Debounce
}
// Nyomógombok állapotának ellenőrzése
if (digitalRead(BUTTON_PIN_1) == LOW) {
rightIndicator();
}
if (digitalRead(BUTTON_PIN_2) == LOW) {
leftIndicator();
}
if (digitalRead(BUTTON_PIN_3) == LOW) {
brakeLights = true;
} else {
brakeLights = false;
}
if (digitalRead(BUTTON_PIN_4) == LOW) {
reverseLights = true;
} else {
reverseLights = false;
}
// Fő vezérlési logika
if (hazardLights) {
hazard();
} else if (brakeLights) {
brake();
} else if (reverseLights) {
reverse();
} else if (runningLights) {
running();
} else if (knightRider) {
knightRiderEffect();
} else {
allOff();
}
}
void running() {
// Menetfény beállítása
setColor(strip1, strip1.Color(255, 255, 255)); // Fehér fény
setColor(strip2, strip2.Color(255, 255, 255)); // Fehér fény
setColor(strip3, strip3.Color(127, 0, 0)); // Piros fény 50%-os fényerővel
setColor(strip4, strip4.Color(127, 0, 0)); // Piros fény 50%-os fényerővel
}
void hazard() {
// Vészvillogó beállítása
setColor(strip1, strip1.Color(255, 165, 0)); // Narancssárga fény
setColor(strip2, strip2.Color(255, 165, 0)); // Narancssárga fény
setColor(strip3, strip3.Color(255, 165, 0)); // Narancssárga fény
setColor(strip4, strip4.Color(255, 165, 0)); // Narancssárga fény
delay(500);
allOff();
delay(500);
}
void knightRiderEffect() {
// Knight Rider effektus
for (int i = 0; i < 50; i++) {
strip1.setPixelColor(i, strip1.Color(255, 0, 0));
strip2.setPixelColor(i, strip2.Color(255, 0, 0));
strip1.show();
strip2.show();
delay(20);
strip1.setPixelColor(i, strip1.Color(0, 0, 0));
strip2.setPixelColor(i, strip2.Color(0, 0, 0));
}
for (int i = 49; i >= 0; i--) {
strip1.setPixelColor(i, strip1.Color(255, 0, 0));
strip2.setPixelColor(i, strip2.Color(255, 0, 0));
strip1.show();
strip2.show();
delay(20);
strip1.setPixelColor(i, strip1.Color(0, 0, 0));
strip2.setPixelColor(i, strip2.Color(0, 0, 0));
}
}
void rightIndicator() {
// Jobb index beállítása
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 50; i++) {
strip1.setPixelColor(i, strip1.Color(255, 165, 0));
strip3.setPixelColor(i, strip3.Color(255, 165, 0));
strip1.show();
strip3.show();
delay(20);
}
for (int i = 49; i >= 0; i--) {
strip1.setPixelColor(i, strip1.Color(0, 0, 0));
strip3.setPixelColor(i, strip3.Color(0, 0, 0));
strip1.show();
strip3.show();
delay(20);
}
}
}
void leftIndicator() {
// Bal index beállítása
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 50; i++) {
strip2.setPixelColor(i, strip2.Color(255, 165, 0));
strip4.setPixelColor(i, strip4.Color(255, 165, 0));
strip2.show();
strip4.show();
delay(20);
}
for (int i = 49; i >= 0; i--) {
strip2.setPixelColor(i, strip2.Color(0, 0, 0));
strip4.setPixelColor(i, strip4.Color(0, 0, 0));
strip2.show();
strip4.show();
delay(20);
}
}
}
void brake() {
// Fék beállítása
setColor(strip3, strip3.Color(255, 0, 0)); // Piros fény
setColor(strip4, strip4.Color(255, 0, 0)); // Piros fény
delay(100);
allOff();
delay(100);
}
void reverse() {
// Tolató lámpa beállítása
setColor(strip3, strip3.Color(255, 255, 255)); // Fehér fény
setColor(strip4, strip4.Color(255, 255, 255)); // Fehér fény
}
void allOff() {
// Minden LED kikapcsolása
setColor(strip1, strip1.Color(0, 0, 0));
setColor(strip2, strip2.Color(0, 0, 0));
setColor(strip3, strip3.Color(0, 0, 0));
setColor(strip4, strip4.Color(0, 0, 0));
}
void setColor(Adafruit_NeoPixel &strip, uint32_t color) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}
strip.show();
}ERC Warnings
not1:IN: Input pin not driven