Need help to reference a library object inside a class

I am trying to run several sensors in one sketch using the millis() approach to running them more or less at the same time. To do that, I’ve put the sensors into classes with time checks. I’ve run into a problem with the DHT_nonblocking library. Mainly I’m trying to figure out how to access the library from within my own class. I’m having trouble passing it as a parameter. the compiler output is below the code. Any help is appreciated.

Here are the relevant snippets of code

#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

class TandH
{
int sensorPin; //the pin the sensor is attached to
long _interval; //interval between temperature readings
DHT_nonblocking &_sensorLib;

public:
TandH(int pin, long interval, DHT_nonblocking &sensorLib)
{
sensorPin = pin;
_interval = interval;
_sensorLib = sensorLib
}
void startDHT ()
{

}
void Update()
{
float temperature;
float humidity;
static unsigned long measurement_timestamp = millis( );

/*

  • Poll for temp & humidy measurement, keeping the state machine alive. Returns
  • true if a measurement is available.
  • Measure once every interval seconds. */
    if( millis( ) - measurement_timestamp > _interval ) // interval was hardcoded to 3000ul
    {
    if( sensorLib.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( “%” );
    }
    }
    }
    };

TandH (DHT_SENSOR_PIN, 3000, dht_sensor);

Arduino: 1.8.12 (Windows 10), Board: “Arduino NANO 33 IoT”

PingWithLED:90:2: error: uninitialized reference member in ‘class DHT_nonblocking&’ [-fpermissive]

TandH(int pin, long interval, DHT_nonblocking &sensorLib)

^~~~~

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino:87:20: note: ‘DHT_nonblocking& TandH::_sensorLib’ should be initialized

DHT_nonblocking &_sensorLib;

^~~~~~~~~~

PingWithLED:94:17: error: use of deleted function ‘DHT_nonblocking& DHT_nonblocking::operator=(const DHT_nonblocking&)’

_sensorLib = sensorLib

^~~~~~~~~

In file included from D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino:32:0:

D:\David\MyDocuments\Arduino\libraries\DHT/dht_nonblocking.h:42:7: note: ‘DHT_nonblocking& DHT_nonblocking::operator=(const DHT_nonblocking&)’ is implicitly deleted because the default definition would be ill-formed:

class DHT_nonblocking

^~~~~~~~~~~~~~~

D:\David\MyDocuments\Arduino\libraries\DHT/dht_nonblocking.h:42:7: error: non-static const member ‘const uint8_t DHT_nonblocking::_pin’, can’t use default assignment operator

D:\David\MyDocuments\Arduino\libraries\DHT/dht_nonblocking.h:42:7: error: non-static const member ‘const uint8_t DHT_nonblocking::_type’, can’t use default assignment operator

D:\David\MyDocuments\Arduino\libraries\DHT/dht_nonblocking.h:42:7: error: non-static const member ‘const uint8_t DHT_nonblocking::_bit’, can’t use default assignment operator

D:\David\MyDocuments\Arduino\libraries\DHT/dht_nonblocking.h:42:7: error: non-static const member ‘const uint32_t DHT_nonblocking::_maxcycles’, can’t use default assignment operator

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino: In member function ‘void TandH::Update()’:

PingWithLED:112:9: error: ‘sensorLib’ was not declared in this scope

if( sensorLib.measure( temperature, humidity ) == true )

^~~~~~~~~

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino:112:9: note: suggested alternative: ‘_sensorLib’

if( sensorLib.measure( temperature, humidity ) == true )

^~~~~~~~~

_sensorLib

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino: At global scope:

PingWithLED:134:51: error: ISO C++ forbids declaration of ‘UtraPing’ with no type [-fpermissive]

UtraPing(int trigPin, int echoPin, long interval )

^

PingWithLED:142:14: error: expected ‘;’ at end of member declaration

void Update()

^

PingWithLED:148:2: error: expected unqualified-id before ‘if’

if (currentMillis - previousMillis > _interval)

^~

PingWithLED:193:22: error: expected ‘)’ before ‘,’ token

TandH (DHT_SENSOR_PIN, 3000, dht_sensor);

^

PingWithLED:193:24: error: expected unqualified-id before numeric constant

TandH (DHT_SENSOR_PIN, 3000, dht_sensor);

^~~~

PingWithLED:194:18: error: expected ‘)’ before ‘,’ token

