#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int NUM_SLIDERS = 5;
const int analogInputs[NUM_SLIDERS] = {A0, A1, A2, A3, A6};
const int muteButtons[NUM_SLIDERS] = {7, 6, 5, 4, 3}; // Arduino pins for mute buttons
const int ledPins[NUM_SLIDERS] = {12, 11, 10, 9, 8}; // Arduino pins for LEDs
bool buttonPressed[NUM_SLIDERS] = {false}; // Array to store button pressed state
bool ledState[NUM_SLIDERS] = {LOW}; // Array to store LED state
int displayVolume[NUM_SLIDERS];
int analogSliderValues[NUM_SLIDERS];
const unsigned long sleepAfter = 15000; // this value will change how long the oled will display until turning off.
unsigned long startTime;
unsigned long currTime;
//Display Stuff
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// see http://javl.github.io/image2cpp/ for how to make these
const unsigned char discord [] PROGMEM = {
0x07,0xf0,0x3f,0x80,0x07,0xf0,0x3f,0x80,0x1f,0xff,0xff,0xe0,0x1f,0xff,0xff,0xe0,0x7f,0xff,0xff,
0xf8,0x7f,0xff,0xff,0xf8,0x7f,0xff,0xff,0xf8,0x7f,0xff,0xff,0xf8,0xff,0xff,0xff,0xfc,0xff,0x1f,
0xe3,0xfc,0xff,0x1f,0xe3,0xfc,0xfc,0x07,0x80,0xfc,0xfc,0x07,0x80,0xfc,0xfc,0x07,0x80,0xfc,0xff,
0x1f,0xe3,0xfc,0xff,0x1f,0xe3,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,
0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0x7f,0x00,0x03,0xf8,0x7f,0xc0,0x0f,0xf8,0x1f,0xc0,0x0f,
0xe0,0x1f,0xc0,0x0f,0xe0
};
const unsigned char steam [] PROGMEM = {
0x00,0x7f,0xf8,0x00,0x01,0xff,0xfe,0x00,0x03,0xff,0xff,0x00,0x07,0xff,0xff,0x80,0x0f,0xff,0xff,
0xc0,0x1f,0xff,0xc1,0xe0,0x3f,0xff,0x9c,0xf0,0x3f,0xff,0xb6,0xf0,0x7f,0xff,0xa2,0xf8,0x7f,0xff,
0xb6,0xf8,0x7f,0xfe,0x1c,0xf8,0x7f,0xfe,0x01,0xf8,0x63,0xfe,0x0f,0xf8,0x63,0xf8,0x1f,0xf8,0x60,
0x40,0xff,0xf8,0x7c,0x01,0xff,0xf8,0x3c,0x09,0xff,0xf0,0x3f,0x89,0xff,0xf0,0x1f,0xcb,0xff,0xe0,
0x1f,0xe7,0xff,0xc0,0x0f,0xff,0xff,0xc0,0x07,0xff,0xff,0x80,0x03,0xff,0xff,0x00,0x01,0xff,0xfe,
0x00,0x00,0x7f,0xf8,0x00
};
const unsigned char sys [] PROGMEM = {
0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,
0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,
0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,
0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xc0,0x00,0x00,0x0c,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,
0x00,0x1f,0xe0,0x00,0x00,0x1f,0xe0,0x00,0x00,0x1f,0xe0,0x00,0x00,0x1f,0xe0,0x00,0x00,0xff,0xfc,
0x00,0x00,0xff,0xfc,0x00
}; // 8,3,__,30,25 - 30x25
const unsigned char mic [] PROGMEM = {
0x03,0xf0,0x00,0x00,0x07,0xf8,0x00,0x00,0x0f,0xfc,0x00,0x00,0x1f,0xfe,0x00,0x40,0x1f,0xfe,0x00,
0xe0,0x1f,0xfe,0x01,0xf0,0x1f,0xfe,0x03,0xf8,0x1f,0xfe,0x07,0xfc,0x7f,0xfe,0x00,0x00,0xff,0xff,
0x80,0x00,0xdf,0xfe,0xc0,0x00,0xdf,0xfe,0xc0,0x00,0xdf,0xfe,0xc0,0x00,0xdf,0xfe,0xc0,0x00,0xdf,
0xfe,0xc0,0x00,0xcf,0xfc,0xc7,0xfc,0xc7,0xf8,0xc3,0xf8,0xc3,0xf0,0xc1,0xf0,0x60,0x01,0x80,0xe0,
0x3f,0xff,0x00,0x40,0x1f,0xfe,0x00,0x00,0x01,0xe0,0x00,0x00,0x01,0xe0,0x00,0x00,0x1f,0xfe,0x00,
0x00,0x1f,0xfe,0x00,0x00
};
const unsigned char browser [] PROGMEM = {
0x30,0x30,0x03,0x80,0x30,0x30,0x07,0x80,0x38,0xf0,0x01,0xe0,0x38,0xf0,0x01,0xe0,0x3f,0xc0,0x01,
0xf0,0x3f,0xfe,0x00,0x70,0xff,0xfe,0x00,0x70,0xff,0xfe,0x00,0x7c,0xff,0xf0,0x00,0x7c,0xff,0xf0,
0x00,0x7c,0xff,0xf0,0x00,0x7c,0xff,0x80,0x01,0xfc,0xff,0xf1,0xc1,0xfc,0xff,0xf1,0xc3,0xfc,0xff,
0xff,0x8f,0xfc,0x7f,0xff,0x0f,0xf8,0x3f,0xc0,0x0f,0xf0,0x3f,0xff,0xff,0xf0,0x3f,0xff,0xff,0xf0,
0x1f,0xff,0xff,0xe0,0x07,0xff,0xff,0x80,0x07,0xff,0xff,0x80,0x01,0xff,0xfe,0x00,0x00,0x3f,0xf0,
0x00,0x00,0x3f,0xf0,0x00
};
void setup() {
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
pinMode(muteButtons[i], INPUT_PULLUP); // set mute buttons as input with internal pull-up resistors
pinMode(ledPins[i], OUTPUT); // set LED pins as output
}
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.display();
startTime = millis();
}
void loop() {
currTime = millis();
updateSliderValues();
sendSliderValues(); // Actually send data (all the time)
// printSliderValues(); // For debug
if (currTime - startTime >= sleepAfter) {
display.clearDisplay();
display.display();
startTime = currTime;
}
delay(10);
}
void updateSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
analogSliderValues[i] = analogRead(analogInputs[i]);
if (analogSliderValues[i] > displayVolume[i] + 10 || analogSliderValues[i] < displayVolume[i] - 10) {
displayVolume[i] = analogSliderValues[i];
displayVol(i);
display.display();
startTime = currTime;
}
// Check if mute button is pressed
if (digitalRead(muteButtons[i]) == LOW) {
if (!buttonPressed[i]) { // If the button was not pressed before
buttonPressed[i] = true; // Set buttonPressed flag to true
ledState[i] = !ledState[i]; // Toggle LED state
digitalWrite(ledPins[i], ledState[i]); // Set LED state
}
// Display "muted" on OLED display
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Potentiometer Muted");
display.display();
} else {
buttonPressed[i] = false; // Set buttonPressed flag to false when button is released
}
}
}
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 displayVol(int i) {
//draw lines and appropriate icon
display.clearDisplay();
int disvol = displayVolume[i] / 10.22;
display.fillRect(8, 32, map(displayVolume[i], 0, 1023, 0, 92), 8, SSD1306_WHITE);
switch (i){
case 0:
display.drawBitmap(8, 3, sys, 30, 25, WHITE);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(43,7); // Start at top-left corner
display.println("System");
display.setCursor(103,32);
display.setTextSize(1);
display.println(disvol);
break;
case 1:
display.drawBitmap(8, 3, mic, 30, 25, WHITE);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(43,7); // Start at top-left corner
display.println("Mic"); // Edit display text here
display.setCursor(103,32);
display.setTextSize(1);
display.println(disvol);
break;
case 2:
display.drawBitmap(8, 3, browser, 30, 25, WHITE);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(43,7); // Start at top-left corner
display.println("Browser"); // Edit display text here
display.setCursor(103,32);
display.setTextSize(1);
display.println(disvol);
break;
case 3:
display.drawBitmap(8, 3, discord, 30, 25, WHITE);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(43,7); // Start at top-left corner
display.println("Discord"); // Edit display text here
display.setCursor(103,32);
display.setTextSize(1);
display.println(disvol);
break;
case 4:
display.drawBitmap(8, 3, steam, 30, 25, WHITE);
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(43,7); // Start at top-left corner
display.println("Game"); // Edit display text here
display.setCursor(103,32);
display.setTextSize(1);
display.println(disvol);
break;
}
}
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");
}
}
}