aHi,
Im bussy with a project; using 2 neopixel sticks, 2 individual neopixels, a 1 watt LED and 2 buttons to make a blinking system for my bike.
The 2 sticks are going on the back of my bike, one left and one right, the individual pixels are going into my steering bar(left and right). Then when I press the left button on the handle bar the left neopixel and stick need to blink. And the same for the right ones, for when I press the right button.
-I have a question about the code, now I have two times a “for” for the “if statement”. Is this the right way to let the whole right or left side to know when they need to blink?
-And Where do I tell the Arduino that one is a stick with 8 neopixels and the other one is just an individual pixel?
I think I have to do that somewhere here right(I have read all the guides for the neopixels but I am still confused about this):
void colorWipeRF(uint32_t c, uint8_t wait) {
for(uint8_t i=0; i<strip_d.numPixels(); i++) {
strip_d.setPixelColor(i, c);
strip_d.show();
delay(wait);
Then I also have a question recording the lag I have, something nothing happened when I press one of the buttons. A friend of me told me to fix this with the millis in the code, I have looked through some example code, but how am I supposed to use this millis code in the mine?
Thank you so much!!
bobby
#include <Adafruit_NeoPixel.h>
//#define PIN 6
//#define PIN 5
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 2000 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
// changed number of pixels
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(8, 5); // left rear strip
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(8, 6); // right rear strip
Adafruit_NeoPixel strip_c = Adafruit_NeoPixel(1, 10); // left front dot
Adafruit_NeoPixel strip_d = Adafruit_NeoPixel(1, 11); // right front dot
const int buttonPinL = 2;
const int buttonPinR = 3;
boolean buttonStateL = 0; // modified to boolean
boolean buttonStateR = 0; // modified to boolean
//const int brakebuttonPin = 4;
//boolean buttonStateBrake = 0; // modified to boolean
const int frontPin = 13;
void setup() {
pinMode(buttonPinL, INPUT);
pinMode(buttonPinR, INPUT);
// pinMode(brakebuttonPin, INPUT);
pinMode(frontPin, OUTPUT);
strip_a.begin();
strip_a.show(); // Initialize all pixels to 'off'
strip_b.begin();
strip_b.show(); // Initialize all pixels to 'off'
strip_c.begin();
strip_c.show(); // Initialize all pixels to 'off'
strip_d.begin();
strip_d.show(); // Initialize all pixels to 'off'
}
void loop() {
buttonStateL = digitalRead(buttonPinL);
buttonStateR = digitalRead(buttonPinR);
//buttonStateBrake = digitalRead(brakebuttonPin);
digitalWrite(frontPin, HIGH);
if (buttonStateL == HIGH) {
for(int i=0; i<10; i++) {
colorWipeL(strip_a.Color(240, 140, 0), 10); //Orange blinking IF button is pressed
strip_a.setBrightness(255); // set brithness of backlight to full
strip_b.setBrightness(128); // dim brithness of opposite stick
delay(250);
colorWipeL(strip_a.Color(0, 0, 0), 0); //Blink
delay(250);
}
for (int i=0; i<10; i++) {
colorWipeLF(strip_c.Color(240, 140, 0), 10); //Orange blinking dot IF button is pressed
strip_c.setBrightness(255); // set brithness of left dot to full
delay(250);
colorWipeLF(strip_c.Color(0, 0, 0), 0); //Blink
delay(250);
}
}
else {
strip_a.setBrightness(120); // set brithness of backlight to 3/4
colorWipeL(strip_a.Color(255, 0, 0), 50); // Red rest of time
strip_c.setBrightness(255); // set brithness of left dot
colorWipeLF(strip_a.Color(123, 104, 238), 50); // Blue rest of time
}
if (buttonStateR == HIGH) {
for(int i=0; i<10; i++) {
colorWipeR(strip_b.Color(240, 140, 0), 10); //Orange IF button is pressed
strip_b.setBrightness(255); // set brithness of backlight to full
strip_a.setBrightness(128); // dim brithness of opposite stick
delay(250);
colorWipeR(strip_b.Color(0, 0, 0), 0); //Blink
delay(250);
}
for (int i=0; i<10; i++) {
colorWipeRF(strip_d.Color(240, 140, 0), 10); //Orange blinking dot IF button is pressed
strip_d.setBrightness(255); // set brithness of left dot to full
delay(250);
colorWipeRF(strip_d.Color(0, 0, 0), 0); //Blink
delay(250);
}
}
else {
strip_b.setBrightness(120); // set brithness of backlight to 3/4
colorWipeR(strip_b.Color(255, 0, 0), 50); // Red rest of time
strip_d.setBrightness(255); // set brithness of left dot
colorWipeRF(strip_d.Color(123, 104, 238), 50); // Blue rest of time
}
/* if (buttonStateBrake == LOW) {
strip_b.setBrightness(255);
strip_a.setBrightness(255);
colorWipeR(strip_b.Color(100, 100, 50), 10); //Orange IF button is pressed
colorWipeR(strip_a.Color(100, 100, 50), 10); //Orange IF button is pressed
// delay(5);
}
else {
strip_b.setBrightness(120); // set brithness of backlight to 3/4
strip_a.setBrightness(120); // set brithness of backlight to 3/4
colorWipeR(strip_b.Color(255, 0, 0), 10); // Red rest of time
colorWipeR(strip_a.Color(255, 0, 0), 10); // Red rest of time
} */
}
// Fill the dots one after the other with a color
void colorWipeL(uint32_t c, uint8_t wait) {
for(uint8_t i=0; i<strip_a.numPixels(); i++) {
strip_a.setPixelColor(i, c);
strip_a.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipeR(uint32_t c, uint8_t wait) {
for(uint8_t i=0; i<strip_b.numPixels(); i++) {
strip_b.setPixelColor(i, c);
strip_b.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipeLF(uint32_t c, uint8_t wait) {
for(uint8_t i=0; i<strip_c.numPixels(); i++) {
strip_c.setPixelColor(i, c);
strip_c.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipeRF(uint32_t c, uint8_t wait) {
for(uint8_t i=0; i<strip_d.numPixels(); i++) {
strip_d.setPixelColor(i, c);
strip_d.show();
delay(wait);
}
}