Hallo Forum,
ich verwende mal wieder einen Code der nicht gänzlich von mir stammt. Ich lasse alle 5 Sekunden Daten(Wetter) ausgeben. Nun möchte ich gerne diese Daten nur alle 15Minuten ausgegeben bekommen, doch leider gelingt mir das nicht so. Ich dachte das übernimmt der Timer1, wahrscheinlich nimmt er jedoch nur in diesem Zeitraum die Daten auf und gibt dennoch bei jedem Sensoroutput alle Daten aus-oder irre ich mich da?
#include <TimerOne.h>
//PIN-Belegung
#define PIN_ANEMOMETER 2
#define PIN_RAIN 3
#define PIN_VANE 0
volatile int numRevsAnemometer = 0;
volatile int numClicksRain = 0;
volatile float WindSpeed = 0;
volatile float Percipitation = 0;
volatile int WindDir = 0;
float h = 0;
float t = 0;
/*below counts the number of times we go to the
timer interrupt, allows for calcualtion
of multiples of the timer frequency*/
int visits_counter = 0;
/*The value below * 5 seconds = defines
timer frequency for rain calculation
e.g. top_times = 6 (* 5 = 30 seconds)*/
int top_times = 10;
#include "DHT.h"
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(115200);
dht.begin();
pinMode(PIN_ANEMOMETER, INPUT);
digitalWrite(PIN_ANEMOMETER, HIGH);
attachInterrupt(0, countAnemometer, FALLING);
pinMode(PIN_RAIN, INPUT);
digitalWrite(PIN_RAIN, HIGH);
attachInterrupt(1, countRain, FALLING);
//ISR associated with pin2, goes to countAnemometer function and is triggered when pin goes
//from HIGH to LOW
Timer1.initialize(90000000);
// initialize timer1, and set a 5 second period - we are sampling at 5 seconds intervals
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
}
void loop()
{
char buff[64];
int len = 64;
int i;
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
// Serial.println("Failed to read from DHT");
Serial.println("");
} else {
}
}
void countAnemometer() {
numRevsAnemometer++;
}//end countAnemometer()
void countRain() {
numClicksRain++;
}//end countRain
void callback()
{
/*the ISR for the timer interrupt, called every 5 seconds*/
//check how many times the switch was closed on this period? this value is on numRevsAnemometer
WindSpeed = (numRevsAnemometer/ 900) * 2.4; //2.4 K/h for one switch closure per second
numRevsAnemometer = 0;
/*rain caculation*/
if (visits_counter < top_times) visits_counter++;
else{
Percipitation = 0.28*(numClicksRain*60/900);
//0.2794 mm per contact closure; this step gives number of clicks per minute unit = mm per minute
numClicksRain = 0;
visits_counter = 0;
}
/*Get wind direction*/
WindDir = analogRead(PIN_VANE);
WindDir >>= 2;
Serial.println(WindSpeed);
Serial.println(WindDir);
Serial.println(Percipitation);
Serial.println(h);
Serial.println(t);
}
vielen Dank für eure unermüdliche Hilfe