Topic: joystick
Hi!
RemoteXY is a great solution!
Simple question or Issue:
I want to do a simple solution to use in RC cars, I want control velocity (Up and DOWN) with PWM and direction with (RIGHT and LEFT).
This code is for show the values in serie, it works great:
void loop()
{
RemoteXY_Handler ();
VELOCIDADE = RemoteXY.joystick_1_y;
DIRECAO = RemoteXY.joystick_1_x;
Serial.println("Y-----------------------");
Serial.println(VELOCIDADE);
Serial.println("X-----------------------");
Serial.println(DIRECAO);
delay(100); // To see the values
}
But if I put some if's to control, I admit I have some mistake but I no longer see the "good" values in the
Serial.print
My code is:
void loop()
{
RemoteXY_Handler ();
VELOCIDADE = RemoteXY.joystick_1_y;
DIRECAO = RemoteXY.joystick_1_x;
Serial.println("Y-----------------------");
Serial.println(VELOCIDADE);
Serial.println("X-----------------------");
Serial.println(DIRECAO);
if (VELOCIDADE > 0) {
analogWrite(PIN_MOTOR_UP, VELOCIDADE*2.55);
analogWrite(PIN_MOTOR_DOWN, 0);
}
if (VELOCIDADE = 0) {
analogWrite(PIN_MOTOR_UP, 0);
analogWrite(PIN_MOTOR_DOWN, 0);
}
if (VELOCIDADE < 0) {
analogWrite(PIN_MOTOR_DOWN, -VELOCIDADE*2.55);
analogWrite(PIN_MOTOR_UP, 0);
}
if (DIRECAO > 50) {
digitalWrite(PIN_MOTOR_RIGHT, HIGH);
digitalWrite(PIN_MOTOR_LEFT, LOW);
}
if (DIRECAO < -50) {
digitalWrite(PIN_MOTOR_RIGHT, LOW);
digitalWrite(PIN_MOTOR_LEFT, HIGH);
}
if ((DIRECAO < 50) and (DIRECAO > -50)){
digitalWrite(PIN_MOTOR_RIGHT, LOW);
digitalWrite(PIN_MOTOR_LEFT, LOW);
}
}
How I should to do to make this simple example work?
Thanks a lot!
AS