CheeseBoard
A library for use with the CheeseBoard Cheddar platform
Public Types | Public Member Functions | List of all members
CbRotaryInputClass Class Reference

#include <CbRotaryInput.h>

Public Types

typedef void(* t_buttonCb) (uint16_t)
 
typedef void(* t_rotaryCb) (int8_t, int32_t)
 

Public Member Functions

 CbRotaryInputClass (uint8_t buttonPin, uint8_t aPin, uint8_t bPin)
 
void begin (t_buttonCb buttonCb=NULL, t_rotaryCb rotaryCb=NULL)
 
void update ()
 
int32_t getEncoderPosition ()
 
bool buttonPushed ()
 

Detailed Description

CbRotaryInputClass.

Handy wrapper class for the dual functions of the rotary encoder device:

  1. Push button
  2. Rotary encoder for left/right type input

This class lets a user register callbacks to be triggered when the rotary encoder is moved and/or the button is pushed.

Definition at line 18 of file CbRotaryInput.h.

Member Typedef Documentation

◆ t_buttonCb

typedef void(* CbRotaryInputClass::t_buttonCb) (uint16_t)

A function pointer to a fuction which can be used as a callback for button presses.

The parameter to the function is the number of milliseconds the button was pushed for.

Definition at line 25 of file CbRotaryInput.h.

◆ t_rotaryCb

typedef void(* CbRotaryInputClass::t_rotaryCb) (int8_t, int32_t)

A function pointer to a fuction which can be used as a callback for rotary movement events.

The parameters to the function are:

Parameters
int8_tthe direction of turn. -1 mean widdershins, +1 means anti-widdershins.
int32_tthe current position of the rotary dial. It starts at 0 and accumulates.

Definition at line 34 of file CbRotaryInput.h.

Constructor & Destructor Documentation

◆ CbRotaryInputClass()

CbRotaryInputClass::CbRotaryInputClass ( uint8_t  buttonPin,
uint8_t  aPin,
uint8_t  bPin 
)

Constructor.

Parameters
buttonPinthe pin to which the button leg of the encoder input is attached.
aPinthe pin to which the A leg of the rotary encoder input is attached.
bPinthe pin to which the B leg of the rotary encoder input is attached.

Definition at line 7 of file CbRotaryInput.cpp.

Member Function Documentation

◆ begin()

void CbRotaryInputClass::begin ( t_buttonCb  buttonCb = NULL,
t_rotaryCb  rotaryCb = NULL 
)

Initializtion.

Parameters
buttonCbpointer to function which will be called when the button is pushed.
rotaryCbpointer to function which will be called when the encoder is moved.

This function is typically called from begin() in sketches.

Definition at line 19 of file CbRotaryInput.cpp.

◆ buttonPushed()

bool CbRotaryInputClass::buttonPushed ( )

Test if the button is currently pushed.

Returns
true if the button is push at the time of calling.

Definition at line 54 of file CbRotaryInput.cpp.

◆ getEncoderPosition()

int32_t CbRotaryInputClass::getEncoderPosition ( )

Fetch the current position of the rotary encoder

Returns
The position of the encoder. After instantiation of the CbRotaryInputClass, the position is 0.

Definition at line 49 of file CbRotaryInput.cpp.

◆ update()

void CbRotaryInputClass::update ( )

Update the state of the CbRotaryInputClass.

Should be called frequently (at least every few ms), typically from loop().

Definition at line 27 of file CbRotaryInput.cpp.


The documentation for this class was generated from the following files: