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) {