Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import serial
- import requests
- from socketIO_client import SocketIO, LoggingNamespace
- import threading
- import winsound
- #Sound file paths
- winSound = 'c:\\bigclaw-mega\sounds\completed.wav'
- pokeSound = 'c:\\bigclaw-mega\sounds\squeak'
- #Serial Setup
- arduino = serial.Serial('COM6', 9600, timeout=5)
- try:
- # Python 2
- import thread
- except:
- # Python 3
- import _thread as thread
- # Listener listens for feedback from Arduino on the serial port
- def listener():
- while True:
- if arduino.inWaiting():
- data = arduino.readline().decode('ascii')[:-2]
- #data = arduino.readline(arduino.inWaiting()).decode('ascii')
- print(data)
- #IF PRIZE WIN
- if data == "prizeWin":
- print("Winner Winner Chicken Dinner!")
- winsound.PlaySound(winSound,winsound.SND_FILENAME)
- #IF POKE
- elif data == "Poke":
- winsound.PlaySound(pokeSound,winsound.SND_FILENAME)
- #arduino.flushInput()
- # The Trigger below fires when a new (arg) happens
- def handle_command(args):
- #Commands
- #If Right Button Pressed
- if(args['command'].lower()=="r"):
- print(args['user'],"is moving right")
- arduino.write(b'r')
- #If Left Button Pressed
- elif(args['command'].lower()=="l"):
- print(args['user'],"is moving left")
- arduino.write(b'l')
- #If Up Button Pressed
- elif(args['command'].lower()=="f"):
- print(args['user'],"is moving forward")
- arduino.write(b'f')
- #If Down Button Pressed
- elif(args['command'].lower()=="b"):
- print(args['user'],"is moving back")
- arduino.write(b'b')
- #If Drop Button Pressed
- elif(args['command'].lower()=="g" and args['key_position'].lower()=="down"):
- currentUser = args['user']
- print(args['user'],"is dropping")
- arduino.write(b'g')
- #If Poke Button Pressed
- elif(args['command'].lower()=="q" and args['key_position'].lower()=="down"):
- print(args['user'],"is poking")
- arduino.write(b'q')
- def onHandleCommand(*args):
- thread.start_new_thread(handle_command, args)
- #thread.start_new_thread(listener, args)
- threading.Thread(target=listener).start()
- def onHandleControlConnect(*args):
- controlSocketIO.emit('robot_id', str(robotID))
- robotID = ascascascascasc
- url = 'httpcasascascascascasc
- controlHostPort = requests.get(url).json()
- controlSocketIO = SocketIO(controlHostPort['host'], controlHostPort['port'], LoggingNamespace, transports='websocket')
- controlSocketIO.on('connect', onHandleControlConnect)
- controlSocketIO.on('command_to_robot', onHandleCommand)
- controlSocketIO.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement