Arduino Forum

Using Arduino => Programming Questions => Topic started by: DanieleRasi on Jan 12, 2019, 09:26 pm

Title: Joystick and ServoMotors ITA/ENG
Post by: DanieleRasi on Jan 12, 2019, 09:26 pm
                                                             ___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****
------
Title: Re: Joystick and ServoMotors ITA/ENG
Post by: vaj4088 on Jan 13, 2019, 12:04 am
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% ?

Title: Re: Joystick and ServoMotors ITA/ENG
Post by: DanieleRasi on Jan 13, 2019, 12:31 pm
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
Title: Re: Joystick and ServoMotors ITA/ENG
Post by: Robin2 on Jan 13, 2019, 12:47 pm
The program in this link (http://forum.arduino.cc/index.php?topic=338028.) should do what you want.

...R
Title: Re: Joystick and ServoMotors ITA/ENG
Post by: DanieleRasi on Jan 13, 2019, 12:59 pm
Thank you very much! @Robin2