// ESP32 + Ortak Anot 7 Segment
// 1. Buton: Artır
// 2. Buton: Azalt
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;
// Ortak anot: 1 = segment yanacak (LOW yazılır)
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++) {
// ortak anot → yanacaksa LOW
digitalWrite(segPins[i], digits[n][i] ? LOW : HIGH);
}
}
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(segPins[i], OUTPUT);
digitalWrite(segPins[i], HIGH); // başlangıçta kapalı
}
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);
// ARTIRMA
if (lastInc == HIGH && incState == LOW) {
countDigit = (countDigit + 1) % 10;
showDigit(countDigit);
delay(150); // debounce
}
// AZALTMA
if (lastDec == HIGH && decState == LOW) {
countDigit = (countDigit + 9) % 10; // 0 → 9
showDigit(countDigit);
delay(150); // debounce
}
lastInc = incState;
lastDec = decState;
}