2021-08-15 21:28:09 +03:00

48 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#define CLK 2
#define DT 3
#define SW 4
#include "GyverEncoder.h"
//Encoder enc1(CLK, DT); // для работы без кнопки
Encoder enc1(CLK, DT, SW); // для работы c кнопкой
//Encoder enc1(CLK, DT, SW, TYPE2); // для работы c кнопкой и сразу выбираем тип
//Encoder enc1(CLK, DT, ENC_NO_BUTTON, TYPE2); // для работы без кнопки и сразу выбираем тип
// Варианты инициализации:
// Encoder enc; // не привязан к пину
// Encoder enc(пин CLK, пин DT); // энкодер без кнопки (ускоренный опрос)
// Encoder enc(пин CLK, пин DT, пин SW); // энкодер с кнопкой
// Encoder enc(пин CLK, пин DT, пин SW, тип); // энкодер с кнопкой и указанием типа
// Encoder enc(пин CLK, пин DT, ENC_NO_BUTTON, тип); // энкодер без кнопкой и с указанием типа
void setup() {
Serial.begin(9600);
enc1.setType(TYPE2);
}
void loop() {
// обязательная функция отработки. Должна постоянно опрашиваться
enc1.tick();
if (enc1.isTurn()) { // если был совершён поворот (индикатор поворота в любую сторону)
// ваш код
}
if (enc1.isRight()) Serial.println("Right"); // если был поворот
if (enc1.isLeft()) Serial.println("Left");
if (enc1.isRightH()) Serial.println("Right holded"); // если было удержание + поворот
if (enc1.isLeftH()) Serial.println("Left holded");
//if (enc1.isPress()) Serial.println("Press"); // нажатие на кнопку (+ дебаунс)
//if (enc1.isRelease()) Serial.println("Release"); // то же самое, что isClick
if (enc1.isClick()) Serial.println("Click"); // одиночный клик
if (enc1.isSingle()) Serial.println("Single"); // одиночный клик (с таймаутом для двойного)
if (enc1.isDouble()) Serial.println("Double"); // двойной клик
if (enc1.isHolded()) Serial.println("Holded"); // если была удержана и энк не поворачивался
//if (enc1.isHold()) Serial.println("Hold"); // возвращает состояние кнопки
}