// ROW: 1-Yellow, 2-Red, 3-Green
// COLUMN: 1-Blue, 2-Purlple, 3-grey
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED display width and height
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Create an OLED display object (I2C address 0x3C)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Potentiometer configuration
const int potPin = A0;
const int ledPin = 9;
const int[] rowPins = {2,4};
const int[] colPins = {8,12};
// Initialize OLED and setup components
void setup() {
// Initialize serial monitor
Serial.begin(9600);
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Macro Keyboard"));
display.display();
pinMode(ledPin, OUTPUT);
pinMode(pushBtn, INPUT_PULLUP);
}
// Main loop
void loop() {
// Read potentiometer value and calculate volume (0-100%)
int potValue = analogRead(potPin);
int volume = map(potValue, 0, 1023, 0, 100);
int ledBrightness = map(potValue, 0, 1023, 0, 255);
analogWrite(ledPin, ledBrightness);
for(int row: rowPin)
// Display volume on OLED
display.clearDisplay();
display.setCursor(0, 0);
display.println(F("Macro Keyboard"));
display.setCursor(0, 16);
display.print(F("Volume: "));
display.print(volume);
display.print(F("%"));
display.display();
delay(100); // Small delay to debounce buttons
}