Skip to content

Commit

Permalink
oop w wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
arossaadhikary committed Apr 10, 2024
1 parent 1ad90a9 commit 990fbd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions electrical_code/wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import serial
import time

class Wheels:
def __init__(self, port_num):
self.arduino = serial.Serial(port=port_num, baudrate=115200, timeout=0.1)

def write_read(self, x):
self.arduino.write(bytes(x, 'utf-8'))
time.sleep(0.05)

def move(self, angle, dist):
angle_str = str(angle).zfill(3)
dist_str = str(dist).zfill(3)
command = angle_str + dist_str
self.write_read(command)

if __name__ == "__main__":
myFirstWheel = Wheels("your_port_number_here")
myFirstWheel.move(angle_value, distance_value)
4 changes: 4 additions & 0 deletions electrical_code/wheels_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "./wheels.py"

w = Wheels("COM4")
w.move("100100")

0 comments on commit 990fbd3

Please sign in to comment.