Last active
September 19, 2017 01:38
-
-
Save robo8080/47ec85a1a71c124aadec4ddc320635ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MicroPython + Grove I2C motor driver | |
from microbit import * | |
#i2c.init(freq=100000, sda=pin20, scl=pin19) | |
while True: | |
# Forwards | |
print('Forwards') | |
display.show(Image.ARROW_N) | |
i2c.write(0x0f, bytearray([0x82,0x46,0x46])) | |
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01])) | |
sleep(3000) | |
# Stop | |
i2c.write(0x0f, bytearray([0x82,0x00,0x00])) | |
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01])) | |
sleep(2000) | |
# Backwards | |
display.show(Image.ARROW_S) | |
print('Backwards') | |
i2c.write(0x0f, bytearray([0x82,0x46,0x46])) | |
i2c.write(0x0f, bytearray([0xaa,0x05,0x01])) | |
sleep(3000) | |
# Stop | |
i2c.write(0x0f, bytearray([0x82,0x00,0x00])) | |
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01])) | |
sleep(2000) | |
# Slow Turn Left | |
display.show(Image.ARROW_W) | |
print('Left Turn') | |
i2c.write(0x0f, bytearray([0x82,0x46,0x46])) | |
i2c.write(0x0f, bytearray([0xaa,0x09,0x01])) | |
sleep(3000) | |
# Stop | |
i2c.write(0x0f, bytearray([0x82,0x00,0x00])) | |
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01])) | |
sleep(2000) | |
# Sharp Right Turn | |
display.show(Image.ARROW_E) | |
print('Right Turn') | |
i2c.write(0x0f, bytearray([0x82,0x46,0x46])) | |
i2c.write(0x0f, bytearray([0xaa,0x06,0x01])) | |
sleep(3000) | |
# Stop | |
i2c.write(0x0f, bytearray([0x82,0x00,0x00])) | |
i2c.write(0x0f, bytearray([0xaa,0x0a,0x01])) | |
sleep(5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment