29 lines
605 B
C++
29 lines
605 B
C++
#include "encoder.h"
|
|
|
|
// public:
|
|
|
|
// constructor : sets pins as inputs and turns on pullup resistors
|
|
RotaryEncoder::RotaryEncoder( const String& argName, int argClkPin, int argDtPin, int argPinMode) : name(argName), clkPin ( argClkPin), dtPin( argDtPin )
|
|
{
|
|
// set pin a and b to be input with pull up enabled
|
|
pinMode(clkPin, argPinMode);
|
|
pinMode(dtPin, argPinMode);
|
|
|
|
position = 0;
|
|
}
|
|
|
|
void RotaryEncoder::update(void)
|
|
{
|
|
digitalRead(dtPin) ? position++ : position--;
|
|
}
|
|
|
|
int RotaryEncoder::getPosition ()
|
|
{
|
|
return position;
|
|
}
|
|
|
|
void RotaryEncoder::clearPosition()
|
|
{
|
|
position = 0;
|
|
}
|