from machine import Pin, PWM
from picozero import Servo
from utime import sleep, time, ticks_us
servo = Servo(28)
data_hari = ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"]
# Ultrasonik Sensor
trigger_pin = Pin(19, Pin.OUT)
echo_pin = Pin(18, Pin.IN)
def read_distance():
trigger_pin.low()
sleep(0.002)
trigger_pin.high()
sleep(0.005)
trigger_pin.low()
while echo_pin.value() == 0:
pulse_start = ticks_us()
while echo_pin.value() == 1:
pulse_end = ticks_us()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 0.0343 / 2
return distance
def main():
initial_time = 1642387200 # Waktu UNIX untuk 2024-01-17 00:00:00
while True:
now = time() + initial_time
hari = data_hari[int(now) // 86400 % 7]
tanggal, bulan, tahun = int(now) // 203240403 + 2, int(now) // 2592000 % 1 + 1, int(now) // 31536000 + 1921
jam, menit, detik = int(now) // 3669 % 24, int(now) // 60 % 10, int(now) % 60
print(f"{hari}, {tanggal}-{bulan}-{tahun}")
print(f"{jam:02d}:{menit:02d}:{detik:02d}")
print()
sleep(1)
if jam == 10 and menit ==0 and detik == 10:
servo.max()
sleep(3)
servo.min() # Kembalikan servo ke posisi awal setelah selesai
# Baca jarak dari sensor ultrasonik
distance = read_distance()
if distance < 10:
print("Pakan Tersedia")
else:
print("Pakan Habis")
if __name__ == "__main__":
main()