#include <Adafruit_NeoPixel.h>
#define PIN_E 6
#define PIN_D 5
#define PINFREIO 12
#define PINSETA 14
#define NUM_LEDS 8
#define CHAVESQU 2
#define CHAVEDIR 3
Adafruit_NeoPixel stripE = Adafruit_NeoPixel(NUM_LEDS, PIN_E, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripD = Adafruit_NeoPixel(NUM_LEDS, PIN_D, NEO_GRB + NEO_KHZ800);
byte estado=0;
void setup() {
pinMode(PINFREIO, INPUT_PULLUP);
pinMode(CHAVESQU, INPUT_PULLUP);
pinMode(CHAVEDIR, INPUT_PULLUP);
pinMode(PINSETA, INPUT_PULLUP);
stripE.begin();
stripD.begin();
stripD.setBrightness(180);
stripE.setBrightness(180);
apaga();
}
void loop() {
checaestado();
while (digitalRead(PINFREIO)==LOW) freio();
apaga();
}
void apaga(){
stripD.clear();
stripE.clear();
stripD.show();
stripE.show();
}
void setadir(){
for (int i = NUM_LEDS; i >= 0; i--) {
stripD.setPixelColor(i, 255, 255, 0);
stripD.show();
delay(100);
}
apaga();
}
void setaesq(){
for (int i = NUM_LEDS; i >= 0; i--) {
stripE.setPixelColor(i, 255, 255, 0);
stripE.show();
delay(100);
}
apaga();
}
void piscalerta(){
/*for (int i = NUM_LEDS; i >= 0; i--) {
stripE.setPixelColor(i, 255, 255, 0);
stripD.setPixelColor(i, 255, 255, 0);
} */
for (int i = NUM_LEDS; i >= 0; i--) {
stripE.setPixelColor(i,0xFFFF00);
stripD.setPixelColor(i,0xFFFF00);
}
stripE.show();
stripD.show();
delay(400);
apaga();
delay(400);
}
void freio(){
for (int i = NUM_LEDS; i >= 0; i--) {
stripE.setPixelColor(i, 255, 0, 0);
stripD.setPixelColor(i, 255, 0, 0);
}
stripE.show();
stripD.show();
}
void checaestado(){
while (digitalRead(PINSETA) == LOW) piscalerta();
while (digitalRead(CHAVESQU) == LOW) setaesq();
while (digitalRead(CHAVEDIR) == LOW) setadir();
}