Created
September 22, 2018 12:07
-
-
Save BarrYPL/7de8dfdd8736418d5133c7488e50fdf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include <FastLED.h> | |
#define NUM_LEDS 30 | |
#define LED_PIN 6 | |
#define POWER_LED 9 | |
#define ANALOG_READ 0 | |
#define KNOB_PIN A1 | |
#define KNOB2_PIN A3 | |
int sensorPin = A0; | |
int sensorValue = 0; | |
int vum = 0; | |
int ran = 0; | |
int fst = 0; | |
int measur = 0; | |
int up = 0; | |
int dw = 0; | |
float lgh = 0; | |
float hlf = 0; | |
unsigned int Time_Delay = 0; | |
unsigned int Real_Time_Delay = 0; | |
unsigned int Last_Time_Delay = 0; | |
unsigned int Real_Time_White = 0; | |
float knob = 1023.0; | |
float knob2 = 1023.0; | |
int pik = 0; | |
int fls = 351; | |
int wtf = 0; | |
int spr = 0; | |
float gnt = 0; | |
int wts; | |
int k; | |
int nrl; | |
int r; | |
int g; | |
int b; | |
int llgh; | |
int odc; | |
int adc = 0; | |
int adj; | |
int brlg; | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
strip.begin(); | |
strip.show(); | |
Serial.begin (28800); | |
randomSeed(analogRead(A2)); | |
pinMode(POWER_LED, OUTPUT); | |
Reset(); | |
Srednia(); | |
} | |
void Srednia() { | |
for (int i = 0; i < 10; i++) { | |
odc = analogRead (sensorPin); | |
adc = (adc + odc); | |
adj = (adc / 10); | |
} | |
} | |
void Sprawdz() { | |
sensorValue = analogRead (sensorPin); | |
knob = analogRead(KNOB_PIN) / 1023.0; | |
measur = (sensorValue - adj); | |
fst = abs(measur); | |
gnt = (knob * 350); | |
vum = ((fst * NUM_LEDS) / gnt); | |
lgh = vum; | |
hlf = (lgh / 2); | |
knob2 = analogRead(KNOB2_PIN) / 1023.0; | |
nrl = 255 * knob2; | |
} | |
void RandomWhite() { | |
Reset(); | |
Last_Time_Delay = millis(); | |
while (Real_Time_White < fls) { | |
Sprawdz(); | |
strip.setBrightness(nrl); | |
lgh = (lgh * 2); | |
if ((lgh >= (NUM_LEDS - 1)) && (fls < 2000)) { | |
fls = (fls + 351); | |
//Serial.println(lgh); | |
} | |
//Serial.println(lgh); | |
ran = random(1, NUM_LEDS); | |
Serial.println(lgh); | |
strip.setPixelColor(ran, 255, 255, 255); | |
strip.show(); | |
delay(40); | |
strip.setPixelColor(ran, 0, 0, 0); | |
strip.show(); | |
Time_Delay = millis(); | |
Real_Time_White = (Time_Delay - Last_Time_Delay); | |
wtf = (fls - Real_Time_White); | |
if (wtf <= 0) | |
{ | |
Real_Time_Delay = 0; | |
AllWhite(); | |
delay(50); | |
VU_Meter(); | |
} | |
//Serial.println(wtf); | |
} | |
} | |
void Reset() { | |
for (int i = 0; i < NUM_LEDS; i++) { | |
strip.setPixelColor(i, 0, 0, 0); | |
} | |
strip.show(); | |
} | |
void AllWhite() { | |
for (int i = 0; i < NUM_LEDS; i++) { | |
strip.setPixelColor(i, 255, 255, 255); | |
} | |
strip.show(); | |
} | |
int MidPoint(int n) { | |
int sat; | |
sat = (n / 2); | |
return (sat); | |
} | |
void VU_Meter() { | |
for (k = 0; k < 765; k++) { | |
// Serial.println(lgh); | |
Last_Time_Delay = millis(); | |
Sprawdz(); | |
strip.setBrightness(nrl); | |
//Serial.println(lgh); | |
if ((Real_Time_Delay >= 1000) && (lgh > NUM_LEDS)) { | |
RandomWhite(); | |
} | |
else | |
{ | |
while (Real_Time_Delay < 1000) { | |
Sprawdz(); | |
strip.setBrightness(nrl); | |
int n = MidPoint(NUM_LEDS); | |
dw = (n - hlf); | |
up = (n + hlf); | |
for (int z = dw; z < up; z++) { | |
if (llgh > lgh) { | |
for (int x = 0; x < dw; x++) { | |
strip.setPixelColor(x, 0, 0, 0); | |
} | |
for (int c = up; c < NUM_LEDS; c++) { | |
strip.setPixelColor(c, 0, 0, 0); | |
} | |
strip.show(); | |
delay(1); | |
} | |
if (k < 255) { | |
strip.setPixelColor(z, k, 0, 255 - k); | |
strip.show(); | |
} | |
else if (k < 510) { | |
strip.setPixelColor(z, 510 - k, k - 255, 0); | |
strip.show(); | |
} | |
else if (k < 765) { | |
strip.setPixelColor(z, 0, 765 - k, k - 510); | |
strip.show(); | |
} | |
} | |
llgh = lgh; | |
delay(5); | |
Time_Delay = millis(); | |
Real_Time_Delay = (Time_Delay - Last_Time_Delay); | |
wts = (1000 - Real_Time_Delay); | |
//Serial.println(Time_Delay); | |
} | |
} | |
Sprawdz(); | |
strip.setBrightness(nrl); | |
if (lgh > NUM_LEDS) { | |
RandomWhite(); | |
} | |
else | |
{ | |
Serial.println(lgh); | |
int n = MidPoint(NUM_LEDS); | |
dw = (n - hlf); | |
up = (n + hlf); | |
for (int z = dw; z < up; z++) { | |
if (llgh > lgh) { | |
for (int x = 0; x < dw; x++) { | |
strip.setPixelColor(x, 0, 0, 0); | |
} | |
for (int c = up; c < NUM_LEDS; c++) { | |
strip.setPixelColor(c, 0, 0, 0); | |
} | |
delay(1); | |
strip.show(); | |
} | |
if (k < 255) { | |
strip.setPixelColor(z, k, 0, 255 - k); | |
strip.show(); | |
} | |
else if (k < 510) { | |
strip.setPixelColor(z, 510 - k, k - 255, 0); | |
strip.show(); | |
} | |
else if (k < 765) { | |
strip.setPixelColor(z, 0, 765 - k, k - 510); | |
strip.show(); | |
} | |
} | |
llgh = lgh; | |
delay(5); | |
} | |
} | |
} | |
void loop() { | |
fls = 351; | |
Real_Time_White = 0; | |
Sprawdz(); | |
VU_Meter(); | |
delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment