const int NUM_SLIDERS = 6;
const int analogInputs[NUM_SLIDERS] = {A7, A6, A5, A4, A3, A2};
const int NUM_BUTTONS = 12;
const int NUM_MUTES = 6;
int analogSliderValues[NUM_SLIDERS];
int buttonValues[NUM_BUTTONS];
const int mutableSliders[NUM_MUTES] = {1,2,3,4,5,6};
const int muteButtons[NUM_MUTES] = {13,6,5,4,3,2};
bool muted[NUM_SLIDERS];
int muteValues[NUM_MUTES];
// bool ledState[NUM_SLIDERS] = {LOW};
#include <light_CD74HC4067.h>
// CD74HC4067 mux(7,8,9,10); // create a new CD74HC4067 object with its four select lines
// const int signal_pin = A1; // Pin Connected to Sig pin of CD74HC4067
#include <Keypad.h>
const byte ROWS = 3; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char keyVals[NUM_BUTTONS] = {'0','1','2','3','4','5','6','7','8','9','A','B'};
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A', 'B'},
};
byte rowPins[ROWS] = {7, A0, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8,9,10,11}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
// pinMode(signal_pin, INPUT_PULLUP); // Set as input for reading through signal pin
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
}
for (int i = 0; i < NUM_MUTES; i++) {
pinMode(muteButtons[i], INPUT_PULLUP);
}
}
// static unsigned long lastPressTime = 0;
void loop() {
char customKey = customKeypad.getKey();
for (int i=0; i<NUM_BUTTONS;i++) {
if (customKey == keyVals[i] && buttonValues[i] == 0){
buttonValues[i] = 1;
// lastPressTime = millis();
}
else if (customKey ==keyVals[i] && buttonValues[i] == 1){
buttonValues[i] = 0;
// lastPressTime = millis();
}
}
updateSliderValues();
sendSliderValues(); // Actually send data (all the time)
// printSliderValues(); // For debug
//delay(10);
}
void updateSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
analogSliderValues[i] = analogRead(analogInputs[i]);
}
// for (byte i = 0; i < NUM_BUTTONS; i++) {
// mux.channel(i);
// buttonValues[i] = analogRead(signal_pin);
// }
for (int i = 0; i < NUM_MUTES; i++) {
muteValues[i] = digitalRead(muteButtons[i]);
if (muteValues[i] == 0) {
muted[mutableSliders[i]-1] = true;
// String printedString = String((int)mutableSliders[i]);
// Serial.write(printedString.c_str());
}
else if (muteValues[i] == 1) {
muted[mutableSliders[i]-1] = false;
}
}
for (int i = 0; i < NUM_SLIDERS; i++) {
if (muted[i]) {
analogSliderValues[i] = 0;
}
}
}
void sendSliderValues() {
String builtString = String("");
for (int i = 0; i < NUM_SLIDERS; i++) {
builtString += "s";
builtString += String((int)analogSliderValues[i]);
if (i < NUM_SLIDERS - 1) {
builtString += String("|");
}
}
if(NUM_BUTTONS > 0){
builtString += String("|");
}
for (int i = 0; i < NUM_BUTTONS; i++) {
builtString += "b";
builtString += String((int)buttonValues[i]);
if (i < NUM_BUTTONS - 1) {
builtString += String("|");
}
}
Serial.println(builtString);
}
void printSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
String printedString = String("Slider #") + String(i + 1) + String(": ") + String(analogSliderValues[i]) + String(" mV");
Serial.write(printedString.c_str());
if (i < NUM_SLIDERS - 1) {
Serial.write(" | ");
} else {
Serial.write("\n");
}
}
}