Never worked on this, but just for the fun I have downloaded the micro-bit beta application from
https://www.microsoft.com/en-us/makecode?rtc=1.
Then I selected to obtain the Moto:bit from [url]
https://github.com/sparkfun/pxt-moto-bit[/url
Now you can see the code in Java-script and reverse engineer. Couple of aspects I have found
Code: Select all dec hex
motor_left 8448 2100
motor_right 8192 2000
forward 0 0
backward 1 1
motors_on 28673 7001
motors_off 28672 7000
I2C address 89 59
change polairty right 4608 1200
change polairty left 4864 1300
Looking at the motobit code I would predict the following behaviour
set direction, motor and speed.
unint16 var = motor ( either motor_left or motor_right)
if direction is forward : var |= 0x80 + OR with speed min =0, max = 0x7f
if direction is backward : var OR with speed min = 127, max = 0
write var to 0x59 I2C address
example
0x21FF = max speed forward for motor-left.
0x2000 = max speed backward for motor-right
turn motors on or off
Uint16 value
on : write motors_on (0x7001) to I2C address 0x59
off: write motors_off 0x7000) to I2C address 0x59
reverse polarity
e.g. In case you sent a forward command, but the motor turns backward, you can reverse polarity.
uint16 var =
if right motor : var = change polairty right else var = change polairty left
if reverse polarity : var OR with 0x1
write var to 0x59 I2C address
example
reverse polarity motor right : var = 0x1201
hope this helps and good luck
