Go Down

Topic: Joystick and ServoMotors ITA/ENG (Read 127 times) previous topic - next topic

DanieleRasi

                                                             ___ENGLISH___

Hi, I'm trying to move a servo motor with an analog like that of a PS4 controller, it goes perfectly just for a problem ... When I release the analog, the movement is calculated then once the analogue is released the servomotor goes to the position initial.
Do you know how to solve?
If I have not been clear, write to me that I'll do it again!
Thanks in advance for the answer ...!
Here is the sketch I use !:
#include <Servo.h>
Servant servant1;
int const potPinX = A1;
int potVal;
int angle;

void setup () {
servo1.attach (9);
Serial.begin (9600);
}

void loop () {
potVal = analogRead (potPinX);
Serial.print ("potVal:");
Serial.print (potVal);
angle = map (potVal, 0, 1023, 0, 179);
Serial.print ("angle:");
Serial.println (angle);
servo1.write (angle);
delay (15);

}
**** The Joystick is this **** = https://www.ebay.it/itm/2x-JoyStick-Breakout-Module-Shield-PS2-Game-Switches-Controller-for-Arduino/283312054526?ssPageName = STRK% 3AMEBIDX% 3AIT & _trksid = p2057872.m2749.l2649
**** The engines are these ****: https://www.ebay.it/itm/MG90S-Servo-motore-RC-auto-servocomando-robotica-arduino-mini-modellismo-kit/123367743478?ssPageName = STRK% 3AMEBIDX% 3AIT & var = 423762598811 & _trksid = p2057872.m2749.l2649
**** Usage: Arduino UNO ****
------

                                                            ___ITALIANO___

Salve, sto cercando di far muovere un servomotore con un analogico tipo quello di un controller PS4, va perfettamente solo per un problema... Quando rilascio l'analogico, il movimento viene calcolato quindi una volta rilasciato l'analogico il servomotore va alla posizione iniziale.
Sapete come risolvere?
Se nn sono stato chiaro scrivetemelo che vi rispiego!
Grazie in anticipo per la risposta...!
Ecco lo sketch che uso!:
#include <Servo.h>
Servo servo1;
int const potPinX = A1;
int potVal;
int angle;

void setup() {
servo1.attach(9);
Serial.begin(9600);
}

void loop() {
potVal = analogRead(potPinX);
Serial.print("potVal: ");
Serial.print(potVal);
angle = map(potVal, 0, 1023, 0, 179);
Serial.print("angle: ");
Serial.println(angle);
servo1.write(angle);
delay(15);

}
****Il Joystick รจ questo**** = https://www.ebay.it/itm/2x-JoyStick-Breakout-Module-Shield-PS2-Game-Switches-Controller-for-Arduino/283312054526?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649
****I motori sono questi****: https://www.ebay.it/itm/MG90S-Servo-motore-RC-auto-servocomando-robotica-arduino-mini-modellismo-kit/123367743478?ssPageName=STRK%3AMEBIDX%3AIT&var=423762598811&_trksid=p2057872.m2749.l2649
****Uso : Arduino UNO****
------

vaj4088

How is the program supposed to "know" that the servo is not supposed to go back to the initial position?
What is your real requirement?

How is going to 50% and then to 10% to be handled differently from going to 50% and then to 0% ?


DanieleRasi

Thanks for the answer, sorry but I am a beginner, my problem is to set up arduino that once released the analog joystick, the servomotor remains in the last position set.
Thanks again

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

DanieleRasi


Go Up