Handle quadrature encoder input
It is now possible to act on the input from the encoder, no effort to debounce has been made yet.
This commit is contained in:
parent
3b2bf1d967
commit
321972878b
|
@ -1,6 +1,7 @@
|
|||
#define F_CPU 8000000UL
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -86,6 +87,26 @@ void lcd_splash() {
|
|||
}
|
||||
}
|
||||
|
||||
ISR(PCINT0_vect) {
|
||||
cli();
|
||||
|
||||
while (~PINB & (1 << PB7));
|
||||
|
||||
// if PB6 Low -> CW
|
||||
if (PINB & (1 << PB6)) {
|
||||
OCR0B++;
|
||||
if (OCR0B > 100)
|
||||
OCR0B = 100;
|
||||
// if PB6 High -> CCW
|
||||
} else {
|
||||
OCR0B--;
|
||||
if (OCR0B > 100)
|
||||
OCR0B = 0;
|
||||
}
|
||||
|
||||
sei();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
// FastPWM: 1.25kHz
|
||||
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
||||
|
@ -94,8 +115,12 @@ int main(void) {
|
|||
OCR0B = 10;
|
||||
DDRD |= (1 << PD5);
|
||||
|
||||
bool reverse = 0;
|
||||
// Encoder setup
|
||||
PORTB |= (1 << PB7) | (1 << PB6);
|
||||
PCICR |= (1 << PCIE0);
|
||||
PCMSK0 |= (1 << PCINT7);
|
||||
|
||||
// SPI setup
|
||||
spi_init();
|
||||
lcd_init();
|
||||
lcd_splash();
|
||||
|
|
Loading…
Reference in a new issue