我正在 arduino 中创建自己的库来控制泵。该库非常简单:
泵.h
#ifndef Pump_h
#define Pump_h
#include "Arduino.h"
class Pump
{
public:
Pump(int pin);
void Open(void);
void Close(void);
boolean IsOpen(void);
private:
int _pin;
bool _status;
};
#endif
泵.cpp
#include "Arduino.h"
#include "Pump.h"
Pump::Pump(int pin)
{
pinMode(pin, OUTPUT);
digitalWrite(pin,HIGH);
_pin = pin;
_status = false;
}
void Pump::Open(void)
{
digitalWrite(_pin, LOW);
_status = true;
}
void Pump::Close(void)
{
digitalWrite(_pin, HIGH);
_status = false;
}
boolean Pump::IsOpen(void)
{
return _status;
}
环形()
#include <Pump.h>
#define PUMP1 Pump(9)
void loop() {
BridgeClient client = server.accept(); // Get clients coming from server
if (client) { // There is a new request from client?
Console.println("Client connected");
process(client); // Process request
client.stop(); // Close connection and free resources.
}
Console.println(PUMP1.IsOpen());
delay(50); // Poll every 50ms
}
问题是当我在 Arduino 的 loop() 函数中调用 IsOpen 函数时,我总是得到错误,并且 Pump 立即关闭。我的代码有什么问题?