Class 使用Arduino初始化,使用SoftwareSerial作为变量

Class 使用Arduino初始化,使用SoftwareSerial作为变量,class,arduino,Class,Arduino,尝试在Arduino 1.0中使用类并将SoftwareSerial设置为变量,但没有成功 class SensorGPS: public Thread { private: SoftwareSerial* serialGPS; // RX, TX public: SensorGPS() { serialGPS = new SoftwareSerial(10,11); serialGPS.begin

尝试在Arduino 1.0中使用类并将SoftwareSerial设置为变量,但没有成功

class SensorGPS: public Thread
{
  private: 
        SoftwareSerial* serialGPS; // RX, TX
  public:
        SensorGPS()
        {
          serialGPS = new SoftwareSerial(10,11);
          serialGPS.begin(4800);
        }
}
serialGPS.begin返回错误

arduino_sketch.ino: In constructor 'SensorGPS::SensorGPS()':
arduino_sketch:31: error: request for member 'begin' in '((SensorGPS*)this)->SensorGPS::serialGPS', which is of non-class type 'SoftwareSerial*'
arduino_sketch.ino: In member function 'virtual void SensorGPS::run()':
arduino_sketch:37: error: request for member 'read' in '((SensorGPS*)this)->SensorGPS::serialGPS', which is of non-class type 'SoftwareSerial*'
arduino_sketch:44: error: request for member 'write' in '((SensorGPS*)this)->SensorGPS::serialGPS', which is of non-class type 'SoftwareSerial*'
如果在设置变量时删除*

SoftwareSerial serialGPS(10,11); // RX, TX
arduino_sketch:21: error: expected identifier before numeric constant
arduino_sketch:21: error: expected ',' or '...' before numeric constant
变量的结果错误

SoftwareSerial serialGPS(10,11); // RX, TX
arduino_sketch:21: error: expected identifier before numeric constant
arduino_sketch:21: error: expected ',' or '...' before numeric constant

这个问题适用于所有需要值作为初始值的类。Dht11模块的另一示例(1);生成相同的错误。

注意示例Dht11库的相同问题。所以我更改了构造函数(库)

示例Dht11打开Dht11.h 来自

Dht11(uint8_t newPin) : humidity(-1), temperature(-1), pin(newPin) { }
To(添加了函数setPin)

现在在Arduino草图中,我可以在使用前设置销。大多数库都可以使用此解决方案

class SensorTemperatureHumidity: public Thread
{
  private: 
        static const int Pin = 3;
        Dht11 module;
  public:
        SensorTemperatureHumidity() {
          module.setPin(Pin); // Set my pin usage
        }
}