Compare commits
2 Commits
c151a7bb67
...
f48f18ac64
| Author | SHA1 | Date |
|---|---|---|
|
|
f48f18ac64 | 6 years ago |
|
|
3dafc11535 | 6 years ago |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,69 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#define ENC_PORT PORTD
|
||||
#define ENC_DDR DDRD
|
||||
#define ENC_A PIND&(1<<2)
|
||||
#define ENC_B PIND&(1<<4)
|
||||
#define ENC_CCW 0
|
||||
#define ENC_CW 1
|
||||
|
||||
void encoder_action(uint8_t dir);
|
||||
|
||||
volatile uint8_t encoder_direction;
|
||||
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
if (ENC_B)
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
encoder_action(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
encoder_action(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ISR (PCINT3_vect){
|
||||
if (ENC_B)
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
encoder_action(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
encoder_action(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue