Hello everybody, I wanted to make this timer with Neopixels. The timer works by pressing a button that has to be kept pressed otherwise the timer should stop. The thing is that this is (this is probably obvious to you lol) that this is not achivable with the delay function as its a blocking function. So i wanted to switch to a millis function instead, but this way i can't make the timer work.
I only tried with the function called colorWipeWork which i pasted right here but below you can find the full code. If you can help me it would be awesome.
void colorWipeWork(uint32_t color, int wait)
{
for(int i=0; i<strip.numPixels(); i++)
{ // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
const long interval = 93750;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis == currentMillis;
}
}
}
but here you can finde the full code if you wish
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define LED_PIN 2
#define Button 7
#define Buzzer 6
#define LED_COUNT 16
String start25 = "start";
long previousMillis = 0;
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
pinMode(Button, INPUT);
pinMode(Buzzer, OUTPUT);
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(10); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
int buttonState = 0;
Serial.println("Please enter a command: ");
buttonState = digitalRead(Button);
while(buttonState == HIGH)
{
Serial.println("25 min timer started");
colorWipeWork(strip.Color(150, 0, 0), 100); // Work Red
Serial.println("Timer finished");
strip.clear();
theaterChaseRainbow(1);
delay(150);
theaterChaseRainbow(1);
theaterChaseRainbow(1);
delay(150);
theaterChaseRainbow(1);
delay(100); // Rainbow-enhanced theaterChase variant
strip.clear(); // Set all pixels in RAM to 0 (off)
colorWipePause(strip.Color(0, 100, 0), 100); // PauseGreen
strip.clear();
}
if (buttonState == LOW)
{
strip.clear();
ClearLEDS();
}
}
void colorWipeWork(uint32_t color, int wait)
{
for(int i=0; i<strip.numPixels(); i++)
{ // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
const long interval = 93750;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis == currentMillis;
}
}
}
void colorWipePause(uint32_t color, int wait)
{
for(int i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, color);
strip.show();
delay(150);
}
}
void theaterChaseRainbow(int wait)
{
int firstPixelHue = 0;
for(int a=0; a<30; a++)
{
for(int b=0; b<3; b++)
{
strip.clear();
for(int c=b; c<strip.numPixels(); c += 3)
{
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue));
strip.setPixelColor(c, color);
strip.show();
delay(wait);
firstPixelHue += 65536 / 90;
}
}
}
}
void ClearLEDS() {
for (uint16_t i=0; i<LED_COUNT; i++) strip.setPixelColor(i,0);
}