UltraPing(pingPin, echoPin, 1500);

^

PingWithLED:194:20: error: conflicting declaration ‘UltraPing echoPin’

UltraPing(pingPin, echoPin, 1500);

^~~~~~~

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino:30:11: note: previous declaration as ‘const int echoPin’

const int echoPin = A7;

^~~~~~~

PingWithLED:194:29: error: expected unqualified-id before numeric constant

UltraPing(pingPin, echoPin, 1500);

^~~~

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino: In function ‘void setup()’:

PingWithLED:199:3: error: ‘Tandh’ was not declared in this scope

Tandh.startDHT;

^~~~~

D:\David\MyDocuments\Dave’s Stuff\Saunacontroller\Arduino\PingWithLED\PingWithLED.ino:199:3: note: suggested alternative: ‘TandH’

Tandh.startDHT;

^~~~~

TandH

Using library DHT at version 1.0 in folder: D:\David\MyDocuments\Arduino\libraries\DHT
exit status 1
uninitialized reference member in ‘class DHT_nonblocking&’ [-fpermissive]

@dduehren, since you have 34 posts in the forums already, it difficult for me to understand how you missed this post: Read this before posting a programming question .... Pay particular attention to Item #6 which explains how to properly post code using CODE TAGS.

I do try things, read as much on the web as I can and still get stuck. That’s why I post things here, because, despite all of it, that’s where I am. I tried to copy several examples I found here and elsewhere. And I could have posted the entire sketch but thought that wasteful. I did provide some of the compiler output but couldn’t post all of it because it was too big. I have attached both the entire but incomplete sketch - I’m testing how to pass a library instance to a class - and the full compiler output below.

It’s hard to understand a resource like this Standard C++ when I don’t know how to express the problem in the terms of the resource. I tried to learn from this example but had problems: https://forum.arduino.cc/index.php?topic=352813.0 I looked at callbacks, and passing function pointers, etc but I haven’t figured out the particulars and was hoping for some expert guidance. I also figured the problem was in the code I posted and now I’ve attached the whole sketch, even though the loop code isn’t written yet. Maybe I’m being lazy and need to take a day or two to learn how to do this, but I thought I’d ask.

At the highest level, what I’m trying to do is to wrap the DHT_nonblocking library functionality (DHT is a Temp and Humidity Library that uses a state machine). I can’t seem to start the state machine inside my class, which is the first option I tried, perhaps incorrectly. Ideally I’d like to wrap up everything about the temp sensor in my class and have it start the state machine, etc. Failing that, I tried to start it externally, and somehow pass it to the class. I guess another option is to somehow do a callback to the library. Obviously some of what I’m looking for isn’t just the particulars of the code, but what is the best approach to use and then how to do it. This is a general them that I expect to do for other functionality that exist in stand alone sketches. In the complete code, you’ll see I want to do something similar for a distance sensor, which I may ultimately move to a non-blocking approach.

So I hope you can help.

Thanks

Thanks,

CompilerOutput.txt (15.9 KB)

PingWithLED.ino (6.07 KB)

And I will use code tags in the future. I'm sorry for the sloppiness. In my latest experiment, I tried to start the DHT state machine inside the Update method - to solve scope issues. Here's the relevant code

class TandH
  {
	private:
	int sensorPin;		//the pin the sensor is attached to
	long _interval;		//interval between temperature readings
	//DHT_nonblocking dht_sensor(pin, DHT_SENSOR_TYPE );
	int _type;  //sensor type
  
	public:
	TandH(int pin, long interval, int type)
	{
		sensorPin = pin;
		_interval = interval;
		_type = type;
	}

	void Update()
	{
	float temperature;
	float humidity;
  static unsigned long measurement_timestamp = millis( );
  DHT_nonblocking dht_sensor(sensorPin, _type );
     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds. */
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
	}
  }
	}
  };

When I do this, the compiler complains:
no matching function for call to 'DHT_nonblocking::measure(float&, float&)'
as if it doesn't know about the library. My previous questions about the best way to do this remain. Passing arguments around complicates the use of the library.

I don’t have that library installed. But, if you want to have a class object (whose constructor takes parameters) as a member of another class, then you have to use an Initializer List:

#include <dht_nonblocking.h>

