// ESP32 + 7 Segment (Ortak Katot) + 2 Buton
// Ortak katot: Segment ON = HIGH, Segment OFF = LOW
const int segPins[7] = {21, 19, 18, 5, 17, 16, 4}; // a,b,c,d,e,f,g
const int BTN_INC = 15; // artırma butonu (GND'ye basılır)
const int BTN_DEC = 23; // azaltma butonu (GND'ye basılır)
int countDigit = 0;
// a b c d e f g (1 = segment yanacak)
const uint8_t digits[10][7] = {
{1,1,1,1,1,1,0}, // 0
{0,1,1,0,0,0,0}, // 1
{1,1,0,1,1,0,1}, // 2
{1,1,1,1,0,0,1}, // 3
{0,1,1,0,0,1,1}, // 4
{1,0,1,1,0,1,1}, // 5
{1,0,1,1,1,1,1}, // 6
{1,1,1,0,0,0,0}, // 7
{1,1,1,1,1,1,1}, // 8
{1,1,1,1,0,1,1} // 9
};
void showDigit(int n) {
for (int i = 0; i < 7; i++) {
digitalWrite(segPins[i], digits[n][i] ? HIGH : LOW);
}
}
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segPins[i], OUTPUT);
digitalWrite(segPins[i], LOW);
}
pinMode(BTN_INC, INPUT_PULLUP);
pinMode(BTN_DEC, INPUT_PULLUP);
showDigit(countDigit);
}
void loop() {
static int lastInc = HIGH;
static int lastDec = HIGH;
int incState = digitalRead(BTN_INC);
int decState = digitalRead(BTN_DEC);
// Artırma: HIGH -> LOW (basılma anı)
if (lastInc == HIGH && incState == LOW) {
countDigit = (countDigit + 1) % 10;
showDigit(countDigit);
delay(150); // debounce
}
// Azaltma: HIGH -> LOW (basılma anı)
if (lastDec == HIGH && decState == LOW) {
countDigit = (countDigit + 9) % 10; // 0'dan geri gidince 9 olsun diye
showDigit(countDigit);
delay(150); // debounce
}
lastInc = incState;
lastDec = decState;
}