// ESP32 + 3x Potansiyometre + RGB LED (ortak katot) + OLED
// 3 pot ile R/G/B renk mikseri, OLED'de HEX + değer gösterimi
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// ADC pinleri (input-only, ADC1 — WiFi ile uyumlu)
#define POT_R_PIN 34
#define POT_G_PIN 35
#define POT_B_PIN 32
// PWM pinleri (RGB LED — ortak katot)
#define LED_R_PIN 25
#define LED_G_PIN 26
#define LED_B_PIN 27
#define PWM_FREQ 5000
#define PWM_RES 8 // 8-bit (0-255)
#define SCREEN_W 128
#define SCREEN_H 64
#define OLED_ADDR 0x3C
Adafruit_SSD1306 oled(SCREEN_W, SCREEN_H, &Wire, -1);
uint8_t rVal = 0, gVal = 0, bVal = 0;
uint8_t prevR = 255, prevG = 255, prevB = 255;
void lcdAt(int x, int y, uint8_t size, const String &text) {
oled.setTextSize(size);
oled.setCursor(x, y);
oled.print(text);
}
String toHex(uint8_t v) {
String s = String(v, HEX);
s.toUpperCase();
if (s.length() < 2) s = "0" + s;
return s;
}
void drawSplash() {
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
lcdAt(6, 10, 2, "BlueGrays");
lcdAt(4, 40, 1, "Renk Mikser v1.0");
oled.drawRoundRect(2, 2, 124, 60, 6, SSD1306_WHITE);
oled.display();
}
void drawMain() {
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
// Başlık
lcdAt(0, 0, 1, "> Renk Mikser");
oled.drawLine(0, 10, 127, 10, SSD1306_WHITE);
// 3 bar (R, G, B) — Y=14-22
lcdAt(0, 14, 1, "R");
oled.drawRect(10, 14, 100, 6, SSD1306_WHITE);
int wR = (100 * rVal) / 255;
oled.fillRect(10, 14, wR, 6, SSD1306_WHITE);
lcdAt(114, 14, 1, String(rVal));
lcdAt(0, 23, 1, "G");
oled.drawRect(10, 23, 100, 6, SSD1306_WHITE);
int wG = (100 * gVal) / 255;
oled.fillRect(10, 23, wG, 6, SSD1306_WHITE);
lcdAt(114, 23, 1, String(gVal));
lcdAt(0, 32, 1, "B");
oled.drawRect(10, 32, 100, 6, SSD1306_WHITE);
int wB = (100 * bVal) / 255;
oled.fillRect(10, 32, wB, 6, SSD1306_WHITE);
lcdAt(114, 32, 1, String(bVal));
// HEX kod büyük — Y=45
String hex = "#" + toHex(rVal) + toHex(gVal) + toHex(bVal);
oled.setTextSize(2);
int hexW = hex.length() * 12;
oled.setCursor((128 - hexW) / 2, 46);
oled.print(hex);
oled.display();
}
void setup() {
Wire.begin();
if (!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
while (1);
}
drawSplash();
delay(2500);
// PWM kanalları
ledcAttach(LED_R_PIN, PWM_FREQ, PWM_RES);
ledcAttach(LED_G_PIN, PWM_FREQ, PWM_RES);
ledcAttach(LED_B_PIN, PWM_FREQ, PWM_RES);
// ADC 12-bit
analogReadResolution(12);
}
void loop() {
// 3 pot oku ve 0-4095 → 0-255 map
rVal = map(analogRead(POT_R_PIN), 0, 4095, 0, 255);
gVal = map(analogRead(POT_G_PIN), 0, 4095, 0, 255);
bVal = map(analogRead(POT_B_PIN), 0, 4095, 0, 255);
// RGB LED'e PWM uygula
ledcWrite(LED_R_PIN, rVal);
ledcWrite(LED_G_PIN, gVal);
ledcWrite(LED_B_PIN, bVal);
// Sadece değer değiştiyse OLED güncelle (flicker azalır)
if (rVal != prevR || gVal != prevG || bVal != prevB) {
drawMain();
prevR = rVal; prevG = gVal; prevB = bVal;
}
delay(50);
}
Loading
ssd1306
ssd1306