// === WOKWI DEMO KODU (video için) ===
// Bu kod WebSocket sunucusunu simüle eder.
// Wokwi'de gerçek tarayıcı bağlanamaz, ama buton + LCD demo'su tam çalışır.
// Gerçek WebSocket kodu BlueGrays uygulamasında!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Pin tanimlari / Pin definitions
#define BTN_PLUS_PIN 5 // Sayi arttir / Increment
#define BTN_MINUS_PIN 4 // Sayi azalt / Decrement
int counter = 0;
unsigned long lastPress = 0;
const unsigned long DEBOUNCE_MS = 250;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void updateLcd() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Web: 1 client");
lcd.setCursor(0, 1);
lcd.print("Sayac: ");
lcd.print(counter);
}
void setup() {
pinMode(BTN_PLUS_PIN, INPUT_PULLUP);
pinMode(BTN_MINUS_PIN, INPUT_PULLUP);
// V1 default I2C: SDA=21 SCL=22
Wire.begin(21, 22);
lcd.init();
lcd.backlight();
// Splash 3sn
lcd.setCursor(3, 0);
lcd.print("BlueGrays");
lcd.setCursor(1, 1);
lcd.print("WS Counter v1");
delay(3000);
updateLcd();
}
void loop() {
// Buton + (GPIO 5) basildi mi?
if (digitalRead(BTN_PLUS_PIN) == LOW && millis() - lastPress >= DEBOUNCE_MS) {
counter++;
updateLcd();
lastPress = millis();
}
// Buton - (GPIO 4) basildi mi?
if (digitalRead(BTN_MINUS_PIN) == LOW && millis() - lastPress >= DEBOUNCE_MS) {
counter--;
updateLcd();
lastPress = millis();
}
delay(10);
}