70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
#include <Arduino.h>
|
|
#include <TempSensor.h>
|
|
#include <HumiditySensor.h>
|
|
#include <TinyPower.h>
|
|
#include <DHT.h>
|
|
|
|
#define SEND_INTERVAL (int)(5*60/8)
|
|
#define SEND_VCC_INTERVAL (int)(60*60/8)
|
|
|
|
// Pins
|
|
#define TEMP_POSITIVE PIN_B3
|
|
#define SENDER PIN_B2
|
|
#define DHT_PIN PIN_B4
|
|
|
|
struct DhtValues {
|
|
int temperature;
|
|
int humidity;
|
|
};
|
|
DhtValues readTemp();
|
|
|
|
TempSensor tempSensor = TempSensor(TEMP_SENSOR, SENDER);
|
|
HumiditySensor humidSensor = HumiditySensor(TEMP_SENSOR, SENDER);
|
|
DHT dht(DHT_PIN, DHT22);
|
|
|
|
volatile int counter = 0;
|
|
|
|
void setup() {
|
|
|
|
tempSensor.setup();
|
|
pinMode(TEMP_POSITIVE, OUTPUT);
|
|
digitalWrite(TEMP_POSITIVE, HIGH);
|
|
dht.begin();
|
|
|
|
TinyPower::setup();
|
|
TinyPower::enableWdt(WDTO_8S);
|
|
}
|
|
|
|
void loop() {
|
|
if (counter % SEND_VCC_INTERVAL == 0) {
|
|
DhtValues values = readTemp();
|
|
tempSensor.sendTempAndVoltage(values.temperature);
|
|
delay(100);
|
|
humidSensor.sendHumidity(values.humidity);
|
|
counter = 0;
|
|
} else if (counter % SEND_INTERVAL == 0) {
|
|
DhtValues values = readTemp();
|
|
tempSensor.sendTemp(values.temperature);
|
|
delay(100);
|
|
humidSensor.sendHumidity(values.humidity);
|
|
}
|
|
TinyPower::sleep();
|
|
}
|
|
|
|
DhtValues readTemp() {
|
|
digitalWrite(TEMP_POSITIVE, HIGH);
|
|
delay(10);
|
|
DhtValues dhtValues;
|
|
dhtValues.temperature = roundf(dht.readTemperature() * 10);
|
|
dhtValues.humidity = roundf(dht.readHumidity() * 10);
|
|
digitalWrite(TEMP_POSITIVE, LOW);
|
|
return dhtValues;
|
|
}
|
|
|
|
ISR(PCINT0_vect) {
|
|
}
|
|
|
|
ISR(WDT_vect) {
|
|
counter++;
|
|
}
|