from machine import Pin
import time
# Sayıyı tutan global değişken
num = 0
# 7 segment display için pinler
segments = [
Pin(0, Pin.OUT), # a
Pin(1, Pin.OUT), # b
Pin(2, Pin.OUT), # c
Pin(3, Pin.OUT), # d
Pin(4, Pin.OUT), # e
Pin(5, Pin.OUT), # f
Pin(6, Pin.OUT) # g
]
# Sayıların 7 segment kodları
digits = {
0: [0, 0, 0, 0, 0, 0, 1],
1: [1, 0, 0, 1, 1, 1, 1],
2: [0, 0, 1, 0, 0, 1, 0],
3: [0, 0, 0, 0, 1, 1, 0],
4: [1, 0, 0, 1, 1, 0, 0],
5: [0, 1, 0, 0, 1, 0, 0],
6: [0, 1, 0, 0, 0, 0, 0],
7: [0, 0, 0, 1, 1, 1, 1],
8: [0, 0, 0, 0, 0, 0, 0],
9: [0, 0, 0, 0, 1, 0, 0]
}
# Buton pinleri
button_pin_increase = Pin(12, Pin.IN, Pin.PULL_DOWN) # Sayıyı artıracak buton
button_pin_reset = Pin(20, Pin.IN, Pin.PULL_DOWN) # Sayıyı sıfırlayacak buton
# Debouncing için son buton basma zamanı
last_time_increase = 0
last_time_reset = 0
debounce_delay = 200 # 200ms debouncing süresi
# Butona basıldığında çağrılan fonksiyon (Artış)
def button_pressed_increase(pin):
global num, last_time_increase
current_time = time.ticks_ms()
if time.ticks_diff(current_time, last_time_increase) > debounce_delay: # 200ms debounce süresi
num += 1
if num > 9:
num = 0
display_number(num)
print("Num (Increase): ", num)
last_time_increase = current_time
# Butona basıldığında çağrılan fonksiyon (Sıfırlama)
def button_pressed_reset(pin):
global num, last_time_reset
current_time = time.ticks_ms()
if time.ticks_diff(current_time, last_time_reset) > debounce_delay: # 200ms debounce süresi
num = 0
display_number(num)
print("Num (Reset): ", num)
last_time_reset = current_time
# 7 segment ekranda sayıyı göster
def display_number(num):
for i in range(7):
segments[i].value(digits[num][i])
# Kesme ayarları
button_pin_increase.irq(trigger=Pin.IRQ_RISING, handler=button_pressed_increase) # Artış için
button_pin_reset.irq(trigger=Pin.IRQ_RISING, handler=button_pressed_reset) # Sıfırlama için
# Başlangıçta sıfır göster
display_number(num)
# Sonsuz döngü
while True:
time.sleep(0.1) # Sistemi rahatlatmak için kısa bekleme