#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8 // Popular NeoPixel ring size
// Create Neopixel Reference
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
String inString = String(100);
int dbLevel = -999;
#define DELAYVAL 1 // Time (in milliseconds) to pause between pixels
void buffer_fill() { //Fill Serial Buffer
inString = "";
inString = Serial.readStringUntil('x');
if (inString != "") {
//Serial.print("Recieved:");
//Serial.println(inString);//Acknowledge Input
pixels.clear(); // Set all pixel colors to 'off'
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
float fled = inString.toFloat();
//int ledLvl = map(inString.toFloat(), -70, -0.3, -1, 7);
//Serial.println(ledLvl);
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
if (fled >= 0.09) {
for (int x = 0; x < 8; x++) {
pixels.setPixelColor(x, pixels.Color(110, 0, 0));
}
pixels.show(); // Send the updated pixel colors to the hardware and delay to show Clip.
Serial.flush();
delay(750);
}
if (fled < -60) {
for (int x = 0; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -60 && fled < -50) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
for (int x = 1; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -50 && fled < -40) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
for (int x = 2; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -40 && fled < -30) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
for (int x = 3; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -30 && fled < -20) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
pixels.setPixelColor(3, pixels.Color(0, 90, 0));
for (int x = 4; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -20 && fled < -13) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
pixels.setPixelColor(3, pixels.Color(0, 90, 0));
pixels.setPixelColor(4, pixels.Color(0, 90, 0));
for (int x = 5; x < 7; x++) {
pixels.setPixelColor(x, pixels.Color(0, 0, 0));
}
}
if (fled > -13 && fled < -7) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
pixels.setPixelColor(3, pixels.Color(0, 90, 0));
pixels.setPixelColor(4, pixels.Color(0, 90, 0));
pixels.setPixelColor(5, pixels.Color(90, 90, 0));
pixels.setPixelColor(6, pixels.Color(0, 0, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
}
if (fled > -7 && fled < -3) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
pixels.setPixelColor(3, pixels.Color(0, 90, 0));
pixels.setPixelColor(4, pixels.Color(0, 90, 0));
pixels.setPixelColor(5, pixels.Color(100, 90, 0));
pixels.setPixelColor(6, pixels.Color(100, 90, 0));
pixels.setPixelColor(7, pixels.Color(0, 0, 0));
}
if (fled > -3 && fled < -0.09) {
pixels.setPixelColor(0, pixels.Color(0, 90, 0));
pixels.setPixelColor(1, pixels.Color(0, 90, 0));
pixels.setPixelColor(2, pixels.Color(0, 90, 0));
pixels.setPixelColor(3, pixels.Color(0, 90, 0));
pixels.setPixelColor(4, pixels.Color(0, 90, 0));
pixels.setPixelColor(5, pixels.Color(100, 90, 0));
pixels.setPixelColor(6, pixels.Color(100, 90, 0));
pixels.setPixelColor(7, pixels.Color(95, 0, 0));
}
pixels.show(); // Send the updated pixel colors to the hardware.
Serial.flush(); // Clear Serial.
} else {
}
}
void setup() {
// Initialize initial values.
Serial.begin(9600);
pixels.begin(); // INITIALIZE NeoPixel strip object
pixels.setBrightness(64);
Serial.setTimeout(33.3);//30hz
}
void loop() {
//Handle USB communication
// USBMIDI.poll();
buffer_fill();
delay(1);
}