From d4e4f4419783d30a353990c1de0d684b8c8937a6 Mon Sep 17 00:00:00 2001 From: Serge NOEL Date: Mon, 10 Aug 2026 17:10:46 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d=C3=A9placement=20lent=20sur=20Servo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7024d45..b1088e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,7 @@ #define DEFAULT_PALES_SPEED 255 #define DEFAULT_MAX_UP 180 #define DEFAULT_MAX_DOWN 0 +#define VITESSE 20 // Temps en millisecondes entre chaque pas de servo #define EEPROM_SIG_ADDR 0 #define EEPROM_SIG_VALUE 0xA5 @@ -26,6 +27,9 @@ uint8_t ServoMaxUp = DEFAULT_MAX_UP; uint8_t ServoMaxDown = DEFAULT_MAX_DOWN; int STROBE_ON = 0; int HelicoUP = 0; +int currentServoPos = 90; +int targetServoPos = 90; +unsigned long servoNextMillis = 0; /** * Génére un clignotement de la LED pour signaler l'accusé de réception d'une commande DCC. @@ -114,7 +118,7 @@ void notifyDccAccTurnoutOutput(uint16_t Addr, uint8_t Direction, uint8_t OutputP analogWrite(PWM_PIN, Direction ? PalesSpeed : 0); } else if (Addr == 3) { HelicoUP = Direction; - servoMotor.write(Direction ? ServoMaxUp : ServoMaxDown); + targetServoPos = Direction ? ServoMaxUp : ServoMaxDown; } } @@ -163,13 +167,22 @@ static uint8_t strobePhase = 0; */ void loop() { - // Lire le temps actuel en millisecondes unsigned long now = millis(); // Traite les signaux DCC entrants Dcc.process(); - + // Mécanisme de déplacement progressif du servo + if (now >= servoNextMillis) { + servoNextMillis = now + VITESSE; + if (currentServoPos < targetServoPos) { + currentServoPos++; + servoMotor.write(currentServoPos); + } else if (currentServoPos > targetServoPos) { + currentServoPos--; + servoMotor.write(currentServoPos); + } + } if (STROBE_ON) { switch (strobePhase) {