@@ -17,7 +17,7 @@ float current_mA = 0.00, current_mA_Max, current_mA_Avg;
1717float loadvoltage = 0.00 , loadvoltageMax, loadvoltageAvg;
1818float energy = 0.00 , energyPrice = 0.000 , energyCost, energyPrevious, energyDifference;
1919float power = 0.00 , powerMax, powerAvg;
20- int sendTimer, pollingTimer, priceTimer, graphTimer, autoRange, stopwatchResetCounter , counter2, secret, stopwatchTimer;
20+ int sendTimer, pollingTimer, priceTimer, graphTimer, autoRange, countdownResetCon, countdownResetClock , counter2, secret, stopwatchTimer;
2121long stopwatch;
2222int splitTimer1, splitTimer2, splitTimer3, splitTimer4, splitTimer5;
2323int sendTimer1, sendTimer2, sendTimer3, sendTimer4, sendTimer5;
@@ -183,7 +183,11 @@ void sendINA219valuesENERGY() {
183183 energyPrevious = energy;
184184 // ENERGY COST
185185 energyCost = energyCost + ((energyPrice / 1000 / 100 ) * energyDifference);
186- Blynk.virtualWrite (vPIN_ENERGY_COST, String ((energyCost), 8 ));
186+ if (energyCost > 9.999 ){
187+ Blynk.virtualWrite (vPIN_ENERGY_COST, String ((energyCost), 7 ));
188+ } else {
189+ Blynk.virtualWrite (vPIN_ENERGY_COST, String ((energyCost), 8 ));
190+ }
187191}
188192
189193// this is feeding raw data to the graph
@@ -233,7 +237,7 @@ BLYNK_WRITE(vPIN_BUTTON_AUTORANGE) {
233237
234238// RESET AVERAGES
235239BLYNK_WRITE (vPIN_BUTTON_RESET_AVG) {
236- if (param.asInt () && secret == 0 ) {
240+ if (param.asInt ()) {
237241 Blynk.virtualWrite (vPIN_VOLTAGE_AVG, " --- V" );
238242 Blynk.virtualWrite (vPIN_CURRENT_AVG, " --- mA" );
239243 Blynk.virtualWrite (vPIN_POWER_AVG, " --- mW" );
@@ -257,12 +261,23 @@ BLYNK_WRITE(vPIN_BUTTON_RESET_AVG) {
257261 power_AVG_5 = power;
258262 delay (50 );
259263 updateINA219eXtraValues ();
264+ countdownResetCon = timer.setTimeout (1000 , countdownResetConCallback);
265+ } else {
266+ timer.disable (countdownResetCon);
260267 }
268+
269+ }
270+ void countdownResetConCallback () {
271+ Blynk.virtualWrite (vPIN_ENERGY_USED, " 0.000000 mWh" );
272+ Blynk.virtualWrite (vPIN_ENERGY_COST, " 0.00000000" );
273+ energy = 0 ;
274+ energyCost = 0 ;
275+ energyPrevious = 0 ;
261276}
262277
263278// RESET PEAKS
264279BLYNK_WRITE (vPIN_BUTTON_RESET_MAX) {
265- if (param.asInt () && secret == 0 ) {
280+ if (param.asInt ()) {
266281 Blynk.virtualWrite (vPIN_VOLTAGE_PEAK, " --- V" );
267282 Blynk.virtualWrite (vPIN_CURRENT_PEAK, " --- mA" );
268283 Blynk.virtualWrite (vPIN_POWER_PEAK, " --- mW" );
@@ -271,24 +286,14 @@ BLYNK_WRITE(vPIN_BUTTON_RESET_MAX) {
271286 powerMax = power;
272287 delay (50 );
273288 updateINA219eXtraValues ();
274- stopwatchResetCounter = timer.setTimeout (1000 , countdownToReset );
289+ countdownResetClock = timer.setTimeout (1000 , countdownResetClockCallback );
275290 } else {
276- timer.disable (stopwatchResetCounter );
291+ timer.disable (countdownResetClock );
277292 }
278293}
279-
280- // this the callback for holding a button longer than 1 second
281- // it needs work.. secret = 1?? srsly?.. I need to change this
282- void countdownToReset () {
283- secret = 1 ;
284- counter2 = timer.setTimeout (500 , countdownToNormal);
294+ void countdownResetClockCallback () {
285295 Blynk.virtualWrite (vPIN_ENERGY_TIME, " --:--:--:--" );
286296 stopwatch = 0 ;
287- timer.enable (stopwatchTimer);
288- }
289- // callback to change button function back to normal... also needs work
290- void countdownToNormal () {
291- secret = 0 ;
292297}
293298
294299// the stopwatch counter which is run on a timer
0 commit comments