Skip to content

Instantly share code, notes, and snippets.

@nophead
Last active April 24, 2018 15:20
Show Gist options
  • Save nophead/b57427fc6323f6ddee3ae20b4a1df26f to your computer and use it in GitHub Desktop.
Save nophead/b57427fc6323f6ddee3ae20b4a1df26f to your computer and use it in GitHub Desktop.
The main loop
float voltfloat = 0, currentfloat = 0, wattfloat = 0; // real unit values
float voltscalefactor = 0.0307162746 / 256; // calibration constants vary from device to device
float currentscalefactor = 1.553 / 256000;
float wattscalefactor = 15.49521794871 / 2560;
// the loop function runs over and over again forever
void loop() {
digitalWrite ( GREEN_LED, !!(millis() & 512) ); // flash the green LED
server.handleClient(); // run web server
if(new_readings) { // set by interrupt when data received
voltfloat = voltint * voltscalefactor; // convert to real units
currentfloat = currentint * currentscalefactor;
wattfloat = wattint * wattscalefactor;
Serial.printf("V%5.1f, A%4.2f, W%5.1f", voltfloat, currentfloat, wattfloat);
for(int i = 0; i < length; ++i)
Serial.printf(" %02X", data[i]);
Serial.println();
new_readings = false;
}
ArduinoOTA.handle();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment