2023-03-03 04:18:44 +00:00
|
|
|
# AVR_ENCODER
|
|
|
|
|
2023-03-03 05:16:03 +00:00
|
|
|
This is small library for rotary encoders often found being used for controls
|
|
|
|
or volume knobs in embedded platforms.
|
|
|
|
|
|
|
|
|
|
|
|
The recomended way to use the code is by calling the poll_encoder() function
|
|
|
|
in the C file.
|
|
|
|
|
|
|
|
This allows the use of polling for monitoring the state of the encoder. This
|
|
|
|
should be fine for most applications that don't require interrupts for encoder
|
|
|
|
use.
|
|
|
|
|
|
|
|
The only issue would be if running the AVR at very very low speed and
|
|
|
|
preforming too many other taskts to the point that the polling loop doesn't
|
|
|
|
capture the full wave form from the encoder. But this is a well known weakness
|
|
|
|
in polling.
|
|
|
|
|
|
|
|
|
|
|
|
## Demo Funciton:
|
|
|
|
```C
|
|
|
|
//This is just an example function of how you could use it.
|
|
|
|
int demo() {
|
|
|
|
init_encoder();
|
|
|
|
uint8_t volume = 0;
|
|
|
|
led_blink(2);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
switch(poll_encoder()) {
|
|
|
|
case CW:
|
|
|
|
if(volume < 100){volume++;}
|
|
|
|
led_blink(1);
|
|
|
|
break;
|
|
|
|
case CCW:
|
|
|
|
if(volume > 0){volume--;}
|
|
|
|
led_blink(2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;//nothing.
|
|
|
|
}
|
|
|
|
|
|
|
|
//Do other polling operations here
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|