Hello,
Im currently trying to adapt some tail lights using neopixel rings and strips.
The first part of my idea is to have two 12 led rings on dim red as tail lights, when a button is pressed there are two smaller 7 led rings which illuminate at 100% brightness and the outer rings also change to 100% brightness.
The second part is an led strip which will be used for an indicator. when a button is pressed the strip will fill one led after another until the strip is full and then all leds go off at once, a slight pause and then repeat until the button is de-pressed. Similar to new audi sweeping indicators.
I have the above working.
The issue i have i assume is because of the delay used in the code, basically once the indicator button is pressed nothing else responds until the sweep of the indicator is complete.
For example i switch the indicator on and try press the brake light and only when the sweep is complete does the brake light illuminate and again if the brake light button is depressed whilst the indicator is sweeping the light remain on until the indicator completes the sweep.
Can anyone assist me with changing my code? I've been googling frantically and found numerous sites with examples of this process working using Millis but cant work out how to edit my code to use that format.
Thanks in advanced.
// tail and brake
#include <Adafruit_NeoPixel.h>
#define PIN 9
#define NUMPIXELS 38
const int buttonPin = 6;
int buttonState = 0;
// indicator
#define PIN1 10
#define NUMPIXELS1 24
const int buttonPin1 = 7;
int buttonState1 = 0;
Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUMPIXELS1, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS1, PIN1, NEO_GRB + NEO_KHZ800);
// tail light
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 0;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pixels.begin();
pinMode(buttonPin1, INPUT_PULLUP);
pixels1.begin();
strip1.begin();
}
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip1.numPixels(); i++) {
strip1.setPixelColor(i, c);
strip1.show();
delay(wait);
}
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
tailLights();
indicatorSweep();
}
void tailLights() {
// brake lights
if (buttonState == LOW) {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(255, 0, 0)); // all led rings max brightness red colour - Brakes applied
pixels.show();
delay(delayval);
}
}
else
// tail lights
{
for (int i = 0; i < 12; i++) {
pixels.setPixelColor(i, pixels.Color(30, 0, 0)); // first large led ring of 12 leds dim red colour
pixels.show();
delay(delayval);
}
for (int i = 12; i < 19; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); //first small ring of 7 leds off
pixels.show();
delay(delayval);
}
for (int i = 19; i < 31; i++) {
pixels.setPixelColor(i, pixels.Color(30, 0, 0)); // second large ring of 12 leds dim red colour
pixels.show();
delay(delayval);
}
for (int i = 31; i < 38; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // second small ring of 7 leds off
pixels.show();
delay(delayval);
}
}
}
void indicatorSweep() {
// indicator
if (buttonState1 == LOW) { // fills the led strip one by one untill full amber then all off
colorWipe(strip1.Color(255, 60, 0), 20);
colorWipe(strip1.Color(0, 0, 0), 0);
delay(300);
strip1.show();
}
}