#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 10
#define NUMPIXELS 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int ledlighton = 7;
int colorramdom = 1;
int loopledtop = 0;
int colorR = 0;
int colorG = 0;
int colorB = 0;
int colorchange = 10;
int mic = 0;
float mictop = 10;
int mic_basic = 0;
void setup() {
// put your setup code here, to run once:
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
strip.begin(); // This initializes the NeoPixel library.
Serial.begin(9600);
micbasic();
}
void loop() {
musicin2();
}
void musicin2()
{
mic = analogRead(A3);
mic = mic-mic_basic;//335
// if (mic < 10)
// {
// mic = 0;
// }
if (mic < 0)
{
mic = ~mic + 1;
}
if (mic < 4)
{
mic = 0;
}
else
{
mic = mic-3;
}
mic = mic * 2;
/////////////
//mic = mic / 10;
if (mic > 0)
{
Serial.print(mic);
Serial.print("|");
if (mic > 10)
{
mic = 8;
}
Serial.print(mic);
Serial.println("");
/*
*/
ledlighton = random (0, 16);
colorramdom = random (1, 3);
if (colorramdom == 1)
{
colorR = random (101, 255);
colorG = random (101, 255);
colorB = 0;
}
else if (colorramdom == 2)
{ colorR = random (101, 255);
colorG = 0;
colorB = random (101, 255);
}
else if (colorramdom == 3)
{ colorR = 0;
colorG = random (101, 255);
colorB = random (101, 255);
}
// strip.setPixelColor(ledlighton, strip.Color(colorR, colorG, colorB));
strip.setPixelColor(ledlighton, strip.Color(255, 255, 255));
// strip.setPixelColor(ledlighton, strip.Color(colorR, colorG, colorB));
strip.show();
delay(50);
if (mic > 2)
{
for (int i = 1; i < mic; i++)
{
if (colorR - i * colorchange > 0)
{
colorR = colorR - i * colorchange ;
}
else
{
// colorR = colorR + i * colorchange ;
}
if (colorG - i * colorchange > 0)
{
colorG = colorG - i * colorchange ;
}
else
{
// colorG = colorG + i * colorchange ;
}
if (colorB - i * colorchange > 0)
{
colorB = colorB - i * colorchange ;
}
else
{
// colorG = colorG + i * colorchange ;
}
strip.setPixelColor(ledlighton + i, strip.Color(colorR, colorG, colorB));
strip.setPixelColor(ledlighton - i, strip.Color(colorR, colorG, colorB));
strip.show();
delay(20);
}
for (int i = 0; i < mic; i++)
{
strip.setPixelColor(ledlighton + i, strip.Color(0, 0, 0));
strip.setPixelColor(ledlighton - i, strip.Color(0, 0, 0));
strip.show();
delay(30);
}
}
strip.setPixelColor(ledlighton, strip.Color(0, 0, 0));
strip.show();
}
}
void micbasic()
{
for (int mb = 0; mb <20; mb++)
{
mic_basic = mic_basic+analogRead(A3);
}
mic_basic = mic_basic/20;
}
Comments