M5Unit-INFRARED 0.3.0 git rev:2148adc
Loading...
Searching...
No Matches
m5::unit::UnitITR9606 Class Reference

ITR9606 infrared photointerrupter unit. More...

#include <unit_ITR9606.hpp>

Inheritance diagram for m5::unit::UnitITR9606:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitITR9606 ()
 Constructor.
 
config_t config () const
 Gets the config values.
 
void config (const config_t &cfg)
 Set the config values.
 
bool begin () override
 Set the RX pin to input with pull-up and apply the config.
 
void update (const bool force=false) override
 Read the sensor pin and update the detection state.
 
Detection state
bool isDetected () const
 Current detection state.
 
bool wasDetected () const
 Rising edge detection (object entered the slot)
 
bool wasReleased () const
 Falling edge detection (object left the slot)
 
Direct reading
bool readDetection (bool &detected)
 Read the sensor pin state directly.
 

Detailed Description

ITR9606 infrared photointerrupter unit.

The ITR9606 is a transmissive photointerrupter consisting of an IR LED and a phototransistor. When an object passes through the slot and blocks the IR beam, the output changes state. Output is active HIGH: HIGH when blocked (object detected), LOW when clear.

Member Function Documentation

◆ begin()

bool m5::unit::UnitITR9606::begin ( )
override

Set the RX pin to input with pull-up and apply the config.

Returns
True if successful

◆ config() [1/2]

config_t m5::unit::UnitITR9606::config ( ) const
inline

Gets the config values.

Returns
Copy of the current config

◆ config() [2/2]

void m5::unit::UnitITR9606::config ( const config_t & cfg)
inline

Set the config values.

Parameters
cfgConfig to apply on the next begin()

◆ isDetected()

bool m5::unit::UnitITR9606::isDetected ( ) const
inline

Current detection state.

Returns
true if an object is blocking the IR beam (pin is HIGH)

◆ readDetection()

bool m5::unit::UnitITR9606::readDetection ( bool & detected)

Read the sensor pin state directly.

Parameters
[out]detectedtrue if an object is blocking the IR beam
Returns
True if successful

◆ update()

void m5::unit::UnitITR9606::update ( const bool force = false)
override

Read the sensor pin and update the detection state.

Parameters
forceRead immediately, ignoring config_t::interval

◆ wasDetected()

bool m5::unit::UnitITR9606::wasDetected ( ) const
inline

Rising edge detection (object entered the slot)

Returns
true if a new detection occurred since the last update (clear -> blocked transition)

◆ wasReleased()

bool m5::unit::UnitITR9606::wasReleased ( ) const
inline

Falling edge detection (object left the slot)

Returns
true if detection ended since the last update (blocked -> clear transition)