v5.1,Some minor cleanup

v5.1,Some minor cleanup

--- WeatherDisplay.ino
+++ WeatherDisplay.ino
@@ -21,7 +21,7 @@
 String result;
 bool night = false;
 bool toggleDisplay = HIGH;
-bool pastToggleDisplay = toggleDisplay;
+bool pastToggleDisplay = !toggleDisplay;

 Adafruit_ST7735 tft(TFT_CS, TFT_DC, TFT_RST);

@@ -139,15 +139,15 @@
     return;
   }

-// Not sure why this is needed.  It works fine without it
-// while (client.connected() && !client.available()) delay(1); //waits for data
+  // Not sure why this is needed.  It works fine without it
+  // while (client.connected() && !client.available()) delay(1); //waits for data

 #ifdef DEBUG
   Serial.println("Waiting for data");
 #endif

   while (client.connected() && client.available()) { // While connected
-    char c = client.read(); // Gets byte from ethernet buffer
+    char c = client.read(); // Gets byte from WIFI buffer
     result = result + c;
   }

@@ -895,290 +895,290 @@
   return (DOW);
 }

-  /*
-    SUNRISET.C - Computes Sun rise/set times, start/end of twilight, and
-               the length of the day at any date and latitude
-
-    Written as DAYLEN.C, 1989-08-16
-
-    Modified to SUNRISET.C, 1992-12-01
-
-    (c) Paul Schlyter, 1989, 1992
-
-    Released to the public domain by Paul Schlyter, December 1992
-
-    http://stjarnhimlen.se/comp/sunriset.c
-
-  */
-
-  /* The "workhorse" function for sun rise/set times */
-  int __sunriset__( int year, int month, int day, double lon, double lat,
-                    double altit, int upper_limb, double * trise, double * tset )
-  /***************************************************************************/
-  /* Note: year,month,date = calendar date, 1801-2099 only.             */
-  /*       Eastern longitude positive, Western longitude negative       */
-  /*       Northern latitude positive, Southern latitude negative       */
-  /*       The longitude value IS critical in this function!            */
-  /*       altit = the altitude which the Sun should cross              */
-  /*               Set to -35/60 degrees for rise/set, -6 degrees       */
-  /*               for civil, -12 degrees for nautical and -18          */
-  /*               degrees for astronomical twilight.                   */
-  /*         upper_limb: non-zero -> upper limb, zero -> center         */
-  /*               Set to non-zero (e.g. 1) when computing rise/set     */
-  /*               times, and to zero when computing start/end of       */
-  /*               twilight.                                            */
-  /*        *rise = where to store the rise time                        */
-  /*        *set  = where to store the set  time                        */
-  /*                Both times are relative to the specified altitude,  */
-  /*                and thus this function can be used to compute       */
-  /*                various twilight times, as well as rise/set times   */
-  /* Return value:  0 = sun rises/sets this day, times stored at        */
-  /*                    *trise and *tset.                               */
-  /*               +1 = sun above the specified "horizon" 24 hours.     */
-  /*                    *trise set to time when the sun is at south,    */
-  /*                    minus 12 hours while *tset is set to the south  */
-  /*                    time plus 12 hours. "Day" length = 24 hours     */
-  /*               -1 = sun is below the specified "horizon" 24 hours   */
-  /*                    "Day" length = 0 hours, *trise and *tset are    */
-  /*                    both set to the time when the sun is at south.  */
-  /*                                                                    */
-  /**********************************************************************/
-  {
-    double  d,  /* Days since 2000 Jan 0.0 (negative before) */
-            sr,         /* Solar distance, astronomical units */
-            sRA,        /* Sun's Right Ascension */
-            sdec,       /* Sun's declination */
-            sradius,    /* Sun's apparent radius */
-            t,          /* Diurnal arc */
-            tsouth,     /* Time when Sun is at south */
-            sidtime;    /* Local sidereal time */
-
-    int rc = 0; /* Return cde from function - usually 0 */
-
-    /* Compute d of 12h local mean solar time */
-    d = days_since_2000_Jan_0(year, month, day) + 0.5 - lon / 360.0;
-
-    /* Compute the local sidereal time of this moment */
-    sidtime = revolution( GMST0(d) + 180.0 + lon );
-
-    /* Compute Sun's RA, Decl and distance at this moment */
-    sun_RA_dec( d, &sRA, &sdec, &sr );
-
-    /* Compute time when Sun is at south - in hours UT */
-    tsouth = 12.0 - rev180(sidtime - sRA) / 15.0;
-
-    /* Compute the Sun's apparent radius in degrees */
-    sradius = 0.2666 / sr;
-
-    /* Do correction to upper limb, if necessary */
-    if ( upper_limb )
-      altit -= sradius;
-
-    /* Compute the diurnal arc that the Sun traverses to reach */
-    /* the specified altitude altit: */
-    {
-      double cost;
-      cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
-             ( cosd(lat) * cosd(sdec) );
-      if ( cost >= 1.0 )
-        rc = -1, t = 0.0;       /* Sun always below altit */
-      else if ( cost <= -1.0 )
-        rc = +1, t = 12.0;      /* Sun always above altit */
-      else
-        t = acosd(cost) / 15.0; /* The diurnal arc, hours */
-    }
-
-    /* Store rise and set times - in hours UT */
-    *trise = tsouth - t;
-    *tset  = tsouth + t;
-
-    return rc;
-  }  /* __sunriset__ */
-
-  /* The "workhorse" function */
-  double __daylen__( int year, int month, int day, double lon, double lat,
-                     double altit, int upper_limb )
-  /**********************************************************************/
-  /* Note: year,month,date = calendar date, 1801-2099 only.             */
-  /*       Eastern longitude positive, Western longitude negative       */
-  /*       Northern latitude positive, Southern latitude negative       */
-  /*       The longitude value is not critical. Set it to the correct   */
-  /*       longitude if you're picky, otherwise set to to, say, 0.0     */
-  /*       The latitude however IS critical - be sure to get it correct */
-  /*       altit = the altitude which the Sun should cross              */
-  /*               Set to -35/60 degrees for rise/set, -6 degrees       */
-  /*               for civil, -12 degrees for nautical and -18          */
-  /*               degrees for astronomical twilight.                   */
-  /*         upper_limb: non-zero -> upper limb, zero -> center         */
-  /*               Set to non-zero (e.g. 1) when computing day length   */
-  /*               and to zero when computing day+twilight length.      */
-  /**********************************************************************/
-  {
-    double  d,  /* Days since 2000 Jan 0.0 (negative before) */
-            obl_ecl,    /* Obliquity (inclination) of Earth's axis */
-            sr,         /* Solar distance, astronomical units */
-            slon,       /* True solar longitude */
-            sin_sdecl,  /* Sine of Sun's declination */
-            cos_sdecl,  /* Cosine of Sun's declination */
-            sradius,    /* Sun's apparent radius */
-            t;          /* Diurnal arc */
-
-    /* Compute d of 12h local mean solar time */
-    d = days_since_2000_Jan_0(year, month, day) + 0.5 - lon / 360.0;
-
-    /* Compute obliquity of ecliptic (inclination of Earth's axis) */
-    obl_ecl = 23.4393 - 3.563E-7 * d;
-
-    /* Compute Sun's ecliptic longitude and distance */
-    sunpos( d, &slon, &sr );
-
-    /* Compute sine and cosine of Sun's declination */
-    sin_sdecl = sind(obl_ecl) * sind(slon);
-    cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
-
-    /* Compute the Sun's apparent radius, degrees */
-    sradius = 0.2666 / sr;
-
-    /* Do correction to upper limb, if necessary */
-    if ( upper_limb )
-      altit -= sradius;
-
-    /* Compute the diurnal arc that the Sun traverses to reach */
-    /* the specified altitude altit: */
-    {
-      double cost;
-      cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
-             ( cosd(lat) * cos_sdecl );
-      if ( cost >= 1.0 )
-        t = 0.0;                      /* Sun always below altit */
-      else if ( cost <= -1.0 )
-        t = 24.0;                     /* Sun always above altit */
-      else  t = (2.0 / 15.0) * acosd(cost); /* The diurnal arc, hours */
-    }
-    return t;
-  }  /* __daylen__ */
-
-  /* This function computes the Sun's position at any instant */
-  void sunpos( double d, double * lon, double * r )
-  /******************************************************/
-  /* Computes the Sun's ecliptic longitude and distance */
-  /* at an instant given in d, number of days since     */
-  /* 2000 Jan 0.0.  The Sun's ecliptic latitude is not  */
-  /* computed, since it's always very near 0.           */
-  /******************************************************/
-  {
-    double M,         /* Mean anomaly of the Sun */
-           w,         /* Mean longitude of perihelion */
-           /* Note: Sun's mean longitude = M + w */
-           e,         /* Eccentricity of Earth's orbit */
-           E,         /* Eccentric anomaly */
-           x, y,      /* x, y coordinates in orbit */
-           v;         /* True anomaly */
-
-    /* Compute mean elements */
-    M = revolution( 356.0470 + 0.9856002585 * d );
-    w = 282.9404 + 4.70935E-5 * d;
-    e = 0.016709 - 1.151E-9 * d;
-
-    /* Compute true longitude and radius vector */
-    E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
-    x = cosd(E) - e;
-    y = sqrt( 1.0 - e * e ) * sind(E);
-    *r = sqrt( x * x + y * y );          /* Solar distance */
-    v = atan2d( y, x );                  /* True anomaly */
-    *lon = v + w;                        /* True solar longitude */
-    if ( *lon >= 360.0 )
-      *lon -= 360.0;                   /* Make it 0..360 degrees */
-  }
-
-  void sun_RA_dec( double d, double * RA, double * dec, double * r )
-  /******************************************************/
-  /* Computes the Sun's equatorial coordinates RA, Decl */
-  /* and also its distance, at an instant given in d,   */
-  /* the number of days since 2000 Jan 0.0.             */
-  /******************************************************/
-  {
-    double lon, obl_ecl, x, y, z;
-
-    /* Compute Sun's ecliptical coordinates */
-    sunpos( d, &lon, r );
-
-    /* Compute ecliptic rectangular coordinates (z=0) */
-    x = *r * cosd(lon);
-    y = *r * sind(lon);
-
-    /* Compute obliquity of ecliptic (inclination of Earth's axis) */
-    obl_ecl = 23.4393 - 3.563E-7 * d;
-
-    /* Convert to equatorial rectangular coordinates - x is unchanged */
-    z = y * sind(obl_ecl);
-    y = y * cosd(obl_ecl);
-
-    /* Convert to spherical coordinates */
-    *RA = atan2d( y, x );
-    *dec = atan2d( z, sqrt(x * x + y * y) );
-
-  }  /* sun_RA_dec */
-
-  /******************************************************************/
-  /* This function reduces any angle to within the first revolution */
-  /* by subtracting or adding even multiples of 360.0 until the     */
-  /* result is >= 0.0 and < 360.0                                   */
-  /******************************************************************/
+/*
+ Computes Sun rise/set times, start/end of twilight, and
+ the length of the day at any date and latitude
+
+  Written as DAYLEN.C, 1989-08-16
+
+  Modified to SUNRISET.C, 1992-12-01
+
+  (c) Paul Schlyter, 1989, 1992
+
+  Released to the public domain by Paul Schlyter, December 1992
+
+  http://stjarnhimlen.se/comp/sunriset.c
+
+*/
+
+/* The "workhorse" function for sun rise/set times */
+int __sunriset__( int year, int month, int day, double lon, double lat,
+                  double altit, int upper_limb, double * trise, double * tset )
+/***************************************************************************/
+/* Note: year,month,date = calendar date, 1801-2099 only.             */
+/*       Eastern longitude positive, Western longitude negative       */
+/*       Northern latitude positive, Southern latitude negative       */
+/*       The longitude value IS critical in this function!            */
+/*       altit = the altitude which the Sun should cross              */
+/*               Set to -35/60 degrees for rise/set, -6 degrees       */
+/*               for civil, -12 degrees for nautical and -18          */
+/*               degrees for astronomical twilight.                   */
+/*         upper_limb: non-zero -> upper limb, zero -> center         */
+/*               Set to non-zero (e.g. 1) when computing rise/set     */
+/*               times, and to zero when computing start/end of       */
+/*               twilight.                                            */
+/*        *rise = where to store the rise time                        */
+/*        *set  = where to store the set  time                        */
+/*                Both times are relative to the specified altitude,  */
+/*                and thus this function can be used to compute       */
+/*                various twilight times, as well as rise/set times   */
+/* Return value:  0 = sun rises/sets this day, times stored at        */
+/*                    *trise and *tset.                               */
+/*               +1 = sun above the specified "horizon" 24 hours.     */
+/*                    *trise set to time when the sun is at south,    */
+/*                    minus 12 hours while *tset is set to the south  */
+/*                    time plus 12 hours. "Day" length = 24 hours     */
+/*               -1 = sun is below the specified "horizon" 24 hours   */
+/*                    "Day" length = 0 hours, *trise and *tset are    */
+/*                    both set to the time when the sun is at south.  */
+/*                                                                    */
+/**********************************************************************/
+{
+  double  d,  /* Days since 2000 Jan 0.0 (negative before) */
+          sr,         /* Solar distance, astronomical units */
+          sRA,        /* Sun's Right Ascension */
+          sdec,       /* Sun's declination */
+          sradius,    /* Sun's apparent radius */
+          t,          /* Diurnal arc */
+          tsouth,     /* Time when Sun is at south */
+          sidtime;    /* Local sidereal time */
+
+  int rc = 0; /* Return cde from function - usually 0 */
+
+  /* Compute d of 12h local mean solar time */
+  d = days_since_2000_Jan_0(year, month, day) + 0.5 - lon / 360.0;
+
+  /* Compute the local sidereal time of this moment */
+  sidtime = revolution( GMST0(d) + 180.0 + lon );
+
+  /* Compute Sun's RA, Decl and distance at this moment */
+  sun_RA_dec( d, &sRA, &sdec, &sr );
+
+  /* Compute time when Sun is at south - in hours UT */
+  tsouth = 12.0 - rev180(sidtime - sRA) / 15.0;
+
+  /* Compute the Sun's apparent radius in degrees */
+  sradius = 0.2666 / sr;
+
+  /* Do correction to upper limb, if necessary */
+  if ( upper_limb )
+    altit -= sradius;
+
+  /* Compute the diurnal arc that the Sun traverses to reach */
+  /* the specified altitude altit: */
+  {
+    double cost;
+    cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
+           ( cosd(lat) * cosd(sdec) );
+    if ( cost >= 1.0 )
+      rc = -1, t = 0.0;       /* Sun always below altit */
+    else if ( cost <= -1.0 )
+      rc = +1, t = 12.0;      /* Sun always above altit */
+    else
+      t = acosd(cost) / 15.0; /* The diurnal arc, hours */
+  }
+
+  /* Store rise and set times - in hours UT */
+  *trise = tsouth - t;
+  *tset  = tsouth + t;
+
+  return rc;
+}  /* __sunriset__ */
+
+/* The "workhorse" function */
+double __daylen__( int year, int month, int day, double lon, double lat,
+                   double altit, int upper_limb )
+/**********************************************************************/
+/* Note: year,month,date = calendar date, 1801-2099 only.             */
+/*       Eastern longitude positive, Western longitude negative       */
+/*       Northern latitude positive, Southern latitude negative       */
+/*       The longitude value is not critical. Set it to the correct   */
+/*       longitude if you're picky, otherwise set to to, say, 0.0     */
+/*       The latitude however IS critical - be sure to get it correct */
+/*       altit = the altitude which the Sun should cross              */
+/*               Set to -35/60 degrees for rise/set, -6 degrees       */
+/*               for civil, -12 degrees for nautical and -18          */
+/*               degrees for astronomical twilight.                   */
+/*         upper_limb: non-zero -> upper limb, zero -> center         */
+/*               Set to non-zero (e.g. 1) when computing day length   */
+/*               and to zero when computing day+twilight length.      */
+/**********************************************************************/
+{
+  double  d,  /* Days since 2000 Jan 0.0 (negative before) */
+          obl_ecl,    /* Obliquity (inclination) of Earth's axis */
+          sr,         /* Solar distance, astronomical units */
+          slon,       /* True solar longitude */
+          sin_sdecl,  /* Sine of Sun's declination */
+          cos_sdecl,  /* Cosine of Sun's declination */
+          sradius,    /* Sun's apparent radius */
+          t;          /* Diurnal arc */
+
+  /* Compute d of 12h local mean solar time */
+  d = days_since_2000_Jan_0(year, month, day) + 0.5 - lon / 360.0;
+
+  /* Compute obliquity of ecliptic (inclination of Earth's axis) */
+  obl_ecl = 23.4393 - 3.563E-7 * d;
+
+  /* Compute Sun's ecliptic longitude and distance */
+  sunpos( d, &slon, &sr );
+
+  /* Compute sine and cosine of Sun's declination */
+  sin_sdecl = sind(obl_ecl) * sind(slon);
+  cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
+
+  /* Compute the Sun's apparent radius, degrees */
+  sradius = 0.2666 / sr;
+
+  /* Do correction to upper limb, if necessary */
+  if ( upper_limb )
+    altit -= sradius;
+
+  /* Compute the diurnal arc that the Sun traverses to reach */
+  /* the specified altitude altit: */
+  {
+    double cost;
+    cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
+           ( cosd(lat) * cos_sdecl );
+    if ( cost >= 1.0 )
+      t = 0.0;                      /* Sun always below altit */
+    else if ( cost <= -1.0 )
+      t = 24.0;                     /* Sun always above altit */
+    else  t = (2.0 / 15.0) * acosd(cost); /* The diurnal arc, hours */
+  }
+  return t;
+}  /* __daylen__ */
+
+/* This function computes the Sun's position at any instant */
+void sunpos( double d, double * lon, double * r )
+/******************************************************/
+/* Computes the Sun's ecliptic longitude and distance */
+/* at an instant given in d, number of days since     */
+/* 2000 Jan 0.0.  The Sun's ecliptic latitude is not  */
+/* computed, since it's always very near 0.           */
+/******************************************************/
+{
+  double M,         /* Mean anomaly of the Sun */
+         w,         /* Mean longitude of perihelion */
+         /* Note: Sun's mean longitude = M + w */
+         e,         /* Eccentricity of Earth's orbit */
+         E,         /* Eccentric anomaly */
+         x, y,      /* x, y coordinates in orbit */
+         v;         /* True anomaly */
+
+  /* Compute mean elements */
+  M = revolution( 356.0470 + 0.9856002585 * d );
+  w = 282.9404 + 4.70935E-5 * d;
+  e = 0.016709 - 1.151E-9 * d;
+
+  /* Compute true longitude and radius vector */
+  E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
+  x = cosd(E) - e;
+  y = sqrt( 1.0 - e * e ) * sind(E);
+  *r = sqrt( x * x + y * y );          /* Solar distance */
+  v = atan2d( y, x );                  /* True anomaly */
+  *lon = v + w;                        /* True solar longitude */
+  if ( *lon >= 360.0 )
+    *lon -= 360.0;                   /* Make it 0..360 degrees */
+}
+
+void sun_RA_dec( double d, double * RA, double * dec, double * r )
+/******************************************************/
+/* Computes the Sun's equatorial coordinates RA, Decl */
+/* and also its distance, at an instant given in d,   */
+/* the number of days since 2000 Jan 0.0.             */
+/******************************************************/
+{
+  double lon, obl_ecl, x, y, z;
+
+  /* Compute Sun's ecliptical coordinates */
+  sunpos( d, &lon, r );
+
+  /* Compute ecliptic rectangular coordinates (z=0) */
+  x = *r * cosd(lon);
+  y = *r * sind(lon);
+
+  /* Compute obliquity of ecliptic (inclination of Earth's axis) */
+  obl_ecl = 23.4393 - 3.563E-7 * d;
+
+  /* Convert to equatorial rectangular coordinates - x is unchanged */
+  z = y * sind(obl_ecl);
+  y = y * cosd(obl_ecl);
+
+  /* Convert to spherical coordinates */
+  *RA = atan2d( y, x );
+  *dec = atan2d( z, sqrt(x * x + y * y) );
+
+}  /* sun_RA_dec */
+
+/******************************************************************/
+/* This function reduces any angle to within the first revolution */
+/* by subtracting or adding even multiples of 360.0 until the     */
+/* result is >= 0.0 and < 360.0                                   */
+/******************************************************************/
 #define INV360    ( 1.0 / 360.0 )

-  double revolution( double x )
-  /*****************************************/
-  /* Reduce angle to within 0..360 degrees */
-  /*****************************************/
-  {
-    return ( x - 360.0 * floor( x * INV360 ) );
-  }  /* revolution */
-
-  double rev180( double x )
-  /*********************************************/
-  /* Reduce angle to within +180..+180 degrees */
-  /*********************************************/
-  {
-    return ( x - 360.0 * floor( x * INV360 + 0.5 ) );
-  }  /* revolution */
-
-
-  /*******************************************************************/
-  /* This function computes GMST0, the Greenwich Mean Sidereal Time  */
-  /* at 0h UT (i.e. the sidereal time at the Greenwhich meridian at  */
-  /* 0h UT).  GMST is then the sidereal time at Greenwich at any     */
-  /* time of the day.  I've generalized GMST0 as well, and define it */
-  /* as:  GMST0 = GMST - UT  --  this allows GMST0 to be computed at */
-  /* other times than 0h UT as well.  While this sounds somewhat     */
-  /* contradictory, it is very practical:  instead of computing      */
-  /* GMST like:                                                      */
-  /*                                                                 */
-  /*  GMST = (GMST0) + UT * (366.2422/365.2422)                      */
-  /*                                                                 */
-  /* where (GMST0) is the GMST last time UT was 0 hours, one simply  */
-  /* computes:                                                       */
-  /*                                                                 */
-  /*  GMST = GMST0 + UT                                              */
-  /*                                                                 */
-  /* where GMST0 is the GMST "at 0h UT" but at the current moment!   */
-  /* Defined in this way, GMST0 will increase with about 4 min a     */
-  /* day.  It also happens that GMST0 (in degrees, 1 hr = 15 degr)   */
-  /* is equal to the Sun's mean longitude plus/minus 180 degrees!    */
-  /* (if we neglect aberration, which amounts to 20 seconds of arc   */
-  /* or 1.33 seconds of time)                                        */
-  /*                                                                 */
-  /*******************************************************************/
-
-  double GMST0( double d )
-  {
-    double sidtim0;
-    /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr  */
-    /* L = M + w, as defined in sunpos().  Since I'm too lazy to */
-    /* add these numbers, I'll let the C compiler do it for me.  */
-    /* Any decent C compiler will add the constants at compile   */
-    /* time, imposing no runtime or code overhead.               */
-    sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) +
-                          ( 0.9856002585 + 4.70935E-5 ) * d );
-    return sidtim0;
-  }  /* GMST0 */
+double revolution( double x )
+/*****************************************/
+/* Reduce angle to within 0..360 degrees */
+/*****************************************/
+{
+  return ( x - 360.0 * floor( x * INV360 ) );
+}  /* revolution */
+
+double rev180( double x )
+/*********************************************/
+/* Reduce angle to within +180..+180 degrees */
+/*********************************************/
+{
+  return ( x - 360.0 * floor( x * INV360 + 0.5 ) );
+}  /* revolution */
+
+
+/*******************************************************************/
+/* This function computes GMST0, the Greenwich Mean Sidereal Time  */
+/* at 0h UT (i.e. the sidereal time at the Greenwhich meridian at  */
+/* 0h UT).  GMST is then the sidereal time at Greenwich at any     */
+/* time of the day.  I've generalized GMST0 as well, and define it */
+/* as:  GMST0 = GMST - UT  --  this allows GMST0 to be computed at */
+/* other times than 0h UT as well.  While this sounds somewhat     */
+/* contradictory, it is very practical:  instead of computing      */
+/* GMST like:                                                      */
+/*                                                                 */
+/*  GMST = (GMST0) + UT * (366.2422/365.2422)                      */
+/*                                                                 */
+/* where (GMST0) is the GMST last time UT was 0 hours, one simply  */
+/* computes:                                                       */
+/*                                                                 */
+/*  GMST = GMST0 + UT                                              */
+/*                                                                 */
+/* where GMST0 is the GMST "at 0h UT" but at the current moment!   */
+/* Defined in this way, GMST0 will increase with about 4 min a     */
+/* day.  It also happens that GMST0 (in degrees, 1 hr = 15 degr)   */
+/* is equal to the Sun's mean longitude plus/minus 180 degrees!    */
+/* (if we neglect aberration, which amounts to 20 seconds of arc   */
+/* or 1.33 seconds of time)                                        */
+/*                                                                 */
+/*******************************************************************/
+
+double GMST0( double d )
+{
+  double sidtim0;
+  /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr  */
+  /* L = M + w, as defined in sunpos().  Since I'm too lazy to */
+  /* add these numbers, I'll let the C compiler do it for me.  */
+  /* Any decent C compiler will add the constants at compile   */
+  /* time, imposing no runtime or code overhead.               */
+  sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) +
+                        ( 0.9856002585 + 4.70935E-5 ) * d );
+  return sidtim0;
+}  /* GMST0 */


170  report / sec

170  report / sec

--- _41-promini-nrf24-ads1115/_41-promini-nrf24-ads1115.ino
+++ _41-promini-nrf24-ads1115/_41-promini-nrf24-ads1115.ino
@@ -72,8 +72,9 @@
   noOfWake++;
   counterForloop_old = counterForloop;
   checkRangenow = true;
-  detachInterrupt(digitalPinToInterrupt(2));
+  //detachInterrupt(digitalPinToInterrupt(2));
   radio.powerUp();
+  checkRecordBttn();
 }

 void sleepNow() {
@@ -112,7 +113,8 @@
   // radio
   radio.begin();
   radio.setChannel(CHANNEL);
-  radio.setPALevel(RF24_PA_LOW);
+  //radio.setPALevel(RF24_PA_LOW);
+  radio.setPALevel(RF24_PA_HIGH);
   radio.setDataRate(RF24_250KBPS);
   //radio.setAutoAck(1);
   radio.setRetries(15, 15);
@@ -153,6 +155,7 @@
   float multiplier = 0.125F;
   results = ads.readADC_Differential_0_1();

+  /*
   Serial.print("noOfWakeup : ");
   Serial.print(noOfWake);
   Serial.print(" : counterForloop : ");
@@ -162,26 +165,34 @@
   Serial.print(" : results : ");
   Serial.print(results * multiplier);
   Serial.print(" mA ----> ");
-
+  */
+
+  /*
   if (counterForloop > (counterForloop_old + 10)) {
     checkRecordBttn();
   }
+  */

   payload.data1 = results * multiplier ;
   payload.data2 = rangeStatus;

   payload._salt = noOfWake ;
-  payload.volt = readVcc();
-
+  //payload.volt = readVcc();
+  payload.volt = 3300;
+
+  /*
   Serial.print(payload.data1);
   Serial.print(" : data2 : ");
   Serial.println(payload.data2);
-
-  if ( rangeStatus == 1 || rangeStatus == 3 || rangeStatus == 2 ) {
+  */
+
+  //if ( rangeStatus == 1 || rangeStatus == 3 || rangeStatus == 2 ) {
+  //if ( rangeStatus != 0 ) {
+
     //radio.powerUp();
     radio.write(&payload , sizeof(payload));
     //radio.powerDown();
-  }
+  //}

   digitalWrite(ledPin, LOW);
   counterForloop++;


power-meter update

power-meter update

--- _06-power-meter/_06-power-meter.ino
+++ _06-power-meter/_06-power-meter.ino
@@ -206,8 +206,11 @@
     sentMills = millis();
   }

-  delay(100);
-
+  if ( revMills > 0 ) {
+    delay(int(float(revMills)/10));
+  }else {
+    delay(100);
+  }
 }

 void sendmqttMsg(String payload)


Sync improvement

Sync improvement

--- Master.ino
+++ Master.ino
@@ -13,7 +13,7 @@
 #define blueLED 4 //acknowledgement & blue led port
 #define thErrON 0.9 //threshold multipler HIGH leds
 #define thErrOFF 1.5 //threshold multipler LOW leds
-#define setupWaitTime 0 //(ms) delay at setup time
+#define setupWaitTime 1 //(ms) delay at setup time
 #define fbTime 250 //(ms) feedback led on time
 #define cycTime 250 //(ms) feedback led off time
 #define sync "MODE_sync" // keyword for start sync seq (transmitter side)
@@ -92,6 +92,7 @@
   Serial.print("\nWaiting for threshold sequence or type ");
   Serial.print(sync);
   Serial.println(" to send threshold sequence");
+  uint16_t r_h, g_h, b_h;
   setupMain: //come back here untill sync seq start
   if (Serial.available() > 0) //if there is an input data
   {
@@ -113,9 +114,25 @@
   Serial.print("Getting threshold values");
   Serial.print(".");
   //set threshold for red HIGH
-  th_Val[1].r_t = ((float) r * thErrON);
-  th_Val[1].g_t = ((float) g * thErrOFF);
-  th_Val[1].b_t = ((float) b * thErrOFF);
+  r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(r > r_h)
+    {
+      r_h = r;
+      g_h = g;
+      b_h = b;
+    }
+    else
+    {
+      th_Val[1].r_t = ((float) r_h * thErrON);
+      th_Val[1].g_t = ((float) g_h * thErrOFF);
+      th_Val[1].b_t = ((float) b_h * thErrOFF);
+      break;
+    }
+  }
+
   while(r > th_Val[0].r_t) //wait until red is LOW
   {
     tcs.getRawData(&r, &g, &b, &c); //get env info
@@ -128,9 +145,24 @@
   }
   delay(setupWaitTime);
   //set threshold for green high
-  th_Val[2].r_t = ((float) r * thErrOFF);
-  th_Val[2].g_t = ((float) g * thErrON);
-  th_Val[2].b_t = ((float) b * thErrOFF);
+    r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(g > g_h)
+    {
+      r_h = r;
+      g_h = g;
+      b_h = b;
+    }
+    else
+    {
+      th_Val[2].r_t = ((float) r_h * thErrOFF);
+      th_Val[2].g_t = ((float) g_h * thErrON);
+      th_Val[2].b_t = ((float) b_h * thErrOFF);
+      break;
+    }
+  }
   while(g > th_Val[0].g_t) //wait until green is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -143,9 +175,24 @@
   }
   delay(setupWaitTime);
   //set threshold for blue high
-  th_Val[3].r_t = ((float) r * thErrOFF);
-  th_Val[3].g_t = ((float) g * thErrOFF);
-  th_Val[3].b_t = ((float) b * thErrON);
+  r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(b > b_h)
+    {
+      r_h = r;
+      g_h = g;
+      b_h = b;
+    }
+    else
+    {
+      th_Val[3].r_t = ((float) r_h * thErrOFF);
+      th_Val[3].g_t = ((float) g_h * thErrOFF);
+      th_Val[3].b_t = ((float) b_h * thErrON);
+      break;
+    }
+  }
   while(b > th_Val[0].b_t)
   {
     tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
@@ -158,9 +205,34 @@
   }
   delay(setupWaitTime);
   //set threshold for red-green high
