Hi! I have two motors that are connected to a Arduino via a motor board. I've connected a spark fun gesture sensor. I'm trying to have it move as x or y changes to create a follow robot. Please let me know what I'm doing wrong. Its driving me crazy!! ![]()
int Left_Reverse = 13;
int Left_Forward = 11;
int Right_Forward = 10;
int Right_Reverse = 12;
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(Left_Forward, OUTPUT); // sets L1 the digital pin as output
pinMode(Left_Reverse, OUTPUT); // sets L2 the digital pin as output
pinMode(Right_Forward, OUTPUT); // sets L3 the digital pin as output
pinMode(Right_Reverse, OUTPUT); // sets L4 the digital pin as output
}
void loop(void)
{
byte x,z,g;
Wire.beginTransmission(0x10);
Wire.write(0x08);
Wire.endTransmission();
Wire.requestFrom(0x10, 1, true);
if (Wire.available()) {
x = Wire.read();
}
Wire.beginTransmission(0x10);
Wire.write(0x0a);
Wire.endTransmission();
Wire.requestFrom(0x10, 1, true);
if (Wire.available()) {
z = Wire.read();
}
Wire.beginTransmission(0x10);
Wire.write(0x04);
Wire.endTransmission();
Wire.requestFrom(0x10, 1, true);
if (Wire.available()) {
g = Wire.read();
}
Serial.print("X = ");
Serial.print(x);
Serial.print(", Z = ");
Serial.print(z);
if (g != 0) {
Serial.print(" gesture ");
Serial.print(g);
}
Serial.println(".");
if (x>60)analogWrite(Left_Forward, 90);
}