Hi there,
I'm trying to make a creative countup timer with 1 LED equalling 1 minute and some intermittent effects to signify longer periods of time being passed like 5 minutes.
At the moment doing it on a smaller time scale and trying to create the following behaviours on a 60 LED neopixel strip:
- Start with no lights, add 1 green light every delay of 500 and a buzzer noise (this I have managed to do)
- For every green light, the next light along is flashing red, to indicate it is next (I have managed this with the following code, but without the flashing part:
#include <Adafruit_NeoPixel.h>
int LEDPIN = 6;
const int buzzer = 2;
int NUMPIXELS = 60;
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDPIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
int delayblinkval = 100;
int i = 0;
void setup() {
pixels.clear();
pixels.begin(); // This initializes the NeoPixel library.
pinMode(buzzer, OUTPUT);
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<60;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0));
pixels.setPixelColor(i+1, pixels.Color(150,0,0));
tone(buzzer,1000);
delay(50);
tone(buzzer,500);
delay(50);
tone(buzzer,1500);
noTone(buzzer);
pixels.show();
delay(delayval);
}
pixels.clear();
}
Then:
3. Every 5 lights, play a separate buzzer sound and flash all lights to indicate that 5 lights have passed.
I've tried to do it with a nested "for" loop but it's conflicting somewhere and not showing any lights.
#include <Adafruit_NeoPixel.h>
int LEDPIN = 6;
const int buzzer = 2;
int NUMPIXELS = 60;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDPIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
int delayblinkval = 100;
int i = 0;
void setup() {
pixels.clear();
pixels.begin(); // This initializes the NeoPixel library.
pinMode(buzzer, OUTPUT);
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<60;i++) {
pixels.setPixelColor(i, pixels.Color(0,150,0));
pixels.setPixelColor(i+1, pixels.Color(150,0,0));
tone(buzzer,1000);
delay(50);
tone(buzzer,500);
delay(50);
tone(buzzer,1500);
noTone(buzzer);
pixels.show();
delay(delayval);
for(int k=i;k<60;k+5){
tone(buzzer,1000);
delay(500);
tone(buzzer,500);
delay(500);
tone(buzzer,1500);
noTone(buzzer);
}}
pixels.clear();
}
Any help very much appreciated.
Ben