API Documentation v0.0.1
Loading...
Searching...
No Matches
RotaryEncoderTest.ino
1* Rotary Encoder Test Sketch
2* Outputs "Turning" when rotated, "PUSH" when pressed
3*/
4
5#include "RotaryEncoder.h"
6
7// Pin definitions (from Board.h)
8const int ENC_SW = 24; // Switch/push button
9const int ENC_A = 22; // Encoder A
10const int ENC_B = 23; // Encoder B
11
12RotaryEncoder encoder(ENC_A, ENC_B, RotaryEncoder::LatchMode::TWO03);
13int lastPos = 0;
14
15void setup() {
16 Serial.begin(9600);
17 pinMode(ENC_SW, INPUT_PULLUP);
18 Serial.println("Rotary Encoder Test Ready");
19}
20
21void loop() {
22 encoder.tick();
23
24 // Check rotation
25 int newPos = encoder.getPosition();
26 if (newPos != lastPos) {
27 Serial.println("Turning");
28 lastPos = newPos;
29 }
30
31 // Check button press
32 static bool lastButtonState = HIGH;
33 bool buttonState = digitalRead(ENC_SW);
34 if (buttonState == LOW && lastButtonState == HIGH) {
35 Serial.println("PUSH");
36 delay(50); // Simple debounce
37 }
38 lastButtonState = buttonState;
39}
void setup()
Arduino Setup Function.
void loop()
Arduino Loop Function.
bool buttonState[20]
Array to hold the current state of the 20 DDI buttons.