-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServo_Assignment_With_Touch.py
More file actions
38 lines (31 loc) · 1.04 KB
/
Servo_Assignment_With_Touch.py
File metadata and controls
38 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Graham Lenert
#Servo Control
#This assignment makes a servo turn when a wire is touched,
# and turns it another way when another wire is touched
import board
import digitalio
import analogio
import time #importing libraries
import simpleio
import pulseio
from adafruit_motor import servo
import touchio
#sets the PWM pin for servo
pwm = pulseio.PWMOut(board.D9, duty_cycle=2 ** 15, frequency=50)
touch_A1 = touchio.TouchIn(board.A1) #activates the touch wires
touch_A2 = touchio.TouchIn(board.A2)
# Create a servo object, my_servo.
my_servo = servo.Servo(pwm) q #sets the servo pin to the pwm pin
servo_angle = 0 #starts servo at 0
while True:
#if wire 1 touched, turn servo
if touch_A1.value and servo_angle < 180:
print("touched a1")
servo_angle += 5
my_servo.angle = servo_angle
#if wire 2 touched, turn servo
if touch_A2.value and servo_angle > 0:
print("touched a2")
servo_angle -= 5
my_servo.angle = servo_angle
time.sleep(0.01) #sleep for execution safety