/**
* @file BasicReadExample.ino
* @author Alex Casal (https://github.com/alexitoo00)
* @brief A basic example to obtain all possible properties of a rotary encoder
* @version 1.0
* @date 2023-06-08
*
* @copyright Copyright (c) 2023
*
*/
#include "NewEncoder.h"
int direction;
NewEncoder encoder; // Create an instance of the class NewEncoder
void setup()
{
// pin A or CLOCK, pin B or DATA, number of steps per turn and pin of SWITCH button
encoder.begin(3, 2, 4);
Serial.begin(9600);
}
unsigned long delayTime = 0;
void loop()
{
encoder.Update(); // Call this function as frequently as possible (in this case, each loop)
if (millis() - delayTime < 200) // Optimized delay
return;
delayTime = millis();
PrintData();
encoder.Reset();
}
void PrintData()
{
Serial.print("Steps: \t\t-\t");
Serial.println(encoder.GetSteps());
}