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

API for the RPR220-based Grove IR Reflective Sensor. More...

Detailed Description

UPM module for the Grove IR reflective sensor. The sensitivity can be adjusted with the potentiometer on the sensor module. It has a range of approximately 15 mm, and a quick response time.

It detects high-contrast dark areas on a light background.

This module allows the user to determine the current status (black detected or not). Additionally, if desired, an interrupt service routine (ISR) can be installed that is called when black is detected. Either method can be used, depending on your use case.

rpr220.jpg
// This example uses a simple method to determine current status
// Instantiate an RPR220 digital pin D2
// This was tested on the Grove IR Reflective Sensor
upm::RPR220 rpr220(2);
while (shouldRun) {
if (rpr220.blackDetected())
cout << "Black detected" << endl;
else
cout << "Black NOT detected" << endl;
upm_delay_us(100000); // 100ms
}
// This example uses an interrupt handler to increment a counter
// Instantiate an RPR220 digital pin D2
// This was tested on the Grove IR Reflective Sensor
upm::RPR220 rpr220(2);
// Here, we setup our Interupt Service Routine (ISR) to count
// 'black' pulses detected.
rpr220.installISR(rprISR, NULL);
while (shouldRun) {
cout << "Counter: " << counter << endl;
upm_delay(1);
}

Public Member Functions

 RPR220 (int pin)
 
 ~RPR220 ()
 
bool blackDetected ()
 
void installISR (void(*isr)(void *), void *arg)
 
void uninstallISR ()
 

Constructor & Destructor Documentation

RPR220 ( int  pin)

RPR220 constructor

Parameters
pinDigital pin to use
~RPR220 ( )

RPR220 destructor

Here is the call graph for this function:

Member Function Documentation

bool blackDetected ( )

Gets the status of the pin; true means black has been detected

Returns
True if the sensor has detected black

Here is the call graph for this function:

void installISR ( void(*)(void *)  isr,
void *  arg 
)

Installs an ISR to be called when black is detected

Parameters
isrPointer to a function to be called on interrupt
argPointer to an object to be supplied as an argument to the ISR.

Here is the call graph for this function:

void uninstallISR ( )

Uninstalls the previously installed ISR

Here is the call graph for this function:


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