/*****************************************************************
light & sound signal
by Steve Barth 2022
*****************************************************************/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define NUMPIXELS 12
#define startpin 3 // start button
#define stoppin 4 // stop button
#define sndPin 12 // piezo
#define ledPin 10
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800);
int i= 0;
int delayval = 100; // led delay
byte val = 0; // variable for reading the start pin status
int offState = 0; // variable for off button status
int notes[] = {262, 294, 330, 349}; // piezo tones
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(sndPin, OUTPUT);
pinMode(startpin, INPUT);
pinMode(stoppin, INPUT);
pixels.begin(); //setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
}
void loop()
{
val = digitalRead(startpin);
// read input value
if (val == HIGH)
{ // (button pressed)
Serial.println("start");
SetPixels();
//digitalWrite(ledPin, LOW);
}
/*offState = digitalRead(stoppin);
if (offState == HIGH)
{
Serial.println("stop");
//digitalWrite(ledPin, LOW);
}
else {
//digitalWrite(ledPin, HIGH);
}*/
}
void SetPixels()
{
for (int i = 11; i <= NUMPIXELS; i--)
{
pixels.setPixelColor(i, pixels.Color(random()+100, random()+50,random()+200));
pixels.show(); // updated pixel color
delay(delayval);
//Serial.println(i);
//pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
if ( i < 1 )
{
i=12;
}
}
}