Skip to content

Commit

Permalink
Handle the new revision of Waveshare board
Browse files Browse the repository at this point in the history
  • Loading branch information
tokk-nv committed Nov 9, 2020
1 parent d21d158 commit 05022cb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jetbot/motor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def __init__(self, driver, channel, *args, **kwargs):

self._driver = driver
self._motor = self._driver.getMotor(channel)
if(channel == 1):
self._ina = 1
self._inb = 0
else:
self._ina = 2
self._inb = 3
atexit.register(self._release)

@traitlets.observe('value')
Expand All @@ -30,9 +36,15 @@ def _write_value(self, value):
self._motor.setSpeed(speed)
if mapped_value < 0:
self._motor.run(Adafruit_MotorHAT.FORWARD)
self._driver._pwm.setPWM(self._ina,0,0)
self._driver._pwm.setPWM(self._inb,0,speed*16)
else:
self._motor.run(Adafruit_MotorHAT.BACKWARD)
self._driver._pwm.setPWM(self._ina,0,speed*16)
self._driver._pwm.setPWM(self._inb,0,0)

def _release(self):
"""Stops motor by releasing control"""
self._motor.run(Adafruit_MotorHAT.RELEASE)
self._driver._pwm.setPWM(self._ina,0,0)
self._driver._pwm.setPWM(self._inb,0,0)

0 comments on commit 05022cb

Please sign in to comment.