Get data from multiple variables to a function

Hi Everyone,

I'm working with the Adafruit SAMD21 (M0) to get data from multiples sensors.

For Example the PressureSensor I get the data only by the function
SensorPressure spres; and afther that I get the data by an spres.getPressure();

I have a cpp file with the instructions for each sensor and a h
file with the variables.

The cpp File of Pressure Sensor,
//Initialize SensorPressure
SensorPressure::SensorPressure()
{
}

With the function SensorPressure spres; I have access to all the variables on the SensorPressure.cpp

However, If try to create a function SensorRain sRain; I show this error on Arduino IDE.

error: no matching function for call to 'SensorRain::SensorRain()'
58 | SensorRain sRain;
| ^~~~~
In file included from C:\Users\User\Documents\Arduino\File_Temp\File_Temp.ino:15:
C:\Users\User\Documents\Arduino\libraries\SensorRain/SensorRain.h:13:2: note: candidate: 'SensorRain::SensorRain(int)'
13 | SensorRain(int interrupt_pin);
| ^~~~~~~~~~
Blockquote

I can not read the variables on the SensorRain.cpp Files.

Thanks for your help.

You have a strange view of the word "function",
you should look up its meaning in the C++ context again.

Your pressure sensor seems to be on I2C and has a default address,
so you can define such an object without any parameters/specification.

The rain sensor seems to need a pin to work on, which you did not specify.

SensorRain sRain(yourSensorPin); may work better, at least it will compile.

this part of the error message

tells you that the constructor for the rain sensor requires a parameter (likely a PIN number given the name) so if that pin is, say, pin 3 then your code needs to be like

#include "SensorRain.h"
const byte rainSensorPin = 3;
SensorRain sRain(rainSensorPin);

EDIT: need :eyeglasses:, exactly what @Whandall said....

Hello Whandall , J-M-L,

Thanks, Now is working the lecture of SensorPin.... :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.