Hi
In this program Voltmeter Ua is working ok after adding Voltmeter Ub
I have an error = 'Ub' was not declared in this scope .
What I doing wrong ?
#include "EmonLib.h"
EnergyMonitor emon1Ub;
//Ua
const int numReadings = 10;
int readings [numReadings];
int readIndex = 0;
long total = 0;
int Vala = 0;
//Ub
const int numReadingsb = 10;
int readingsb [numReadingsb];
int readIndexb = 0;
long totalb = 0;
int Valb = 0;
//----------------------------------------------------------------
void setup() {
emon1Ub.current(PA2, 1000); // Ux ornge
Serial.begin(115200);
}
//-------------------------------------------------------------
void loop() {
double Ub = emon1Ub.calcIrms(5);
readAnalogSmootha(); // Ua
Smoothb(); // Ub
Serial.print(" Avala = "); Serial.print(Vala);
Serial.print(" Aavga = "); Serial.print(smootha());
// Serial.print(" Avalb = "); Serial.print(Valb);
//Serial.print(" Aavgb = "); Serial.println(smoothb());
Serial.print(" Ub = "); Serial.print(Ub);
Serial.print(" Aavgb = "); Serial.println(smoothb());
}
//Ua
void readAnalogSmootha( ) { /* function readAnalogSmooth */
Vala = analogRead(PA1);
}
long smootha() { /* function smooth */
long averagea;
total = total - readings[readIndex];
readings[readIndex] = Vala;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
averagea = total / numReadings;
return averagea;
}
// Ub
//void readAnalogSmoothb( ) { /* function readAnalogSmooth */
void Smoothb( ) {
// Valb = analogRead(PA2);
Valb = Ub;
}
long smoothb() { /* function smooth */
long averageb;
totalb = totalb - readingsb[readIndexb];
readingsb[readIndexb] = Valb;
totalb = totalb + readingsb[readIndexb];
readIndexb = readIndexb + 1;
if (readIndexb >= numReadingsb) {
readIndexb = 0;
}
averageb = totalb / numReadingsb;
return averageb;
}
///////////