Hello,
I have a small neopixel stick. On this stick I would like to display two effects in a row.
1.) a repeating running light with e.g. 10 repetitions.
2.) a stroboscope effect which should flash 50 times fast afterwards
After that the function should be finished.
I am not so good at programming.
Theoretically my project works. but the esp8266 crashes if my while loop has more than 5 repetitions.
Also I don't know if the delay is so good with the stroboscope effect.
At the moment the function is called in the loop, but in the future it should just be called once by another action.
Am I on the right track? can anyone give me some helpful tips?
#include <Adafruit_NeoPixel.h>
#define PIN_NEO_PIXEL 0 // The ESP8266 D3
#define NUM_PIXELS 8 // The number of LEDs (pixels) on NeoPixel LED strip
//Adafruit_NeoPixel tira(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel tira = Adafruit_NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
//byte mState = 0;
byte iteration = 0;
//timing stuff
unsigned long commonMillis;
unsigned long switchMillis;
bool flag = true;
int zaehler1 = 1;
int zaehler2 = 1;
void setup() {
//NeoPixel.begin(); // initialize NeoPixel strip object (REQUIRED)
tira.begin(); // initialize NeoPixel strip object (REQUIRED)
tira.show();
tira.setBrightness(50);
}
void loop() {
yamato();
}
void yamato() {
while (zaehler1 < 5) //(millis() - commonMillis >= 100) //flag == true &&
{
if (millis() - commonMillis >= 100) {
//restart the TIMER
commonMillis = millis();
//Led color red
tira.setPixelColor(iteration, 255, 0, 0);
tira.setBrightness(50);
tira.show();
//next LED
iteration++;
}
if (iteration > 7) {
tira.clear();
tira.show();
iteration = 0;
zaehler1 = zaehler1 + 1;
}
}
tira.clear();
tira.show();
delay(100);
if (zaehler2 < 50)
{
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
tira.setPixelColor(pixel, tira.Color(255, 255, 255)); // Led color white
tira.setBrightness(80);
}
tira.show();
//next LED
delay(20);
tira.clear();
tira.show();
zaehler2 = zaehler2 + 1;
} else {
zaehler1 = 1;
zaehler2 = 1;
}
}
ok, that solved the crash problem. thank you very much.
Now, If I do not execute this in the loop funkction. I have to change the second part of the code somehow.
I tried to do a while too, but it does not flash anymore. It just lights up.
#include <Adafruit_NeoPixel.h>
#define PIN_NEO_PIXEL 0 // The ESP8266 D3
#define NUM_PIXELS 8 // The number of LEDs (pixels) on NeoPixel LED strip
Adafruit_NeoPixel tira = Adafruit_NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
//byte mState = 0;
byte iteration = 0;
//timing stuff
unsigned long commonMillis;
unsigned long switchMillis;
bool flag = true;
int counter1 = 1;
int counter2 = 1;
void setup() {
tira.begin();
tira.show();
tira.setBrightness(50);
yamato();
}
void loop() {
}
void yamato() {
while (counter1 < 10)
{
yield(); // or delay(0);
if (millis() - commonMillis >= 100) {
//restart the TIMER
commonMillis = millis();
//Led color red
tira.setPixelColor(iteration, 255, 0, 0);
tira.setBrightness(50);
tira.show();
//next LED
iteration++;
}
if (iteration > 7) {
tira.clear();
tira.show();
iteration = 0;
counter1 = counter1 + 1;
}
}
tira.clear();
tira.show();
delay(100);
while (counter2 < 50)
{
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
tira.setPixelColor(pixel, tira.Color(255, 255, 255)); // Led color white
tira.setBrightness(80);
}
tira.show();
delay(20);
tira.clear();
tira.show();
counter2 = counter2 + 1;
}
if (counter2 == 50) {
counter1 = 1;
counter2 = 1;
}
}
setBrightness() was intended to be called once, in setup(), to limit the current/brightness of the LEDs throughout the life of the sketch. It is not intended as an animation effect itself!