This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
// Пример с прямой работой библиотеки на прерываниях
#include<EncButton.h>
EncButton<EB_TICK,2,3,4>enc;// энкодер с кнопкой <A, B, KEY>
//EncButton<EB_TICK, 2, 3> enc; // просто энкодер <A, B>
//EncButton<EB_TICK, 4> enc; // просто кнопка <KEY>
voidsetup(){
Serial.begin(9600);
// желательно подключить оба пина энкодера на внешние прерывания по CHANGE
// можно использовать PCINT https://github.com/NicoHood/PinChangeInterrupt
attachInterrupt(0,isr,CHANGE);// D2
attachInterrupt(1,isr,CHANGE);// D3
// подключил оба прерывания на одну функцию
}
voidisr(){
enc.tickISR();// в прерывании вызываем тик ISR
}
voidloop(){
// тут тоже вызываем тик, нужен для
// корректной работы дебаунсов и прочих таймеров!!!
enc.tick();
if(enc.turn()){// любой поворот
Serial.print("turn ");
Serial.println(enc.counter);// вывод счётчика
}
// имитация загруженной программы, обработка происходит в прерывании