Ajout déplacement lent sur Servo

This commit is contained in:
Serge NOEL
2026-08-10 17:10:46 +02:00
parent 504ffb651c
commit d4e4f44197
+16 -3
View File
@@ -15,6 +15,7 @@
#define DEFAULT_PALES_SPEED 255 #define DEFAULT_PALES_SPEED 255
#define DEFAULT_MAX_UP 180 #define DEFAULT_MAX_UP 180
#define DEFAULT_MAX_DOWN 0 #define DEFAULT_MAX_DOWN 0
#define VITESSE 20 // Temps en millisecondes entre chaque pas de servo
#define EEPROM_SIG_ADDR 0 #define EEPROM_SIG_ADDR 0
#define EEPROM_SIG_VALUE 0xA5 #define EEPROM_SIG_VALUE 0xA5
@@ -26,6 +27,9 @@ uint8_t ServoMaxUp = DEFAULT_MAX_UP;
uint8_t ServoMaxDown = DEFAULT_MAX_DOWN; uint8_t ServoMaxDown = DEFAULT_MAX_DOWN;
int STROBE_ON = 0; int STROBE_ON = 0;
int HelicoUP = 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. * 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); analogWrite(PWM_PIN, Direction ? PalesSpeed : 0);
} else if (Addr == 3) { } else if (Addr == 3) {
HelicoUP = Direction; HelicoUP = Direction;
servoMotor.write(Direction ? ServoMaxUp : ServoMaxDown); targetServoPos = Direction ? ServoMaxUp : ServoMaxDown;
} }
} }
@@ -163,13 +167,22 @@ static uint8_t strobePhase = 0;
*/ */
void loop() void loop()
{ {
// Lire le temps actuel en millisecondes
unsigned long now = millis(); unsigned long now = millis();
// Traite les signaux DCC entrants // Traite les signaux DCC entrants
Dcc.process(); 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) { if (STROBE_ON) {
switch (strobePhase) { switch (strobePhase) {