class TandH {
  public:
    TandH(uint8_t pin, uint32_t interval, uint8_t type) : sensor(pin, type) {
      _interval = interval;
    }

  private:
    DHT_nonblocking sensor;
    uint32_t _interval;

};

TandH theSensor(DHT_SENSOR_PIN, 3000, dht_sensor);

void setup() {
}

void loop() {
}

Is this what you mean? If so, I get the following error: class ‘TandH’ does not have any field named ‘sensor’

/*
  Ping))) Sensor
  This sketch performs three functions.  It reads an ultrasonic range finder, read temperature and humidity and blinks an LED
  Two sketches and the LED function have been combined into a single sketch.  And delay based timing has been changed to 
  millis based time sharing.  The timinig is used to determine how often the readings are done and the LED blinked.
  


static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11


class TandH
  {
	private:
	uint8_t sensorPin;	//the pin the sensor is attached to
	uint32_t _interval;		//interval between temperature readings
	DHT_nonblocking sensor;
	uint8_t _type;  //sensor type
  
	public:
	TandH(uint8_t pin, uint32_t interval, uint8_t type) : sensor(pin, type)
	{
		sensorPin = pin;
		_interval = interval;
		_type = type;
 
	}

	void Update()
	{
	float temperature;
	float humidity;
  static unsigned long measurement_timestamp = millis( );

     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds. */
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
    if( sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
	}
  }
	}
  };
  
DHT_nonblocking dht_sensor(sensorPin, _type );

TandH theSensor1(DHT_SENSOR_PIN, 3000, DHT_SENSOR_TYPE, dht_sensor);

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {


}

Why is half your code commented out?

Why are you defining a global DHT_nonblocking when you said that you wanted it inside the TandH class?

Compare the the skeletal code I posted.

Sorry my mistake, I edited out comments and didn’t close it properly. It appears to me that there are two choices. Does the dht_sensor get instantiated inside TandH or outside of it? If it’s inside of it, where does that happen? When I try it inside the Update, it doesn’t seem to know about the functions inside of it, which I don’t understand. If it’s done outside of it, then I need to pass a reference to it to TandH.

And here’s the code again with proper commenting.

/*
  Ping))) Sensor
  This sketch performs three functions.  It reads an ultrasonic range finder, read temperature and humidity and blinks an LED
  Two sketches and the LED function have been combined into a single sketch.  And delay based timing has been changed to 
  millis based time sharing.  The timinig is used to determine how often the readings are done and the LED blinked.

*/


static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11


class TandH
  {
	private:
	uint8_t sensorPin;	//the pin the sensor is attached to
	uint32_t _interval;		//interval between temperature readings
	DHT_nonblocking sensor;
	uint8_t _type;  //sensor type
  
	public:
	TandH(uint8_t pin, uint32_t interval, uint8_t type) : sensor(pin, type)
	{
		sensorPin = pin;
		_interval = interval;
		_type = type;
 
	}

	void Update()
	{
	float temperature;
	float humidity;
  static unsigned long measurement_timestamp = millis( );

     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds. */
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
    if( sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
	}
  }
	}
  };
  
DHT_nonblocking dht_sensor(sensorPin, _type );

TandH theSensor1(DHT_SENSOR_PIN, 3000, DHT_SENSOR_TYPE, dht_sensor);

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {


}

Is this the library? https://github.com/olewolf/DHT_nonblocking

If so, the measurement function takes pointers. See the example that comes with the library.

This is an expansion of how you include an object within your custom class:

#include <dht_nonblocking.h>

#define DHT_SENSOR_PIN  A6
#define DHT_SENSOR_TYPE DHT_TYPE_11

class TandH {
  public:
    TandH(uint8_t pin, uint32_t interval, uint8_t type) : sensor(pin, type) {
      _interval = interval;
    }

    bool meas(float *tempPtr, float *humidPtr) {
      return sensor.measure(tempPtr, humidPtr);
    }

  private:
    DHT_nonblocking sensor;
    uint32_t _interval;

};

TandH theSensor(DHT_SENSOR_PIN, 3000, DHT_SENSOR_TYPE);

void setup() {
  float t, h;

  if (theSensor.meas(&t, &t)) {
    // do stuff with temp and humidity
  }
}

void loop() {
}

Yes this is the library and the example code is what I started with. I am trying to convert the example code into a class so that I can easily mix it with other sensors, etc. I don’t understand the comment about the pointer. In your example, you moved the test (the if statement) out of the class, which defeats the purpose of putting it in the class in the first place. Maybe that’s my mistake since it already has a timer function. But then I have that mess in the main loop. I’d like to keep it clean and just call Tanh.Update() in the main loop. I’m not sure why you put in the setup section.

I appreciate your help.

The code I posted wasn’t meant to implement your project. It simply illustrated how to include a class object as a member of another class, how to invoke the constructor of that contained class using an initializer list (as I said in Reply #4), and how to access methods of the contained class from within the containing class. That is, after all, the subject line of your post.

It’s up to you to use those techniques in implementing your project.

I certainly appreciate the help, I'm still trying to figure out how to use it. Some of this is certainly due to my ignorance. I just got the rest of the sketch to work, for example, but only after realizing that the dependent functions of the UltraPing class that were private, had to be in the private part of the class.

One question I have for you is whether I need to instantiate the DHT_nonblocking sensor outside of the class or should I do it from within the class using either a .start function, or otherwise keeping track of the fact that it's already been instantiated. If it's inside the case, then do I need your initializer? Why can't I just start it from within the container class if the arguments for it are given to the container class?

I will continue to ponder and experiment with what you have written.

This is what I have so far, but the compiler complains:

no matching function for call to 'DHT_nonblocking::measure(float&, float&)
I know the initializer does something, because when I take it out, it complains at that place in the code.
Is the instantiation line OK?

/*
  Ping))) Sensor
  This sketch performs three functions.  It reads an ultrasonic range finder, read temperature and humidity and blinks an LED
  Two sketches and the LED function have been combined into a single sketch.  And delay based timing has been changed to 
  millis based time sharing.  The timing is used to determine how often the readings are done and the LED blinked.
*/


static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11


class TandH
  {
	private:
	uint8_t _pin;	//the pin the sensor is attached to
	uint32_t _interval;		//interval between temperature readings
	DHT_nonblocking sensor;
	uint8_t _type;  //sensor type
  
	public:
	TandH(uint8_t pin, uint32_t interval, uint8_t type) : sensor(pin, type)
	{
		_interval = interval;
	}
 
	void Update()
	{
	float temperature;
	float humidity;
  static unsigned long measurement_timestamp = millis( );

     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds. */
  
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
    if( sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
	}
  }
	}
  };
  
  
//DHT_nonblocking dht_sensor(sensorPin, _type );
//Flasher led1(ledPin, 1500, 1500);
TandH theSensor1(DHT_SENSOR_PIN, 3000, DHT_SENSOR_TYPE);
//UltraPing dist1(pingPin, echoPin, 1500);

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {
led1.Update();
dist1.Update();

}

Another experiment following the technique of https://forum.arduino.cc/index.php?topic=352813.0
produces similar result. I’m stumped. Next I’ll try making a separate .h and .cpp file as in the other forum.

theSensor1(dht_sensor);

no matching function for call to ‘DHT_nonblocking::measure(float&, float&)’

/*
  Ping))) Sensor
  This sketch performs three functions.  It reads an ultrasonic range finder, read temperature and humidity and blinks an LED
  Two sketches and the LED function have been combined into a single sketch.  And delay based timing has been changed to 
  millis based time sharing.  The timinig is used to determine how often the readings are done and the LED blinked.
*/


static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11


class TandH
  {
	private:

	uint32_t _interval;		//interval between temperature readings
  
	public:

    TandH(uint32_t interval)
	{
		_interval = interval;
	}
 
	void Update(DHT_nonblocking &sensor)
	{
	float temperature;
	float humidity;
  static unsigned long measurement_timestamp = millis( );

     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds. */
  
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
    if( sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
	}
  }
	}
  };
  

DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);

TandH theSensor1(3000);


void setup() {
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {

theSensor1(dht_sensor);

}

I tried to simplify the problem by simply making it pass the sensor object to a function. According to the other post https://forum.arduino.cc/index.php?topic=352813.0
the following should work, but the compiler complains.
Any suggestions?

static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);

void DHT_update(uint32_t interval, DHT_nonblocking *sensor)
  {
  float temperature;
  float humidity;
  static unsigned long measurement_timestamp = millis( );

     /*
  * Poll for temp & humidy measurement, keeping the state machine alive.  Returns
  * true if a measurement is available.
  *  Measure once every interval seconds.
  */
    if( millis( ) - measurement_timestamp > interval )   // interval was hardcoded to 3000ul 
  {
    if( sensor.measure( temperature, humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
  }
  }
  }
  
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
//  theSensor1.Start;
}

