Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int8_t lookup_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
- static uint8_t enc_val = 0;
- int A = 2;
- int B = 3;
- volatile long enc_count = 0;
- volatile long last_time = 0;
- void encoder()
- {
- last_time = millis();
- enc_val = enc_val << 2;
- enc_val = enc_val | ((PIND & 0b1100) >> 2);
- enc_count = enc_count + lookup_table[enc_val & 0b1111];
- }
- void setup()
- {
- attachInterrupt(0,encoder,CHANGE);
- attachInterrupt(1,encoder,CHANGE);
- Serial.begin(9600);
- }
- void loop()
- {
- Serial.println(1/(millis()-last_time));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement