-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoderNano.h
More file actions
34 lines (28 loc) · 799 Bytes
/
EncoderNano.h
File metadata and controls
34 lines (28 loc) · 799 Bytes
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
#include "Arduino.h"
// these are hardware interrupt pins and specific for the different kinds of Arduinos
#define ENCODERINTPIN_1 2
#define ENCODERINTPIN_2 3
class EncoderNano
{
public:
EncoderNano();
long getCount();
void setCount(long pos);
void encoderCount_1();
void encoderCount_2();
private:
volatile long counter;
};
// ADD THIS TO YOUR PROJECT CODE //
/*
* Includes:
#include "EncoderNano.h"
* Declarations:
EncoderNano encoder;
void encoderCount_1() {encoder.encoderCount_1();}
void encoderCount_2() {encoder.encoderCount_2();}
* In the setup() routine:
attachInterrupt(digitalPinToInterrupt(ENCODERINTPIN_1), encoderCount_1, CHANGE);
attachInterrupt(digitalPinToInterrupt(ENCODERINTPIN_2), encoderCount_2, CHANGE);
*/
// now you can read with encoder.getCount()