问题描述:

I'm working with an Arduino UNO in my first attempt to use the OO in Wiring.

I just have a question which I need help with;

I'm using a class for a DHT22 sensor from freetronics, found here http://www.freetronics.com/products/humidity-and-temperature-sensor-module.

Say I have a class i made called Sensor, where DHT is the library for the freetronics sensor, and DHT dht(5, DHT22) Initialises the sensor on pin 5 (which could be any digital pin):

#include "arduino.h"

#include <DHT.h>

DHT dht(1, DHT22);

class Sensor{

public:

Sensor(int);

};

Sensor::Sensor(int pin){

DHT dht(pin, DHT22);

}

This is the only way to initialise DHT that does not throw compile errors, even though it is re-initialising that variiable, but if I try to put DHT dht() as a private variable it doesn't work.

But my question is, if i create two of these Objects, will they be using the same object reference dht? Or is the initialising code for dht in the correct area to act only inside the instances' scope?

Please tell me if this is confusing, and I appreciate any help in advance, Thank You :)

相关阅读:
Top