// Project abandoned
// last change log:
// 05/04/2024
// organized wires
// removed LEDs because it was not working correctlly
// the oled display is enough
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
const int numPins = 6;
const int buttonPins[numPins] = {2, 3, 4, 5, 6, 7};
const int analogPins[4] = {A0, A1, A2, A3};
const int maxAnalogValue = 1023;
const String pinsnames[4] = {"DISCORD", "BROWSER" , "MIC" , "ELSE"};
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
for(int i=0; i<numPins; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
pinMode(analogPins[i], INPUT);
}
display.clearDisplay();
}
void loop() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
for (int i = 0; i < 4; i++) {
int sensorValue = analogRead(analogPins[i]);
float percentage = (sensorValue / (float)maxAnalogValue) * 100.0;
int barLength = map(sensorValue, 0, maxAnalogValue, 0, SCREEN_WIDTH);
display.setCursor(0, i*14);
display.print(pinsnames[i]);
display.print(": ");
display.print(percentage);
display.println("%");
display.drawFastHLine(0, (i)*14+9, barLength, WHITE);
display.drawFastHLine(0, (i)*14+10, barLength, WHITE);
}
for (int i = 0; i < numPins; i++) {
int buttonState = digitalRead(buttonPins[i]);
if(buttonState == LOW) {
display.setCursor(0, 55);
display.print("Button ");
display.print(i+1);
display.println(" is pressed");
display.println(i);
}
}
display.display();
delay(100);
}