Mercurial > tote-had
changeset 5:60ccacc24cab
First draft of robot.py
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 11 Mar 2016 13:12:01 +0100 |
| parents | d279d961c91b |
| children | bfbc645e9dea |
| files | python/robot.py |
| diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/robot.py Fri Mar 11 13:12:01 2016 +0100 @@ -0,0 +1,19 @@ +from machine import I2C, Pin +import ustruct + + +class Robot: + I2C_ADDRESS = 0x09 + + def __init__(self): + self.i2c = I2C(sda=Pin(0), scl=Pin(2)) + + def leg_move_to(self, leg, x, y, z): + data = ustruct.pack("Bbbbb", 4 * leg, 1, x, y, z) + while True: + try: + self.i2c.writeto(self.I2C_ADDRESS, data) + except OSError: + pass + else: + break
