浏览代码

Scan the state more often

The code previously scanned fairly rarely due to the thingspeak code long delay.
Now it scans every second or so, making adjustments to the PWM more frequent.
This code also adds a spinner so you can verify that it's adjusting things.
Ron Kuris 10 年之前
父节点
当前提交
f9ff5cd8f1
共有 1 个文件被更改,包括 17 次插入6 次删除
  1. 17 6
      MPPT_Code_ESP8266/MPPT_Code_ESP8266.ino

+ 17 - 6
MPPT_Code_ESP8266/MPPT_Code_ESP8266.ino

@@ -395,6 +395,7 @@ void loop()
   led_output();                      // led indication
   led_output();                      // led indication
   lcd_display();                    // lcd display
   lcd_display();                    // lcd display
   wifi_datalog();
   wifi_datalog();
+  delay(500);
 }
 }
 
 
 //------------------------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------------------------
@@ -551,19 +552,32 @@ void lcd_display()
  lcd.setCursor(15,3);
  lcd.setCursor(15,3);
  if (load_status == 1)
  if (load_status == 1)
  {
  {
-    lcd.print("On");
+    lcd.print("On  ");
  }
  }
  else
  else
  {
  {
-   lcd.print("Off");
+   lcd.print("Off ");
  } 
  } 
+ spinner();
 }
 }
+void spinner(void) {
+  static int cspinner;
+  static char spinner_chars[] = { '/','-','\\','|' };
+  cspinner++;
+  lcd.print(spinner_chars[cspinner%4]);
+}
+
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 //----------------------------- ESP8266 WiFi ------------------------------
 //----------------------------- ESP8266 WiFi ------------------------------
 //--------------------------Plot System data on thingspeak.com-------------
 //--------------------------Plot System data on thingspeak.com-------------
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 void wifi_datalog()
 void wifi_datalog()
 {
 {
+  // thingspeak needs 15 sec delay between updates
+  static int lastlogged;
+  if ( seconds - lastlogged < 16 )
+      return;
+  lastlogged = seconds;
  // convert to string
  // convert to string
   char buf[16];
   char buf[16];
   String strTemp = dtostrf( sol_volts, 4, 1, buf);
   String strTemp = dtostrf( sol_volts, 4, 1, buf);
@@ -600,8 +614,5 @@ void wifi_datalog()
     ser.println("AT+CIPCLOSE");
     ser.println("AT+CIPCLOSE");
     // alert user
     // alert user
     Serial.println("AT+CIPCLOSE");
     Serial.println("AT+CIPCLOSE");
-  }
-    
-  // thingspeak needs 15 sec delay between updates
-  delay(16000);  
+  } 
 }
 }