Some refactoring
This commit is contained in:
parent
78317d6c4f
commit
1273bcae49
11 changed files with 182 additions and 234 deletions
|
|
@ -4,17 +4,18 @@
|
|||
#define ENABLE_DEBUG // comment out to disable debug
|
||||
|
||||
#define TIMER_MILLISECOND 60*1000 // poling in minutes
|
||||
#define INDICATOR_PIN 13 // diod
|
||||
|
||||
// POWER CONSUMPTION SENSOR
|
||||
#define POWERCON_ENABLED // comment out to disable sensor
|
||||
#define POWERCON_SENSOR SensorBH1750()
|
||||
#define POWERCON_PROTOCOL ProtocolOregon(118)
|
||||
#define POWERCON_PROTOCOL ProtocolOregon(11, 118)
|
||||
#define POWER_TIMER_MULTIPLIER 1
|
||||
|
||||
// TEMPERATURE SENSOR
|
||||
#define TEMPERATURE_ENABLED // comment out to disable sensor
|
||||
#define TEMPERATURE_SENSOR SensorDHT11(5)
|
||||
#define TEMPERATURE_PROTOCOL ProtocolOregon(100)
|
||||
#define TEMPERATURE_SENSOR SensorDHT11(10)
|
||||
#define TEMPERATURE_PROTOCOL ProtocolOregon(11, 100)
|
||||
#define TEMPERATURE_TIMER_MULTIPLIER 1
|
||||
|
||||
// LIGHT SENSOR
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#include "HalConfiguration.h"
|
||||
|
||||
// Utility functions
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEBUG(msg) \
|
||||
Serial.println(msg); \
|
||||
Serial.flush();
|
||||
|
|
@ -18,60 +22,81 @@
|
|||
#endif
|
||||
|
||||
|
||||
inline void pulse(short pin, short count)
|
||||
{
|
||||
while (--count >= 0)
|
||||
{
|
||||
digitalWrite(INDICATOR_PIN, HIGH);
|
||||
delay(150);
|
||||
digitalWrite(INDICATOR_PIN, LOW);
|
||||
if (count != 0) delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// INTERFACES
|
||||
|
||||
class Sensor
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
};
|
||||
|
||||
class SensorPowerConsumption : public Sensor
|
||||
{
|
||||
public:
|
||||
// returns number of pulses from power meter
|
||||
virtual unsigned int getConsumption() = 0;
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
|
||||
class SensorTemperature : public Sensor
|
||||
{
|
||||
public:
|
||||
virtual int getTemperature() = 0;
|
||||
virtual int getHumidity() = 0;
|
||||
};
|
||||
|
||||
class SensorLight : public Sensor
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual unsigned int getLuminosity() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual void send() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct PowerData
|
||||
{
|
||||
unsigned int consumption;
|
||||
};
|
||||
class SensorPowerConsumption : public Sensor
|
||||
{
|
||||
public:
|
||||
// returns number of pulses from power meter
|
||||
virtual void read(PowerData& data) = 0;
|
||||
};
|
||||
class ProtocolPowerConsumption : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setConsumption(unsigned int cons) = 0;
|
||||
virtual void send(const PowerData& data) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct TemperatureData
|
||||
{
|
||||
float temperature;
|
||||
short humidity;
|
||||
};
|
||||
class SensorTemperature : public Sensor
|
||||
{
|
||||
public:
|
||||
virtual void read(TemperatureData& data) = 0;
|
||||
};
|
||||
class ProtocolTemperature : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setTemperature(float temp) = 0;
|
||||
virtual void setHumidity(unsigned char humidity) = 0;
|
||||
virtual void send(const TemperatureData& data) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct LightData
|
||||
{
|
||||
unsigned int lumen;
|
||||
};
|
||||
class SensorLight : public Sensor
|
||||
{
|
||||
public:
|
||||
virtual void read(LightData& data) = 0;
|
||||
};
|
||||
class ProtocolLight : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setLuminosity(int lumen) = 0;
|
||||
virtual void send(const LightData& data) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // HALINTERFACES_H
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ A interrupt based sensor device that reads multiple sensors and transmits
|
|||
the data to a central location.
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "HalConfiguration.h"
|
||||
#include "HalInterfaces.h"
|
||||
|
|
@ -34,6 +33,7 @@ void setup()
|
|||
#ifdef ENABLE_DEBUG
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
pinMode(INDICATOR_PIN, OUTPUT);
|
||||
|
||||
// Setup Sensors and protocols
|
||||
#ifdef POWERCON_ENABLED
|
||||
|
|
@ -64,6 +64,8 @@ void setup()
|
|||
Interrupt::setCallback(timerInterruptFunc);
|
||||
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt
|
||||
|
||||
|
||||
pulse(INDICATOR_PIN, 3);
|
||||
DEBUG("Ready");
|
||||
}
|
||||
|
||||
|
|
@ -77,17 +79,17 @@ void timerInterruptFunc()
|
|||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(INDICATOR_PIN, HIGH);
|
||||
noInterrupts();
|
||||
|
||||
// Send power consumption
|
||||
#ifdef POWERCON_ENABLED
|
||||
if(timerMultiplier == POWER_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int consumption = powerSensor->getConsumption();
|
||||
DEBUGF("Read POWERCON_SENSOR= consumption:%d", consumption);
|
||||
powerSensor->reset();
|
||||
powerProtocol->setConsumption(consumption);
|
||||
powerProtocol->send();
|
||||
static PowerData powerData;
|
||||
powerSensor->read(powerData); // not needed, only here for future use
|
||||
DEBUGF("Read POWERCON_SENSOR= consumption:%d", powerData.consumption);
|
||||
powerProtocol->send(powerData);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -95,12 +97,10 @@ void loop()
|
|||
#ifdef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier == TEMPERATURE_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int temperature = tempSensor->getTemperature();
|
||||
unsigned int humidity = tempSensor->getHumidity();
|
||||
DEBUGF("Read TEMPERATURE_SENSOR= temperature:%d, humidity:%d", temperature, humidity);
|
||||
tempProtocol->setTemperature(temperature);
|
||||
tempProtocol->setHumidity(humidity);
|
||||
tempProtocol->send();
|
||||
static TemperatureData tempData;
|
||||
tempSensor->read(tempData);
|
||||
DEBUGF("Read TEMPERATURE_SENSOR= temperature:%d, humidity:%d", tempData.temperature, tempData.humidity);
|
||||
tempProtocol->send(tempData);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -108,14 +108,15 @@ void loop()
|
|||
#ifdef LIGHT_ENABLED
|
||||
if(timerMultiplier == LIGHT_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int lumen = lightSensor->getLuminosity();
|
||||
DEBUG("Read LIGHT_SENSOR= lumen:%d", lumen);
|
||||
lightProtocol->setLuminosity(lumen);
|
||||
lightProtocol->send();
|
||||
static LightData lightData;
|
||||
lightSensor->read(lightData);
|
||||
DEBUG("Read LIGHT_SENSOR= lumen:%d", lightData.lumen);
|
||||
lightProtocol->send(lightData);
|
||||
}
|
||||
#endif
|
||||
|
||||
interrupts();
|
||||
digitalWrite(INDICATOR_PIN, LOW);
|
||||
|
||||
DEBUG("Sleeping");
|
||||
Interrupt::sleep();
|
||||
|
|
|
|||
|
|
@ -1,35 +1,29 @@
|
|||
#include "ProtocolOregon.h"
|
||||
|
||||
#define RF_TX_PIN 10
|
||||
#define RF_DELAY 512
|
||||
#define RF_DELAY_LONG RF_DELAY*2
|
||||
#define RF_SEND_HIGH() digitalWrite(RF_TX_PIN, HIGH)
|
||||
#define RF_SEND_LOW() digitalWrite(RF_TX_PIN, LOW)
|
||||
#define RF_SEND_HIGH() digitalWrite(txPin, HIGH)
|
||||
#define RF_SEND_LOW() digitalWrite(txPin, LOW)
|
||||
|
||||
|
||||
void ProtocolOregon::setup()
|
||||
{
|
||||
pinMode(RF_TX_PIN, OUTPUT);
|
||||
pinMode(txPin, OUTPUT);
|
||||
RF_SEND_LOW();
|
||||
}
|
||||
|
||||
void ProtocolOregon::setTemperature(float temp)
|
||||
|
||||
void ProtocolOregon::send(const PowerData& data)
|
||||
{
|
||||
this->temperature = temp;
|
||||
}
|
||||
void ProtocolOregon::setHumidity(unsigned char humidity)
|
||||
{
|
||||
this->humidity = humidity;
|
||||
}
|
||||
void ProtocolOregon::setConsumption(unsigned int cons)
|
||||
{
|
||||
this->temperature = cons;
|
||||
this->humidity = 0;
|
||||
send(data.consumption, 0);
|
||||
}
|
||||
|
||||
void ProtocolOregon::send(const TemperatureData& data)
|
||||
{
|
||||
send(data.temperature, data.humidity);
|
||||
}
|
||||
|
||||
|
||||
void ProtocolOregon::send()
|
||||
void ProtocolOregon::send(float temperature, short humidity)
|
||||
{
|
||||
byte buffer[9];
|
||||
setType(buffer, 0x1A,0x2D); //temperature/humidity sensor (THGR2228N)
|
||||
|
|
|
|||
|
|
@ -8,18 +8,17 @@
|
|||
class ProtocolOregon : public ProtocolTemperature, public ProtocolPowerConsumption
|
||||
{
|
||||
public:
|
||||
ProtocolOregon(unsigned char address) : address(address){};
|
||||
ProtocolOregon(short pin, unsigned char address) : txPin(pin), address(address){};
|
||||
|
||||
virtual void setup();
|
||||
virtual void setTemperature(float temp);
|
||||
virtual void setHumidity(unsigned char humidity);
|
||||
virtual void setConsumption(unsigned int cons); //Power
|
||||
virtual void send();
|
||||
private:
|
||||
unsigned char address;
|
||||
float temperature;
|
||||
unsigned char humidity;
|
||||
virtual void send(const TemperatureData& data);
|
||||
virtual void send(const PowerData& data);
|
||||
|
||||
private:
|
||||
short txPin;
|
||||
unsigned char address;
|
||||
|
||||
void send(float temperature, short humidity);
|
||||
void setType(byte *data, byte b1, byte b2);
|
||||
void setChannel(byte *data, byte channel);
|
||||
void setId(byte *data, byte id);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,40 @@ based on Christopher Laws, March, 2013 code.
|
|||
#include <util/delay.h>
|
||||
|
||||
|
||||
#define BH1750_I2CADDR 0x23
|
||||
|
||||
// No active state
|
||||
#define BH1750_POWER_DOWN 0x00
|
||||
|
||||
// Waiting for measurement command
|
||||
#define BH1750_POWER_ON 0x01
|
||||
|
||||
// Reset data register value - not accepted in POWER_DOWN mode
|
||||
#define BH1750_RESET 0x07
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10
|
||||
|
||||
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE_2 0x11
|
||||
|
||||
// Start measurement at 4lx resolution. Measurement time is approx 16ms.
|
||||
#define BH1750_CONTINUOUS_LOW_RES_MODE 0x13
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_HIGH_RES_MODE 0x20
|
||||
|
||||
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_HIGH_RES_MODE_2 0x21
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_LOW_RES_MODE 0x23
|
||||
|
||||
|
||||
|
||||
void SensorBH1750::setup() {
|
||||
Wire.begin();
|
||||
configure(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
|
|
@ -30,69 +64,34 @@ void SensorBH1750::configure(uint8_t mode) {
|
|||
case BH1750_ONE_TIME_HIGH_RES_MODE_2:
|
||||
case BH1750_ONE_TIME_LOW_RES_MODE:
|
||||
// apply a valid mode change
|
||||
write8(mode);
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
Wire.write(mode);
|
||||
Wire.endTransmission();
|
||||
_delay_ms(10);
|
||||
break;
|
||||
default:
|
||||
// Invalid measurement mode
|
||||
#if BH1750_DEBUG == 1
|
||||
Serial.println("Invalid measurement mode");
|
||||
#endif
|
||||
DEBUG("Invalid measurement mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int SensorBH1750::getConsumption()
|
||||
{
|
||||
return pulses;
|
||||
}
|
||||
void SensorBH1750::reset()
|
||||
void SensorBH1750::read(PowerData& data)
|
||||
{
|
||||
data.consumption = pulses;
|
||||
pulses = 0;
|
||||
}
|
||||
|
||||
unsigned int SensorBH1750::getLuminosity(void) {
|
||||
void SensorBH1750::read(LightData& data) {
|
||||
uint16_t level;
|
||||
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
Wire.requestFrom(BH1750_I2CADDR, 2);
|
||||
#if (ARDUINO >= 100)
|
||||
level = Wire.read();
|
||||
level <<= 8;
|
||||
level |= Wire.read();
|
||||
#else
|
||||
level = Wire.receive();
|
||||
level <<= 8;
|
||||
level |= Wire.receive();
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
#if BH1750_DEBUG == 1
|
||||
Serial.print("Raw light level: ");
|
||||
Serial.println(level);
|
||||
#endif
|
||||
|
||||
level = level/1.2; // convert to lux
|
||||
|
||||
#if BH1750_DEBUG == 1
|
||||
Serial.print("Light level: ");
|
||||
Serial.println(level);
|
||||
#endif
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
|
||||
void SensorBH1750::write8(uint8_t d) {
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
#if (ARDUINO >= 100)
|
||||
Wire.write(d);
|
||||
#else
|
||||
Wire.send(d);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
data.lumen = level/1.2; // convert to lux
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,3 @@
|
|||
/*
|
||||
|
||||
This is a library for the BH1750FVI Digital Light Sensor
|
||||
breakout board.
|
||||
|
||||
The board uses I2C for communication. 2 pins are required to
|
||||
interface to the device.
|
||||
|
||||
Datasheet:
|
||||
http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-e.pdf
|
||||
|
||||
based on Christopher Laws, March, 2013 code.
|
||||
|
||||
*/
|
||||
#ifndef SensorBH1750_H
|
||||
#define SensorBH1750_H
|
||||
|
||||
|
|
@ -19,52 +5,16 @@ based on Christopher Laws, March, 2013 code.
|
|||
#include "HalInterfaces.h"
|
||||
|
||||
|
||||
#define BH1750_DEBUG 0
|
||||
|
||||
#define BH1750_I2CADDR 0x23
|
||||
|
||||
// No active state
|
||||
#define BH1750_POWER_DOWN 0x00
|
||||
|
||||
// Waiting for measurement command
|
||||
#define BH1750_POWER_ON 0x01
|
||||
|
||||
// Reset data register value - not accepted in POWER_DOWN mode
|
||||
#define BH1750_RESET 0x07
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10
|
||||
|
||||
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE_2 0x11
|
||||
|
||||
// Start measurement at 4lx resolution. Measurement time is approx 16ms.
|
||||
#define BH1750_CONTINUOUS_LOW_RES_MODE 0x13
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_HIGH_RES_MODE 0x20
|
||||
|
||||
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_HIGH_RES_MODE_2 0x21
|
||||
|
||||
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
// Device is automatically set to Power Down after measurement.
|
||||
#define BH1750_ONE_TIME_LOW_RES_MODE 0x23
|
||||
|
||||
|
||||
class SensorBH1750 : public SensorPowerConsumption, public SensorLight{
|
||||
public:
|
||||
virtual void setup();
|
||||
virtual unsigned int getLuminosity();
|
||||
virtual unsigned int getConsumption();
|
||||
virtual void reset();
|
||||
virtual void read(PowerData& data);
|
||||
virtual void read(LightData& data);
|
||||
|
||||
void configure(uint8_t mode);
|
||||
private:
|
||||
unsigned int pulses;
|
||||
void write8(uint8_t data);
|
||||
|
||||
void configure(uint8_t mode);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,40 +13,22 @@
|
|||
// + added comments
|
||||
// + removed all non DHT11 specific code
|
||||
// + added references
|
||||
// Refactored by Ziver Koc
|
||||
//
|
||||
|
||||
#include "SensorDHT11.h"
|
||||
|
||||
|
||||
SensorDHT11::SensorDHT11(int pin)
|
||||
{
|
||||
this->pin = pin;
|
||||
}
|
||||
|
||||
void SensorDHT11::setup(){}
|
||||
int SensorDHT11::getTemperature()
|
||||
{
|
||||
return temperature;
|
||||
}
|
||||
int SensorDHT11::getHumidity()
|
||||
{
|
||||
return humidity;
|
||||
}
|
||||
|
||||
// returnvalues:
|
||||
// 0 : OK
|
||||
// -1 : checksum error
|
||||
// -2 : timeout
|
||||
int SensorDHT11::read()
|
||||
|
||||
void SensorDHT11::read(TemperatureData& data)
|
||||
{
|
||||
// BUFFER TO RECEIVE
|
||||
uint8_t bits[5];
|
||||
uint8_t bits[5] = {0};
|
||||
uint8_t cnt = 7;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// EMPTY BUFFER
|
||||
for (int i=0; i< 5; i++) bits[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
|
|
@ -58,24 +40,40 @@ int SensorDHT11::read()
|
|||
// ACKNOWLEDGE or TIMEOUT
|
||||
unsigned int loopCnt = 10000;
|
||||
while(digitalRead(pin) == LOW)
|
||||
if (loopCnt-- == 0) return -2;
|
||||
if (loopCnt-- == 0)
|
||||
{
|
||||
DEBUG("DHT11 timeout");
|
||||
return;;
|
||||
}
|
||||
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
if (loopCnt-- == 0) return -2;
|
||||
if (loopCnt-- == 0)
|
||||
{
|
||||
DEBUG("DHT11 timeout");
|
||||
return;;
|
||||
}
|
||||
|
||||
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
|
||||
for (int i=0; i<40; i++)
|
||||
{
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == LOW)
|
||||
if (loopCnt-- == 0) return -2;
|
||||
if (loopCnt-- == 0)
|
||||
{
|
||||
DEBUG("DHT11 timeout");
|
||||
return;;
|
||||
}
|
||||
|
||||
unsigned long t = micros();
|
||||
|
||||
loopCnt = 10000;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
if (loopCnt-- == 0) return -2;
|
||||
if (loopCnt-- == 0)
|
||||
{
|
||||
DEBUG("DHT11 timeout");
|
||||
return;;
|
||||
}
|
||||
|
||||
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
|
||||
if (cnt == 0) // next byte?
|
||||
|
|
@ -86,14 +84,14 @@ int SensorDHT11::read()
|
|||
else cnt--;
|
||||
}
|
||||
|
||||
// WRITE TO RIGHT VARS
|
||||
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
|
||||
humidity = bits[0];
|
||||
temperature = bits[2];
|
||||
|
||||
uint8_t sum = bits[0] + bits[2];
|
||||
if (bits[4] != sum)
|
||||
DEBUG("DHT11 checksum error");
|
||||
|
||||
if (bits[4] != sum) return -1;
|
||||
return 0;
|
||||
// WRITE TO RIGHT VARS
|
||||
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
|
||||
data.temperature = bits[2];
|
||||
data.humidity = bits[0];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,19 @@
|
|||
//
|
||||
// FILE: dht11.h
|
||||
// VERSION: 0.3.2
|
||||
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
|
||||
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
|
||||
//
|
||||
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
|
||||
//
|
||||
// URL: http://arduino.cc/playground/Main/DHT11Lib
|
||||
//
|
||||
// HISTORY:
|
||||
// George Hadjikyriacou - Original version
|
||||
// see dht.cpp file
|
||||
// *** Terry King: Changed include Arduino.h for 1.0x
|
||||
#ifndef dht11_h
|
||||
#define dht11_h
|
||||
#ifndef SensorDHT11_h
|
||||
#define SensorDHT11_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "HalInterfaces.h"
|
||||
|
||||
#define DHT11LIB_VERSION "0.3.2"
|
||||
|
||||
class SensorDHT11 : public SensorTemperature
|
||||
{
|
||||
public:
|
||||
SensorDHT11(int pin);
|
||||
SensorDHT11(short pin) : pin(pin) {};
|
||||
|
||||
virtual void setup();
|
||||
virtual int getTemperature();
|
||||
virtual int getHumidity();
|
||||
int read();
|
||||
virtual void read(TemperatureData& data);
|
||||
|
||||
private:
|
||||
unsigned int pin;
|
||||
float temperature;
|
||||
unsigned char humidity;
|
||||
short pin;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ void SensorPhotocell::setup()
|
|||
Interrupt::setupPinInterrupt(PC2); //PC3
|
||||
}
|
||||
|
||||
unsigned int SensorPhotocell::getConsumption()
|
||||
void SensorPhotocell::read(PowerData& data)
|
||||
{
|
||||
return pulse;
|
||||
data.consumption = pulse;
|
||||
}
|
||||
|
||||
void SensorPhotocell::reset()
|
||||
|
|
|
|||
|
|
@ -9,11 +9,10 @@ class SensorPhotocell : public SensorPowerConsumption
|
|||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
virtual unsigned int getConsumption();
|
||||
virtual void read(PowerData& data);
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
Interrupt* interrupt;
|
||||
unsigned int pulse;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue