1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
const byte pin = 2;
volatile byte state = LOW;
volatile unsigned long temps = 0, last_temps = 0;
volatile byte cpt = 0;
void setup() {
pinMode( pin, INPUT_PULLUP );
attachInterrupt( digitalPinToInterrupt( pin ), set_interrupt, RISING );
Serial.begin( 9200 );
}
void loop() {
Serial.print( "temps " );
Serial.println( temps );
Serial.print ( "compteur trous " );
Serial.println( cpt );
Serial.print ( "etat " );
Serial.println( state );
delay(1000);
}
void set_interrupt(){
temps = millis();
state = 0;
// rebond du capteur
if( ( temps - last_temps ) > 100 ) {
++cpt;
last_temps = temps;
state = 3;
}
} |
Partager