# mPy - demo servo control on esp32s2
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-07-04  initial release

from	machine 	import	Pin, PWM, freq; 		freq(240000000)
from	micropython	import	const
import	time

# ====================== Test ==========================

# constants not visible outside module, saving RAM
_min = const(65536 // 40)			# 0.5 mSec
_mid = const(65536 // 20)			# 1.0 mSec
_max = const(_min + _mid)			# 1.5 mSec

def test():
#    servo = PWM(Pin(16), freq=50, duty_u16=_mid)		# 65536 = 20 mSec
    servo = PWM(Pin(2), freq=50, duty_u16=_mid)		# servo 0 on RW2050
    while True:
        servo.duty_u16(_min)
        time.sleep(1)
        servo.duty_u16(_mid)
        time.sleep(1)
        servo.duty_u16(_max)
        time.sleep(1)

# ======================= Main ==========================

test()

# ======================== End ==========================
