模擬器內建範例:
1 2 3 4 5 6 7 8 9 10 | # Using the Servo # Make sure you have the Servo checkbox marked! import machine import pyb # The pyboard has four simple servo connections servo = pyb.Servo(1) servo.angle(90, 100) |
用ADC來控制伺服馬達的角度:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Using the Servo # Make sure you have the Servo checkbox marked! import machine import pyb import time # The pyboard has four simple servo connections servo = pyb.Servo(1) y4 = machine.Pin('Y4') adc = pyb.ADC(y4) while True: value = adc.read() / 255 * 180-90 servo.angle(int(value), 5000) time.sleep_ms(100) |
沒有留言:
張貼留言