Skip to content

Commit a1ccd7e

Browse files
authored
Merge pull request #159 from TheKitty/master
Code for the guide Motorized Turntable
2 parents 91e8339 + 8374e01 commit a1ccd7e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

motorized-turntable/turntable.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import board
2+
import time
3+
import pulseio
4+
from digitalio import DigitalInOut, Direction, Pull
5+
from analogio import AnalogIn
6+
import adafruit_motor.servo
7+
8+
pwm = pulseio.PWMOut(board.D5, frequency=50)
9+
servo = adafruit_motor.servo.Servo(pwm)
10+
switch = DigitalInOut(board.D7)
11+
switch.direction = Direction.INPUT
12+
switch.pull = Pull.UP
13+
pot = AnalogIn(board.A0)
14+
15+
continuous = adafruit_motor.servo.ContinuousServo(pwm)
16+
17+
def val(pin):
18+
# divides voltage (65535) to get a value between 0 and 1
19+
return pin.value / 65535
20+
21+
while True:
22+
23+
if switch.value:
24+
continuous.throttle = val(pot) * -1
25+
else:
26+
continuous.throttle = val(pot) * 1
27+
28+
time.sleep(0.001)

0 commit comments

Comments
 (0)