new time management

This commit is contained in:
lukas-heiligenbrunner 2020-04-12 21:10:31 +02:00
parent 33236b4a11
commit e0cb8e74ca

View File

@ -4,11 +4,15 @@
#include "Arduino.h"
#define MINVOLTAGE 2.5
#define OHM 4.7
#define OHM 4.9
#define INTERVALTIME 5 // refresh interval in secs
#define MEASUREPIN A3
#define MOSFETPIN A2
unsigned long oldtime = -1;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
@ -16,9 +20,11 @@ void setup() {
pinMode(MEASUREPIN, INPUT_PULLUP);
digitalWrite(MOSFETPIN, LOW);
oldtime = micros();
}
int i = 0;
unsigned int time = 0;
double all = 0;
void loop() {
@ -28,24 +34,24 @@ void loop() {
digitalWrite(MOSFETPIN, HIGH);
double current = voltage / OHM;
double watt = current * voltage;
double amphours = current / 360; // every 10secs is a measurement point...
double amphours = current / (3600.0 / INTERVALTIME); // every 10secs is a measurement point...
all += amphours;
Serial.print(all * 1000, 5);
Serial.print(all * 1000.0, 5);
Serial.print("mA/h already captured after - ");
Serial.print(i * 10);
Serial.print(time * INTERVALTIME);
Serial.println("s");
Serial.print("Watts: ");
Serial.println(watt);
Serial.print("Current: ");
Serial.println(current);
i++;
time++;
} else if (voltage <= MINVOLTAGE) {
digitalWrite(MOSFETPIN, LOW);
Serial.print("FINISHED voltage below minvoltage - ");
Serial.print(all * 1000, 5);
Serial.print("mA/h in - ");
Serial.print(i * 10);
Serial.print(time * INTERVALTIME);
Serial.println("s");
Serial.println("please restart the print");
delay(999999999);
@ -55,5 +61,7 @@ void loop() {
Serial.print("Voltage: ");
Serial.println(voltage);
delay(10000);
int delaytime = INTERVALTIME * 1000 - ((micros() - oldtime) / 1000);
oldtime = micros();
delay(delaytime);
}