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 |
Partager