Skip to content

Commit c8322d4

Browse files
committed
fixing variable scopes
1 parent 1fb1452 commit c8322d4

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/RotaryEncoder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const int8_t KNOBDIR[] = {
4040

4141
RotaryEncoder::RotaryEncoder(int pin1, int pin2, LatchMode mode)
4242
{
43+
int sig1 = 0;
44+
int sig2 = 0;
45+
4346
// Remember Hardware Setup
4447
_pin1 = pin1;
4548
_pin2 = pin2;
@@ -50,8 +53,8 @@ RotaryEncoder::RotaryEncoder(int pin1, int pin2, LatchMode mode)
5053
pinMode(pin1, INPUT_PULLUP);
5154
pinMode(pin2, INPUT_PULLUP);
5255
// when not started in motion, the current state of the encoder should be 3
53-
int sig1 = digitalRead(_pin1);
54-
int sig2 = digitalRead(_pin2);
56+
sig1 = digitalRead(_pin1);
57+
sig2 = digitalRead(_pin2);
5558
}
5659

5760
_oldState = sig1 | (sig2 << 1);
@@ -113,7 +116,6 @@ void RotaryEncoder::setPosition(long newPosition)
113116
// Slow, but Simple Variant by directly Read-Out of the Digital State within loop-call
114117
void RotaryEncoder::tick(void)
115118
{
116-
unsigned long now = millis();
117119
int sig1 = digitalRead(_pin1);
118120
int sig2 = digitalRead(_pin2);
119121
tick(sig1, sig2);
@@ -122,6 +124,7 @@ void RotaryEncoder::tick(void)
122124
// When a faster method than digitalRead is available you can _tick with the 2 values directly.
123125
void RotaryEncoder::tick(int sig1, int sig2)
124126
{
127+
unsigned long now = millis();
125128
int8_t thisState = sig1 | (sig2 << 1);
126129

127130
if (_oldState != thisState) {

0 commit comments

Comments
 (0)