Code is stuck on the for loops

they move on ther own now

there's no dead zone?

how do i ad that
im relatively new to programing

presumably the joysticks are at the center of there range when neutral and the resulting dX/dY would be zero. but looks like that value isn't exactly when neutral.

try setting G to a smaller value

if that's not good enough, try subtracting the value when the joysticks are neutral to the corresponding dX/dY

or changing the - MAX/2 values subtracted from the analog reads

#include <Servo.h>

Servo servoX;
Servo servoY;
  
int X = 0;
int Y = 0;
int posX = 0;
int posY = 0;  
int reset = 0; 

void setup() {
  servoX.attach(6);
  servoY.attach(5);
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  Serial.begin (9600);
  pinMode(12,INPUT);

}

void loop() {


 
if (X > 550){posX > 0; posX <= 180; posX += 2;}
if (X < 500){posX > 0; posX <= 180; posX -= 2;}
if (Y > 550){posY > 0; posY <= 180; posY += 2;}
if (Y < 500){posY > 0; posY <= 180; posY -= 2;}
if (reset == 1 ){posX = 0; posY = 0;}

servoX.write(posX);
servoY.write(posY);
reset = digitalRead(12); 
X = analogRead(A0);
Y = analogRead(A1);
Serial.println(X);
Serial.println(Y);
Serial.println(reset);
delay(20);
}

fix!

what does "fix!" mean? You are in a programming user-forum not on snap-chatter

Nice. I don't argue with success, but these lines

if (X > 550){posX > 0; posX <= 180; posX += 2;}
if (X < 500){posX > 0; posX <= 180; posX -= 2;}
if (Y > 550){posY > 0; posY <= 180; posY += 2;}
if (Y < 500){posY > 0; posY <= 180; posY -= 2;}

are a bit complicated way to say

if (X > 550) {posX += 2;}
if (X < 500) {posX -= 2;}
if (Y > 550) {posY += 2;}
if (Y < 500) {posY -= 2;}

These perfectly valid C++ lines of code do… absolutely nothing:

posX > 0;

posY <= 180;

They are probably optimised right out of your code.

What do you think they were doing? They literally calculate a value and throw it away…

a7

Thx for the Help and the suggestions.

properly formatted

    if (X > 550)  {
        posX > 0;
        posX <= 180;
        posX += 2;
    }

and nothing other than

    if (X > 550)
        posX += 2;

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