-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncoders.cpp
More file actions
53 lines (44 loc) · 1.11 KB
/
Encoders.cpp
File metadata and controls
53 lines (44 loc) · 1.11 KB
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
#include "Encoders.h"
void Encoders::begin (int pinNumber)
{
switch (whichISR_)
{
case 0:
attachInterrupt (pinNumber, isr0, RISING); //CHANGE); //FALLING);
instance0_ = this;
break;
case 1:
attachInterrupt (pinNumber, isr1, RISING); //CHANGE); //FALLING);
instance1_ = this;
break;
}
} // end of Encoders::begin
// constructor
Encoders::Encoders (const byte whichISR) : whichISR_ (whichISR)
{
counter_ = 0;
pinState = HIGH;
}
// ISR glue routines
void Encoders::isr0 ()
{
instance0_->handleInterrupt (0,1); // get these values from DaulHBridge.cpp
} // end of Encoders::isr0
void Encoders::isr1 ()
{
instance1_->handleInterrupt (3,2);
} // end of Encoders::isr1
// for use by ISR glue routines
Encoders * Encoders::instance0_;
Encoders * Encoders::instance1_;
// class instance to handle an interrupt
void Encoders::handleInterrupt (int pin0, int pin1)
{
int pinLevel1 = digitalRead(pin1);
if (pinLevel1 == HIGH) {
counter_++;
} else {
counter_--;
}
pinState = !pinState;
} // end of Encoders::handleInterrupt