Skip to content

Commit

Permalink
Adding set count and moving encoders into object context
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Oct 16, 2018
1 parent dabb9bf commit 6ba8bc7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/Encoder/Encoder.ino
Expand Up @@ -4,13 +4,18 @@ ESP32Encoder encoder;
ESP32Encoder encoder2;
void setup(){
Serial.begin(115200);
encoder.setCount(37);// set starting count value
encoder2.setCount(42);// set starting count value
Serial.println("Encoder Start = "+String((int32_t)encoder.getCount()));

// Attache pins for use as encoder pins
encoder.attachFullQuad(36, 39);
// Attache pins for use as encoder pins
encoder2.attachFullQuad(34, 35);
}

void loop(){
// Loop and read the count
Serial.println("Encoder count = "+String((int32_t)encoder.getCount())+" "+String((int32_t)encoder2.getCount()));
delay(100);
}
4 changes: 3 additions & 1 deletion src/ESP32Encoder.h
Expand Up @@ -9,7 +9,7 @@ class ESP32Encoder {
int aPinNumber;
int bPinNumber;
int64_t count=0;

static ESP32Encoder *encoders[MAX_ESP32_ENCODERS];
public:
ESP32Encoder();
~ESP32Encoder();
Expand All @@ -18,5 +18,7 @@ class ESP32Encoder {
int64_t getCount();
void interruptA();
void interruptB();
boolean isAttached(){return attached;}
void setCount(int64_t value);

};

0 comments on commit 6ba8bc7

Please sign in to comment.