Hello! Please help me with a node for zmpt101b , I have a working sketch, but all attempts to make a node out of it myself ended in failure.
Sketch:
double sensorValue1 = 0;
double sensorValue2 = 0;
int crosscount = 0;
int climb_flag = 0;
int val[100];
int max_v = 0;
double VmaxD = 0;
double VeffD = 0;
double Veff = 0;
void setup() {
Serial.begin(9600);
pinMode(A1, INPUT);
}
void loop() {
for (int i=0; i<100; i++) {
sensorValue1 = analogRead(A1);
if (analogRead(A1) > 511) { val[i] = sensorValue1; }
else { val[i] = 0; }
delay(1);
}
max_v = 0;
for ( int i = 0; i < 100; i++ ) {
if ( val[i] > max_v ) { max_v = val[i]; }
val[i] = 0;
}
if (max_v != 0) {
VmaxD = max_v;
VeffD = VmaxD / sqrt(2);
Veff = (((VeffD - 420.76) / -90.24) * -210.2) + 210.2;
}
else { Veff = 0; }
Serial.print("Voltage: ");
Serial.println(Veff);
VmaxD = 0;
delay(100);
}