new time management
This commit is contained in:
parent
33236b4a11
commit
e0cb8e74ca
24
src/main.cpp
24
src/main.cpp
@ -4,11 +4,15 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define MINVOLTAGE 2.5
|
#define MINVOLTAGE 2.5
|
||||||
#define OHM 4.7
|
#define OHM 4.9
|
||||||
|
|
||||||
|
#define INTERVALTIME 5 // refresh interval in secs
|
||||||
|
|
||||||
#define MEASUREPIN A3
|
#define MEASUREPIN A3
|
||||||
#define MOSFETPIN A2
|
#define MOSFETPIN A2
|
||||||
|
|
||||||
|
unsigned long oldtime = -1;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
@ -16,9 +20,11 @@ void setup() {
|
|||||||
pinMode(MEASUREPIN, INPUT_PULLUP);
|
pinMode(MEASUREPIN, INPUT_PULLUP);
|
||||||
|
|
||||||
digitalWrite(MOSFETPIN, LOW);
|
digitalWrite(MOSFETPIN, LOW);
|
||||||
|
|
||||||
|
oldtime = micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
unsigned int time = 0;
|
||||||
double all = 0;
|
double all = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -28,24 +34,24 @@ void loop() {
|
|||||||
digitalWrite(MOSFETPIN, HIGH);
|
digitalWrite(MOSFETPIN, HIGH);
|
||||||
double current = voltage / OHM;
|
double current = voltage / OHM;
|
||||||
double watt = current * voltage;
|
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;
|
all += amphours;
|
||||||
Serial.print(all * 1000, 5);
|
Serial.print(all * 1000.0, 5);
|
||||||
Serial.print("mA/h already captured after - ");
|
Serial.print("mA/h already captured after - ");
|
||||||
Serial.print(i * 10);
|
Serial.print(time * INTERVALTIME);
|
||||||
Serial.println("s");
|
Serial.println("s");
|
||||||
|
|
||||||
Serial.print("Watts: ");
|
Serial.print("Watts: ");
|
||||||
Serial.println(watt);
|
Serial.println(watt);
|
||||||
Serial.print("Current: ");
|
Serial.print("Current: ");
|
||||||
Serial.println(current);
|
Serial.println(current);
|
||||||
i++;
|
time++;
|
||||||
} else if (voltage <= MINVOLTAGE) {
|
} else if (voltage <= MINVOLTAGE) {
|
||||||
digitalWrite(MOSFETPIN, LOW);
|
digitalWrite(MOSFETPIN, LOW);
|
||||||
Serial.print("FINISHED voltage below minvoltage - ");
|
Serial.print("FINISHED voltage below minvoltage - ");
|
||||||
Serial.print(all * 1000, 5);
|
Serial.print(all * 1000, 5);
|
||||||
Serial.print("mA/h in - ");
|
Serial.print("mA/h in - ");
|
||||||
Serial.print(i * 10);
|
Serial.print(time * INTERVALTIME);
|
||||||
Serial.println("s");
|
Serial.println("s");
|
||||||
Serial.println("please restart the print");
|
Serial.println("please restart the print");
|
||||||
delay(999999999);
|
delay(999999999);
|
||||||
@ -55,5 +61,7 @@ void loop() {
|
|||||||
Serial.print("Voltage: ");
|
Serial.print("Voltage: ");
|
||||||
Serial.println(voltage);
|
Serial.println(voltage);
|
||||||
|
|
||||||
delay(10000);
|
int delaytime = INTERVALTIME * 1000 - ((micros() - oldtime) / 1000);
|
||||||
|
oldtime = micros();
|
||||||
|
delay(delaytime);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user