implemented basic motor class
This commit is contained in:
parent
2ccfc37ae8
commit
51f797cc4b
|
@ -1 +1,35 @@
|
||||||
# empty file
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
class Motor:
|
||||||
|
def __init__(self, enable, dir1, dir2):
|
||||||
|
self.enable_pin = machine.Pin(enable, machine.Pin.OUT)
|
||||||
|
self.dir1_pin = machine.Pin(dir1, machine.Pin.OUT)
|
||||||
|
self.dir2_pin = machine.Pin(dir2, machine.Pin.OUT)
|
||||||
|
|
||||||
|
self.direction = 1 # default direction: dir1_pin = HIGH, dir2_pin = LOW
|
||||||
|
self.reverse()
|
||||||
|
|
||||||
|
def reverse(self):
|
||||||
|
print("reversing direction")
|
||||||
|
self.direction = not self.direction
|
||||||
|
self.dir1_pin.value(self.direction)
|
||||||
|
self.dir2_pin.value(not self.direction)
|
||||||
|
|
||||||
|
def spin(self,seconds):
|
||||||
|
self.enable_pin.value(1)
|
||||||
|
time.sleep(seconds)
|
||||||
|
self.enable_pin.value(0)
|
||||||
|
|
||||||
|
print("setting up pins")
|
||||||
|
m1 = Motor(4, 16, 5)
|
||||||
|
m2 = Motor(14, 0, 2)
|
||||||
|
print("setup complete")
|
||||||
|
|
||||||
|
print("Motor test")
|
||||||
|
print("Motor 1:")
|
||||||
|
m1.spin(0.1)
|
||||||
|
print("Motor 2:")
|
||||||
|
m2.spin(0.1)
|
||||||
|
|
||||||
|
print("done!")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user