from machine import Pin, PWM,Timer
from time import ticks_ms
PIR = Pin(19,Pin.OUT)
Servo = PWM(Pin(13), freq = 50, duty = 0)
def PIR_get(TM): #Tentukan fungsi balik
print(PIR.value())
print("t:",ticks_ms())
TM = Timer(0)
TM.init(period = 250,mode = Timer.PERIODIC,callback = PIR_get)
x = 0
while True:
if PIR.value() == 1:
x = 180
else:
x = 0
Servo.duty(int((x/90+0.5)/20*1023))