int ledPin = 3; // LED connected to digital pin 3 int inPin = 2; // pushbutton connected to digital pin 2 int val = 0; // variable to store the read value int val_ancien = 0; // variable to store the read value void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output pinMode(inPin, INPUT_PULLUP); // sets the digital pin 7 as input with internal PULL UP val_ancien=digitalRead(inPin); // read the input pin } int compteur_front_descendant=0; void loop() { //le code suivant sert à afficher la valeur de compteur_front_descendant tout les 10000 exécutions de loop static int cpt_loop=0; cpt_loop++; if ( (cpt_loop%10000)==0) Serial.println(compteur_front_descendant); //digitalRead pour lire l'état de la broche est lent, on le remplace par une lecture directe du registre // val = digitalRead(inPin); // read the input pin val= (PIND>>2)&1; //compteur_front_descendant est incrémenté si un front descendant est détecté if ((val==LOW) && (val_ancien==HIGH)) { compteur_front_descendant++; } val_ancien=val; }