So i've spent quite some time with this project, I have most of the functions working.
my arduino (redboard from sparkfun, set as uno in ide) will look for 2 switches on pins 11&12, both wired to ground and programmed with internal pullup.
there are 3 if statements
one looks for both switches to be "LOW" (This loop doesn't work correctly)
the other 2 look for just one of the 2 switches to be "LOW" and will make the neopixels colorWipe to either the left or right in red or blue
My loop that doesn't work is the void colorWipeDUAL
its function is to make both left and right scan out at the same time (like a traffic adviser for a vehicle)
the selection of color and time work but I realize that having two for statements isn't working.
The red color will come on quickly then it will turn on the blue very slowly (and repeat as long as the switches are "LOW"
how can I restructure the loop to solve my issue.
here is my code, comments added for the identifications of key structures and information;
#include <Adafruit_NeoPixel.h>
#define left 12
#define right 11
#define PIN 13
int buttonState = 0;
int buttonState2 = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(56, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(left, INPUT);
digitalWrite(left, HIGH);
pinMode(right, INPUT);
digitalWrite(right, HIGH);
strip.begin();
colorWipe(strip.Color(5, 5, 5), 0); // dim white no chase
strip.show(); // Initialize all pixels to 'off'
}
//loop goes forward, starts halfway
void colorWipe2(uint32_t c, uint8_t wait) {
for(uint16_t i=29; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//error with this loop
void colorWipeDual(uint32_t c, uint8_t wait, uint32_t b) {
for (uint16_t i=29; i<strip.numPixels(); i++){
for(int16_t t=28; t>-1; t--) {
strip.setPixelColor(t, b); //t is the pixel number scans to the right (color currently set to red)
strip.setPixelColor(i, c); //i is the pixel number scans to the left (color currently set to blue)
strip.show();
delay(wait);
}
}
}
//loop goes in reverse working, starts halfway
void colorWipeREV(uint32_t c, uint8_t wait) {
for(int16_t i=28; i>-1; i--) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void loop() {
buttonState = digitalRead(left);
buttonState2 = digitalRead(right);
if ((buttonState == LOW) && (buttonState2 == LOW)) { //this works corrently
// turn LED on:
colorWipeDual (strip.Color(0, 0, 100), 10, strip.Color(100, 0, 0)); // middle out color wipe with RGB color (delay) then another RGB color
strip.show();
colorWipe(strip.Color(5, 5, 5), 0); // dim white no chase
strip.show();
}
if ((buttonState == LOW) && (buttonState2 == HIGH)) {
// turn LED on:
colorWipeREV(strip.Color(100, 0, 0), 20); // red
strip.show();
colorWipeREV(strip.Color(5, 5, 5), 0); // dim white no chase
strip.show();
}
if ((buttonState2 == LOW) && (buttonState == HIGH)){
// turn LED on:
colorWipe2(strip.Color(0, 0, 100), 20); // blue
strip.show();
colorWipe(strip.Color(5, 5, 5), 0); // dim white no chase
strip.show();
}
}