void loop() {
DHT(3000, &dht_sensor);
}

And here’s the compiler output

D:\David\MyDocuments\Dave's Stuff\Saunacontroller\Arduino\OnlyTandH\OnlyTandH.ino: In function 'void DHT_update(uint32_t, DHT_nonblocking*)':

OnlyTandH:23:16: error: request for member 'measure' in 'sensor', which is of pointer type 'DHT_nonblocking*' (maybe you meant to use '->' ?)

     if( sensor.measure( temperature, humidity ) == true )

                ^~~~~~~

D:\David\MyDocuments\Dave's Stuff\Saunacontroller\Arduino\OnlyTandH\OnlyTandH.ino: In function 'void loop()':

OnlyTandH:42:1: error: 'DHT' was not declared in this scope

 DHT(3000, &dht_sensor);

 ^~~

Using library DHT at version 1.0 in folder: D:\David\MyDocuments\Arduino\libraries\DHT 
exit status 1
request for member 'measure' in 'sensor', which is of pointer type 'DHT_nonblocking*' (maybe you meant to use '->' ?)

There are times when I’m an idiot. I have the function based approach working. There are several errors in the code above, the biggest one that’s been there all along is no using the dht library properly, trying to collapse the code. Here’s the working functional version. Now I’m trying to encapsulate it in a class that takes an interval, a pin, and a type of sensor and does the rest.

static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
uint32_t measurement_timestamp;


/*
 * Poll for a measurement, keeping the state machine alive.  Returns
 * true if a measurement is available.
 */

static bool measure_environment( float *temperature, float *humidity )
{
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      return( true );
    }
  return( false );
}

void DHT_Update(uint32_t interval)
  {
  float temperature;
  float humidity;
  
    if( millis( ) - measurement_timestamp > interval )   // interval was hardcoded to 3000ul 
  {
     /* Measure temperature and humidity.  If the functions returns
     true, then a measurement is available. */
  if( measure_environment( &temperature, &humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
  }
  }
  }
  
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  measurement_timestamp = millis();
}

void loop() {
DHT_Update(6000);
}

And here’s the class version. I’m not passing an object reference as I once thought I would do. This does demonstrate how to initialize an embedded object that takes arguments.

static const int DHT_SENSOR_PIN = A6;
const int pingPin = A5;
const int echoPin = A7;
const int ledPin = 1;  // test for configuration
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11

class TandH
{
  private:
  uint32_t measurement_timestamp;
  uint8_t _pin;
  uint8_t _type;
  uint32_t _interval;
  DHT_nonblocking dht_sensor;
/*
 * Poll for a measurement, keeping the state machine alive.  Returns
 * true if a measurement is available.
 */

bool measure_environment( float *temperature, float *humidity )
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      return( true );
    }
  return( false );
  }
  //Constructor - creates instance of TandH and initializes the sensor state machine
  //DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
 public:
  TandH(uint32_t interval, uint8_t pin, uint8_t type): dht_sensor(pin, type){
    _interval = interval;
 //   dht_sensor(pin, type); 
    measurement_timestamp = 0;
  }
  void Update()
  {
  float temperature;
  float humidity;
  
    if( millis( ) - measurement_timestamp > _interval )   // interval was hardcoded to 3000ul 
  {
     /* Measure temperature and humidity.  If the functions returns
     true, then a measurement is available. */
  if( measure_environment( &temperature, &humidity ) == true )
    {
    measurement_timestamp = millis( );
    Serial.print( "T = " );
    Serial.print( temperature, 1 );
    Serial.print( " deg. C, H = " );
    Serial.print( humidity, 1 );
    Serial.println( "%" );
  }
  }
  }
};

TandH dht1(6000, DHT_SENSOR_PIN, DHT_SENSOR_TYPE);  //Instantiate and initialize the dht sensor 
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {
dht1.Update();
}

I don't see what value your separate 'measure_environment()' function adds. You could just move what it does inside your 'Update()' function.

Also, your indenting could use some improvement. Hit Ctrl-t in the Arduino IDE to properly format your code for easier reading and debugging.