Hi
I'm building a light set for a scooter so i have 16 x red pixels that become running (KNIGHT RIDER STYLE) when the brake is pressedand the brightness increases
Also i have 2 sets 5 orange indicators left and right that also do a running sketch when the correct button is high
the code for the brake switch works well and the indicators but when i put the code together it seems to just ignore any of the code except for the red brake lights and the buttons don't work
code attached
thanks in advance
Marky
#include <Adafruit_NeoPixel.h>
#define BB_PIN 11
#define LB_PIN 9
#define RB_PIN 6
#define LB_PIN 5
//#define RB_PIN 6
#define BPIXEL_PIN 7 // Digital IO pin connected to the NeoPixels.
#define LPIXEL_PIN 3
#define RPIXEL_PIN 2
#define BPIXEL_COUNT 16
#define LPIXEL_COUNT 5
#define RPIXEL_COUNT 5
Adafruit_NeoPixel BRAKELIGHT = Adafruit_NeoPixel(BPIXEL_COUNT, BPIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel LEFT = Adafruit_NeoPixel(LPIXEL_COUNT, LPIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel RIGHT = Adafruit_NeoPixel(RPIXEL_COUNT , RPIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BB_PIN , INPUT_PULLUP);
BRAKELIGHT .begin();
BRAKELIGHT .show(); // Initialize all pixels to 'off'
LEFT.begin();
LEFT.show(); // Initialize all pixels to 'off'
RIGHT.begin();
RIGHT.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState_1 = digitalRead(BB_PIN );
bool newState_2 = digitalRead(LB_PIN );
bool newState_3 = digitalRead(RB_PIN );
startShow_1(showType);
// Check if state changed from high to low (button press).
if (newState_1 == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_1 = digitalRead(BB_PIN );
if (newState_1 == LOW) {
showType++;
if (showType > 1)
showType = 0;
}
}
startShow_2(showType);
// Check if state changed from high to low (button press).
if (newState_2 == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_2 = digitalRead(BB_PIN );
if (newState_2 == LOW) {
showType++;
if (showType > 1)
showType = 0;
startShow_2(showType);
}
}
startShow_3(showType);
// Check if state changed from high to low (button press).
if (newState_3 == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_3 = digitalRead(BB_PIN );
if (newState_3 == LOW) {
showType++;
if (showType > 1)
showType = 0;
startShow_3(showType);
}
}
}
void startShow_1(int i) {
switch (i) {
case 0: setPixelColor(BRAKELIGHT .Color(0, 0, 0), 12);
// break;
case 1: setPixelColor(BRAKELIGHT .Color(225, 0, 0), 12);
// break;
case 2: setPixelColor(BRAKELIGHT .Color(0, 0, 0), 12);
// break;
case 3: setPixelColor(BRAKELIGHT .Color(225, 0, 0), 12);
//break;
case 4: setPixelColor(BRAKELIGHT .Color(0, 0, 0), 12);
case 5: setPixelColor(BRAKELIGHT .Color(50, 0, 0), 12);
break;
}
}
void startShow_2(int i) {
switch (i) {
case 0: setPixelColor(LEFT.Color(0, 0, 0), 12);
// break;
case 1: setPixelColor(LEFT .Color(225, 0, 0), 12);
// break;
case 2: setPixelColor(LEFT .Color(0, 0, 0), 12);
// break;
case 3: setPixelColor(LEFT .Color(225, 0, 0), 12);
//break;
case 4: setPixelColor(LEFT .Color(0, 0, 0), 12);
case 5: setPixelColor(LEFT .Color(50, 0, 0), 12);
break;
}
}
void startShow_3(int i) {
switch (i) {
case 0: setPixelColor(RIGHT.Color(0, 0, 0), 12);
// break;
case 1: setPixelColor(RIGHT .Color(225, 0, 0), 12);
// break;
case 2: setPixelColor(RIGHT .Color(0, 0, 0), 12);
// break;
case 3: setPixelColor(RIGHT .Color(225, 0, 0), 12);
//break;
case 4: setPixelColor(RIGHT .Color(0, 0, 0), 12);
case 5: setPixelColor(RIGHT .Color(50, 0, 0), 12);
break;
}
}
// Fill the dots one after the other with a color
void setPixelColor(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < BRAKELIGHT .numPixels(); i++) {
BRAKELIGHT .setPixelColor(i, c);
BRAKELIGHT .show();
delay(wait);
{
}
LEFT .setPixelColor(i, c);
LEFT .show();
delay(wait);
}
{
RIGHT.show(); // Initialize all pixels to 'off'
RIGHT.begin();
delay (50) ; // Delay 500ms before the light of another LED
}
}