hi, bro estoy tratando de usar tu app de android, es la mejor que e visto, con la parte de los botones no tengo problemas pero no entiendo como usar la el joystick para controlar motores dc con un puente H, si me pudieras dar una orientacion seria exelente, es lo que me falta para terminar el proyecto, te dejo el link del puente h que yo uso.
Pololu - TB6612FNG Dual Motor Driver Carrier
Hi nemesis159
For general matters such as DC motor control, Google is your best friend
This is a quick basic example for one motor, using joyY (joystick vertical moves)
Pin configuration is based on 328P chip
*** AndroLED V10.3 modification: ***
/* add this code in the define section */
#define AIN1 4 // connect AIN1 to Arduino pin 4 ...
#define AIN2 5
#define PWMA 6
#define STBY 7
/* add this code in the setup function */
pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWMA,OUTPUT);
pinMode(STBY,OUTPUT);
digitalWrite(STBY, HIGH);
/* replace getJoystickState() with this one */
void getJoystickState(byte data[5]) {
int joyX = (data[1]<<7) + data[2];
int joyY = (data[3]<<7) + data[4];
joyX = joyX - 200; // Offset to avoid
joyY = joyY - 200; // transmitting negative numbers
joyY = map(joyY, -100, +100, -255, 255);
joyX = map(joyX, -100, +100, -255, 255);
if(!DEBUG) {
Serial.print("Joystick data: ");
Serial.print(joyX);
Serial.print(", ");
Serial.println(joyY);
}
if(joyY > 0) {
digitalWrite (AIN1,HIGH);
digitalWrite (AIN2,LOW);
} else if(joyY < 0) {
digitalWrite (AIN1,LOW);
digitalWrite (AIN2,HIGH);
} else {
digitalWrite (AIN1,LOW);
digitalWrite (AIN2,LOW);
analogWrite(PWMA,joyY);
}
Option/Data Range should be set to -100 +100
Please note that DC motors do not work well with low PWM values
Should you have motors with built in rotary encoders, consider adding PID control
Full discussion here
Let us know how it works (can't test it now)