commit 882b793cd2b7f86473e675ff3fdfb3021aa55acc Author: lukas-heiligenbrunner Date: Fri Apr 10 23:00:28 2020 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b88e78d --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,44 @@ +// +// Created by lukas on 10.04.20. +// +#include "Arduino.h" + +#define MINVOLTAGE 2.5 +#define OHM 55 + +void setup() { + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + pinMode(8, OUTPUT); + pinMode(A0, INPUT); + + digitalWrite(8, LOW); +} + +int i = 0; +double all = 0; + +void loop() { + Serial.println(); + double voltage = (float) (analogRead(A0)) / 1024 * 5; + if (voltage > MINVOLTAGE) { + digitalWrite(8, HIGH); + double current = voltage / OHM; + double watt = current * voltage; + double amphours = watt / 360; + all += amphours; + Serial.print(all * 1000, 5); + Serial.print("mA/h already captured after - "); + Serial.print(i * 10); + Serial.println("s"); + i++; + } else { + digitalWrite(8, LOW); + Serial.print("FINISHED voltage below minvoltage - "); + Serial.print(all / 1000, 5); + Serial.print("mA/h in - "); + Serial.print(i * 10); + Serial.println("s"); + } + delay(10000); +} \ No newline at end of file