RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::SoundSensor Class Reference

FC-04 sound sensor - reads sound level as an analog value through a PCF8591 ADC channel. More...

#include <SoundSensor.h>

Inheritance diagram for RumPi::SoundSensor:
[legend]
Collaboration diagram for RumPi::SoundSensor:
[legend]

Public Member Functions

 SoundSensor (unsigned int pcfBasePinNumber, int pcfI2CAddress)
 Builds a sound sensor bound to the given PCF8591 base pin number and I2C address. More...
 
virtual ~SoundSensor ()
 Destroys the sensor, turning it off first. More...
 
virtual void TurnOn () override
 No-op: the sound sensor is passive and reads on demand, so there is nothing to turn on. More...
 
virtual void TurnOff () override
 No-op: the sound sensor holds no resources that need releasing when turned off. More...
 
virtual void ProcessRawValues () override
 No-op: the sound sensor reads its value on demand in ReadRawAnalogValue, so there are no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the sensor's PCF8591 base pin number and I2C address to a string. More...
 
int ReadRawAnalogValue () const
 Reads the raw analog sound value from the PCF8591 base pin. More...
 
unsigned int GetPCFBasePinNumber () const
 Gets the PCF8591 base pin number this sensor reads from. More...
 
int GetPCFI2CAddress () const
 Gets the PCF8591 I2C address. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Attributes

unsigned int myPCFBasePinNumber
 The PCF8591 base pin number this sensor reads from. More...
 
int myPCFI2CAddress
 The PCF8591 I2C address. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

FC-04 sound sensor - reads sound level as an analog value through a PCF8591 ADC channel.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ SoundSensor()

RumPi::SoundSensor::SoundSensor ( unsigned int  pcfBasePinNumber,
int  pcfI2CAddress 
)

Builds a sound sensor bound to the given PCF8591 base pin number and I2C address.

Author
Eddie O'Hagan
Date
8/13/2026
SoundSensor soundSensor(basePin, 0x48);
SoundSensor(unsigned int pcfBasePinNumber, int pcfI2CAddress)
Builds a sound sensor bound to the given PCF8591 base pin number and I2C address.
Definition: SoundSensor.cpp:18
Parameters
[in]pcfBasePinNumberThe PCF8591 base pin number this sensor reads from.
[in]pcfI2CAddressThe PCF8591 I2C address.

◆ ~SoundSensor()

RumPi::SoundSensor::~SoundSensor ( )
virtual

Destroys the sensor, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
SoundSensor* soundSensor = new SoundSensor(basePin, 0x48);
delete soundSensor;

Member Function Documentation

◆ GetPCFBasePinNumber()

unsigned int RumPi::SoundSensor::GetPCFBasePinNumber ( ) const

Gets the PCF8591 base pin number this sensor reads from.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = soundSensor.GetPCFBasePinNumber();
Returns
The PCF8591 base pin number.

◆ GetPCFI2CAddress()

int RumPi::SoundSensor::GetPCFI2CAddress ( ) const

Gets the PCF8591 I2C address.

Author
Eddie O'Hagan
Date
8/13/2026
int address = soundSensor.GetPCFI2CAddress();
Returns
The PCF8591 I2C address.

◆ ProcessRawValues()

void RumPi::SoundSensor::ProcessRawValues ( )
overridevirtual

No-op: the sound sensor reads its value on demand in ReadRawAnalogValue, so there are no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
soundSensor.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ReadRawAnalogValue()

int RumPi::SoundSensor::ReadRawAnalogValue ( ) const

Reads the raw analog sound value from the PCF8591 base pin.

Author
Eddie O'Hagan
Date
8/13/2026
int value = soundSensor.ReadRawAnalogValue();
Returns
The raw analog sound value.

◆ ToString()

std::string RumPi::SoundSensor::ToString ( ) const
overridevirtual

Serializes the sensor's PCF8591 base pin number and I2C address to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = soundSensor.ToString();
Returns
A multi-line string describing the sensor.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::SoundSensor::TurnOff ( )
overridevirtual

No-op: the sound sensor holds no resources that need releasing when turned off.

Author
Eddie O'Hagan
Date
8/13/2026
soundSensor.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::SoundSensor::TurnOn ( )
overridevirtual

No-op: the sound sensor is passive and reads on demand, so there is nothing to turn on.

Author
Eddie O'Hagan
Date
8/13/2026
soundSensor.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myPCFBasePinNumber

unsigned int RumPi::SoundSensor::myPCFBasePinNumber
private

The PCF8591 base pin number this sensor reads from.

◆ myPCFI2CAddress

int RumPi::SoundSensor::myPCFI2CAddress
private

The PCF8591 I2C address.


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