Skip to content

Instantly share code, notes, and snippets.

@pipinn
Created October 9, 2019 01:48
Show Gist options
  • Save pipinn/fa5d26e8bece45cb6ebf5603288e52c8 to your computer and use it in GitHub Desktop.
Save pipinn/fa5d26e8bece45cb6ebf5603288e52c8 to your computer and use it in GitHub Desktop.
#servo : sg90
from machine import Timer,PWM
import lcd
import image
import time
import sys
lcd.init()
img = image.Image()
tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
ch = PWM(tim, freq=50, duty=2.5, pin=35)
arg = {-90:2.5, 0:7.25, 90:12} # arg:duty
try:
while True:
ch.duty(arg[0])
img.draw_string(60, 100, "arg 0", scale=3)
lcd.display(img)
time.sleep(1)
img.clear()
ch.duty(arg[-90])
img.draw_string(60, 100, "arg -90", scale=3)
lcd.display(img)
time.sleep(1)
img.clear()
ch.duty(arg[0])
img.draw_string(60, 100, "arg 0", scale=3)
lcd.display(img)
time.sleep(1)
img.clear()
ch.duty(arg[90])
img.draw_string(60, 100, "arg +90", scale=3)
lcd.display(img)
time.sleep(1)
img.clear()
except:
lcd.clear()
ch.deinit()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment