Bjr,
Je ne saisis pas pourquoi la variable 'etat' peut être différente de HIGH avec RISING comme paramètre.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "increment.h"
 
 
// instance capteur positions
increment roue( 2, 8 );
 
void setup() { 
 
  Serial.begin( 9200 );
 
}
 
 
void loop() {
 
	Serial.print( "temps " );
	Serial.println( roue.get_itemps() );
	Serial.print ( "compteur trous " );
	Serial.println(  roue.get_iposi() );
	Serial.print ( "etat  " );
	Serial.println( increment::etat );
 
	delay(1000);
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
#ifndef INCREMENT_H
#define INCREMENT_H
 
#if defined(ARDUINO) && ARDUINO >= 100
	#include "Arduino.h"
#else
	#include "WProgram.h"
#endif
 
//capteur roue perforée
class increment{
	public:
 
		//temporaire en teste
		static volatile byte etat;
 
		//constructeur pin interruption, nombre de perforations de la roue
		increment( byte tpin = 0, byte tperfo = 1 ){
 
			PIN = tpin;
			pinMode( PIN, INPUT );
 
			nbr_perforation = tperfo;
 
			//numero d'interruption max 6 pour choix fonction static
			num_interrupt = digitalPinToInterrupt( PIN );
 
			if( num_interrupt >= max_interrupt){
				num_interrupt = max_interrupt-1;
			}
 
			//interruption mode
			attachInterrupt( num_interrupt, set_interrupt, RISING );
 
		}		
 
		static set_interrupt(){
 
			increment::temps = millis();
 
			// rebond du capteur
			if( ( increment::temps - increment::last_temps ) > 100 ) {
 
				++increment::posi;
				increment::last_temps = increment::temps;
 
				//tempraire en teste
				increment::etat = digitalRead( 2 );
			}
 
		};
 
 
		unsigned long get_itemps(){
 
			return increment::temps;
		};
 
		byte get_iposi(){
			return increment::posi;
		};
 
	protected:
		//pin d'interruption 
		byte PIN;
		//nombre de positions roue
		byte nbr_perforation;
		//numero interruption
		int num_interrupt;
		//nombre d'interruptions
		const byte max_interrupt = 6;
 
 
	private:
		//temps interruption
		static volatile unsigned long temps;
		static volatile unsigned long last_temps;
 
		//compteur trous
		static volatile byte posi;
 
};
 
//déclaration attribut static class 
volatile unsigned long increment::temps;
volatile unsigned long increment::last_temps;
volatile byte increment::posi;
//temporaire
volatile byte increment::etat;
 
#endif
Retour :

temps 0
compteur trous 0
etat 0

temps 6317
compteur trous 1
etat 1

temps 10988
compteur trous 2
etat 0

temps 13955
compteur trous 3
etat 1

temps 17102
compteur trous 4
etat 0