You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB

#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 40
#define PIN_STRIP 17
bool shouldUpdateLights = false;
uint8_t lightMode = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800);
void lightOff() {
for(int i = 0; i < NUM_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(0,0,0));
}
portDISABLE_INTERRUPTS();
pixels.show();
portENABLE_INTERRUPTS();
}
void lightWhite() {
for(int i = 0; i < NUM_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(180,180,180));
}
portDISABLE_INTERRUPTS();
pixels.show();
portENABLE_INTERRUPTS();
}
void lightPolice() {
// Temporary mode to test
for(int i = 0; i < NUM_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(0,0,180));
}
portDISABLE_INTERRUPTS();
pixels.show();
portENABLE_INTERRUPTS();
}
void lightBlinkers(bool isLeft) {
// Temporary mode to test
for(int i = 0; i < NUM_LEDS; i++) {
if(i<10 && isLeft) pixels.setPixelColor(i, pixels.Color(180,180,0));
else if(i>30 && !isLeft) pixels.setPixelColor(i, pixels.Color(180,180,0));
else pixels.setPixelColor(i, pixels.Color(180,180,180));
}
portDISABLE_INTERRUPTS();
pixels.show();
portENABLE_INTERRUPTS();
}
void lightBackFront() {
for(int i = 0; i < NUM_LEDS; i++) {
if(i<5 || i>34) pixels.setPixelColor(i, pixels.Color(190,0,0));
else pixels.setPixelColor(i, pixels.Color(180,180,180));
}
portDISABLE_INTERRUPTS();
pixels.show();
portENABLE_INTERRUPTS();
}
void updateLights() {
if(lightActive) {
Serial.println("light active");
switch(lightMode) {
case 0:
lightBackFront();
Serial.println("normal");
break;
case 1:
lightBlinkers(true); // left
Serial.println("blink");
break;
case 2:
lightBlinkers(false); // right
Serial.println("plink");
break;
case 3:
lightPolice();
Serial.println("plice");
break;
}
}else {
Serial.println("light inactive");
lightOff();
}
shouldUpdateLights = false;
}
void setupLights() {
portDISABLE_INTERRUPTS();
pixels.begin();
portENABLE_INTERRUPTS();
delay(1);
lightOff();
}