Last active
September 9, 2017 11:59
-
-
Save YuuichiAkagawa/6a0c41b85958cb80a2068e50d72b43ef to your computer and use it in GitHub Desktop.
OpenMVカメラでGrove I2C Motor Driverテスト
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
import utime | |
from machine import I2C, Pin, info | |
i2c = I2C(sda=Pin('P5'), scl=Pin('P4'), freq=100000) | |
i2caddr = 0xf | |
#set frequence(3921Hz) | |
buf = bytearray([0x84, 0x02, 0x01]) | |
i2c.writeto(i2caddr, buf) | |
utime.sleep_ms(4) | |
#set direction(BothClockWise) | |
buf = bytearray([0xaa, 0x0a, 0x01]) | |
i2c.writeto(i2caddr, buf) | |
utime.sleep_ms(4) | |
i = 0 | |
d = 1 | |
while True: | |
#motor speed | |
buf = bytearray([0x82, i, i]) | |
i2c.writeto(i2caddr, buf) | |
utime.sleep_ms(100) | |
print(i) | |
if ( d > 0 and i == 255): | |
d = -1 | |
if ( d < 0 and i == 0): | |
d = 1 | |
i = i + d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment