merci pour ta reponse, voici le programme
//potard sur a0 broche centrale
//les 2 autre pin sur 5v et ground
//sabertooth port S1 sur 8 arduino
//moteur sur m1a et m1b
//0v sabertooth sur ground
//RUPTEUR ET OUTPUT
//UN FIL SUR BORNE 2
//UN FIL SUR 5V
//capteur optique ET INPUT
//D0 SUR BORNE 3
//capteur optique si input_pullup
//UN FIL SUR BORNE 2
//UN FIL SUR gnd
#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
#define NOT_AN_INTERRUPT -1
SoftwareSerial SWSerial(NOT_A_PIN, 8); //Pin 8 utilisé pour communiquer avec la Sabertooth
SabertoothSimplified ST(SWSerial); //librairie sabertooth
//commande moteur
const int potar = A0; //la broche pour régler la vitesse
//rupteur
const byte PIN_SIGNAL = 2;
volatile unsigned long last_micros;
//optique
const byte PIN_SIGNAL1 = 3;
unsigned long periode2 = 0;
unsigned long periode3 = 0;
volatile unsigned long last_micros1;
//dephasage
float dephasage = 0;
//COMMUN DEBOUNCING TIME
long debouncing_time = 15; //Debouncing Time in Milliseconds
//angle came
int buttonState = 0;
int lastButtonState = 0;
long temps_total = 0;
int angle2 = 0;
int angle4 = 0;
int angle6 = 0;
int angle8 = 0;
const int angle_total = 360;
long p1 = 0;
long p2 = 0;
long p3 = 0;
long p4 = 0;
long p5 = 0;
long p6 = 0;
long p7 = 0;
long p8 = 0;
int compteur =0;
volatile byte compteur_ticks = 0;
volatile byte compteur_optique = 0;
//unsigned long previousMicros = 0;
//unsigned long previousMicros1 = 0;
float periode=0;
float periode1=0;
float vitesse1=0;
float vitesse2=0;
float vitesse3=0;
void debounceInterrupt1() {compteur_optique++;}
//void debounceInterrupt() {compteur ++;}
unsigned long previousMicros = micros();
unsigned long previousMicros1 = micros();
unsigned long fin_rupteur = 0;
unsigned long fin_opto = 0;
float delta = 0;
/** Fonction setup() */
void tick() {
// compteur++; /*incremente à chaque signal LOW*/
// if(compteur % 4 ==0){ /*si le resultat est divisible par 4 on passe à la suite*/
fin_rupteur = micros();
//static unsigned long previousMicros = 0; /*static variable conservée entre 2 appels à la fonction / initialisation qu'une seule fois */
unsigned long currentMicros = micros(); /*le nombre de microSecondes depuis le début du programme */
/* Calcul le temps écoulé depuis le précédent front */
periode = currentMicros - previousMicros; /*le nombre de microSecondes depuis la dernière interruption*/
/* Met à jour la variable pour la prochaine interruption */
previousMicros = currentMicros; /*on se souvient du nombre de microSecondes depuis le début du programme*/
//}
}
void debounceInterrupt() {
if((long)(micros() - last_micros) >= debouncing_time*100) {
tick();
last_micros = micros();
}
}
void setup () {
Serial.begin(115200);
SWSerial.begin(38400);
/* Met la broche en sortie */
pinMode(PIN_SIGNAL, OUTPUT);
attachInterrupt(digitalPinToInterrupt(PIN_SIGNAL), debounceInterrupt, FALLING);
pinMode(PIN_SIGNAL1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_SIGNAL1), debounceInterrupt1, FALLING);
}
void loop() {
int vitesse = analogRead(potar);
ST.motor(1,vitesse /8);
periode2 = pulseIn(PIN_SIGNAL1, LOW, 1000000);
periode3 = pulseIn(PIN_SIGNAL1, HIGH, 1000000);
Serial.print("vitesse optique ");
vitesse1 = 60000000 / (periode2+periode3);
Serial.println(vitesse1);
if (compteur_optique >= 1)
{
if (fin_rupteur > 0)
{
fin_opto = micros();
}
periode1 = micros() - previousMicros1;
previousMicros1 = micros();
compteur_optique = 0;
}
if (fin_opto > 0 )
{
delta = fin_opto - fin_rupteur;
fin_rupteur = 0;
fin_opto = 0;
}
if (( (vitesse1>1) && (vitesse1<550) ))
{
vitesse2 = (((delta/1000000)*360)/(1/(vitesse1/60))/10);;
Serial.print("vitesse2 ");
Serial.println(vitesse2);
}
Serial.print("delta t ");
Serial.println(((delta/1000000)*360)/(1/(vitesse1/60)));
Serial.println(" ");
Serial.print("delta ");
Serial.println(((delta/1000000)*360)/(1/(vitesse1/60)) - vitesse2);
Serial.println(" ");
delay(500);
// lit l'état actuel du bouton poussoir et le mémorise dans la variable
buttonState = digitalRead(PIN_SIGNAL);
// compare l'état actuel du bouton poussoir à l'état précédent mémorisé
if (buttonState != lastButtonState) {
/* Mesure la durée de la période */
p1 = pulseIn(PIN_SIGNAL, LOW);
// Serial.print("p1: ");
// Serial.println(p1);
}
if (buttonState != lastButtonState){
p2 = pulseIn(PIN_SIGNAL, HIGH);
// Serial.print("p2: ");
// Serial.println(p2);
}
if (buttonState != lastButtonState){
p3 = pulseIn(PIN_SIGNAL, LOW);
// Serial.print("p3: ");
// Serial.println(p3);
}
if (buttonState != lastButtonState){
p4 = pulseIn(PIN_SIGNAL, HIGH);
// Serial.print("p4: ");
// Serial.println(p4);
}
if (buttonState != lastButtonState){
p5 = pulseIn(PIN_SIGNAL, LOW);
// Serial.print("p5: ");
// Serial.println(p5);
}
if (buttonState != lastButtonState){
p6 = pulseIn(PIN_SIGNAL, HIGH);
// Serial.print("p6: ");
// Serial.println(p6);
}
if (buttonState != lastButtonState){
p7 = pulseIn(PIN_SIGNAL, LOW);
// Serial.print("p7: ");
// Serial.println(p7);
}
if (buttonState != lastButtonState){
p8 = pulseIn(PIN_SIGNAL, HIGH);
// Serial.print("p8: ");
// Serial.println(p8);
}
// affiche le temps total
temps_total = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
// Serial.print("temps total: ");
// Serial.println(temps_total);
// affiche l'angle inter fermé
angle2 = (p2 * angle_total) / (temps_total) ;
Serial.print("angle 2: ");
Serial.println(angle2);
// affiche l'angle inter fermé
angle4 = (p4 * angle_total) / (temps_total) ;
Serial.print("angle 4: ");
Serial.println(angle4);
// affiche l'angle inter fermé
angle6 = (p6 * angle_total) / (temps_total) ;
Serial.print("angle 6: ");
Serial.println(angle6);
// affiche l'angle inter fermé
angle8 = (p8 * angle_total) / (temps_total) ;
Serial.print("angle 8: ");
Serial.println(angle8);
}