/
#include <LiquidCrystal.h> // include standard LCD library
LiquidCrystal lcd(5,18,19,21,22,23);
const int potPin1 = 34;
const int potPin2 = 35;
int pot1Value, pot2Value = 0;
// Declare floats for potentiometer voltages
float pot1Voltage = 0.00;
float pot2Current = 0.00;
float Power = 0.00;
float Energy = 0.00;
float IncrementalPower = 0.00;
void setup() {
Serial.begin(115200);
lcd.begin(16,2);
// delay(100);
// pinMode(potPin1,INPUT_PULLUP);
}
void loop() {
// Measures the value of the potentiometer
pot1Value = analogRead(potPin1);
pot1Voltage = 3.3 * analogRead(potPin1)/4095;
pot2Value = analogRead(potPin2);
pot2Current = 3.3 * pot2Value/4095;
Power = pot1Voltage * pot2Current;
IncrementalPower += Power;
Energy = IncrementalPower / 3600;
Serial.println((String)pot1Value + ", " + (String)pot2Value);
Serial.println((String)pot1Voltage + "V, " + (String)pot2Current + "A");
Serial.println(String(pot1Voltage,3) + "V, " + String(pot2Current,3) + "A");
Serial.println((String)Power + "W");
Serial.println(IncrementalPower, 3);
Serial.println((String)Energy + "Wh");
char buff[18]; // make enough space
snprintf(buff,(sizeof(buff)-1),"%6.3fV,%6.3fA",pot1Voltage,pot2Current);
Serial.println(buff);
lcd.clear();
lcd.setCursor(0,0);
//lcd.println((String)pot1Value + " " + (String)pot2Value);
//lcd.setCursor(0,1);
lcd.println((String)pot1Voltage + "V " + (String)pot2Current + "A");
lcd.setCursor(0,1);
lcd.println((String)Power + "W");
delay(1000);
}