-  th_Val[4].r_t = ((float) r * thErrON);
-  th_Val[4].g_t = ((float) g * thErrON);
-  th_Val[4].b_t = ((float) b * thErrOFF);
+   r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(r > r_h)
+    {
+      r_h = r;
+      if(b_h < b)
+      {
+        b_h = b;
+      }
+    }
+    else if(g > g_h)
+    {
+      g_h = g;
+      if(b_h < b)
+      {
+        b_h = b;
+      }
+    }
+    else
+    {
+      th_Val[4].r_t = ((float) r_h * thErrON);
+      th_Val[4].g_t = ((float) g_h * thErrON);
+      th_Val[4].b_t = ((float) b_h * thErrOFF);
+      break;
+    }
+  }
   while((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -173,9 +245,35 @@
   }
   delay(setupWaitTime);
   //set threshold for red-blue high
-  th_Val[5].r_t = ((float) r * thErrON);
-  th_Val[5].g_t = ((float) g * thErrOFF);
-  th_Val[5].b_t = ((float) b * thErrON);
+     r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(r > r_h)
+    {
+      r_h = r;
+      if(g_h < g)
+      {
+        g_h = g;
+      }
+    }
+    else if(b > b_h)
+    {
+      b_h = b;
+      if(g_h < g)
+      {
+        g_h = g;
+      }
+    }
+    else
+    {
+      th_Val[5].r_t = ((float) r_h * thErrON);
+       th_Val[5].g_t = ((float) g_h * thErrOFF);
+        th_Val[5].b_t = ((float) b_h * thErrON);
+      break;
+    }
+  }
+
   while((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -188,9 +286,34 @@
   }
   delay(setupWaitTime);
   //set threshold for green-blue high
-  th_Val[6].r_t = ((float) r * thErrOFF);
-  th_Val[6].g_t = ((float) g * thErrON);
-  th_Val[6].b_t = ((float) b * thErrON);
+     r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(b > b_h)
+    {
+      b_h = b;
+      if(r_h < r)
+      {
+        r_h = r;
+      }
+    }
+    else if(g > g_h)
+    {
+      g_h = g;
+      if(r_h < r)
+      {
+        r_h = r;
+      }
+    }
+    else
+    {
+     th_Val[6].r_t = ((float) r_h * thErrOFF);
+     th_Val[6].g_t = ((float) g_h * thErrON);
+     th_Val[6].b_t = ((float) b_h * thErrON);
+      break;
+    }
+  }
   while((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
   {
     tcs.getRawData(&r, &g, &b, &c);
@@ -203,9 +326,31 @@
   }
   delay(setupWaitTime);
   //set threshold for red-green-blue high
-  th_Val[7].r_t = ((float) r * thErrON);
-  th_Val[7].g_t = ((float) g * thErrON);
-  th_Val[7].b_t = ((float) b * thErrON);
+     r_h = g_h = b_h = 0;
+  while(true)
+  {
+    tcs.getRawData(&r, &g, &b, &c); //get env info
+    if(r > r_h)
+    {
+      r_h = r;
+    }
+    else if(g > g_h)
+    {
+      g_h = g;
+    }
+    else if (b_h < b)
+      {
+        b_h = b;
+      }
+    else
+    {
+       th_Val[7].r_t = ((float) r_h * thErrON);
+       th_Val[7].g_t = ((float) g_h * thErrON);
+        th_Val[7].b_t = ((float) b_h * thErrON);
+      break;
+    }
+  }
+
   while((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
   {
     tcs.getRawData(&r, &g, &b, &c);


Setting for trigger duration Preparatory work for timetable

--- ANI_CameraRemote/ANI_CameraRemote.ino
+++ ANI_CameraRemote/ANI_CameraRemote.ino
@@ -15,6 +15,8 @@
   20180506 Hint: Use ESP8266 V2.4.0 since V2.4.1 has problems
   20180510 First Version for M5Stack
   20180511 M5Stack: WiFi OFF by default, config menu, C button as value accelerator
+  20180528 Setting for trigger duration
+  20180528 Preparatory work for timetable
   --------------------------------------------------*/
 #ifdef ESP32
 #include <M5Stack.h>
@@ -42,6 +44,7 @@
 const unsigned long default_delayToStart = 0;      // Delay in seconds till start of timelapse
 const unsigned long default_numberOfShots = 10;    // Number of shots in timelapse mode
 const unsigned long default_delayBetweenShots = 5; // Delay between shots in timelapse mode
+const unsigned long default_triggerDuration = 0;   // Duration of trigger ON in seconds (0 = 250ms)
 const unsigned long default_autorefresh = 5;       // In timelapse mode autorefresh webGUI every 5 seconds, 0 = autorefresh off
 const int timelapseAutoStart = 0;                  // 1 = Autostart timelapse mode, 0 = No autostart

@@ -53,7 +56,7 @@

 // Global variables
 const String prgTitle = "ANI Camera Remote";
-const String prgVersion = "1.3";
+const String prgVersion = "1.4";
 const String screenHeaderLine = prgTitle + " " + prgVersion;
 const int versionMonth = 5;
 const int versionYear = 2018;
@@ -61,20 +64,37 @@
 const int timeSlot = 250; // timeslot in ms
 const int timeSlotsPerSecond = 1000 / timeSlot;

+// timeTable syntax:
+// Elements separated by comma
+// Elements can be:
+//   Delay between shots in seconds (e.g. 5)
+//   Repeat number * Delay between shots in seconds (e.g. 1000*13)
+//   _ and delay in seconds (do nothing) (e.g. _3600)
+//   ! and duration for trigger ON in seconds (e.g. !2), 0 = 250ms
+//
+// Examples:
+//   10,15,20,25,30
+//   _18000,50000*5,20000*10
+//   !5,50000*10
+String timeTable = ""; // only loadable via GET parameters, not in UI
+
 unsigned long delayToStart = default_delayToStart;
 unsigned long numberOfShots = default_numberOfShots;
 unsigned long delayBetweenShots = default_delayBetweenShots;
+unsigned long triggerDuration = default_triggerDuration;
 unsigned long autorefresh = default_autorefresh;
 unsigned long previousTimeSlotMillis = 0;
 unsigned long currentDelayToStart = 0;
 unsigned long currentNShots = 0;
-unsigned long NumberOfShotsSinceStart = 0; //
+unsigned long currentTDuration = 0;
+unsigned long NumberOfShotsSinceStart = 0;
 unsigned long currentDelayBetweenShots = 0;
+unsigned long currentTriggerDuration = 0;
 unsigned long currentAutorefresh = 0;
 int currentTimelapseAutoStart = timelapseAutoStart;

 unsigned long secCounter = 0; // count the seconds since start of timelapse
-unsigned long timeSlotCounter = 0; // count the timeslots since start of timelapse
+unsigned long timeSlotCounter = 0; // count the timeslots in a second

 int highlightLine = 2;
 int lastDialogLine = 8;
@@ -114,7 +134,7 @@

 void loop()
 {
-  process();
+  processTimeSlots();
   checkAndProcessStartPin();
   processKeyboard();
   if (wifiON)
@@ -149,7 +169,7 @@
         extractParams(sParam);
         process_mode();
       }
-      sResponse = generateHTMLPage(delayToStart, numberOfShots, delayBetweenShots);
+      sResponse = generateHTMLPage(delayToStart, numberOfShots, delayBetweenShots, triggerDuration);
       generateOKHTML(sResponse, sHeader);
     }
     else // 404 if error
@@ -175,6 +195,8 @@
     currentDelayToStart = 0;
     currentNShots = 0;
     currentDelayBetweenShots = 0;
+    currentTriggerDuration = 0;
+    currentTDuration = 0;
     currentExecMode == NONE;
   }
   else if (currentExecMode == TIMELAPSESTOP)
@@ -190,7 +212,9 @@
     delayToStart = default_delayToStart;
     numberOfShots = default_numberOfShots;
     delayBetweenShots = default_delayBetweenShots;
+    triggerDuration = default_triggerDuration;
     currentNShots = 0;
+    currentTDuration = 0;
     trigger(OFF);
     currentExecMode = NONE;
   }
@@ -205,6 +229,8 @@
     timeSlotCounter = 0;
     currentDelayToStart = delayToStart;
     currentDelayBetweenShots = delayBetweenShots;
+    currentTriggerDuration = triggerDuration;
+    currentTDuration = triggerDuration;
     NumberOfShotsSinceStart = 0;
     if (delayToStart == 0)
     {
@@ -218,7 +244,7 @@
   previousTimeSlotMillis = millis();
 }

-void process()
+void processTimeSlots()
 {
   checkInactivity();

@@ -226,16 +252,13 @@
     return;

   unsigned long currentTimeSlotMillis = millis();
+
   if ((currentTimeSlotMillis - previousTimeSlotMillis) > timeSlot) // 250 ms time slot
   {
-    if (currentTriggerMode == ON)
-    {
-      trigger(OFF);
-      if ((currentNShots <= 0) && (currentExecMode == TIMELAPSERUNNING))  // End of Timelapse mode
-        currentExecMode = TIMELAPSESTOP;
-    }
-
     previousTimeSlotMillis = currentTimeSlotMillis;
+
+    if ((currentTriggerMode == ON) && (currentTDuration == 0)) // only if trigger duration is 250ms
+      switchTriggerOffAndCheckStatus();

     timeSlotCounter++; // Count the timeslots
     if (timeSlotCounter == timeSlotsPerSecond)
@@ -243,13 +266,20 @@
       secCounter++; // Count the seconds
       timeSlotCounter = 0;

+      if ((currentTriggerMode == ON) && (currentTDuration > 0))
+      {
+        currentTDuration--;
+        if (currentTDuration == 0)
+          switchTriggerOffAndCheckStatus();
+      }
+
       if (currentDelayToStart > 0) // Start delay
       {
         currentDelayToStart--;
         onDisplay(MAINSCREEN);
       }
       else if (currentDelayBetweenShots > 0)
-        if ((secCounter % currentDelayBetweenShots ) == 0) // Delay between shots
+        if ((secCounter % currentDelayBetweenShots) == 0) // Delay between shots
         {
           if (currentNShots >= 1) // more than one shot timelapse?
           {
@@ -264,6 +294,14 @@
   }
 }

+void switchTriggerOffAndCheckStatus()
+{
+  trigger(OFF);
+  currentTDuration = currentTriggerDuration;
+  if ((currentNShots <= 0) && (currentExecMode == TIMELAPSERUNNING))  // End of Timelapse mode
+    currentExecMode = TIMELAPSESTOP;
+}
+
 void extractParams(String params)
 {
   params[0] = ' ';
@@ -318,12 +356,16 @@
         numberOfShots = elemValue.toInt();
       if (elemName == "DELAYBETWEENSHOTS")
         delayBetweenShots = elemValue.toInt();
+      if (elemName == "TRIGGERDURATION")
+        triggerDuration = elemValue.toInt();
+      if (elemName == "TIMETABLE")
+        timeTable = elemValue;
     }
     idx = par.indexOf("&");
   }
 }

-String generateHTMLPage(unsigned long sDelay, unsigned long nShots, unsigned long interval)
+String generateHTMLPage(unsigned long sDelay, unsigned long nShots, unsigned long interval, unsigned long tDuration)
 {
   String refreshLine = "";
   String remainingTimeLine = "";
@@ -368,6 +410,7 @@
                   "
Delay to start:	<input " + stateNotInTimelapse + " id=delayToStart name=delayToStart type=number min=0 step=1 value=" + String(sDelay) + "> sec
"
                   "
Number of shots:	<input " + stateNotInTimelapse + " id=numberOfShots name=numberOfShots type=number min=1 step=1 value=" + String(nShots) + ">
"
                   "
Interval:	<input " + stateNotInTimelapse + " id=delayBetweenShots name=delayBetweenShots type=number min=1 step=1 value=" + String(interval) + "> sec
"
+                  "
Trigger duration (0=250ms):	<input " + stateNotInTimelapse + " id=triggerDuration name=triggerDuration type=number min=0 step=1 value=" + String(tDuration) + "> sec
"
                   "

"
                   "

"
                   "
" + waitForGPIOLine + ""
@@ -521,15 +564,15 @@
         outLCD(2, "Delay to Start: " + String(delayToStart), TFT_WHITE);
         outLCD(3, "Number of Shots: " + String(numberOfShots), TFT_WHITE);
         outLCD(4, "Interval: " + String(delayBetweenShots), TFT_WHITE);
+        outLCD(5, "Trigger duration: " + String(triggerDuration), TFT_WHITE);
         if (startPin > -1)
-          outLCD(5, "Wait for GPIO" + String(startPin), TFT_YELLOW);
-        outLCD(6, "START", TFT_YELLOW);
-        outLCD(7, "STOP", TFT_YELLOW);
-        outLCD(8, "ONE SHOT", TFT_YELLOW);
-        outLCD(9, "RESET", TFT_YELLOW);
-        outLCD(10, "Remaining delay: " + String(currentDelayToStart), TFT_GREEN);
-        outLCD(11, "Remaining shots: " + String(currentNShots), TFT_GREEN);
-        lastDialogLine = 9;
+          outLCD(6, "Wait for GPIO" + String(startPin), TFT_YELLOW);
+        outLCD(7, "START", TFT_YELLOW);
+        outLCD(8, "STOP", TFT_YELLOW);
+        outLCD(9, "ONE SHOT", TFT_YELLOW);
+        outLCD(10, "RESET", TFT_YELLOW);
+        outLCD(11, "Rem. delay: " + String(currentDelayToStart) + " shots: " + String(currentNShots), TFT_GREEN);
+        lastDialogLine = 10;
         break;
       }
     case CONFIGSCREEN:
@@ -554,11 +597,12 @@
           case 2: delayToStart = limitsUpDown(upDownFactor, delayToStart, 0, LONG_MAX); break;
           case 3: numberOfShots = limitsUpDown(upDownFactor, numberOfShots, 1, LONG_MAX) ; break;
           case 4: delayBetweenShots = limitsUpDown(upDownFactor, delayBetweenShots, 1, LONG_MAX); break;
-          case 5: setAndDoProcessMode(WAITFORGPIO); break;
-          case 6: setAndDoProcessMode(TIMELAPSESTART); break;
-          case 7: setAndDoProcessMode(TIMELAPSESTOP); break;
-          case 8: setAndDoProcessMode(ONESHOT); break;
-          case 9: setAndDoProcessMode(RESET); break;
+          case 5: triggerDuration = limitsUpDown(upDownFactor, triggerDuration, 0, LONG_MAX); break;
+          case 6: setAndDoProcessMode(WAITFORGPIO); break;
+          case 7: setAndDoProcessMode(TIMELAPSESTART); break;
+          case 8: setAndDoProcessMode(TIMELAPSESTOP); break;
+          case 9: setAndDoProcessMode(ONESHOT); break;
+          case 10: setAndDoProcessMode(RESET); break;
         }
         break;
       }


format

format

--- examples/Widgets/Eventor/Eventor.ino
+++ examples/Widgets/Eventor/Eventor.ino
@@ -38,9 +38,9 @@

 void sendFlagToServer() {
   if (flag) {
-     Blynk.virtualWrite(V0, 1);
+    Blynk.virtualWrite(V0, 1);
   } else {
-     Blynk.virtualWrite(V0, 0);
+    Blynk.virtualWrite(V0, 0);
   }
   flag = !flag;
 }
@@ -59,8 +59,8 @@
 }

 BLYNK_WRITE(V1) {
-   //here you'll get 0 or 255
-   int ledValue = param.asInt();
+  //here you'll get 0 or 255
+  int ledValue = param.asInt();
 }

 void loop()


Add check for unsupported band

Add check for unsupported band

--- examples/raw-feather/raw-feather.ino
+++ examples/raw-feather/raw-feather.ino
@@ -266,6 +266,8 @@

   // default tx power for US: 21 dBm
   LMIC.txpow = 21;
+#else
+# error Unsupported LMIC regional configuration.
 #endif

   // disable RX IQ inversion


Update simple menu sketch, showing button, toggle button, dial and a callback

--- examples/simple_menu/simple_menu.ino
+++ examples/simple_menu/simple_menu.ino
@@ -1,34 +1,50 @@
 #include <Adafruit_GFX.h>    // Core graphics library
-#include <Adafruit_TFTLCD.h> // Hardware-specific library
-#include <TouchScreen.h>
+#include <ILI9341_t3.h>
+#include <UTouch.h>
 #include <gfx_ui.h>
+#include <SPI.h>

-TouchScreen ts = TouchScreen(6, A1, A2, 7, 300);
-Adafruit_TFTLCD tft(A3, A2, A1, A0, A4);
-GFX_UI ui(tft, ts, 179, 145, 856, 920);
+GFX_UI ui;

-uint16_t text_color = rgb(100, 100, 200);
-uint16_t button_color = rgb(0, 0, 100);
+Color text_color = {200, 200, 200};
+Color button_color = {80, 80, 80};

-uint16_t rgb(byte red, byte green, byte blue) {
-  return (((31*(red+4))/255)<<11) | (((63*(green+2))/255)<<5) | ((31*(blue+4))/255);
+void callback1(UIElement& caller) {
+	// If caller is needed, cast it like so:
+	// Button& call_button = static_cast<Button&>(caller);
+
+	Color new_color = {random(255), random(255), random(255)};
+	ui.set_bg_color(new_color);
+	Dial* pdial = static_cast<Dial*>(ui.get_element_by_name("dial"));
+	pdial->set_value(pdial->get_value()+5);
 }

-void callback1() {
-}
-Button button1 = Button(40, 40, tft.width()-80, 40, "Button 1", callback1, button_color, text_color);
+Button button1 = Button("button1", 40, 40, 0, 40, "Button 1", callback1, button_color, text_color);
+ToggleButton button2 = ToggleButton("button2", 40, 79, 0, 40, "Button 1", callback1, button_color.encode(), text_color.encode());
+Dial dial = Dial("dial", 0, 150, 20, -10, 100, 1, button_color, text_color);

-Label header = Label(0, 0, tft.width(), 20, "Testing", 2, 0, text_color);
+Label header = Label("label", 0, 0, 0, 20, "Testing", 2, 0, text_color.encode());
+unsigned long last_frame = millis();

 void setup(void) {
-  Serial.begin(9600);
+	Serial.begin(9600);
+	ui.init(0, 1);

-  tft.reset();
-  uint16_t identifier = tft.readID();
-  tft.begin(identifier);
+	// Set values that might depend on the ui rotation after initialising the ui.
+	button1.set_width(ui.width()-80);
+	button2.set_width(ui.width()-80);
+	header.set_width(ui.width());
+	dial.set_x(ui.width()/2);

-  ui.add(button1);
-  ui.add(header);
+	// Draw pretty background, before adding (and thereby drawing) elements
+	for (int y=0; y<ui.get_lcd().height(); y++) {
+		ui.get_lcd().drawLine(0, y, ui.get_lcd().width(), y, Color({y-150, y-150, y-150}));
+	}
+
+	ui.add(button1);
+	ui.add(button2);
+	ui.add(header);
+	ui.add(dial);
 }

 void loop() {


remove print for pins

remove print for pins

--- examples/adafruitio_secure_airlift/adafruitio_secure_airlift.ino
+++ examples/adafruitio_secure_airlift/adafruitio_secure_airlift.ino
@@ -76,7 +76,6 @@

   // if the AirLift's pins were defined above...
   #ifdef SET_PINS
-    Serial.println("Setting pins...");
     WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
   #endif


It takes 5 seconds for force to develop

It takes 5 seconds for force to develop

--- quick_release/quick_release.ino
+++ quick_release/quick_release.ino
@@ -11,7 +11,7 @@

 // Timing variables
 const int PREDELAY  = 10;      // in ms, before stim goes on
-const int STIMDELAY = 250;     // in ms, between stim and shutter
+const int STIMDELAY = 5000;    // in ms, between stim and shutter
 const int SHUTTERDELAY = 1000; // in µs, between shutter and length
 const int STEPDELAY = 200;     // in µs, between length and camera
 const int EXPOSUREDUR = 100;   // in µs, camera image duration  TODO: SEND THIS ONE OVER SERIAL TOO


Attempts at putting some debug code into system.

--- arduino/server_controlled_colours/server_controlled_colours.ino
+++ arduino/server_controlled_colours/server_controlled_colours.ino
@@ -34,7 +34,7 @@
 int blue = 0;
 int green = 0;

-//#define DEBUG
+#define DEBUG

 void setup() {
   // set up the devices
@@ -65,7 +65,12 @@
     #ifdef DEBUG
     Serial.println("Not Connected - check connection and start again");
     #endif
-    while (1) {}
+    while (1) {
+      //digitalWrite(13, HIGH);
+      //delay(1000);
+      //digitalWrite(13, LOW);
+      //delay(1000);
+    }
   }

   digitalWrite(13, HIGH);


Fix door sensor polarity

Fix door sensor polarity

The messages being published for door open/closed were
reversed - fix.


Typeatron's ping response

Typeatron's ping response

--- typeatron/mark1/arduino/typeatron/typeatron.ino
+++ typeatron/mark1/arduino/typeatron/typeatron.ino
@@ -264,7 +264,7 @@
     sprintf(errstr, "received OSC message of length %d to %s", length, buffer);
     sendInfo(errstr);

-    playMorseInt(length);
+    //playMorseInt(length);

     OSCMessage messageIn;

@@ -277,6 +277,7 @@
     } else {
         int called;
         called = messageIn.dispatch("/exo/tt/photo/get", receivePhotoGetMessage);
+        called = messageIn.dispatch("/exo/tt/ping", receivePingMessage);
         called = messageIn.dispatch("/exo/tt/rgb/set", receiveRgbSetMessage);
         called = messageIn.dispatch("/exo/tt/vibro", receiveVibroMessage);
     }
@@ -327,6 +328,14 @@
     sampler_photoresistor.endSample();

     sendLightLevel();
+}
+
+void receivePingMessage(class OSCMessage &m) {
+    // send reply as soon as possible
+    sendPingReply();
+
+    writeRGBColor(GREEN);
+    playMorseString("p");
 }

 void receiveRgbSetMessage(class OSCMessage &m) {


Switched if-else for switch-case

Switched if-else for switch-case

--- PySerial/Robust_Prompting_PythonCode_and_ArduinoSketch/robust.ino
+++ PySerial/Robust_Prompting_PythonCode_and_ArduinoSketch/robust.ino
@@ -1,4 +1,4 @@
-char ch;
+char char_input;

 void setup () {
   pinMode(13, OUTPUT);
@@ -8,23 +8,25 @@

 void loop() {

-  if (Serial.available())
+  if (Serial.available() > 0)
   {
-
-     ch = Serial.read();
-
-     if ( ch == '1' ) {
-       Serial.println(analogRead(A0)); // if '1' is received, then send back analog read A0
-     }
-     else if (ch == '2') {
+
+      char_input = Serial.read();
+
+      switch (char_input) {
+      case '1':
+        Serial.println(analogRead(A0)); // if '1' is received, then send back analog read A0
+      break;
+      case '2':
        digitalWrite(13,HIGH); // if '2' is received, turn on the led attached to 13
-     }
-     else if (ch == '3') {
+      break;
+      case '3':
        digitalWrite(13,LOW); // if '3' is received then turn off the led attached 13
-     } else {
-       delay(10);
-     }
-
+      break;
+      default:
+        delay(10);
+      break;
+      }
   }

 }


Prep for merge

Prep for merge

--- src/Gortobot_v3c.ino
+++ src/Gortobot_v3c.ino
@@ -1,5 +1,4 @@
 /* Gortobot v3c */
-

 // TODO: battery classes, abstract, fake
 // TODO: gps classes, abstract, fake


Update example.

Update example.

--- examples/mqtt/mqtt_super_simple/mqtt_super_simple.ino
+++ examples/mqtt/mqtt_super_simple/mqtt_super_simple.ino
@@ -9,22 +9,12 @@

 #include <pt.h>

-#ifdef ESP8266
-extern "C" {
-#include "user_interface.h"
-}
-#endif
-
-
-const char* ssid     = "NAT.WRTNODE";
-const char* pass     = "devicenetwork";
-
 MqttConnector *mqtt;
 WiFiConnector *wifi;

 void init_hardware()
 {
-  Serial.begin(115200);
+  Serial.begin(9600);
   delay(10);
   Serial.println();
   Serial.println("BEGIN");
@@ -34,61 +24,97 @@

 void init_wifi()
 {
-  wifi = new WiFiConnector(ssid, pass);
+  // use flash memory ssid & smartconfig
+  wifi = new WiFiConnector();
+
+  // wifi = new WiFiConnector(ssid, password);

   wifi->on_connecting([&](const void* message)
   {
-    Serial.print("connecting ");
-    Serial.println ((char*)message);
+    Serial.println("connecting ");
+    // Serial.println ((char*)message);
     delay(500);
   });

   wifi->on_connected([&](const void* message)
   {
-    Serial.print ("WIFI CONECTED: ");
-    Serial.println ((char*)message);
+    Serial.println("WIFI CONECTED: ");
+    // Print the IP address
+    Serial.println(WiFi.localIP());
+    // Serial.println ((char*)message);
   });

   wifi->on_disconnected([&](const void* message)
   {
-    Serial.print ("WIFI DISCONECTED: ");
-    Serial.print ("WIFI DISCONECTED: ");
-    Serial.print ("WIFI DISCONECTED: ");
-    Serial.println ((char*)message);
+    Serial.println("WIFI DISCONECTED.");
+    // Serial.println ((char*)message);
+  });
+
+  wifi->on_smartconfig_enter([&](const void* message)
+  {
+    Serial.println("ENTER SMARTCONFIG.");
+  });
+
+  wifi->on_smartconfig_done([&](const void* message)
+  {
+    Serial.println("SMARTCONFIG DONE.");
+  });
+
+  wifi->on_smartconfig_doing([&](const void* message)
+  {
+    // Serial.println("CONFIGURING WIFI..");
+    // delay(500);
   });

   wifi->connect();

 }
-
 void init_mqtt()
 {

-  mqtt = new MqttConnector("mqtt.tespa.io");
+  mqtt = new MqttConnector("iot.eclipse.org");
+  mqtt->prepare_configuration([&](MqttConnector::Config * config) -> void {
+    // do nothing.
+    Serial.print("HOST: ");
+    Serial.print(config->mqttHost);

-  mqtt->prepare_configuration([&](MqttConnector::Config * config) -> void {
+    Serial.print(" PORT: ");
+    Serial.println(config->mqttPort);

+    Serial.print("__PUBLICATION TOPIC -> ");
+    Serial.println(config->topicPub);
+    Serial.print("__SUBSCRIPTION TOPIC -> ");
+    Serial.println(config->topicSub);
   });
-
-  mqtt->prepare_configuration(NULL);

   mqtt->prepare_data([&](JsonObject * root) -> void {
     JsonObject& data = root->at("d");
-    // data["myName"] = "0x001";
+    data["myName"] = "NAzT";
     data["adc"] = analogRead(A0);
-    data["sdk"] = system_get_sdk_version();
-  }, 1500);
+    data["tag"] = "paris";
+    data["zone"] = "1";
+  }, 5000);

-  mqtt->prepare_subscribe(NULL);
   mqtt->prepare_subscribe([&](MQTT::Subscribe * sub) -> void {
-    // (sub)->add_topic("HELLO");
   });

   mqtt->after_prepare_data([&](JsonObject * root) -> void {
     JsonObject& data = root->at("d");
-    //delete data["version"];
+
+    // Serial.println("DATA: ");
+    // data.printTo(Serial);
+    // Serial.println();
+    // Serial.println();
+    // Serial.println();
+
+    data.remove("version");
+    data.remove("flash_id");
+    data.remove("flash_size");
+    data.remove("chip_id");
+    data.remove("sdk");
+    data.remove("counter");
   });

   mqtt->on_message([&](const MQTT::Publish & pub) -> void {
@@ -99,8 +125,13 @@
   });

   mqtt->on_connecting([&](int count, bool * flag) {
-    Serial.print("CONNECTION: ");
+    Serial.print("MQTT CONNECTING..: ");
     Serial.println(count);
+  });
+
+  mqtt->on_published([&](const MQTT::Publish & pub) -> void {
+    Serial.print("PUBLISHED: ");
+    Serial.println(pub.payload_string());
   });

   mqtt->connect();


Delete LedMatrix_Code.ino

Delete LedMatrix_Code.ino

--- libraries/LedMatrix/LedMatrix_Code/LedMatrix_Code.ino
+++ libraries/LedMatrix/LedMatrix_Code/LedMatrix_Code.ino
@@ -1,34 +0,0 @@
-#include <LedMatrix.h>
-
-LedMatrix ledmatrix(11, 13, 12);
-
-void setup() {
-  Serial.begin(115200);
-
-  ledmatrix.writeFull(0x3FFFFFFF);
-  delay(1000);
-
-  ledmatrix.clearMatrix();
-  delay(1000);
-
-}
-
-void loop() {
-  ledmatrix.setLed(1, 1);
-  ledmatrix.setLed(2, 2);
-  ledmatrix.setLed(3, 3);
-  ledmatrix.setLed(4, 4);
-  ledmatrix.setLed(5, 5);
-
-
-  printLong(ledmatrix.readFull());
-}
-
-void printLong(unsigned long toprint) {
-  unsigned long i;
-  for(i = 0; i < 32; i++) {
-    if(toprint & (1L << (31 - i))) Serial.print("1");
-    else Serial.print("0");
-  }
-  Serial.println("");
-}


Achieved communication with ESP8266!

Achieved communication with ESP8266!

--- software/_proto_ESPTesting/ESPNano/ESPNano.ino
+++ software/_proto_ESPTesting/ESPNano/ESPNano.ino
@@ -4,18 +4,18 @@
 #define PASS    "27304600"
 #define DST_IP  "220.181.111.85"

-SoftwareSerial dbgSerial(11, 10);
+SoftwareSerial dbgSerial(11, 10); //Rx, Tx

 void setup(){
 	//Open serial communication
-	Serial.begin(115200);
+	Serial.begin(9600);
 	Serial.setTimeout(5000);

-	dbgSerial.begin(57600);
+	dbgSerial.begin(9600);
 	dbgSerial.println("ESP8266 Demo");

 	//Test if the module is ready
-	Serial.println("AT");
+	Serial.print("AT\015\012");
 	delay(2000);
 	if(Serial.available())
 	{
@@ -30,6 +30,6 @@

 void loop(){
 	if(Serial.available()){
-		dbgSerial.print(Serial.read(), DEC);
+		dbgSerial.print((char) Serial.read());
 	}
 }


Enable receive LED.

Enable receive LED.

--- Arduino/sketches/LazerTagRelay/LazerTagRelay.ino
+++ Arduino/sketches/LazerTagRelay/LazerTagRelay.ino
@@ -29,6 +29,7 @@
   Serial.println(LAZERTAG_IR_VERSION_FULL);
   Serial.println("Start");
   lazerTagReceive.enableIRIn();
+  lazerTagReceive.blink13(true);
 }

 void loop()


baudrate updated

baudrate updated

--- PaperTapePuncher.ino
+++ PaperTapePuncher.ino
@@ -54,7 +54,7 @@

 void setup() {
   // initialize serial communication at 9600 bits per second:
-  Serial.begin(115200);
+  Serial.begin(38400);

   // initialize the input pins
   pinMode(PinBit0, OUTPUT); // bit 0


Small edit

Small edit

--- src/HC_NodeMcuCode.ino
+++ src/HC_NodeMcuCode.ino
@@ -48,12 +48,12 @@
   ****************************************************/

 // Note: Libaries are inluced in "Project Dependencies" file platformio.ini
+#include <private.h>         // Passwords etc not for github
 #include <ESP8266WiFi.h>     // ESP8266 core for Arduino https://github.com/esp8266/Arduino
 #include <PubSubClient.h>    // Arduino Client for MQTT https://github.com/knolleary/pubsubclient
 #include <RCSwitch.h>        // RF control lib, https://github.com/sui77/rc-switch
 #include <DHT.h>             // DHT Sensor lib, https://github.com/adafruit/DHT-sensor-library
 #include <Adafruit_Sensor.h> // Have to add for the DHT to work https://github.com/adafruit/Adafruit_Sensor
-#include <private.h>         // Passwords etc not for github
 #include <ESP8266mDNS.h>     // Needed for Over-the-Air ESP8266 programming https://github.com/esp8266/Arduino
 #include <WiFiUdp.h>         // Needed for Over-the-Air ESP8266 programming https://github.com/esp8266/Arduino
 #include <ArduinoOTA.h>      // Needed for Over-the-Air ESP8266 programming https://github.com/esp8266/Arduino
@@ -521,7 +521,7 @@
   // Initialize pin start values
   digitalWrite(DIGITAL_PIN_LED_NODEMCU, LOW); // Lights on HIGH
   digitalWrite(DIGITAL_PIN_LED_ESP, HIGH); // Lights on LOW
-  // set serial speed
+  // Set serial speed
   Serial.begin(115200);
   Serial.println("Setup Starting");


Allow setting an alarm from the keypad!

Allow setting an alarm from the keypad!

--- menu.ino
+++ menu.ino
@@ -1,7 +1,13 @@
+#include <string.h>
+
 #include "time.h"

 #include "menu.h"
 #include "pcd8544.h"
+
+char input_buffer[4] = {'\0', '\0', '\0', '\0'};
+char clock[6] = {'0', '0', ':', '0', '0', '\0'};
+uint8_t current_i = 0;

 void menu_init(void) {
     pcd8544_clear();
@@ -13,11 +19,71 @@
     pcd8544_write_string(clock);
 }

+static inline bool input_past_twelve(void) {
+    return input_buffer[0] > '2' || (input_buffer[0] == '2' && input_buffer[1] > '4');
+}
+
+static inline void clear_input(void) {
+    memset(input_buffer, 0x00, 4);
+    sprintf(clock, "00:00");
+    current_i = 0;
+}
+
+static inline void update_drawn_clock_from_input(void) {
+    uint8_t i = current_i % 4;
+    if (i == 0)
+        sprintf(clock, "00:00");
+    else if (i == 1)
+        sprintf(clock, "0%c:00", input_buffer[0]);
+    else if (i == 2) {
+        if (input_past_twelve())
+            sprintf(clock, "0%c:0%c", input_buffer[0], input_buffer[1]);
+        else
+            sprintf(clock, "%c%c:00", input_buffer[0], input_buffer[1]);
+    } else if (i == 3) {
+        if (input_past_twelve()) {
+            if (input_buffer[1] > '5')
+                clear_input();
+            else
+                sprintf(clock, "0%c:%c%c", input_buffer[0], input_buffer[1], input_buffer[2]);
+        } else {
+            if (input_buffer[2] > '5')
+                sprintf(clock, "%c%c:0%c", input_buffer[0], input_buffer[1], input_buffer[2]);
+            else
+                sprintf(clock, "%c%c:%c0", input_buffer[0], input_buffer[1], input_buffer[2]);
+        }
+    } else {
+        if (input_past_twelve() || input_buffer[2] > '5')
+            clear_input();
+        else
+            sprintf(clock, "%c%c:%c%c", input_buffer[0], input_buffer[1], input_buffer[2], input_buffer[3]);
+    }
+}
+
+static inline void persist_clock_as_alarm(void) {
+    time_t alarm = (clock[4] - '0') * SECS_PER_MIN;
+    alarm += (clock[3] - '0') * SECS_PER_MIN * 10;
+    alarm += (clock[1] - '0') * SECS_PER_HOUR;
+    alarm += (clock[0] - '0') * SECS_PER_HOUR * 10;
+
+    time_t elapsed_now = elapsed_seconds_today(current_timestamp);
+    if (elapsed_now > alarm)
+        alarm += SECS_PER_DAY;
+    alarm_set_default_timestamp(current_timestamp - elapsed_now + alarm);
+}
+
 void menu_action(char button) {
     last_menu_action_time = current_timestamp;
-    char data[27];
-    snprintf(data, 27, "The button '%c' was pressed", button);
-    menu_content(data);
+    if ('0' <= button && button <= '9') {
+        input_buffer[current_i++ % 4] = button;
+        update_drawn_clock_from_input();
+        pcd8544_draw_big_clock(clock);
+    } else {
+        // TODO make an actual menu?
+        char data[27];
+        snprintf(data, 27, "The button '%c' was pressed", button);
+        menu_content(data);
+    }
 }

 void menu_title(const char * title) {
@@ -33,11 +99,17 @@
 }

 void menu_check_state(void) {
-    char clock[6];
-    snprintf(clock, 6, "%02lu:%02lu", get_hour(current_timestamp), get_minute(current_timestamp));
+    if (!current_i)
+        sprintf(clock, "%02lu:%02lu", get_hour(current_timestamp), get_minute(current_timestamp));
+
     if (last_menu_action_time > (current_timestamp - 15)) {
         pcd8544_set_backlight_state(true);
-        menu_redraw_clock(clock);
+        if (current_i) {
+            pcd8544_draw_big_clock(clock);
+            if (last_menu_action_time < (current_timestamp - 10))
+                persist_clock_as_alarm();
+        } else
+            menu_redraw_clock(clock);
     } else {
         pcd8544_draw_big_clock(clock);
         if (backlight_blinking)


add yaac instructions to example

add yaac instructions to example

--- examples/KISS/KISS.ino
+++ examples/KISS/KISS.ino
@@ -7,6 +7,16 @@
  * into the HamShield RF jack. Connect the Arduino to wall
  * power and then to your computer via USB. Issue commands
  * via the KISS equipment.
+ *
+ * To use the KISS example with YAAC:
+ * 1. open the configure YAAC wizard
+ * 2. follow the prompts and enter in your details until you get to the "Add and Configure Interfaces" window
+ * 3. Choose "Add Serial KISS TNC Port"
+ * 4. Choose the COM port for your Arduino
+ * 5. set baud rate to 9600 (default)
+ * 6. set it to KISS-only: with no command to enter KISS mode (just leave the box empty)
+ * 7. Use APRS protocol (default)
+ * 8. hit the next button and follow directions to finish configuration
 */

 #include <HamShield.h>


Update sketch_aug08b.ino

Update sketch_aug08b.ino

--- plane/RECEIVER/sketch_aug08b/sketch_aug08b.ino
+++ plane/RECEIVER/sketch_aug08b/sketch_aug08b.ino
@@ -1,4 +1,5 @@
 /*
+*
 * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
 */
 struct dataStruct{
@@ -7,7 +8,6 @@
   int angleV2;
 }myData1;

-int value = 0; // set values you need to zero
 #include <SPI.h>
 #include <nRF24L01.h>
 #include <RF24.h>
@@ -18,7 +18,6 @@
 Servo myServo;
 Servo myServo1;
 Servo firstESC;
-boolean buttonState = 0;
 void setup() {
   pinMode(button, INPUT);
   myServo.attach(5);
@@ -28,8 +27,7 @@
   radio.openWritingPipe(addresses[0]); // 00002
   radio.openReadingPipe(1, addresses[1]); // 00001
       radio.setPALevel(RF24_PA_MAX);
-      radio.setDataRate(RF24_250KBPS);
-
+      radio.setDataRate(RF24_250KBPS);
       radio.setRetries(15,15);

   Serial.begin(115200);
@@ -61,7 +59,6 @@

              firstESC.writeMicroseconds( myData1.angleV2);
                if(Serial.available())
-               value = Serial.parseInt();
                Serial.println( myData1.angleV);
                Serial.println( myData1.angleV1);
                Serial.println( myData1.angleV2);