-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlumaudiono.ino
62 lines (54 loc) · 1.51 KB
/
lumaudiono.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Adafruit_NeoPixel.h>
// This corresponds to the data pin you've connected your LEDs with
#define PIN 6
#define LED_COUNT 600
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);
int incomingByte = 0;
int currentByte = 0;
void setup()
{
Serial.setTimeout(10);
// This seems to bum out at any higher rate
Serial.begin(19200);
while (!Serial)
{
;
}
strip.begin();
strip.show();
}
void loop()
{
if (Serial.available() > 0)
{
// Expecting audio peeking scale in the form of an int from 0-50 (sent at the matching baud-rate, 19200)
incomingByte = Serial.parseInt();
if (incomingByte != currentByte)
{
currentByte = incomingByte;
int byteAsPercent = (currentByte * 100 / 50);
strip.clear();
// Depending on high the audio peak is the more leds are light up in the rainbow colour wheel
for (int i = 0; i < LED_COUNT * byteAsPercent / 100; i++)
{
strip.setPixelColor(i, Wheel(((i * 256 / LED_COUNT)) & 255));
}
strip.show();
}
}
}
uint32_t Wheel(byte WheelPos)
{
WheelPos = 255 - WheelPos;
if (WheelPos < 85)
{
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170)
{
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}