#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "GyverEncoder.h"
#define TFT_DC 2
#define TFT_CS 15
#define Encoder_CLK 14
#define Encoder_DT 13
#define Encoder_SW 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Encoder enc1(Encoder_CLK, Encoder_DT, Encoder_SW); // для работы c кнопкой
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// enc1.setType(TYPE2);
tft.begin();
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello ESP32");
tft.setCursor(24, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can do SPI :-)");
tft.setCursor(0, 0);
}
void loop() {
// put your main code here, to run repeatedly:
// обязательная функция отработки. Должна постоянно опрашиваться
enc1.tick();
if (enc1.isTurn()) { // если был совершён поворот (индикатор поворота в любую сторону)
// ваш код
Serial.println("isTurn");
tft.println("isTurn");
}
if (enc1.isRight()) {
Serial.println("Right"); // если был поворот
tft.println("Right");
}
if (enc1.isLeft()){
Serial.println("Left");
tft.println("Left");
}
if (enc1.isRightH()) {
Serial.println("Right holded"); // если было удержание + поворот
tft.println("Right holded");
}
if (enc1.isLeftH()){
Serial.println("Left holded");
tft.println("Left holded");
}
if (enc1.isPress()){
Serial.println("Press"); // нажатие на кнопку (+ дебаунс)
tft.println("Press");
}
if (enc1.isClick()){
Serial.println("Click"); // отпускание кнопки (+ дебаунс)
tft.println("Click");
}
//if (enc1.isRelease()) Serial.println("Release"); // то же самое, что isClick
if (enc1.isHolded()){
Serial.println("Holded"); // если была удержана и энк не поворачивался
tft.println("Holded");
}
//if (enc1.isHold()) Serial.println("Hold"); // возвращает состояние кнопки
}