from machine import Pin
import time
# ================= SHIFT REGISTER PINLER =================
data = Pin(0, Pin.OUT)
clock = Pin(1, Pin.OUT)
latch = Pin(5, Pin.OUT)
data.value(0)
clock.value(0)
latch.value(0)
# ================= LED MAPPING =================
YESIL = 0b00000001
SARI = 0b00000010
KIRMIZI = 0b00000100
# ================= SHIFT REGISTER =================
def shift_out(value):
latch.value(0)
time.sleep_us(50)
for i in range(7, -1, -1):
clock.value(0)
bit = (value >> i) & 1
data.value(bit)
time.sleep_us(100)
clock.value(1)
time.sleep_us(100)
clock.value(0)
data.value(0)
time.sleep_us(50)
latch.value(1)
time.sleep_us(500)
latch.value(0)
time.sleep_us(100)
# ================= LCD =================
class LCD:
def __init__(self, rs, e, d4, d5, d6, d7):
self.rs = Pin(rs, Pin.OUT)
self.e = Pin(e, Pin.OUT)
self.data_pins = [
Pin(d4, Pin.OUT),
Pin(d5, Pin.OUT),
Pin(d6, Pin.OUT),
Pin(d7, Pin.OUT)
]
self.init_lcd()
def pulse_enable(self):
self.e.value(1)
time.sleep_us(100)
self.e.value(0)
time.sleep_us(100)
def send_nibble(self, data):
for i in range(4):
self.data_pins[i].value((data >> i) & 1)
self.pulse_enable()
def send_byte(self, data, rs):
self.rs.value(rs)
self.send_nibble(data >> 4)
self.send_nibble(data & 0x0F)
def init_lcd(self):
time.sleep_ms(50)
self.send_nibble(0x03)
time.sleep_ms(5)
self.send_nibble(0x03)
time.sleep_ms(5)
self.send_nibble(0x03)
time.sleep_ms(1)
self.send_nibble(0x02)
self.send_byte(0x28, 0)
self.send_byte(0x0C, 0)
self.send_byte(0x06, 0)
self.send_byte(0x01, 0)
time.sleep_ms(5)
def print(self, text):
for char in text:
self.send_byte(ord(char), 1)
def clear(self):
self.send_byte(0x01, 0)
time.sleep_ms(3)
def set_cursor(self, row, col):
addr = (0x80 + col) if row == 0 else (0xC0 + col)
self.send_byte(addr, 0)
# ================= LCD INIT =================
lcd = LCD(12, 11, 10, 9, 8, 7)
shift_out(0)
print("Format: Sicaklik,Agirlik")
print("Ornek: 25,300")
# ================= MAIN LOOP =================
while True:
try:
line = input("Gir (T,W): ")
temp_str, weight_str = line.split(",")
temp = float(temp_str)
weight = float(weight_str)
if temp > 25:
durum = "COK SICAK"
led = KIRMIZI
elif temp >= 15:
durum = "NORMAL"
led = SARI
else:
durum = "DUSUK"
led = YESIL
# Önce LCD
lcd.clear()
lcd.set_cursor(0, 0)
lcd.print("T:{:.1f}C".format(temp))
lcd.set_cursor(1, 0)
lcd.print("W:{:.0f}g".format(weight))
# Sonra LED
shift_out(led)
print("Durum:", durum)
except Exception as e:
print("Format hatali! Hata:", e)
time.sleep(0.3)ERC Warnings
flop1:D: Input pin not driven
flop1:CLK: Clock driven by combinatorial logic