[elektro] rotary encoder, mit csinálok rosszul?
uprogc .
uprogc at gmail.com
Mon Jan 2 14:00:31 CET 2017
En igy csinaltam ;)
static int8_t states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
uint8_t RotaryCurrentState = 0x00;
uint8_t RotaryTransition = 0;
int8_t RotaryPosition = 0;
enum e_encoder { WAITING, LEFT, RIGHT };
typedef enum e_encoder rotate;
//NOTE Ezt hivjuk le/felfuto elnel is ITbol
// read_encoder_sig(() ez csak azt mondja meg hogy 0 vagy 1 szint van az
adott PINen
void callback_menu_enc()
{
RotaryCurrentState = ( (read_encoder_sig(ROT_ENC_PORT, ROT_ENC_TRIGGER
) << 1) |
read_encoder_sig(ROT_ENC_PORT, ROT_ENC_DIRECTION ));
RotaryTransition = (RotaryTransition <<2 ) | RotaryCurrentState;
RotaryPosition = RotaryPosition + states[RotaryTransition & 0x0F];
//CW Transition
if (RotaryPosition == 4)
{
e = LEFT;
RotaryPosition = 0;
}
//CCW Transition
else if (RotaryPosition == -4)
{
e = RIGHT;
RotaryPosition = 0;
}
else
{
e = WAITING; // ez is kell
}
switch(e) {
case LEFT:
//
break;
case RIGHT:
//
break;
case WAITING:
default:
break;
}
}
Remelem nem maradt le semmi ;)
Szabi
More information about the Elektro
mailing list