Tea Pack / Motor_Encoders

Dependents:   VNH5019_2 VNH5019_1

Embed: (wiki syntax)

« Back to documentation index

Encoder Class Reference

Encoder Class Reference

Class for the digital quadrature encoder. More...

#include <Encoder.h>

Public Member Functions

 Encoder (PinName InA, PinName InB)
 Class contructor.
int getDist ()
 Function for repetitive getting counts from the encoder.
int getTotalDist ()
 Function returning total counts, direction dependent.
void clr ()
 Function setting total distance to zero.
void setEnabled (bool)
 Function for enabling encoder interrupts detection.
bool isEnabled ()
 Function for getting state of encoders.

Detailed Description

Class for the digital quadrature encoder.

This class is using two pins for detecting all edges generated by the quadrature encoder.

Writen by: Jan Crha (TeaPack_CZ), 2016.

Last modified: 2016-09-21

Example:

  #include "mbed.h"
  #include "Encoder.h"
  
  Serial PC(USBTX,USBRX);
  Encoder encoder(p11,p12);
  
  int main(){
  
  encoder.setEnabled(true);
  
  while(1)
  {
      PC.printf("%d",encoder.getDist());
      wait(0.1);
  }
  }

Definition at line 32 of file Encoder.h.


Constructor & Destructor Documentation

Encoder ( PinName  InA,
PinName  InB 
)

Class contructor.

Both pins have to be compatible with the InterruptIn class.

Definition at line 3 of file Encoder.cpp.


Member Function Documentation

void clr (  )

Function setting total distance to zero.

Definition at line 27 of file Encoder.cpp.

int getDist (  )

Function for repetitive getting counts from the encoder.

Returns:
returns number of edges detected from the last call

Definition at line 14 of file Encoder.cpp.

int getTotalDist (  )

Function returning total counts, direction dependent.

counts can be set to zero by calling function clr()

Definition at line 22 of file Encoder.cpp.

bool isEnabled (  )

Function for getting state of encoders.

Definition at line 46 of file Encoder.cpp.

void setEnabled ( bool  state )

Function for enabling encoder interrupts detection.

Definition at line 32 of file Encoder.cpp.