1

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

2

Re: joystick

The code I post have good values in the Serial.print...
But is not working... maybe my mistake!!
But I  can´t understand the problem of my code :s
Some help will be great!

3

Re: joystick

Maybe PIN_MOTOR used same pin that RemoteXY used for SoftSerial?
Please publish all sketch.

4

Re: joystick

if (VELOCIDADE = 0) {

https://cdn.meme.am/cache/instances/folder823/500x/75841823.jpg