-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpio_interface.py
More file actions
73 lines (58 loc) · 1.61 KB
/
Copy pathgpio_interface.py
File metadata and controls
73 lines (58 loc) · 1.61 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
import os
import thread
#
# # For Robot:
# MAIN_SERVO_PIN = 0
# MAIN_MESSAGE_PIN = 1
#
# # For james:
# # MAIN_SERVO_PIN = 22
# # MAIN_MESSAGE_PIN = 23
#
# TIME_BETWEEN = (1 / 1000) * 50
# value = 1
#
#
# START_COM = [1,1,1,1,1,1,1,1]
# END_COM = [0,0,0,0,0,0,0,0]
# RESET = [0,0]
# MAX_LEN_MESSAGE = 10
def sendByte( cmd, pin ):
for bit in cmd:
os.system("gpio write %s %s" % (pin, bit))
time.sleep(TIME_BETWEEN)
def sendServoCommand(servoNum, degrees):
print("EXECUTION START:")
sendByte(START_COM, MAIN_SERVO_PIN)
servoNumBinary = list('{0:08b}'.format(servoNum))
degreesBinary = list('{0:08b}'.format(degrees))
print(servoNumBinary)
print(degreesBinary)
sendByte(servoNumBinary, MAIN_SERVO_PIN)
sendByte(degreesBinary, MAIN_SERVO_PIN)
sendByte(END_COM, MAIN_SERVO_PIN)
print("EXECUTION END")
def sendTwitterNameCommand(message):
finalArray = [0]*MAX_LEN_MESSAGE
if len(message) > MAX_LEN_MESSAGE:
print("Message too long")
else:
sendByte(START_COM, MAIN_MESSAGE_PIN)
messageBin = [ bin(ord(ch))[2:].zfill(8) for ch in message ]
for x in range(0,MAX_LEN_MESSAGE):
if x < len(message):
finalArray[x] = messageBin[x]
else:
finalArray[x] = '00000000'
sendByte(finalArray[x], MAIN_MESSAGE_PIN)
sendByte(END_COM, MAIN_MESSAGE_PIN)
def setup():
os.system("gpio mode %s out" % (MAIN_MESSAGE_PIN))
os.system("gpio mode %s out" % (MAIN_SERVO_PIN))
def outName(name):
setup()
thread.start_new_thread(sendTwitterNameCommand,(name, ) )
def outServo(num, degree):
setup()
thread.start_new_thread(sendServoCommand,(num, degree, ) )