-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcb_client.py
35 lines (32 loc) · 1.13 KB
/
tcb_client.py
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
# Set all the variables necessary to connect to Twitch IRC
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
import cfg, socket, time, re, atexit, datetime
# create a default object, no changes to I2C address or frequency
mh = Adafruit_MotorHAT(addr=0x60)
# recommended for auto-disabling motors on shutdown!
def turnOffMotors():
mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE)
mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)
atexit.register(turnOffMotors)
# network functions go here
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.6', 9000))
while True:
response = s.recv(1024).decode("utf-8")
for r in response.split('\r\n'):
if r.startswith("MOVE"): #move the arm
#get the arguments
args = r.split(' ')
motor = mh.getMotor(int(args[1]))
if args[2] == 'FW':
direction = Adafruit_MotorHAT.FORWARD
else:
direction = Adafruit_MotorHAT.BACKWARD
speed = int(args[3])
#move the motor
motor.setSpeed(speed)
motor.run(direction)
time.sleep(0.8)
motor.run(Adafruit_MotorHAT.RELEASE)