#include <Adafruit_NeoPixel.h>
#define NUM_SLIDERS 5
#define NUM_PIXELS 16
#define NUM_BUTTONS NUM_SLIDERS
#define MAX_POT_VALUE 1022
const int analogInputs[NUM_SLIDERS] = {A0, A1, A2, A3, A4};
const int stripPin[NUM_SLIDERS] = {3, 4, 5, 6, 7};
const int digitalInputs[NUM_BUTTONS] = {8, 9, 10, 11, 12};
int analogSliderValues[NUM_SLIDERS];
int buttonState[NUM_BUTTONS];
int oldButtonState[NUM_BUTTONS] = {0, 0, 0, 0, 0};
int mute[NUM_BUTTONS] = {1, 1, 1, 1, 1};
Adafruit_NeoPixel strips[NUM_SLIDERS];
uint32_t colors[NUM_SLIDERS] = {
strips[0].Color(221, 160, 221), //purple
strips[1].Color(255, 69, 0), //orange
strips[2].Color(50, 205, 50), //green
strips[3].Color(255, 255, 51), //yellow
strips[4].Color(0, 191, 255) //blue
};
void setup() {
for(int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
strips[i] = Adafruit_NeoPixel(NUM_PIXELS, stripPin[i], NEO_GRB + NEO_KHZ800);
strips[i].setBrightness(5);
}
for(int i = 0; i < NUM_BUTTONS; i++)
pinMode(digitalInputs[i], INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
updateSliderValues();
sendSliderValues(); // Actually send data (all the time)
buttonActions();
neopixel();
delay(10);
}
void updateSliderValues() {
for(int i = 0; i < NUM_SLIDERS; i++)
analogSliderValues[i] = analogRead(analogInputs[i]) * mute[i];
}
void sendSliderValues() {
String builtString = String("");
for(int i = 0; i < NUM_SLIDERS; i++) {
builtString += String((int)analogSliderValues[i]);
if(i < NUM_SLIDERS -1)
builtString += String("|");
}
Serial.println(builtString);
}
void buttonActions() {
for(int i = 0; i < NUM_BUTTONS; i++) {
oldButtonState[i] = buttonState[i];
buttonState[i] = digitalRead(digitalInputs[i]);
if(buttonState[i] == LOW && oldButtonState[i] == HIGH)
mute[i] = !mute[i];
}
}
void neopixel() {
int pixelValue[NUM_SLIDERS];
for(int i = 0; i < NUM_SLIDERS; i++) {
pixelValue[i] = map(analogSliderValues[i], 0, MAX_POT_VALUE, 0, NUM_PIXELS + 1);
if(pixelValue[i] != 0) {
strips[i].clear();
strips[i].fill(colors[i], 0, pixelValue[i]);
strips[i].show();
} else {
strips[i].clear();
strips[i].show();
}
}
String builtString = String("");
for(int i = 0; i < NUM_SLIDERS; i++) {
builtString += String((int)pixelValue[i]);
if(i < NUM_SLIDERS -1) {
builtString += String("|");
}
}
Serial.println(builtString);
}