1) I can get the swipe up and down to happen. I'm struggling to add a pause before swiping up and down again. Right now, the program cylonEye() works without a pause. cylonEye_notWorking() is, well, not working. I've commented a few trouble spots that might be the issue below.
2) The programs cylonUp() and cylonDown() are only one line of code different. There should be a way to combine these into one program, but I'm not sure how.
Can anyone point me in the right direction?
Thanks.
Code: Select all
//NeoPixel LED Digital Strip Cylon Eye v1.10 Created by EternalCore
#include <Adafruit_NeoPixel.h>
//Settings:
#define PIN 1 //The Pin out your Neopixel DIN strip/stick is connected to (Default is 6)
#define numPixelsInStrip 8 //The total amount of pixel's/led's in your connected strip/stick (Default is 60)
long previousMillis = 0; // will store last time LED was updated
int neoPixelToChange = 0; //track which neoPixel to change
int neoPixel_j = 0; //stores values for program cycles
int fadeDirection = -1;//change sigen to fade up or down
boolean cylonDirection = true; //keeps track of the direction the pixels should swipe
boolean cylonPause = false; //keeps track of the pause inbetween swipes
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixelsInStrip, PIN, NEO_GRB + NEO_KHZ800); //Standered Strip function
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
cylonEye(40,500);
}
void cylonEye(uint8_t swipeSpeed, uint8_t pauseTime){
//if needed, change directions
if (neoPixelToChange > numPixelsInStrip) {
cylonDirection = false;
}
if (neoPixelToChange < 0) {
cylonDirection = true;
}
//run the swipe
if(cylonDirection){
cylonUp(strip.Color(175,0,0), strip.Color(25,0,0), swipeSpeed); // red
} else {
cylonDown(strip.Color(175,0,0), strip.Color(25,0,0), swipeSpeed); // red
}
}
void cylonEye_notWorking(uint8_t swipeSpeed, uint8_t pauseTime){
if (cylonPause){ //we are on a pause break from swipes
unsigned long currentPauseMillis = millis();
//check to see if we've waited long enough
if(currentPauseMillis - previousMillis > pauseTime) { /////////////////////////////// this is not getting called. Why????????????????
// save the last time you checked the pause
previousMillis = currentPauseMillis;
cylonPause = false; //end the pause
}
} else {
//if needed, change directions
if (neoPixelToChange > numPixelsInStrip) {
cylonDirection = false;
}
if (neoPixelToChange < 0) {
cylonDirection = true;
cylonPause = true; //take a break from the swipe
//turn all pixels off
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
}
strip.show();
previousMillis = millis();
}
//run the swipe
if(cylonDirection){
cylonUp(strip.Color(175,0,0), strip.Color(25,0,0), swipeSpeed); // red
} else {
cylonDown(strip.Color(175,0,0), strip.Color(25,0,0), swipeSpeed); // red
}
}
}
void cylonUp(uint32_t c0, uint32_t c1, uint8_t wait) {
unsigned long currentMillis = millis();
//neoPixelToChange * wait
if(currentMillis - previousMillis > wait) {
//turn all pixels off
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
}
// save the last time you changed a NeoPixel
previousMillis = currentMillis;
//change a pixel
strip.setPixelColor(neoPixelToChange, c0); //primary color
strip.setPixelColor(neoPixelToChange-1, c1); //secondary color
strip.setPixelColor(neoPixelToChange+1, c1); //secondary color
strip.show();
neoPixelToChange++;
}
}
void cylonDown(uint32_t c0, uint32_t c1, uint8_t wait) {
unsigned long currentMillis = millis();
//neoPixelToChange * wait
if(currentMillis - previousMillis > wait) {
//turn all pixels off
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
}
// save the last time you changed a NeoPixel
previousMillis = currentMillis;
//change a pixel
strip.setPixelColor(neoPixelToChange, c0); //primary color
strip.setPixelColor(neoPixelToChange-1, c1); //secondary color
strip.setPixelColor(neoPixelToChange+1, c1); //secondary color
strip.show();
neoPixelToChange--; //is there any way to combine this with cylonUp, since this is the only line that is different?
}
}
// Fill all the dots with one color
void allColor(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
}
}