|
|
旋转编码器中间的按键要做开关,但是悲剧的发现采用中断抖动没办法消除,电阻电容都加了,现在打算用施密特触发器对按键做消抖,同时也顺便对AB脚进行整形,请问这样应该是可行的吧,顺便求电路~mega2560
#include <RotaryEncoder.h>
RotaryEncoder encoder(14, 15);
int selectpin1 = 2;
boolean selected = false;
void setup(void) {
PCICR |= (1 << PCIE1); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port C.
PCMSK1 |= (1 << PCINT9) | (1 << PCINT10); // This enables the interrupt for pin 14 and 15 of Port C.
pinMode(selectpin1, INPUT_PULLUP); // Button switch or pin for encoder built-in switch
attachInterrupt( digitalPinToInterrupt(selectpin1), button, FALLING);
}
void button (void)
{
selected =! selected;
}
ISR(PCINT1_vect) {
encoder.tick(); // just call tick() to check the state.
}
int Rotator()
{
static int pos = 0;
int newPos = encoder.getPosition();
if (pos != newPos) {
// Serial.print(newPos);
// Serial.println();
if(newPos < pos)
{ dir=1;
pos = newPos;
}
else if(newPos > pos)
{ dir=2;
pos = newPos;
}
}
}
|
|