#include "Servo.h"//add the servomotor library const int pinY = A3; const int pinX = A2; const int led1 = 26; const int led2 = 0; const int servo =2; Servo myServo; void setup() { Serial.begin(9600); pinMode(26, OUTPUT);//Led pinMode(0, OUTPUT);//Led pinMode(1, OUTPUT);//Led myServo.attach(servo); } void loop() { //read the joystick values int xvalue=analogRead(pinX); int yvalue=analogRead(pinY); Serial.print("X: "); Serial.print(xvalue); Serial.print("\t Y: "); Serial.println(yvalue); delay(100); // Délai pour éviter les lectures trop fréquentes int servoAngleX = map(xvalue, 5, 1023, -180, 180);//mapping for have a good relation between the servo and the joystick //switch on the led if x>900 if (xvalue>900){ digitalWrite(led1, HIGH); }else{ digitalWrite(led1, LOW); } if (yvalue>900){ digitalWrite(led2, HIGH); }else{ digitalWrite(led2, LOW); } //move the servo with the x value myServo.write(servoAngleX); }