#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// I2C pinleri / I2C pins
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
const int SDA_PIN = 8;
const int SCL_PIN = 9;
#else
const int SDA_PIN = 21;
const int SCL_PIN = 22;
#endif
// LCD adresi / LCD addr (bazi modul 0x3F)
const uint8_t LCD_ADDR = 0x27;
const uint8_t LCD_COLS = 16;
const uint8_t LCD_ROWS = 2;
LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLS, LCD_ROWS);
unsigned long counter = 0;
unsigned long lastUpdate = 0;
// I2C tarayici / I2C scanner
void scanI2C() {
Serial.println("I2C taraniyor...");
uint8_t deviceCount = 0;
for (uint8_t address = 1; address < 127; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) {
Serial.print("Cihaz bulundu: 0x");
if (address < 16) Serial.print("0");
Serial.println(address, HEX);
deviceCount++;
}
}
if (deviceCount == 0) Serial.println("Hicbir I2C cihazi bulunamadi!");
else Serial.printf("Toplam %d cihaz bulundu.\n", deviceCount);
}
void setup() {
Serial.begin(115200);
delay(200);
// Ozel pinlerle I2C / Start I2C with custom pins
Wire.begin(SDA_PIN, SCL_PIN);
scanI2C();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("BlueGrays ESP32");
lcd.setCursor(0, 1);
lcd.print("Sayac: 0");
}
void loop() {
// 1 sn periyot / 1 s tick (no delay)
if (millis() - lastUpdate >= 1000) {
lastUpdate = millis();
counter++;
// Satiri temizle / Clear old value
lcd.setCursor(0, 1);
lcd.print("Sayac: ");
lcd.setCursor(7, 1);
lcd.print(counter);
Serial.printf("Sayac: %lu\n", counter);
}
}