upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
RPR220 Class Reference

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 = new upm::RPR220(2);
while (shouldRun)
{
if (rpr220->blackDetected())
cout << "Black detected" << endl;
else
cout << "Black NOT detected" << endl;
usleep(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 = new upm::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;
sleep(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

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
void installISR ( void(*)(void *)  isr,
void *  arg 
)

Installs an ISR to be called when black is detected

Parameters
fptrPointer to a function to be called on interrupt
argPointer to an object to be supplied as an argument to the ISR.
void uninstallISR ( )

Uninstalls the previously installed ISR


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