#include <Stepper.h>
#include <Toggle.h>
const int stepsPerRevolution = 200; // à adapter
Stepper moteur(stepsPerRevolution, 8, 9, 10, 11);
const byte pinFdcDroite = 2;
const byte pinFdcGauche = 12;
bool moteurCCW = true;
const byte potPin = A0;
unsigned long attente, dernierPas;
unsigned long maxAttente = 200;
unsigned long minAttente = 2;
Toggle fdcDroite, fdcGauche;
void setup() {
Serial.begin(115200);
fdcDroite.begin(pinFdcDroite);
fdcGauche.begin(pinFdcGauche);
}
void loop() {
unsigned long nouvelleAttente = map(analogRead(potPin), 0, 1023, maxAttente, minAttente);
if (nouvelleAttente != attente) {
attente = nouvelleAttente;
Serial.print("∆t = "); Serial.println(attente);
}
if (attente < maxAttente && millis() - dernierPas >= attente) {
moteur.step(moteurCCW ? 1 : -1);
dernierPas = millis();
}
fdcDroite.poll();
fdcGauche.poll();
if (fdcDroite.onPress() || fdcGauche.onPress()) moteurCCW = !moteurCCW;
}