@@ -109,10 +109,36 @@ void RotaryEncoder::setPosition(long newPosition)
109109
110110
111111void RotaryEncoder::tick (void )
112- {
112+ { // Slow, but Simple Variant by directly Read-Out of the Digital State within loop-call
113113 int sig1 = digitalRead (_pin1);
114114 int sig2 = digitalRead (_pin2);
115- int8_t thisState = sig1 | (sig2 << 1 );
115+ _tick (sig1, sig2);
116+
117+ } // tick()
118+
119+ void RotaryEncoder::tick (int sig1, int sig2)
120+ { // Possibility to make a fast call with digitalFASTRead() option and directly Register Readout
121+ _tick (sig1, sig2);
122+
123+ } // tick()
124+
125+
126+ unsigned long RotaryEncoder::getMillisBetweenRotations () const
127+ {
128+ return (_positionExtTime - _positionExtTimePrev);
129+ }
130+
131+ unsigned long RotaryEncoder::getRPM ()
132+ {
133+ // calculate max of difference in time between last position changes or last change and now.
134+ unsigned long timeBetweenLastPositions = _positionExtTime - _positionExtTimePrev;
135+ unsigned long timeToLastPosition = millis () - _positionExtTime;
136+ unsigned long t = max (timeBetweenLastPositions, timeToLastPosition);
137+ return 60000.0 / ((float )(t * 20 ));
138+ }
139+
140+ void RotaryEncoder::_tick (int _sig1, int _sig2){
141+ int8_t thisState = _sig1 | (_sig2 << 1 );
116142
117143 if (_oldState != thisState) {
118144 _position += KNOBDIR[thisState | (_oldState << 2 )];
@@ -147,22 +173,7 @@ void RotaryEncoder::tick(void)
147173 break ;
148174 } // switch
149175 } // if
150- } // tick()
151-
152-
153- unsigned long RotaryEncoder::getMillisBetweenRotations () const
154- {
155- return (_positionExtTime - _positionExtTimePrev);
156- }
157-
158- unsigned long RotaryEncoder::getRPM ()
159- {
160- // calculate max of difference in time between last position changes or last change and now.
161- unsigned long timeBetweenLastPositions = _positionExtTime - _positionExtTimePrev;
162- unsigned long timeToLastPosition = millis () - _positionExtTime;
163- unsigned long t = max (timeBetweenLastPositions, timeToLastPosition);
164- return 60000.0 / ((float )(t * 20 ));
165- }
176+ } // RotaryEncoder::_tick()
166177
167178
168179// End
0 commit comments