adding files
This commit is contained in:
28
i2c_encoder/encoder.cpp
Normal file
28
i2c_encoder/encoder.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user