Skip to content

Commit c77ee58

Browse files
committed
minor optimization
1 parent 5667576 commit c77ee58

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/RotaryEncoder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void RotaryEncoder::setPosition(long newPosition)
110110

111111
void RotaryEncoder::tick(void)
112112
{
113+
unsigned long now = millis();
113114
int sig1 = digitalRead(_pin1);
114115
int sig2 = digitalRead(_pin2);
115116
int8_t thisState = sig1 | (sig2 << 1);
@@ -124,7 +125,7 @@ void RotaryEncoder::tick(void)
124125
// The hardware has 4 steps with a latch on the input state 3
125126
_positionExt = _position >> 2;
126127
_positionExtTimePrev = _positionExtTime;
127-
_positionExtTime = millis();
128+
_positionExtTime = now;
128129
}
129130
break;
130131

@@ -133,7 +134,7 @@ void RotaryEncoder::tick(void)
133134
// The hardware has 4 steps with a latch on the input state 0
134135
_positionExt = _position >> 2;
135136
_positionExtTimePrev = _positionExtTime;
136-
_positionExtTime = millis();
137+
_positionExtTime = now;
137138
}
138139
break;
139140

@@ -142,7 +143,7 @@ void RotaryEncoder::tick(void)
142143
// The hardware has 2 steps with a latch on the input state 0 and 3
143144
_positionExt = _position >> 1;
144145
_positionExtTimePrev = _positionExtTime;
145-
_positionExtTime = millis();
146+
_positionExtTime = now;
146147
}
147148
break;
148149
} // switch

0 commit comments

Comments
 (0)