Kód: Vybrat vše
#include <Adafruit_NeoPixel.h>
#define leftPin A2 // left audio in on fourth pin fro
#define stripPin PB0 // DIN of leds on second pin from top
#define stripNumOfLeds 30 // the total number of leds
#define ledBrightness 70 // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true)
#define dropDelay 10 // hold time before dropping the leds
#define minValue 10 // min analog input value
#define maxValue 550 // max analog input value (0-1023 equals 0-5V)
#define overflowDelay 20 // overflow hold time
#define middleOffset 0 // offset for the middle led when using one strip
#define orangeLimitAmount 0 // limit the amount of green of the middle LEDs to make them more orange
#define sensitivityFactor 2 //citlivost diod
/*************/
unsigned int stripColor[stripNumOfLeds / 2 - 1]; // half of the number of leds + 1
boolean displayMiddleLed = false; // display the middle led (blue). set to true for one strip, false for two strips or rings
boolean splitStrip = true; // set to true when using 2 strips or rings, false for one strip
float dropFactor = .9; // value for dropping the leds
//******
int numOfSegments = stripNumOfLeds;
int halfNumOfSegments = numOfSegments / 2;
int stripMiddle = stripNumOfLeds / 2;
int maxDisplaySegments = stripNumOfLeds;
float ledFactor, ledFactor_div_numOfSegments;
int leftValue = 0;
int leftAnalogValue = 0;
int prevLeftValue = 0;
int prevLeftAnalogValue = 0;
int leftDropTime = 0;
int i;
unsigned int stripMiddleColor, stripOverflowColor, stripHoldColor;
//**************
Adafruit_NeoPixel strip = Adafruit_NeoPixel(stripNumOfLeds, stripPin, NEO_RGB + NEO_KHZ800);
//*************
void setup() {
strip.begin();
setStripColors();
resetStrip();
}
//*****************8
void loop() {
readValues();
drawValues();
prevLeftAnalogValue = leftAnalogValue;
prevLeftValue = leftValue;
}
//*********************
void readValues() {
leftAnalogValue = analogRead(leftPin);
if (leftAnalogValue < prevLeftAnalogValue) {
leftDropTime++;
if (leftDropTime > dropDelay) {
leftAnalogValue = prevLeftAnalogValue * dropFactor;
leftDropTime = 0;
}
else
leftAnalogValue = prevLeftAnalogValue;
}
leftValue = map(leftAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
if (leftValue > maxDisplaySegments) {
leftValue = maxDisplaySegments;
drawOverflow();
}
}
//************************
void drawValues() {
if (splitStrip) {
for (i = middleOffset; i < leftValue; i++)
{
strip.setPixelColor(i, stripColor[i]);
}
for (i = prevLeftValue; i > leftValue; i--)
{
strip.setPixelColor(i, 0);
}
}
else {
for (i = middleOffset; i < leftValue; i++)
{
strip.setPixelColor(stripMiddle + i, stripColor[i]);
}
for (i = prevLeftValue; i > leftValue; i--)
{
strip.setPixelColor(stripMiddle + i, 0);
}
}
if (displayMiddleLed) {
strip.setPixelColor(stripMiddle, stripMiddleColor);
}
strip.show();
}
//***************
void drawOverflow() {
for (i = 0; i <= numOfSegments; i++) {
strip.setPixelColor(stripMiddle + i, stripOverflowColor);
strip.setPixelColor(stripMiddle - i, stripOverflowColor);
}
strip.show();
delay(overflowDelay);
for (i = 0; i <= numOfSegments; i++) {
strip.setPixelColor(stripMiddle + i, 0);
strip.setPixelColor(stripMiddle - i, 0);
}
strip.show();
}
//****************
void setStripColors() {
int orangeLimit;
ledFactor = (float)ledBrightness / 255;
float orangeFactor = orangeLimitAmount / halfNumOfSegments;
ledFactor_div_numOfSegments = ledFactor / numOfSegments;
stripOverflowColor = strip.Color(min(255, 255 * ledFactor * 1.5), 0, 0);
stripMiddleColor = strip.Color(0, 0, 255 * ledFactor);
stripColor[0] = strip.Color(0, 255 * ledFactor, 0);
for (i = 1; i <= numOfSegments; i++) {
if (i <= halfNumOfSegments)
orangeLimit = (i * orangeFactor);
else
orangeLimit = ((numOfSegments - i) * orangeFactor);
stripColor[i] = strip.Color((255 * i * ledFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments - i) * ledFactor_div_numOfSegments), 0);
}
stripHoldColor = stripColor[numOfSegments];
}
//*********
void resetStrip() {
for (i = 0; i <= numOfSegments; i++) {
strip.setPixelColor(i, 0);
}
strip.show();
}