upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Static Protected Member Functions | Protected Attributes

API for the DFRobot Wheel Encoder. More...

Detailed Description

This sensor was developed for the DFRobot Wheel Encoder, though it could be used for any counting time-based task.

When you instantiate a class of this type, the gpio pin specified is connected to an interrupt. Whenever a low to high transition occurs on the gpio pin, the internal counter is incremented by one.

This class also includes a millisecond counter, so that you can correlate the number of counts to a time period for calculating an RPM or other value as needed.

wheelencoder.jpg
// Instantiate a DFRobot Wheel Encoder on digital pin D2
upm::WheelEncoder sensor(2);
// set the counter to 0 and start counting
sensor.clearCounter();
sensor.startCounter();
while (shouldRun) {
// output milliseconds passed and current sensor count
cout << "Millis: " << sensor.getMillis() << " Count: " << sensor.counter() << endl;
upm_delay(1);
}
sensor.stopCounter();

Public Member Functions

 WheelEncoder (int pin)
 
 ~WheelEncoder ()
 
uint32_t getMillis ()
 
void initClock ()
 
void clearCounter ()
 
void startCounter ()
 
void stopCounter ()
 
uint32_t counter ()
 

Static Protected Member Functions

static void wheelISR (void *ctx)
 

Protected Attributes

mraa::Gpio m_gpio
 

Constructor & Destructor Documentation

WheelEncoder ( int  pin)

DFRobot Wheel Encoder sensor constructor

Parameters
pinDigital pin to use

Here is the call graph for this function:

WheelEncoder destructor

Here is the call graph for this function:

Member Function Documentation

uint32_t getMillis ( )

Returns the number of milliseconds elapsed since initClock() was last called.

Returns
Elapsed milliseconds
void initClock ( )

Resets the clock

Here is the caller graph for this function:

void clearCounter ( )
inline

Resets the counter to 0. The counter should be stopped via stopCounter() prior to calling this function.

Here is the call graph for this function:

void startCounter ( )

Starts the counter. This function will also clear the current count and reset the clock.

Here is the call graph for this function:

Here is the caller graph for this function:

void stopCounter ( )

Stops the counter

Here is the caller graph for this function:

uint32_t counter ( )
inline

Gets the current counter value

Returns
counter value

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