Skip to content

Instantly share code, notes, and snippets.

@HavishNetla
Last active August 23, 2019 21:08
Show Gist options
  • Save HavishNetla/adb125d36ea4b0c903aea9edf04451d2 to your computer and use it in GitHub Desktop.
Save HavishNetla/adb125d36ea4b0c903aea9edf04451d2 to your computer and use it in GitHub Desktop.
import socket
import ast
from ev3dev2.sound import Sound
from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
from ev3dev2.sensor import INPUT_1
from contextlib import closing
sound = Sound()
HOST = '127.0.0.1' # The server's hostname or IP address
PORT = 65432 # The port used by the server
a = LargeMotor(OUTPUT_A)
b = MediumMotor(OUTPUT_B)
c = MediumMotor(OUTPUT_C)
d = LargeMotor(OUTPUT_D)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
# print(sock.connect_ex((HOST, PORT)))
sock.bind(("0.0.0.0", 65432))
print("running")
#sound.play_file('output.wav')
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
orig = (data.decode("utf-8"))
myList = orig.split(',')
print(myList)
if abs(int(float(myList[0]))) > 5:
a.on(int(float(myList[0])) * -1)
else:
a.on(0)
if abs(int(float(myList[1]))) > 5:
d.on(int(float(myList[1])))
else:
d.on(0)
if abs(int(float(myList[2]))) > 5:
c.on(int(float(myList[2])) * -1)
else:
c.on(0)
if abs(int(float(myList[3]))) > 5:
b.on(int(float(myList[3])))
else:
b.on(0)
# if int(float(myList[5])) == 0:
# print(int(float(myList[4])))
# c.on(int(float(myList[4])))
# else:
# print(int(float(myList[5])))
# c.on(int(float(myList[5])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment