#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h> // library requires for IIC communication
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
static const unsigned char image_discord_1_bits[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x03,0xc0,0x07,0x00,0x00,0xfc,0x03,0xc0,0x3f,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x80,0xff,0xff,0xff,0xff,0x01,0xc0,0xff,0xff,0xff,0xff,0x03,0xc0,0xff,0xff,0xff,0xff,0x03,0xe0,0xff,0xff,0xff,0xff,0x07,0xe0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf8,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x1f,0xfc,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x3f,0xfe,0x3f,0xfc,0x3f,0xfc,0x7f,0xfe,0x1f,0xf8,0x1f,0xf8,0x7f,0xfe,0x0f,0xf0,0x0f,0xf0,0x7f,0xfe,0x0f,0xf0,0x0f,0xf0,0x7f,0xff,0x0f,0xf0,0x0f,0xf0,0xff,0xff,0x0f,0xf0,0x0f,0xf0,0xff,0xff,0x0f,0xf0,0x0f,0xf0,0xff,0xff,0x0f,0xf0,0x0f,0xf0,0xff,0xff,0x1f,0xf8,0x1f,0xf8,0xff,0xff,0x7f,0xfe,0x7f,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x8f,0xff,0xff,0xf1,0x7f,0xfc,0x3f,0xfc,0x3f,0xfc,0x3f,0xf0,0x7f,0x00,0x00,0xfe,0x0f,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x80,0x3f,0x00,0x00,0xfc,0x01,0x00,0x1c,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const int NUM_SLIDERS = 4;
const int analogInputs[NUM_SLIDERS] = {A0, A1, A2, A3};
// Slider max is 1023
int analogSliderValues[NUM_SLIDERS];
int progress = 150;
char buffer[32];
void setup(void) {
u8g2.begin(); // start the u8g2 library
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
}
Serial.begin(9600);
}
void loop(void) {
u8g2.clearBuffer(); // clear the internal memory
updateSliderValues();
sendSliderValues(); // Actually send data (all the time)
// printSliderValues(); // For debug
u8g2.drawFrame(2, 4, 15, 54);
u8g2.drawFrame(24, 4, 15, 54);
u8g2.drawBox(5, 7, 9, 48);
u8g2.drawBox(27, 7, 9, 48);
u8g2.drawFrame(42, 4, 15, 54);
u8g2.drawBox(45, 7, 9, 48);
u8g2.drawFrame(60, 4, 15, 54);
u8g2.drawBox(63, 7, 9, 48);
u8g2.setFont(u8g2_font_t0_17b_tr);
sprintf(buffer,"%d %%",(int)analogSliderValues[0]);
u8g2.drawStr(83, 58, buffer);
u8g2.sendBuffer(); // transfer internal memory to the display
delay(10);
}
void updateSliderValues() {
for (int i = 0; i < NUM_SLIDERS; i++) {
analogSliderValues[i] = analogRead(analogInputs[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 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");
}
}
}