Feb 21, 2012 at 11:00am UTC
Hallo people.
My team is building a robot. We have a problem with the programmering.
This is out code:
#include "mbed.h"
I2C i2c(p9, p10); // sda, scl
Serial pc(USBTX, USBRX); // tx, rx
const int addr = 0xB0; // define the I2C Address
int main() {
char cmd[2];
while(1) {
cmd[0] = 0x0; // pointer to command register
cmd[1] = 255; // Start ranging, results in cm
i2c.write(addr, cmd, 2); // Send command string
wait(0.07); // Could also poll, 65ms is typical
// Set pointer to location 2 (first echo)
cmd[0] = 0x01;
i2c.write(addr, cmd, 2);
Then the motor will go full forward!
But how can we make one of the motor goes back (0), and the other one goes forward(255) ??
Feb 21, 2012 at 12:08pm UTC
Is it possible that cmd[0] = 0x0;
addresses the first motor and cmd[0] = 0x01;
the second? If so you need to set cmd[1] = 0;
before the second write() (cmd[1] is still 255 from the last time you set it).