xgo多线程
import threading
import time
#导入xgoedu
from xgoedu import XGOEDU
from xgolib import XGO #导入xgolib
#实例化dog
dog = XGO(port='/dev/ttyAMA0',version="xgolite")
#实例化edu
# XGO_edu = XGOEDU()
# XGO_edu.lcd_text(50,50,'hello',color=(255,0,0),fontsize=50)
# 定义数字线程
class NumberThread(threading.Thread):
def run(self):
XGO_edu = XGOEDU()
for i in range(10):
XGO_edu.lcd_text(50+i*30,50,str(i),color=(255,0,0),fontsize=50)
print(i)
time.sleep(3)
# 定义字母线程
class LetterThread(threading.Thread):
def run(self):
dog = XGO(port='/dev/ttyAMA0',version="xgolite")
def leg_go():
dog.leg(1,[-20,0,111])#z增大蹬地,-20向后移动
dog.leg(3,[-20,0,111])
dog.leg(2,[20,0,84])#抬腿向前
dog.leg(4,[20,0,84])
time.sleep(0.1)
dog.leg(1,[-20,0,95])#恢复高度平衡
dog.leg(3,[-20,0,95])
dog.leg(2,[20,0,95])
dog.leg(4,[20,0,95])
time.sleep(0.1)
dog.leg(2,[-20,0,111])#z增大蹬地,-20向后移动
dog.leg(4,[-20,0,111])
dog.leg(1,[20,0,84])#抬腿向前
dog.leg(3,[20,0,84])
time.sleep(0.1)
dog.leg(2,[-20,0,95])#恢复高度平衡
dog.leg(4,[-20,0,95])
dog.leg(1,[20,0,95])
dog.leg(3,[20,0,95])
time.sleep(0.1)
for c in "ABCDEFGHIJ":
print(c)
leg_go()
time.sleep(1)
# 创建数字线程和字母线程
num_thread = NumberThread()
letter_thread = LetterThread()
# 启动线程
num_thread.start()
letter_thread.start()
# 等待线程结束
# num_thread.join()
# letter_thread.join()