I cant fix my code for my joystick

Look at this example of your sketch... see where I made comments...

int joyX = A0; // pino analógico do eixo X
int joyY = A1; // pino analógico do eixo Y
int joyButton = 2; // pino digital do botão de pressão

// { // not here
void setup() 
{ // YES HERE for setup()
// } // not here
  Serial.begin(9600); // inicia comunicação serial
  pinMode(joyX, INPUT); // entrada leitura eixo X joystick
  pinMode(joyY, INPUT); // entrada leitura eixo y joystick
  pinMode(joyButton, INPUT_PULLUP);// entrada resistor interno pull up pusch button
} // YES HERE for setup()

// { // not here
void loop() 
{// YES HERE for loop()
// } // not here
  int x = analogRead(joyX); // faz a leitura do eixo x (0 a 1023) - analógico
  int y = analogRead(joyY); // faz a leitura do eixo y (0 a 1023) - analógico
  int button = digitalRead(joyButton); // faz a leitura do eixo z (0 ou 1) - digital
  Serial.print("X: ");
  Serial.print(x);
  Serial.print(", Y: ");
  Serial.print(y);
  Serial.print(", Button: ");
  Serial.println(button);
  delay(100);
} // YES HERE for loop()
1 Like

dude thank you so much it worked! wanna be friends?

1 Like

Very good. You will have a lot of fun getting into programming... and with Arduino, you can make devices move and do things.

No.

1 Like

also how to make a code for the servo to rotate?(all of them)

The program for moving a servo is similar to moving a stepper, but the hardware is different.

You can find examples of servo projects online by searching "arduino servo"... here is one example...
https://docs.arduino.cc/learn/electronics/servo-motors/

ii meant with bluetooth

You can do anything, search "arduino bluetooth servo"... the world is at your fingertips.

hey dude, i also wanted help with this code

#include <VarSpeedServo.h>
 
//Cria objeto para controlar o servo base
VarSpeedServo servo_base;
//Cria objeto para controlar o servo inclinacao
VarSpeedServo servo_inclinacao;
 
int pino_x = A4; //Pino ligado ao X do joystick
int pino_y = A5; //Pino ligado ao Y do joystick
int val_x;   //Armazena o valor do eixo X
int val_y;   //Armazena o valor do eixo Y
 
void setup()
{
  //Define a porta a ser ligada ao servo base
  servo_base.attach(7, 1, 180);
  //Define a porta a ser ligada ao servo inclinacao
  servo_inclinacao.attach(8, 1, 180);
}
 
void loop()
{
  //Recebe o valor do joystick, eixo X
  val_x = analogRead(pino_x);
  //Converte o valor lido para um valor entre 1 e 180 graus
  val_x = map(val_x, 0, 1023, 1, 180);
  //Move o servo base para a posicao definida pelo joystick
  servo_base.slowmove(val_x, 60);
  //Recebe o valor do joystick, eixo Y
  val_y = analogRead(pino_y);
  //Converte o valor lido para um valor entre 1 e 180 graus
  val_y = map(val_y, 0, 1023, 1, 180);
  //Move o servo inclinacao para a posicao definida pelo joystick
  servo_inclinacao.slowmove(val_y, 60);
  //Aguarda a movimentacao do servo e reinicia a leitura
  delay(30);
}

it is to move the servo with bluetooth but with the joystick

it gives this error
/usr/local/bin/arduino-cli compile --fqbn arduino:avr:uno --build-cache-path /tmp --output-dir /tmp/417428575/build --build-path /tmp/arduino-build-FCC88B9CBE14B7A09FC1C014833857A6 /tmp/417428575/joystick_calibration_servo

/tmp/417428575/joystick_calibration_servo/servo_controlled_by_joystick.ino:1:10: fatal error: VarSpeedServo.h: No such file or directory
#include <VarSpeedServo.h>
^~~~~~~~~~~~~~~~~
compilation terminated.

Error during build: exit status 1

You have no bluetooth in your program.

You need to add the library file to your IDE. The IDE does not have VarSpeedServo available, so you will need to search for that library file and download it as a ZIP file, then back in your IDE >> SKETCH >> ADD LIBRARY >> ADD ZIP LIBRARY then select the library ZIP file you downloaded... and re-compile.

but i use cloud agent

i use cloud arduino. oh wait i found a button

uh it said an error occurred and it cant perform my action

hello?

You should not bump your topic (adding a post with no information).

ok so ill create a topic abt tht

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.