Coverage for src/main/python/motor.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import machine
2from actuator import Actuator
5class Motor(Actuator):
7 """Motor DC rotates in one direction with current , it's a "one pin controller" """
9 def __init__(self, pin_num, running=False):
10 """ constructor.
11 :param pin_num: number of pin that will give power to the motor
12 :param running: the initial condition of the motor
13 """
14 self.pin = machine.Pin(pin_num, machine.Pin.OUT)
15 self.running = running
16 self.pin.value(running) # 1 to run, 0 to stop
18 def __str__(self):
19 """prints the object."""
20 return "Motor currently is running: {}".format(self.running)
22 def on(self):
23 """starts motor."""
24 self.pin.on()
25 self.running = True
27 def off(self):
28 """stops motor."""
29 self.pin.off()
30 self.running = False
32 def is_running(self):
33 """if the motor is running or not."""
34 return self.running