150 lines
2.9 KiB
C++
150 lines
2.9 KiB
C++
/*
|
|
|
|
#include <Arduino.h>
|
|
|
|
#define AnalogPIN 14
|
|
#define DigitalPIN
|
|
|
|
class WERTE
|
|
{
|
|
public:
|
|
int ANL = 0;
|
|
|
|
unsigned long int NewTime = 0;
|
|
unsigned long int NTBackup = 0;
|
|
unsigned long int OldTime = 0;
|
|
unsigned long int Delta = 0;
|
|
|
|
double IN_STUNDEN = 0;
|
|
double WATT = 0;
|
|
}Mess;
|
|
|
|
class VARIABLEN
|
|
{
|
|
public:
|
|
int COUNT = 0;
|
|
int TIMESTAMP = 0;
|
|
int CAST = 0; // Für delta -> Watt //
|
|
double PLACE = 0;
|
|
|
|
bool FLAG = false;
|
|
bool SIGNAL = false;
|
|
}VAR;
|
|
|
|
// Funktionen_prototypen: //
|
|
void nochimmer();
|
|
void check();
|
|
void calc();
|
|
|
|
void setup()
|
|
{
|
|
void IRAM_ATTR onTimer();
|
|
|
|
hw_timer_t *My_timer = 0;
|
|
My_timer = timerBegin(0, 80, true);
|
|
timerAttachInterrupt(My_timer, &onTimer, true);
|
|
timerAlarmWrite(My_timer, 5000, true);
|
|
timerAlarmEnable(My_timer);
|
|
|
|
Serial.begin(115200);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
//Serial.println(Mess.ANL);
|
|
if(Mess.ANL >= 450)
|
|
{
|
|
check(); // Zeit New & Old richtig einlesen && Aufrufen von NOCHIMMER() //
|
|
}
|
|
|
|
}
|
|
|
|
void IRAM_ATTR onTimer()
|
|
{
|
|
Mess.ANL = analogRead(AnalogPIN);
|
|
}
|
|
|
|
void nochimmer()
|
|
{
|
|
VAR.COUNT = 0;
|
|
|
|
while(1)
|
|
{
|
|
|
|
if(VAR.COUNT > 15)
|
|
{
|
|
break;
|
|
}
|
|
|
|
VAR.TIMESTAMP = millis() + 6;
|
|
while((VAR.TIMESTAMP - millis()) > 0){millis();};
|
|
if(Mess.ANL < 430)
|
|
{
|
|
VAR.COUNT++;
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
Serial.printf("\n\n\n\nSUCCESS\n\n\n\n");
|
|
|
|
calc(); // Ausrechnen von Delta, Watt und eventueller Output //
|
|
}
|
|
|
|
void check()
|
|
{
|
|
Mess.NTBackup = Mess.NewTime;
|
|
Mess.NewTime = millis();
|
|
|
|
|
|
VAR.COUNT = 0;
|
|
VAR.FLAG = false;
|
|
|
|
while(VAR.COUNT != 4 && VAR.FLAG != true)
|
|
{
|
|
VAR.TIMESTAMP = millis() + 6;
|
|
while((VAR.TIMESTAMP - millis()) > 0){millis();}; // Warte 5ms auf neuen Wert //
|
|
// Serial.printf("ANL: %d\n", Mess.ANL);
|
|
if(Mess.ANL >= 450)
|
|
{
|
|
VAR.COUNT++;
|
|
}
|
|
else
|
|
{
|
|
VAR.FLAG = true;
|
|
}
|
|
}
|
|
|
|
Serial.println("-----------------------------------");
|
|
|
|
if(VAR.FLAG == true)
|
|
{
|
|
Mess.NewTime = Mess.NTBackup;
|
|
// Serial.println("...");
|
|
}
|
|
else
|
|
{
|
|
Mess.OldTime = Mess.NTBackup;
|
|
// Serial.printf("TIME: %d\n", Mess.NewTime);
|
|
nochimmer(); // Überprüfen, ob statement noch immer zutrifft //
|
|
}
|
|
}
|
|
|
|
void calc()
|
|
{
|
|
if(Mess.OldTime != 0)
|
|
{
|
|
Mess.Delta = Mess.NewTime - Mess.OldTime;
|
|
|
|
VAR.CAST = Mess.Delta;
|
|
VAR.PLACE = VAR.CAST / 1000;
|
|
Mess.IN_STUNDEN = 60 * (60 / VAR.PLACE);
|
|
Mess.WATT = (1000 * Mess.IN_STUNDEN) / 960;
|
|
|
|
// OUTPUT //
|
|
Serial.printf("Momentanverbauch: DELTA: %d WATT: %0.2f\n", Mess.Delta, Mess.WATT);
|
|
}
|
|
}
|
|
|
|
*/ |