#include "AiEsp32RotaryEncoder.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define ROTARY_ENCODER_A_PIN 19
#define ROTARY_ENCODER_B_PIN 20
#define ROTARY_ENCODER_BUTTON_PIN 21
#define ROTARY_ENCODER_STEPS 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3D
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, -1, ROTARY_ENCODER_STEPS);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire,-1);
void IRAM_ATTR readEncoderISR()
{
rotaryEncoder.readEncoder_ISR();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S2!");
rotaryEncoder.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(32,32);
display.print(F("hello world"));
display.display();
rotaryEncoder.setup(readEncoderISR);
rotaryEncoder.setBoundaries(0,4,false);
rotaryEncoder.setAcceleration(250);
}
void loop() {
if(rotaryEncoder.encoderChanged()){
Serial.println(rotaryEncoder.readEncoder());
}
if (rotaryEncoder.isEncoderButtonClicked())
{
Serial.println("button pressed");}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}