DJ Namaste
Active member
Hello
I am using apa102 and ws2812 leds for some projects using adafruit's neopixel and dotstar libraries. I want to do a colorwipe of one color then a second color to get strobe effects. A for loop works but every time I change the led strand length I have to change the for loop duration to get it to exit the loop after say 50 colorwipe sequences. I would like to make it work based on millis. I found the blink example and attempted to make it work with the digital led strips but the code is skipped over and the next sequence is displayed.
Below is my attempt to make a time based loop that will continue a strobe until the time elapses.
Any idea what im doing wrong?
#include <Adafruit_DotStar.h>
#include <SPI.h>
#define NUMPIXELS 32 // Number of LEDs in strip
#define DATAPIN 6
#define CLOCKPIN 8
Adafruit_DotStar strip = Adafruit_DotStar(
NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BGR);
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
strip.begin(); // Initialize pins for output
strip.show(); // Turn all LEDs off ASAP
}
void loop() {
int j;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
colorWipe(strip.Color(0, 0, 100), 1);
colorWipe(strip.Color(0, 10, 0), 1);
}
for (j = 0; j < 5; j++) {
colorWipe(strip.Color(0, 0, 0), 1);
colorSwipe(strip.Color(100, 0, 0), 1);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
delay(wait);
}
strip.show();
}
// Fill the dots one after the other with a color
void colorSwipe(uint32_t c, uint8_t wait) {
for(uint16_t i=strip.numPixels(); i>0; i--) {
strip.setPixelColor(i, c);
delay(wait);
}
strip.show();
}
I am using apa102 and ws2812 leds for some projects using adafruit's neopixel and dotstar libraries. I want to do a colorwipe of one color then a second color to get strobe effects. A for loop works but every time I change the led strand length I have to change the for loop duration to get it to exit the loop after say 50 colorwipe sequences. I would like to make it work based on millis. I found the blink example and attempted to make it work with the digital led strips but the code is skipped over and the next sequence is displayed.
Below is my attempt to make a time based loop that will continue a strobe until the time elapses.
Any idea what im doing wrong?
#include <Adafruit_DotStar.h>
#include <SPI.h>
#define NUMPIXELS 32 // Number of LEDs in strip
#define DATAPIN 6
#define CLOCKPIN 8
Adafruit_DotStar strip = Adafruit_DotStar(
NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BGR);
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
strip.begin(); // Initialize pins for output
strip.show(); // Turn all LEDs off ASAP
}
void loop() {
int j;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
colorWipe(strip.Color(0, 0, 100), 1);
colorWipe(strip.Color(0, 10, 0), 1);
}
for (j = 0; j < 5; j++) {
colorWipe(strip.Color(0, 0, 0), 1);
colorSwipe(strip.Color(100, 0, 0), 1);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
delay(wait);
}
strip.show();
}
// Fill the dots one after the other with a color
void colorSwipe(uint32_t c, uint8_t wait) {
for(uint16_t i=strip.numPixels(); i>0; i--) {
strip.setPixelColor(i, c);
delay(wait);
}
strip.show();
}