#include "NewEncoder.h"
// Create instance of the NewEncoder class
NewEncoder encoder;
#define encDATA 2
#define encCLK 3
#define endButton 4
void setup()
{
encoder.begin(encDATA, encCLK, endButton); // Initialize encoder
Serial.begin(9600);
}
unsigned long delayTime = 0;
void loop()
{
encoder.Update(); // Call this functions as frequently as possible (in this case, each loop)
if (millis() - delayTime < 200) // Optimized delay
return;
delayTime = millis();
PrintData();
}
void PrintData()
{
Serial.print("Steps: \t");
Serial.print(encoder.GetSteps());
Serial.print(" - Button: \t-\t");
Serial.println(encoder.ButtonPressed() ? "true" : "false");
Serial.println();
// Optional debugging functions:
// Serial.print(" - Degrees: \t-\t");
// Serial.print(encoder.Degrees(), 0); // second parameter is decimal positions
// Serial.print("Direction: \t-\t");
// Serial.println(encoder.GetDirectionName());
// Serial.print("Turns: \t\t-\t");
// Serial.println(encoder.Turns(), 16);
// Serial.print("Turns of turn: \t-\t");
// Serial.println(encoder.PercentageOfTurn(), 16);
// Serial.print("Radians: \t-\t");
// Serial.println(encoder.Radians(), 16);
// Serial.print("Degrees: \t-\t");
// Serial.print(encoder.Degrees(), 16);
// Serial.println("º");
}