Noiasca Encoder
Encoder
Public Member Functions | List of all members
Encoder Class Reference

rotary encoder class More...

#include <NoiascaEncoder.h>

Public Member Functions

 Encoder (byte pinA, byte pinB)
 constructor for encoder More...
 
 Encoder (byte pinA, byte pinB, CallBack funcUpPtr, CallBack funcDownPtr)
 constructor for encoder More...
 
void begin ()
 start hardware More...
 
void encode ()
 function to be called in the background More...
 
int8_t getDirection ()
 get current direction More...
 
int32_t getCounter ()
 get internal counter value More...
 
int32_t read ()
 get actual counter value. More...
 
void setCounter (int32_t newValue)
 set actual countnr value. More...
 
void write (int32_t newValue)
 set actual coutner value. More...
 
bool upClick ()
 gets true if rotary encoder is moved to the right More...
 
bool downClick ()
 gets true if rotary encoder is moved to the left More...
 

Detailed Description

rotary encoder class

Constructor & Destructor Documentation

◆ Encoder() [1/2]

Encoder::Encoder ( byte  pinA,
byte  pinB 
)
inline

constructor for encoder

This constructor is used for a simple rotary encoder connected to two pins.

Parameters
pinAthe first GPIO
pinBthe second GPIO

◆ Encoder() [2/2]

Encoder::Encoder ( byte  pinA,
byte  pinB,
CallBack  funcUpPtr,
CallBack  funcDownPtr 
)
inline

constructor for encoder

This constructor is used for a simple rotary encoder connected to two pins and to define two callback functions fired when the encoder is moved.

Parameters
pinAthe first GPIO
pinBthe second GPIO
funcUpPtra callback function to be called when the rotary encoder is moved to the right/increase
funcDownPtra callback function to be called when the rotary encoder is moved to the left/decrease

Member Function Documentation

◆ begin()

void Encoder::begin ( )
inline

start hardware

call this function in your setup(). It is necessary to set the pins accordingly.

◆ encode()

void Encoder::encode ( )
inline

function to be called in the background

This is the run method of the class. For usual this function is called internally. Call encode() in loop if you are only using the callback functions.

◆ getDirection()

int8_t Encoder::getDirection ( )
inline

get current direction

Returns 1 (clockwise) or -1 (counter clockwise) depending on the rotary usage.

Returns
the current direction: 1 (clockwise) or -1 (counter clockwise)

◆ getCounter()

int32_t Encoder::getCounter ( )
inline

get internal counter value

Returns the internal counter - a signed 32 bit variable.

Returns
the internal counter

◆ read()

int32_t Encoder::read ( )
inline

get actual counter value.

alias function of getCounter for compatibily with Paul Stoffregen encoder library.

See also
getCounter

◆ setCounter()

void Encoder::setCounter ( int32_t  newValue)
inline

set actual countnr value.

Parameters
newValuethe new value for the internal counter

◆ write()

void Encoder::write ( int32_t  newValue)
inline

set actual coutner value.

alias function for setCounter for compatibily with Paul Stoffregen encoder library.

Parameters
newValuethe new value for the internal counter
See also
setCounter

◆ upClick()

bool Encoder::upClick ( )
inline

gets true if rotary encoder is moved to the right

Returns
true when moved to right / clockwise

◆ downClick()

bool Encoder::downClick ( )
inline

gets true if rotary encoder is moved to the left

Returns
true when moved to left / counter clockwise