JMotor
Loading...
Searching...
No Matches
Public Member Functions | List of all members
JEncoderSinglePinChange Class Reference

uses a pin change interrupt library to support more pins than attachInterrupt(). More...

#include <JEncoderSinglePinChange.h>

Inheritance diagram for JEncoderSinglePinChange:
Inheritance graph
[legend]
Collaboration diagram for JEncoderSinglePinChange:
Collaboration graph
[legend]

Public Member Functions

 JEncoderSinglePinChange (byte _encoderPin, float _distPerCountFactor=1.0, bool _reverse=false, unsigned long _slowestIntervalMicros=100000UL, unsigned long _switchBounceIntervalMicros=0, byte _interruptType=CHANGE)
 constructor, sets pins and settings
 
void setUpInterrupts (void(*_isrPointer)(void))
 
void turnOffInterrupts ()
 disable interrupts and stop monitoring encoder
 
- Public Member Functions inherited from JEncoderSingle
bool getRev ()
 get whether the encoder is told it's going backwards currently
 
void setRev (bool _rev)
 set which direction the encoder is moving (if you have external information about direction (like motor power) and want getVel and getDist to go the right direction even with this directionless encoder)
 
long zeroCounter ()
 reset the counter of how far the encoder has turned
 
float getVel ()
 calculates velocity in distance per second where distance was set by setdistPerCountFactor()
 
long getCounter ()
 returns how far the encoder has turned from the zero position
 
float getPos ()
 returns how far the encoder has turned from the zero position converted to distance
 
float getDistPerCountFactor ()
 returns a conversion factor between encoder ticks and distance that can be set for the encoder
 
void setDistPerCountFactor (float _factor)
 set the conversion factor between encoder ticks and distance
 
void setReverse (bool _reverse)
 reverse readings of encoder
 
bool hasDirection ()
 can this encoder measure direction or just speed
 
bool isVelNew ()
 could be useful for only recalculating a control loop if there's new velocity data
 
void run ()
 if an encoder needs to have some code called each loop (like absolute encoder polling encoder and calculating amount turned)
 
void encoderISR (void)
 

Additional Inherited Members

- Protected Member Functions inherited from JEncoderSingle
 JEncoderSingle (byte _encoderPin, float _distPerCountFactor, bool _reverse, unsigned long _slowestIntervalMicros, unsigned long _switchBounceIntervalMicros, byte _interruptType)
 constructor, sets pins and settings
 
- Protected Attributes inherited from JEncoderSingle
unsigned char encoderPin
 
byte interruptType
 

Detailed Description

uses a pin change interrupt library to support more pins than attachInterrupt().

interrupt library (tested with v1.1.0): https://github.com/GreyGnome/EnableInterrupt
platform: AVR (standard Arduinos)

Note
make sure to call setUpInterrupts() when your code starts

Constructor & Destructor Documentation

◆ JEncoderSinglePinChange()

JEncoderSinglePinChange::JEncoderSinglePinChange ( byte  _encoderPin,
float  _distPerCountFactor = 1.0,
bool  _reverse = false,
unsigned long  _slowestIntervalMicros = 100000UL,
unsigned long  _switchBounceIntervalMicros = 0,
byte  _interruptType = CHANGE 
)
inline

constructor, sets pins and settings

Parameters
_encoderPinencoder input pin
_distPerCountFactorconversion factor for getting distance in an actual unit
_reversefalse(default)
_slowestIntervalMicrosafter this many microseconds without an encoder tick velocity is set to zero.
_switchBounceIntervalMicrosignore additional pulses for this many microseconds after each pulse
_interruptTypecounts on RISING, FALLING, or CHANGE interrupt

Member Function Documentation

◆ setUpInterrupts()

void JEncoderSinglePinChange::setUpInterrupts ( void(*)(void)  _isrPointer)
inlinevirtual
Note
interrupt created by jENCODER_SINGLE_MAKE_ISR_MACRO(name of encoder) will be of the form <name of encoder instance>_jENCODER_ISR

Reimplemented from JEncoderSingle.

◆ turnOffInterrupts()

void JEncoderSinglePinChange::turnOffInterrupts ( )
inlinevirtual

disable interrupts and stop monitoring encoder

Note
use setUpInterrupts to start encoder again

Reimplemented from JEncoderSingle.


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