Im doing a project, with 5 potentiometers connected to a OLED 128x64 Screen.
I manage to show all 5 Pot % on the screen, but i want Only to show the active potentiometer, meaning the one I'm touching.
how can i hide everything, but the active one?
Pic. https://i.imgur.com/CdR3Jw0.png
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define POTENTIOMETER_PIN A0
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
const int NUM_SLIDERS = 5;
const int analogInputs[NUM_SLIDERS] = { A0, A1, A2, A3, A4 };
int level = 0;
int level1 = 0;
int level2 = 0;
int level3 = 0;
int level4 = 0;
int PotValue;
int analogSliderValues[NUM_SLIDERS];
void setup() {
for (int i = 0; i < NUM_SLIDERS; i++) {
pinMode(analogInputs[i], INPUT);
}
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
display.display();
delay(2000);
display.clearDisplay();
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
}
void loop() {
level = (analogRead(A0));
level1 = (analogRead(A1));
level2 = (analogRead(A2));
level3 = (analogRead(A3));
level4 = (analogRead(A4));
delay(100);
int level = analogRead(A0);
int percentage = map(level, 0, 1023, 0, 100);
int percentage1 = map(level1, 0, 1023, 0, 100);
int percentage2 = map(level2, 0, 1023, 0, 100);
int percentage3 = map(level3, 0, 1023, 0, 100);
int percentage4 = map(level4, 0, 1023, 0, 100);
display.clearDisplay();
display.setCursor(1, 1);
display.setTextSize(1);
display.setTextColor(WHITE);
display.print("Potentiometer at ");
display.print(percentage);
display.println("%");
display.print("Potentiometer at ");
display.print(percentage1);
display.println("%");
display.print("Potentiometer at ");
display.print(percentage2);
display.println("%");
display.print("Potentiometer at ");
display.print(percentage3);
display.println("%");
display.print("Potentiometer at ");
display.print(percentage4);
display.println("%");
display.display();
updateSliderValues();
sendSliderValues();
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");
}
}
}