v6.0 Remove 16x2 LCD

v6.0 Remove 16x2 LCD

--- GPSLCD.ino
+++ GPSLCD.ino
@@ -5,14 +5,11 @@

   This program communicate with the u-blox NEO-6M GPS module
   through a software serial interface. It then displays certain GPS
-  parameters on a I2C 16x2 (or 20x4) character LCD display module. The
+  parameters on a I2C 20x4 character LCD display module. The
   GPS messages are received by the on-board Arduino UART circuit using
   the SoftwareSerial library. It then uses the TinyGPS++ library to
   decode the GPS NMEA messages. The parameters are then displayed on a
-  16x4 (or 20x4) LCD using the LiquidCrystal_I2C library.
-
-  Note: Both the 16x2 and 20x4 LCDs are supported as these are the most popular
-        LCDs available.
+  20x4 LCD using the LiquidCrystal_I2C library.

    The MIT License (MIT)

@@ -42,27 +39,21 @@

 TinyGPSPlus gps; // This is the GPS object that will pretty much do all the grunt work with the NMEA data
 SoftwareSerial GPSModule(10, 11); // RX, TX
+// Initializes class variables and defines the I2C address of the LCD
 LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
-// Initializes class variables and defines the I2C address of the LCD

 // The setup (runs once at start up)
 void setup()
 {
-  pinMode(BACKLIGHT_SW, INPUT);
-
-#ifdef _16x2
-  // Selects either speed or heading to be displayed
-  pinMode(SPEED_ALTITUDE_SW, INPUT);
-#else
+  pinMode (BACKLIGHT_SW, INPUT);
   // Selects either altitude or the date/time to be displayed
-  pinMode(ALTITUDE_DATE_TIME_SW, INPUT);
+  pinMode (ALTITUDE_DATE_TIME_SW, INPUT);
   // Select switches
-  pinMode(DISPLAY_12_HOUR_SW, INPUT);
-  pinMode(CONVERT_TO_LOCAL_SW, INPUT);
-  pinMode(DISPLAY_HDOP_SW, INPUT);
-  pinMode(CARDINAL_SW, INPUT);
-  pinMode(LOW_SPEED_OVERRIDE, INPUT);
-#endif
+  pinMode (DISPLAY_12_HOUR_SW, INPUT);
+  pinMode (CONVERT_TO_LOCAL_SW, INPUT);
+  pinMode (DISPLAY_HDOP_SW, INPUT);
+  pinMode (CARDINAL_SW, INPUT);
+  pinMode (LOW_SPEED_OVERRIDE, INPUT);
   pinMode (ON_BOARD_LED, OUTPUT); // Turn off on-board LED
   digitalWrite (ON_BOARD_LED, LOW); //       "

@@ -70,9 +61,9 @@
   GPSModule.flush();

   lcd.begin (COLUMN, ROW); // Defines LCD type
-  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); // Sets the pin to control the backlight
+  lcd.setBacklightPin (BACKLIGHT_PIN, POSITIVE); // Sets the pin to control the backlight
   lcd.clear(); // Clear the LCD
-  lcd.home (); // Go to the home position on the LCD
+  lcd.home(); // Go to the home position on the LCD
 } // setup

 // The loop (runs forever and a day :-))
@@ -89,37 +80,37 @@
   bool dataValid; // Data valid from the GPS module
   GPSStruct GPSData; // Holds the GPS data coming from the GPS module
   unsigned long now = millis(); // The time "now"
-#ifndef _16x2
   static unsigned long prevDateTime = TOGGLETIME_INTERVAL;
   static unsigned long prevHeadingTime = TOGGLETIME_INTERVAL;
   static unsigned long prevHdopTime = TOGGLETIME_INTERVAL;
   static bool dateTimeToggle = true;
   static bool headingToggle = true;
   static bool hdopToggle = true;
-  bool display12_24_Hour = !digitalRead(DISPLAY_12_HOUR_SW);
-  bool localUTCTimeDate = !digitalRead(CONVERT_TO_LOCAL_SW);
-  bool displayHdop = !digitalRead(DISPLAY_HDOP_SW);
-  bool cardinal8_16 = !digitalRead(CARDINAL_SW);
-  bool lowSpeedOverride = !digitalRead(LOW_SPEED_OVERRIDE);
-#endif
+  bool display12_24_Hour = !digitalRead (DISPLAY_12_HOUR_SW);
+  bool localUTCTimeDate = !digitalRead (CONVERT_TO_LOCAL_SW);
+  bool displayHdop = !digitalRead (DISPLAY_HDOP_SW);
+  bool cardinal8_16 = !digitalRead (CARDINAL_SW);
+  bool lowSpeedOverride = !digitalRead (LOW_SPEED_OVERRIDE);
+
 #ifdef DATA_VALID_OVERRIDE
   const bool dataValidOverride = true; // Set true to override data valid for debugging
 #else
   const bool dataValidOverride = false; // Set false not to override data valid
 #endif
+
 #ifdef BACKLIGHT_OVERRIDE
   // Override LCD backlight switch
   // Force LCD backlight on/off
-  lcd.setBacklight(BACKLIGHT_ONOFF);
+  lcd.setBacklight (BACKLIGHT_ONOFF);
 #else
   // Turn LCD backlight on/off
-  lcd.setBacklight(digitalRead(BACKLIGHT_SW));
+  lcd.setBacklight (digitalRead (BACKLIGHT_SW));
 #endif

   // Get the data from the GPS module
   while (GPSModule.available()) // While there are characters coming from the GPS module
   {
-    bool b = gps.encode(GPSModule.read()); // This feeds the serial NMEA data into the GPS library one char at a time
+    bool b = gps.encode (GPSModule.read()); // This feeds the serial NMEA data into the GPS library one char at a time
   }
   // Get the GPS data valid flags
   dataValid =
@@ -140,7 +131,6 @@
     GPSData.lon        = gps.location.lng();
     GPSData.speed      = gps.speed.mph();
     GPSData.altitude   = gps.altitude.feet();
-#ifndef _16x2
     GPSData.heading    = gps.course.deg();
     GPSData.hdop       = gps.hdop.value();
     GPSData.year       = gps.date.year();
@@ -149,7 +139,6 @@
     GPSData.hour       = gps.time.hour();
     GPSData.minute     = gps.time.minute();
     GPSData.second     = gps.time.second();
-#endif // #ifndef _16x2
 #else // #ifndef DATA_VALID_OVERRIDE
     // Store the fake GPS data (for debugging)
     GPSData.satellites = 0; // Invalid satellites
@@ -157,7 +146,6 @@
     GPSData.lon        = -74.00d; //   "
     GPSData.speed      = 5.0d;
     GPSData.altitude   = 555.0d;
-#ifndef _16x2
     GPSData.heading    = 60.0d; // ENE or NE (16 cardinal points or 8 cardinal points)
     GPSData.hdop       = 150; // 1.5
     GPSData.year       = 2017;
@@ -166,87 +154,22 @@
     GPSData.hour       = 23; // 7pm my local time
     GPSData.minute     = 10;
     GPSData.second     = 25;
-#endif // #ifndef _16x2
 #endif // #ifndef DATA_VALID_OVERRIDE
+
     // Clear the screen once when leaving initialization
     if (!leftInitialization) {
       leftInitialization = true;
       lcd.clear(); // Clear the LCD
     }
-    // Display the latest info from the gps object which it derived from the data sent by the GPS unit
+
+    // Display the latest info from the gps object
+    // which it derived from the data sent by the GPS unit
     // Send data to the LCD
-#ifdef _16x2 //------------------------------------------------------
-    lcd.home (); // Go to 1st line
-    lcd.print("Lat: ");
-    lcd.print(GPSData.lat);
-    lcd.setCursor (11, 0);
-    lcd.print("SV:");
-    if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0)) {
-      pastSatellites = GPSData.satellites;
-      if (GPSData.satellites == 0) {
-        // Toggle invalid satellites indicator every TOGGLETIME_INTERVAL seconds
-        if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL / 4) {
-          prevInvalidSatellitesTime = now;
-          if (invalidSatellitesToggle) {
-            invalidSatellitesToggle = false;
-            lcd.print("XX");
-          }
-          else {
-            invalidSatellitesToggle = true;
-            lcd.print("  ");
-          } // if (invalidSatellitesToggle)
-        } // if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL)
-      } // if (GPSData.satellites == 0)
-      else if (GPSData.satellites <= 9) {
-        lcd.print(" "); // Blank leading char
-        lcd.print(GPSData.satellites);
-      }
-      else {
-        lcd.print(GPSData.satellites);
-      }
-    } // if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0))
-    lcd.setCursor (0, 1); // Go to 2nd line
-    lcd.print("Lon: ");
-    lcd.print(GPSData.lon);
-    if ((digitalRead(SPEED_ALTITUDE_SW))) {
-      lcd.setCursor (12, 1);
-      if ((GPSData.speed < SPEED_CUTOUT) && (lowSpeedOverride)) {
-        lcd.print("0  ");
-      }
-      else {
-        lcd.print((int16_t)GPSData.speed);
-        lcd.print(" "); // Clear the extra char
-      }
-    }
-    else {
-      lcd.print("     "); // Clear the extra chars
-      if (GPSData.altitude <= 99.9) {
-        lcd.setCursor (14, 1);
-      }
-      else {
-        lcd.setCursor (13, 1);
-      }
-      lcd.print((int16_t)GPSData.altitude); // Altitude
-      // Toggle credit every TOGGLETIME_INTERVAL seconds
-      if (now - prevCreditTime > (TOGGLETIME_INTERVAL / 2)) {
-        prevCreditTime = now;
-        if (creditToggle) { // Display credit
-          creditToggle = false;
-          lcd.print("     "); // Clear the extra chars
-          lcd.print(CREDIT); // Yours truly :-)
-        }
-        else {
-          creditToggle = true;
-          lcd.print("        "); // Clear the extra chars
-        }
-      } // if (now - prevCreditTime > TOGGLETIME_INTERVAL)
-    } // if ((digitalRead(SPEED_ALTITUDE_SW)))
-#else // 20x4 ----------------------------------------------------
-    lcd.home (); // Go to 1st line
-    lcd.print("Lat: ");
-    lcd.print(GPSData.lat);
+    lcd.home(); // Go to 1st line
+    lcd.print ("Lat: ");
+    lcd.print (GPSData.lat);
     lcd.setCursor (15, 0);
-    lcd.print("SV:");
+    lcd.print ("SV:");
     if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0)) {
       pastSatellites = GPSData.satellites;
       if (GPSData.satellites == 0) {
@@ -255,35 +178,35 @@
           prevInvalidSatellitesTime = now;
           if (invalidSatellitesToggle) {
             invalidSatellitesToggle = false;
-            lcd.print("XX");
+            lcd.print ("XX");
           }
           else {
             invalidSatellitesToggle = true;
-            lcd.print("  ");
+            lcd.print ("  ");
           } // if (invalidSatellitesToggle)
         } // if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL)
       } // if (GPSData.satellites == 0)
       else if (GPSData.satellites <= 9) {
-        lcd.print(" "); // Blank leading char
-        lcd.print(GPSData.satellites);
+        lcd.print (" "); // Blank leading char
+        lcd.print (GPSData.satellites);
       }
       else {
-        lcd.print(GPSData.satellites);
+        lcd.print (GPSData.satellites);
       }
     } // if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0))
     lcd.setCursor (0, 1); // Go to 2nd line
-    lcd.print("Lon: ");
-    lcd.print(GPSData.lon);
+    lcd.print ("Lon: ");
+    lcd.print (GPSData.lon);
     // Only display if time/date is selected
-    if ((digitalRead(ALTITUDE_DATE_TIME_SW))) {
+    if ((digitalRead (ALTITUDE_DATE_TIME_SW))) {
       if (!localUTCTimeDate) {
-        lcd.print("      "); // Clear the extra chars
-        uint8_t DOW = dayOfWeek(GPSData.year, GPSData.month, GPSData.day);
-        if (IsDST(GPSData.day, GPSData.month, DOW)) {
-          lcd.print("DST");
+        lcd.print ("      "); // Clear the extra chars
+        uint8_t DOW = dayOfWeek (GPSData.year, GPSData.month, GPSData.day);
+        if (IsDST (GPSData.day, GPSData.month, DOW)) {
+          lcd.print ("DST");
         }
         else {
-          lcd.print(" ST");
+          lcd.print (" ST");
         }
       }
       else { // if (!localUTCTimeDate)
@@ -291,25 +214,25 @@
         displayHdopOnLCD (GPSData.hdop, displayHdop, now,
                           &prevHdopTime, &hdopToggle);
       } // if (!localUTCTimeDate)
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
+    } // if ((digitalRead (ALTITUDE_DATE_TIME_SW)))
     else {
       // Display Hdop
       displayHdopOnLCD (GPSData.hdop, displayHdop, now,
                         &prevHdopTime, &hdopToggle);
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
+    } // if ((digitalRead (ALTITUDE_DATE_TIME_SW)))
     lcd.setCursor (0, 2); // Go to 3rd line
-    lcd.print("Spd: ");
+    lcd.print ("Spd: ");
     if ((GPSData.speed < SPEED_CUTOUT) && (lowSpeedOverride)) {
-      lcd.print("0  ");
+      lcd.print ("0  ");
     }
     else {
-      lcd.print((int16_t)GPSData.speed);
-      lcd.print(" "); // Clear the extra chars
+      lcd.print ((int16_t)GPSData.speed);
+      lcd.print (" "); // Clear the extra chars
     } // if ((GPSData.speed < SPEED_CUTOUT) && (lowSpeedOverride))
     lcd.setCursor (12, 2);
-    lcd.print("Hdg: ");
+    lcd.print ("Hdg: ");
     if ((GPSData.speed < SPEED_CUTOUT) && (lowSpeedOverride)) {
-      lcd.print("0  ");
+      lcd.print ("0  ");
     }
     else {
       // Toggle heading every TOGGLETIME_INTERVAL seconds
@@ -317,33 +240,33 @@
         prevHeadingTime = now;
         if (headingToggle) { // Display cardinal heading
           headingToggle = false;
-          lcd.print(cardinal(GPSData.heading, cardinal8_16));
+          lcd.print (cardinal (GPSData.heading, cardinal8_16));
         }
         else { // Display degrees heading
           headingToggle = true;
-          lcd.print((int16_t)GPSData.heading);
-          if (GPSData.heading <= 99.9) lcd.print(" "); // Clear the extra char
+          lcd.print ((int16_t)GPSData.heading);
+          if (GPSData.heading <= 99.9) lcd.print (" "); // Clear the extra char
         } // if (headingToggle)
       } // if (now - prevHeadingTime > TOGGLETIME_INTERVAL)
     } // if ((GPSData.speed < SPEED_CUTOUT) && (lowSpeedOverride))
     lcd.setCursor (0, 3); // Go to 4th line
-    if ((digitalRead(ALTITUDE_DATE_TIME_SW))) {
-      lcd.print("Alt: ");
-      lcd.print((int16_t)GPSData.altitude);
+    if ((digitalRead (ALTITUDE_DATE_TIME_SW))) {
+      lcd.print ("Alt: ");
+      lcd.print ((int16_t)GPSData.altitude);
       // Toggle credit every TOGGLETIME_INTERVAL seconds
       if (now - prevCreditTime > (TOGGLETIME_INTERVAL / 2)) {
         prevCreditTime = now;
         if (creditToggle) { // Display credit
           creditToggle = false;
-          lcd.print("         "); // Clear the extra chars
-          lcd.print(CREDIT); // Yours truly :-)
+          lcd.print ("         "); // Clear the extra chars
+          lcd.print (CREDIT); // Yours truly :-)
         }
         else {
           creditToggle = true;
-          lcd.print("            "); // Clear the extra chars
+          lcd.print ("            "); // Clear the extra chars
         }
       } // if (now - prevCreditTime > TOGGLETIME_INTERVAL)
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
+    } // if ((digitalRead (ALTITUDE_DATE_TIME_SW)))
     else {
       // Toggle date/time every TOGGLETIME_INTERVAL seconds
       if (now - prevDateTime > TOGGLETIME_INTERVAL) {
@@ -351,7 +274,7 @@
         if (dateTimeToggle) {
           // Display time
           dateTimeToggle = false;
-          lcd.print("Time: ");
+          lcd.print ("Time: ");
           uint8_t hour = GPSData.hour;
           uint8_t day  = GPSData.day;
           uint8_t month = GPSData.month;
@@ -376,104 +299,83 @@
               strcpy (AMPM, "pm");
             }
           } // if (display12_24_Hour)
-          if (hour < 10) lcd.print("0");
-          lcd.print(hour);
-          lcd.print(":");
-          if (GPSData.minute < 10) lcd.print("0");
-          lcd.print(GPSData.minute);
-          lcd.print(":");
-          if (GPSData.second < 10) lcd.print("0");
-          lcd.print(GPSData.second);
+          if (hour < 10) lcd.print ("0");
+          lcd.print (hour);
+          lcd.print (":");
+          if (GPSData.minute < 10) lcd.print ("0");
+          lcd.print (GPSData.minute);
+          lcd.print (":");
+          if (GPSData.second < 10) lcd.print ("0");
+          lcd.print (GPSData.second);
           if (display12_24_Hour) {
-            lcd.print(AMPM);
+            lcd.print (AMPM);
           }
           if (localUTCTimeDate) {
             if (display12_24_Hour) {
-              (DST) ? lcd.print(" DST") : lcd.print("  ST");
+              (DST) ? lcd.print (" DST") : lcd.print ("  ST");
             }
             else {
-              (DST) ? lcd.print("   DST") : lcd.print("    ST");
+              (DST) ? lcd.print ("   DST") : lcd.print ("    ST");
             } // if (display12_24_Hour)
           } // if (localUTCTimeDate)
           if (!localUTCTimeDate) {
             if (display12_24_Hour) {
-              lcd.print(" UTC");
+              lcd.print (" UTC");
             }
             else {
-              lcd.print("   UTC");
+              lcd.print ("   UTC");
             } // if (display12_24_Hour)
           } // if (!localUTCTimeDate)
         } // if (dateTimeToggle)
         else {
           // Display date
           dateTimeToggle = true;
-          lcd.print("Date: ");
+          lcd.print ("Date: ");
           uint8_t hour = GPSData.hour;
           uint8_t day  = GPSData.day;
           uint8_t month = GPSData.month;
           uint16_t year = GPSData.year;
-          bool DST = false;
           if (localUTCTimeDate) {
             // Convert UTC date to local date
-            DST = convertToLocal (&hour, &year, &month,
-                                  &day, GPSData.lon, true); // true means date conversion
+            bool DST = convertToLocal (&hour, &year, &month,
+                                       &day, GPSData.lon, true); // true means date conversion
           } // if (localUTCTimeDate)
-          if (month < 10) lcd.print("0");
-          lcd.print(month);
-          lcd.print("/");
-          if (day < 10) lcd.print("0");
-          lcd.print(day);
-          lcd.print("/");
-          lcd.print(year);
-          printDay (dayOfWeek (year, month, day));
+          if (month < 10) lcd.print ("0");
+          lcd.print (month);
+          lcd.print ("/");
+          if (day < 10) lcd.print ("0");
+          lcd.print (day);
+          lcd.print ("/");
+          lcd.print (year);
+          displayDayOnLCD (dayOfWeek (year, month, day));
         } // if (dateTimeToggle)
       } // if (now - prevDateTime > TOGGLETIME_INTERVAL)
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
-#endif //------------------------------------------------------------
+    } // if ((digitalRead (ALTITUDE_DATE_TIME_SW)))
   } // if (dataValid)
   else {
     // GPS data is not valid, so it must be initializing
-#ifdef _16x2 //------------------------------------------------------
-    // Display initialization screen once every INITIALIZATION_INTERVAL
-    if (now - prevInitializationTime > INITIALIZATION_INTERVAL) {
-      prevInitializationTime = now;
-      lcd.setCursor (6, 0); // Go to 1st line
-      lcd.print("GPS");
-      lcd.setCursor (11, 0);
-      lcd.print("v");
-      lcd.print(VERSION);
-      lcd.setCursor (2, 1); // Go to 2nd line
-      lcd.print("Initializing");
-      lcd.setCursor (15, 1);
-      if (++initializingCounter > 9) initializingCounter = 1; // Limit 1 - 9
-      lcd.print(initializingCounter);
-      leftInitialization = false;
-    }
-#else // 20x4 -------------------------------------------------------
     // Display initialization screen once every INITIALIZATION_INTERVAL
     if (now - prevInitializationTime > INITIALIZATION_INTERVAL) {
       prevInitializationTime = now;
       lcd.setCursor (8, 0); // Go to 1st line
-      lcd.print("GPS");
+      lcd.print ("GPS");
       lcd.setCursor (14, 0);
-      lcd.print("v");
-      lcd.print(VERSION);
+      lcd.print ("v");
+      lcd.print (VERSION);
       lcd.setCursor (4, 1); // Go to 2nd line
-      lcd.print("Initializing");
+      lcd.print ("Initializing");
       lcd.setCursor (6, 2); // Go to 3rd line
-      lcd.print("Data Not");
+      lcd.print ("Data Not");
       lcd.setCursor (7, 3); // Go to 4th line
-      lcd.print("Valid");
+      lcd.print ("Valid");
       lcd.setCursor (19, 3);
       if (++initializingCounter > 9) initializingCounter = 1; // Limit 1 - 9
-      lcd.print(initializingCounter);
+      lcd.print (initializingCounter);
       leftInitialization = false;
     }
-#endif //------------------------------------------------------------
   } // GPS data is not valid
 } // loop

-#ifndef _16x2
 /* Helper functions start here

   Ripped off from Electrical Engineering Stack Exchange
@@ -509,24 +411,24 @@
 //----------------------------------------------------------

 // Print the day of the week on the LCD
-void printDay(uint8_t day)
+void displayDayOnLCD (uint8_t day)
 {
   if (day == 7) day = 0;
   switch (day)
   {
-    case 0:  lcd.print(" Mon"); break;
-    case 1:  lcd.print(" Tue"); break;
-    case 2:  lcd.print(" Wed"); break;
-    case 3:  lcd.print(" Thu"); break;
-    case 4:  lcd.print(" Fri"); break;
-    case 5:  lcd.print(" Sat"); break;
-    case 6:  lcd.print(" Sun"); break;
-    default: lcd.print(" Err");
+    case 0:  lcd.print (" Mon"); break;
+    case 1:  lcd.print (" Tue"); break;
+    case 2:  lcd.print (" Wed"); break;
+    case 3:  lcd.print (" Thu"); break;
+    case 4:  lcd.print (" Fri"); break;
+    case 5:  lcd.print (" Sat"); break;
+    case 6:  lcd.print (" Sun"); break;
+    default: lcd.print (" Err");
   }
 }

 // Compute the cardinal points of the compass
-const char* cardinal(double course, bool cardinalSelect)
+const char* cardinal (double course, bool cardinalSelect)
 {
   if (!cardinalSelect) {
     const char* directions[] = {"N  ", "NNE", "NE ", "ENE", "E  ", "ESE", "SE ", "SSE",
@@ -549,7 +451,7 @@

   Check to see if it's Daylight Savings Time (DST)
 */
-bool IsDST(uint8_t day, uint8_t month , uint8_t DOW)
+bool IsDST (uint8_t day, uint8_t month , uint8_t DOW)
 {
   // Make Day of Week (DOW) match with what Stackoverflow suggests
   // for DOW (Sunday = 0 to Saturday = 6)
@@ -593,9 +495,9 @@
   uint8_t DaysAMonth [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

   // Get Day of Week (DOW)
-  uint8_t DOW = dayOfWeek(*year, *month, *day);
+  uint8_t DOW = dayOfWeek (*year, *month, *day);
   // Get Daylight Saving Time (DST) or Standard Time (ST)
-  bool DST = IsDST(*day, *month, DOW);
+  bool DST = IsDST (*day, *month, DOW);
   // Compute local time (hours)
   int8_t UTCOffset = (int8_t)(lon / 15.0d); // UTC offset
   if (UTCOffset < 0) {
@@ -652,9 +554,9 @@
     // If you care how Hdop is computed (I don't :-)), see the following:
     // http://www2.unb.ca/gge/Resources/gpsworld.may99.pdf
     float hdop = (float)Hdop / 100.0f; // Hdop in X.X format
-    lcd.print(" Hdop:");
+    lcd.print (" Hdop:");
     if (hdop < 10.0f) {
-      lcd.print(hdop);
+      lcd.print (hdop);
     }
     else {
       // Hdop value too large for my LCD, so cross it out
@@ -663,11 +565,11 @@
         *prevHdopTime = now;
         if (*hdopToggle) {
           *hdopToggle = false;
-          lcd.print("XXX");
+          lcd.print ("XXX");
         }
         else {
           *hdopToggle = true;
-          lcd.print("   ");
+          lcd.print ("   ");
         } // if (hdopToggle)
       } // if (now - prevHdopTime > TOGGLETIME_INTERVAL)
     } // if (hdop < 10.0f)
@@ -677,14 +579,14 @@
     float hError = (float)Hdop / 100.0f; // Error in X.X format
     hError *= GPS_RECEIVER_ERROR; // Error in meters
     hError *= _GPS_FEET_PER_METER; // Error in feet
-    lcd.print(" Err: ");
+    lcd.print (" Err: ");
     if (hError < 100.0f) {
-      lcd.print((uint8_t)hError);
+      lcd.print ((uint8_t)hError);
       if (hError < 10.0f) {
-        lcd.print("f "); // feet
+        lcd.print ("f "); // feet
       }
       else {
-        lcd.print("f"); // feet
+        lcd.print ("f"); // feet
       }
     }
     else { // if (hError < 100.0f)
@@ -694,15 +596,13 @@
         *prevHdopTime = now;
         if (*hdopToggle) {
           *hdopToggle = false;
-          lcd.print("XXX");
+          lcd.print ("XXX");
         }
         else {
           *hdopToggle = true;
-          lcd.print("   ");
+          lcd.print ("   ");
         } // if (hdopToggle)
       } // if (now - prevHdopTime > TOGGLETIME_INTERVAL)
     } // if (hError < 100.0f)
   } // if (!HdopSelect)
-}
-
-#endif // #ifndef _16x2
+}


Changed the DELAY_TIME downward.

Changed the DELAY_TIME downward.

Reducing this number has shown that there is less likelihood of
getting into a locked up state where the sound is playing and
won't stop.

--- src/sketch.ino
+++ src/sketch.ino
@@ -40,7 +40,15 @@
 // or increase it, but you might need to increase the STOP_THRESHOLD.
 //
 // Think about it.
-#define DELAY_TIME 200
+//
+// So I had this set to 200ms originally. It worked OK, I guess, but
+// if the switch changes occurred too fast, it was filtering out changes
+// and made the thing hang in play mode with no way to turn it off short
+// of a reset. I tried 100ms and it improved somewhat. Knocking it down
+// to 10ms removed almost all the sensitivity. I'm going to stick with
+// this.
+//
+#define DELAY_TIME 10

 enum MotionState {
   Stopped,


fix broken function

fix broken function

--- src/rf24remotetemp.ino
+++ src/rf24remotetemp.ino
@@ -52,12 +52,7 @@
   return out;
 }

-// function to print the temperature for a device
-float getTempF(DeviceAddress deviceAddress)
-{
-  float tempC = sensors.getTempC(deviceAddress);
-  return DallasTemperature::toFahrenheit(tempC);
-}
+

 // run once at startup
 void setup() {


LED me know if you're alive

LED me know if you're alive

--- WeatherBuddy/WeatherBuddy.ino
+++ WeatherBuddy/WeatherBuddy.ino
@@ -6,7 +6,7 @@
 int reedLed = 10; // LED a
 int val = 0;  // = dus de regensensorwaarde
 int StatoSwitch = 0;
-int onLight = 8; // geeft aan of hij aan is (rood)
+ // andere ledje direct in 5V geeft aan of hij aan is (rood)

 void setup()
@@ -15,12 +15,10 @@
   pinMode(reedLed, OUTPUT);
   pinMode(pinSwitch, INPUT);
   pinMode(LED, OUTPUT);
- pinMode(onLight, OUTPUT);
+

 }
 void loop() {
-  digitalWrite(onLight, HIGH);
-  Serial.print("hoi");
   val = analogRead(regenSensor);
   if (val > 700) {
     digitalWrite(LED, LOW);


ArduinoDueFuncGen: Remove unnecessary check.

git-svn-id: 03a8048b5ee8463be5048a3801110fb50f378627@12590 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd

--- DeviceAdapters/ArduinoDueFuncGen/due_ad660_firmware/due_ad660_firmware.ino
+++ DeviceAdapters/ArduinoDueFuncGen/due_ad660_firmware/due_ad660_firmware.ino
@@ -510,15 +510,10 @@
 // this ISR gets called every time we finish sending a word (sample).
 // If we have not finished, we send the sample for the next channel. If we have
 // finished with all channels, we reset the channel counter and increment the
-// sample index.
+// sample index. Note that g_next_channel > 0 always holds when this ISR is
+// called.
 void SPI_DAC_Handler() {
   NVIC_DisableIRQ(SPI_DAC_IRQn);
-
-  if (g_next_channel == 0) {
-    // We shouldn't be here for the 0th channel: this is spurious.
-    // XXX Do we need this check? It should be a programming error.
-    return;
-  }

   if (g_next_channel >= NUM_CHANNELS) {
     g_next_channel = 0;


Remove finished agenda item

Remove finished agenda item

--- dremelfuge.ino
+++ dremelfuge.ino
@@ -26,10 +26,6 @@
   variables and functions, as if all globals were declared `static` (see large
   comment in loop() for details on `static`)
   */
-
-// 1) Define custom value decorations in THIS FILE, to be fed into lcdPrinter where
-// it will be parsed and the value will be inserted by the placement of the ' ' i.e.
-// "< >" => "<15:00>" (constexpr)

 namespace {


added button sensor to the list of sensors of a given motor

--- jenny5-firmware/jenny5-firmware.ino
+++ jenny5-firmware/jenny5-firmware.ino
@@ -246,11 +246,24 @@
                     dc_motors_controller_TB6612FNG.add_sensor(motor_index, POTENTIOMETER, sensor_index);
                 i += 2;
               }
+              else
+                if (tmp_str[j] == 'B' || tmp_str[j] == 'b'){
+                  int sensor_index;
+                  sscanf(tmp_str + j + 1, "%d", &sensor_index);
+                  if (motor_type == 'S' || motor_type == 's') // attach to stepper motors controller
+                    stepper_motors_controller.add_sensor(motor_index, BUTTON, sensor_index);
+                  else
+                    if (motor_type == 'D' || motor_type == 'd') // attach to DC motors controller
+                      dc_motors_controller_TB6612FNG.add_sensor(motor_index, BUTTON, sensor_index);
+                  i += 2;
+                }
+                else
+                  i++;
               j++;
             }
             i++;
           }
-        else
+          else
           if (tmp_str[i] == 'G' || tmp_str[i] == 'g'){// for debugging purpose
             if (tmp_str[i + 1] == 'S' || tmp_str[i + 1] == 's'){ // gets stepper motor speed and acceleration
               int motor_index;


Update simu_buttonreader_teensy_wheel.ino

I noticed that the battery led could stuck on when a momentary voltage dip happened. I added turning it off in a case where the dip was only momentary. Constantly low battery voltage will now result in the blink effect.

--- simu_buttonreader_teensy_wheel/simu_buttonreader_teensy_wheel.ino
+++ simu_buttonreader_teensy_wheel/simu_buttonreader_teensy_wheel.ino
@@ -1,428 +1,430 @@
-/*
- *  Code to put on the Wheel (connected with Bluetooth to a another system)
-   for wireless bluetooth button/shifter system using
-   two Teensy 3.2 microcontrollers and 2 HC-05 bluetooth modules.
-
-   Authors: Mika Takala & Juha Koljonen 2016
-
-   PINOUT
-   -------------------------------------------------------------------------
-   0 serial rx
-   1 serial tx
-   2 bluetooth status
-   3-12 button inputs
-   13  Teensy's own led
-   14-20 unused
-   21/A7 Battery_low_led
-   22 Connection_led
-   23 Battery voltage adc
-   24-33 unused
-
-   On Teensy 3.1 & 3.2 the following pins are PWM capable:
-   3, 4, 5, 6, 9, 10, 20, 21, 22, 23, 25, 3
-   Absolute maximum current is specified as 20 mA on the datasheet.
-   Authors of this code recommend at least a 82 ohm series resistor
-   for the LED-driving pins when using a typical small 3mm led.
-
-   The LED:s are PWM driven, and their brightness percentage is set
-   via LED_BRIGHTNESS definition. Range is from 0 - 100 %.
-   -------------------------------------------------------------------------
-
-   NOTES ABOUT POWER SAVING MEASURES:
-   -------------------------------------------------------------------------
-   (1)
-   As the system is intended to be battery powered, the recommendation
-   is to program Teensy as USB TYPE = NO USB and use for example 24MHz
-   or 16 MHz clock. These are set from Tools menu in Arduino/Teensyduino
-   IDE. Setting NO USB will require you to press the manual program button
-   on Teensy to upload the code, but it will save a lot of power.
-
-   (2)
-   Additionally you can set all unused inputs as outputs, which
-   makes them not floating and they will consume less power that way.
-   This has been implemented with a macro, and it has NOT been enabled
-   as default.
-   PLEASE BE SURE TO NOT HAVE ANYTHING CONNECTED TO THE UNUSED PINS
-   LISTED IN InitialiseIO() FUNCTION. THE AUTHOR(S) TAKE NOT RESPONSIBILITY
-   IF YOU MANAGE TO FRY/SHORT OUT A PIN OR YOUR TEENSY MICROCONTROLLER.
-   -------------------------------------------------------------------------
-
-   NOTE ABOUT BATTERY VOLTAGE ADC MEASUREMENT
-   -------------------------------------------------------------------------
-   As typical resistors have 5% or even 10% tolerance, you should
-   use a multimeter to measure when the battery voltage starts to indicate
-   low voltage by blinkin the led, and then adjust
-   BATTERY_LOW_VOLTAGE_THRESHOLD accordingly.
-
-   If you are running on 1-cell LiPO battery, you shouldn't discharge
-   it more than 80% of its capacity, leaving 20% capacity in the battery.
-   This equals to about 3.75 volts. This is recommended, because deeper
-   discharges will start to reduce overall battery life.
-
-   One way to do your ADC/voltage divider calibration is to set
-   the variable to quite high value, for example 3800. Start with a known
-   full battery, and see when the low battery voltage measurement triggers.
-   Then measure the battery voltage using a multimeter.
-   Then you can use maths like this:
-   3600     =   YOUR_MEASURED_VOLTAGE
-   X        =   3.75
-
-   X = 3600 * 3.75 / YOUR_MEASURED_VOLTAGE
-
-   This will result in a value for BATTERY_LOW_VOLTAGE_THRESHOLD that should
-   work, as ADC is linear. Round up to the next even hundred to be
-   extra safe.
-   -------------------------------------------------------------------------
-*/
-
-// used pin definitions, other than buttons
-#define btStatus 2
-#define teensyLed 13
-#define batteryLed 21
-#define connectionLed 22
-#define batteryADC 23
-
-
-// define led brighness here in percentage
-#define LED_BRIGHTNESS 5
-// for 82 ohm series resistor and small 3mm red/green through-hole
-// led, 5 % seems fine.
-#define ledOutputValue 255*LED_BRIGHTNESS/100
-
-
-// Define if you want to blink Teensy's own led or not.
-// Defined value = yes, commented out = no
-#define BLINK_TEENSY_LED
-
-
-// Adjust to fit your voltage divider and battery.
-// This value is good starting point for 33k / 11.85k
-// resistors when using internal 1.2V voltage reference on Teensy 3.2.
-#define BATTERY_LOW_VOLTAGE_THRESHOLD 3600
-
-
-// Uncomment this to save a bit of battery power.
-// DANGER: Please make double sure that all your unconnected pins
-// are correctly set in InitialiseIO() -function.
-// Errors here will permanently damage your Teensy microcontroller.
-
-// #define POWERSAVING_WITH_PINS_AS_OUTPUTS
-
-
-// Included the Bounce2 library found here :
-// https://github.com/thomasfredericks/Bounce2
-// The library has been modified to use digitalReadFast().
-// Fast reactions are needed in the buttons. Therefore in the library,
-// this is defined:
-//  By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h"
-//  you can activate the alternative debouncing method. This method is
-//  a lot more responsive, but does not cancel noise.
-#include "Bounce2.h"
-
-
-// Bouncer instances connected to buttons.
-// If you have more or less buttons,
-// adjust this to your liking.
-Bounce debouncer3 = Bounce();
-Bounce debouncer4 = Bounce();
-Bounce debouncer5 = Bounce();
-Bounce debouncer6 = Bounce();
-Bounce debouncer7 = Bounce();
-Bounce debouncer8 = Bounce();
-Bounce debouncer9 = Bounce();
-Bounce debouncer10 = Bounce();
-Bounce debouncer11 = Bounce();
-Bounce debouncer12 = Bounce();
-
-// Two bytes to store button status
-volatile int buttons_0_6 = 0b00000000;
-volatile int buttons_7_13 = 0b10000000; // MSB indicates which is it.
-volatile short int ledStatus = 0;
-
-// periodic status intervals in milliseconds
-long const int StatusInterval = 1500;
-long const int BatteryInterval = 1000;
-long const int WaitIndicationInterval = 200;
-
-unsigned long int lastStatusUpdate = 0;
-unsigned long int lastBatteryUpdate = 0;
-unsigned long int lastWaitIndicationUpdate = 0;
-
-
-boolean batteryLow = false;
-byte batteryLedStatus = 0;
-
-boolean btConnected = false;
-byte connectionLedStatus = 0;
-
-void setup()
-{
-  InitialiseIO();
-
-  // Show that we are booting up
-
-  digitalWriteFast(connectionLed, HIGH);
-  digitalWriteFast(batteryLed, HIGH);
-  delay(1000);
-  digitalWriteFast(connectionLed, LOW);
-  digitalWriteFast(batteryLed, LOW);
-
-  // Define/set debounce intervalls here to suit your buttons
-  // Remember to adjust the amount of these if you have
-  // more or less buttons.
-  debouncer3.attach(3);  debouncer3.interval(5);
-  debouncer4.attach(4);  debouncer4.interval(5);
-  debouncer5.attach(5);  debouncer5.interval(5);
-  debouncer6.attach(6);  debouncer6.interval(5);
-  debouncer7.attach(7);  debouncer7.interval(5);
-  debouncer8.attach(8);  debouncer8.interval(5);
-  debouncer9.attach(9);  debouncer9.interval(5);
-  debouncer10.attach(10);  debouncer10.interval(5);
-  debouncer11.attach(11);  debouncer11.interval(5);
-  debouncer12.attach(12);  debouncer12.interval(5);
-
-  buttons_0_6 = 0b00000000;
-  buttons_7_13 = 0b10000000;
-
-  lastStatusUpdate = millis();
-  lastBatteryUpdate = millis();
-  lastWaitIndicationUpdate = millis();
-
-  // Connect to Bt module
-  Serial1.begin(57600); // use same baud rate as you have set your BT modules
-  Serial1.flush();
-
-  // turn off teensy led
-  digitalWriteFast(teensyLed, LOW);
-}
-
-void loop() {
-  // Check Bluetooth status
-  if (digitalReadFast(btStatus)) {
-    analogWrite(connectionLed, ledOutputValue);
-    btConnected = true;
-  } else btConnected = false;
-
-  // Go through all buttons if connected. Button press is detected on falling edge.
-  if (btConnected) {
-    updateButtons();
-    sanityUpdate();
-  } else {
-    runWaitBtIndication();
-  }
-
-  checkBattery();
-}
-
-void runWaitBtIndication() {
-  if (millis() > (lastWaitIndicationUpdate + WaitIndicationInterval)) {
-    lastWaitIndicationUpdate = millis();
-    if(connectionLedStatus) {
-      analogWrite(connectionLed, ledOutputValue);
-    } else{
-      analogWrite(connectionLed, 0);
-    }
-    connectionLedStatus = !connectionLedStatus;
-  }
-}
-
-void checkBattery() {
-  // check battery voltage at defined intervals.
-  if (millis() > (lastBatteryUpdate + BatteryInterval)) {
-    lastBatteryUpdate = millis();
-
-    // check if battery low:
-    if (analogRead(batteryADC) < BATTERY_LOW_VOLTAGE_THRESHOLD) {
-      batteryLow = true;
-      buttons_7_13 |= 0b01000000; // this bit tells battery status to base unit
-
-    } else {
-      batteryLow = false;
-      buttons_7_13 &= ~(0b01000000); // this bit tells battery status to base unit
-    }
-
-    if (batteryLow) {
-      if(batteryLedStatus) {
-        analogWrite(batteryLed, ledOutputValue);
-      } else {
-        analogWrite(batteryLed, 0);
-      }
-      batteryLedStatus = !batteryLedStatus;
-    }
-  }
-}
-
-void sanityUpdate() {
-  // Periodic sanity update
-  // sends known button statuses to the base system at defined intervalls.
-  if(millis() > (lastStatusUpdate + StatusInterval)) {
-      lastStatusUpdate = millis();
-      Serial1.write(buttons_0_6);
-      Serial1.write(buttons_7_13);
-
-    #ifdef BLINK_TEENSY_LED
-    // 13 = red led on teensy 3.2. Might as well flash it.
-    // as aliveness status.
-    // Pin 13 is not PWM capable, so just regular digitalWriteFasts here.
-    if(ledStatus) {
-      ledStatus = 0;
-      digitalWriteFast(teensyLed, LOW);
-    } else {
-      ledStatus = 1;
-      digitalWriteFast(teensyLed, HIGH);
-    }
-    #endif
-  }
-}
-
-
-void updateButtons() {
-  // updates each button status and sees if it changed.
-  // add more or less code according to suit your buttons.
-  //
-  debouncer3.update();
-  if(debouncer3.fell()) {
-    buttons_0_6 |= 0b00000001;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer3.rose()) {
-    buttons_0_6 &= ~(0b00000001);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer4.update();
-  if(debouncer4.fell()) {
-    buttons_0_6 |= 0b00000010;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer4.rose()) {
-    buttons_0_6 &= ~(0b00000010);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer5.update();
-  if(debouncer5.fell()) {
-    buttons_0_6 |= 0b00000100;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer5.rose()) {
-    buttons_0_6 &= ~(0b00000100);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer6.update();
-  if(debouncer6.fell()) {
-    buttons_0_6 |= 0b00001000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer6.rose()) {
-    buttons_0_6 &= ~(0b00001000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer7.update();
-  if(debouncer7.fell()) {
-    buttons_0_6 |= 0b00010000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer7.rose()) {
-    buttons_0_6 &= ~(0b00010000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer8.update();
-  if(debouncer8.fell()) {
-    buttons_0_6 |= 0b00100000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer8.rose()) {
-    buttons_0_6 &= ~(0b00100000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer9.update();
-  if(debouncer9.fell()) {
-    buttons_0_6 |= 0b01000000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer9.rose()) {
-    buttons_0_6 &= ~(0b01000000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer10.update();
-  if(debouncer10.fell()) {
-    buttons_7_13 |= 0b00000001;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer10.rose()) {
-    buttons_7_13 &= ~(0b00000001);
-    Serial1.write(buttons_7_13);
-  }
-
-  debouncer11.update();
-  if(debouncer11.fell()) {
-    buttons_7_13 |= 0b00000010;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer11.rose()) {
-    buttons_7_13 &= ~(0b00000010);
-    Serial1.write(buttons_7_13);
-  }
-
-  debouncer12.update();
-  if(debouncer12.fell()) {
-    buttons_7_13 |= 0b00000100;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer12.rose()) {
-    buttons_7_13 &= ~(0b00000100);
-    Serial1.write(buttons_7_13);
-  }
-}
-
-
-
-void InitialiseIO(){
-  pinMode(btStatus, INPUT);
-  pinMode(3, INPUT_PULLUP);
-  pinMode(4, INPUT_PULLUP);
-  pinMode(5, INPUT_PULLUP);
-  pinMode(6, INPUT_PULLUP);
-  pinMode(7, INPUT_PULLUP);
-  pinMode(8, INPUT_PULLUP);
-  pinMode(9, INPUT_PULLUP);
-  pinMode(10, INPUT_PULLUP);
-  pinMode(11, INPUT_PULLUP);
-  pinMode(12, INPUT_PULLUP);
-  pinMode(teensyLed, OUTPUT);
-  pinMode(batteryLed, OUTPUT);
-  pinMode(connectionLed, OUTPUT);
-  pinMode(batteryADC, INPUT);
-  digitalWriteFast(teensyLed, LOW);
-  digitalWriteFast(connectionLed, LOW);
-  digitalWriteFast(batteryLed, LOW); // By default the battery is not empty at startup.
-
-  analogReadRes(12);
-  analogReadAveraging(5);
-  analogReference(INTERNAL);
-
-  // By default, all pins are inputs.
-  // Unused inputs in an electrically noisy environment will consume many
-  // mA of power. This is because their voltage floats to a value which makes the input state
-  // switch, and all switching of digital circuitry consumes power.
-  // Please be double sure that you have not connected anything to these pins,
-  // as errors here might fry you Teensy.
-
-  #ifdef POWERSAVING_WITH_PINS_AS_OUTPUTS
-  // list your unused digital pins here
-  pinMode(14, OUTPUT);
-  pinMode(15, OUTPUT);
-  pinMode(16, OUTPUT);
-  pinMode(17, OUTPUT);
-  pinMode(18, OUTPUT);
-  pinMode(19, OUTPUT);
-  pinMode(20, OUTPUT);
-  pinMode(24, OUTPUT);
-  pinMode(25, OUTPUT);
-  pinMode(26, OUTPUT);
-  pinMode(27, OUTPUT);
-  pinMode(28, OUTPUT);
-  pinMode(29, OUTPUT);
-  pinMode(30, OUTPUT);
-  pinMode(31, OUTPUT);
-  pinMode(32, OUTPUT);
-  pinMode(33, OUTPUT);
-  #endif
-}
-
+/*
+ *  Code to put on the Wheel (connected with Bluetooth to a another system)
+   for wireless bluetooth button/shifter system using
+   two Teensy 3.2 microcontrollers and 2 HC-05 bluetooth modules.
+
+   Authors: Mika Takala & Juha Koljonen 2016
+
+   PINOUT
+   -------------------------------------------------------------------------
+   0 serial rx
+   1 serial tx
+   2 bluetooth status
+   3-12 button inputs
+   13  Teensy's own led
+   14-20 unused
+   21/A7 Battery_low_led
+   22 Connection_led
+   23 Battery voltage adc
+   24-33 unused
+
+   On Teensy 3.1 & 3.2 the following pins are PWM capable:
+   3, 4, 5, 6, 9, 10, 20, 21, 22, 23, 25, 3
+   Absolute maximum current is specified as 20 mA on the datasheet.
+   Authors of this code recommend at least a 82 ohm series resistor
+   for the LED-driving pins when using a typical small 3mm led.
+
+   The LED:s are PWM driven, and their brightness percentage is set
+   via LED_BRIGHTNESS definition. Range is from 0 - 100 %.
+   -------------------------------------------------------------------------
+
+   NOTES ABOUT POWER SAVING MEASURES:
+   -------------------------------------------------------------------------
+   (1)
+   As the system is intended to be battery powered, the recommendation
+   is to program Teensy as USB TYPE = NO USB and use for example 24MHz
+   or 16 MHz clock. These are set from Tools menu in Arduino/Teensyduino
+   IDE. Setting NO USB will require you to press the manual program button
+   on Teensy to upload the code, but it will save a lot of power.
+
+   (2)
+   Additionally you can set all unused inputs as outputs, which
+   makes them not floating and they will consume less power that way.
+   This has been implemented with a macro, and it has NOT been enabled
+   as default.
+   PLEASE BE SURE TO NOT HAVE ANYTHING CONNECTED TO THE UNUSED PINS
+   LISTED IN InitialiseIO() FUNCTION. THE AUTHOR(S) TAKE NOT RESPONSIBILITY
+   IF YOU MANAGE TO FRY/SHORT OUT A PIN OR YOUR TEENSY MICROCONTROLLER.
+   -------------------------------------------------------------------------
+
+   NOTE ABOUT BATTERY VOLTAGE ADC MEASUREMENT
+   -------------------------------------------------------------------------
+   As typical resistors have 5% or even 10% tolerance, you should
+   use a multimeter to measure when the battery voltage starts to indicate
+   low voltage by blinkin the led, and then adjust
+   BATTERY_LOW_VOLTAGE_THRESHOLD accordingly.
+
+   If you are running on 1-cell LiPO battery, you shouldn't discharge
+   it more than 80% of its capacity, leaving 20% capacity in the battery.
+   This equals to about 3.75 volts. This is recommended, because deeper
+   discharges will start to reduce overall battery life.
+
+   One way to do your ADC/voltage divider calibration is to set
+   the variable to quite high value, for example 3800. Start with a known
+   full battery, and see when the low battery voltage measurement triggers.
+   Then measure the battery voltage using a multimeter.
+   Then you can use maths like this:
+   3600     =   YOUR_MEASURED_VOLTAGE
+   X        =   3.75
+
+   X = 3600 * 3.75 / YOUR_MEASURED_VOLTAGE
+
+   This will result in a value for BATTERY_LOW_VOLTAGE_THRESHOLD that should
+   work, as ADC is linear. Round up to the next even hundred to be
+   extra safe.
+   -------------------------------------------------------------------------
+*/
+
+// used pin definitions, other than buttons
+#define btStatus 2
+#define teensyLed 13
+#define batteryLed 21
+#define connectionLed 22
+#define batteryADC 23
+
+
+// define led brighness here in percentage
+#define LED_BRIGHTNESS 5
+// for 82 ohm series resistor and small 3mm red/green through-hole
+// led, 5 % seems fine.
+#define ledOutputValue 255*LED_BRIGHTNESS/100
+
+
+// Define if you want to blink Teensy's own led or not.
+// Defined value = yes, commented out = no
+#define BLINK_TEENSY_LED
+
+
+// Adjust to fit your voltage divider and battery.
+// This value is good starting point for 33k / 11.85k
+// resistors when using internal 1.2V voltage reference on Teensy 3.2.
+#define BATTERY_LOW_VOLTAGE_THRESHOLD 3600
+
+
+// Uncomment this to save a bit of battery power.
+// DANGER: Please make double sure that all your unconnected pins
+// are correctly set in InitialiseIO() -function.
+// Errors here will permanently damage your Teensy microcontroller.
+
+// #define POWERSAVING_WITH_PINS_AS_OUTPUTS
+
+
+// Included the Bounce2 library found here :
+// https://github.com/thomasfredericks/Bounce2
+// The library has been modified to use digitalReadFast().
+// Fast reactions are needed in the buttons. Therefore in the library,
+// this is defined:
+//  By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h"
+//  you can activate the alternative debouncing method. This method is
+//  a lot more responsive, but does not cancel noise.
+#include "Bounce2.h"
+
+
+// Bouncer instances connected to buttons.
+// If you have more or less buttons,
+// adjust this to your liking.
+Bounce debouncer3 = Bounce();
+Bounce debouncer4 = Bounce();
+Bounce debouncer5 = Bounce();
+Bounce debouncer6 = Bounce();
+Bounce debouncer7 = Bounce();
+Bounce debouncer8 = Bounce();
+Bounce debouncer9 = Bounce();
+Bounce debouncer10 = Bounce();
+Bounce debouncer11 = Bounce();
+Bounce debouncer12 = Bounce();
+
+// Two bytes to store button status
+volatile int buttons_0_6 = 0b00000000;
+volatile int buttons_7_13 = 0b10000000; // MSB indicates which is it.
+volatile short int ledStatus = 0;
+
+// periodic status intervals in milliseconds
+long const int StatusInterval = 1500;
+long const int BatteryInterval = 1000;
+long const int WaitIndicationInterval = 200;
+
+unsigned long int lastStatusUpdate = 0;
+unsigned long int lastBatteryUpdate = 0;
+unsigned long int lastWaitIndicationUpdate = 0;
+
+
+boolean batteryLow = false;
+byte batteryLedStatus = 0;
+
+boolean btConnected = false;
+byte connectionLedStatus = 0;
+
+void setup()
+{
+  InitialiseIO();
+
+  // Show that we are booting up
+
+  digitalWriteFast(connectionLed, HIGH);
+  digitalWriteFast(batteryLed, HIGH);
+  delay(1000);
+  digitalWriteFast(connectionLed, LOW);
+  digitalWriteFast(batteryLed, LOW);
+
+  // Define/set debounce intervalls here to suit your buttons
+  // Remember to adjust the amount of these if you have
+  // more or less buttons.
+  debouncer3.attach(3);  debouncer3.interval(5);
+  debouncer4.attach(4);  debouncer4.interval(5);
+  debouncer5.attach(5);  debouncer5.interval(5);
+  debouncer6.attach(6);  debouncer6.interval(5);
+  debouncer7.attach(7);  debouncer7.interval(5);
+  debouncer8.attach(8);  debouncer8.interval(5);
+  debouncer9.attach(9);  debouncer9.interval(5);
+  debouncer10.attach(10);  debouncer10.interval(5);
+  debouncer11.attach(11);  debouncer11.interval(5);
+  debouncer12.attach(12);  debouncer12.interval(5);
+
+  buttons_0_6 = 0b00000000;
+  buttons_7_13 = 0b10000000;
+
+  lastStatusUpdate = millis();
+  lastBatteryUpdate = millis();
+  lastWaitIndicationUpdate = millis();
+
+  // Connect to Bt module
+  Serial1.begin(57600); // use same baud rate as you have set your BT modules
+  Serial1.flush();
+
+  // turn off teensy led
+  digitalWriteFast(teensyLed, LOW);
+}
+
+void loop() {
+  // Check Bluetooth status
+  if (digitalReadFast(btStatus)) {
+    analogWrite(connectionLed, ledOutputValue);
+    btConnected = true;
+  } else btConnected = false;
+
+  // Go through all buttons if connected. Button press is detected on falling edge.
+  if (btConnected) {
+    updateButtons();
+    sanityUpdate();
+  } else {
+    runWaitBtIndication();
+  }
+
+  checkBattery();
+}
+
+void runWaitBtIndication() {
+  if (millis() > (lastWaitIndicationUpdate + WaitIndicationInterval)) {
+    lastWaitIndicationUpdate = millis();
+    if(connectionLedStatus) {
+      analogWrite(connectionLed, ledOutputValue);
+    } else{
+      analogWrite(connectionLed, 0);
+    }
+    connectionLedStatus = !connectionLedStatus;
+  }
+}
+
+void checkBattery() {
+  // check battery voltage at defined intervals.
+  if (millis() > (lastBatteryUpdate + BatteryInterval)) {
+    lastBatteryUpdate = millis();
+
+    // check if battery low:
+    if (analogRead(batteryADC) < BATTERY_LOW_VOLTAGE_THRESHOLD) {
+      batteryLow = true;
+      buttons_7_13 |= 0b01000000; // this bit tells battery status to base unit
+
+    } else {
+      batteryLow = false;
+      buttons_7_13 &= ~(0b01000000); // this bit tells battery status to base unit
+    }
+
+    if (batteryLow) {
+      if(batteryLedStatus) {
+        analogWrite(batteryLed, ledOutputValue);
+      } else {
+        analogWrite(batteryLed, 0);
+      }
+      batteryLedStatus = !batteryLedStatus;
+    } else {
+      analogWrite(batteryLed, 0);
+    }
+  }
+}
+
+void sanityUpdate() {
+  // Periodic sanity update
+  // sends known button statuses to the base system at defined intervalls.
+  if(millis() > (lastStatusUpdate + StatusInterval)) {
+      lastStatusUpdate = millis();
+      Serial1.write(buttons_0_6);
+      Serial1.write(buttons_7_13);
+
+    #ifdef BLINK_TEENSY_LED
+    // 13 = red led on teensy 3.2. Might as well flash it.
+    // as aliveness status.
+    // Pin 13 is not PWM capable, so just regular digitalWriteFasts here.
+    if(ledStatus) {
+      ledStatus = 0;
+      digitalWriteFast(teensyLed, LOW);
+    } else {
+      ledStatus = 1;
+      digitalWriteFast(teensyLed, HIGH);
+    }
+    #endif
+  }
+}
+
+
+void updateButtons() {
+  // updates each button status and sees if it changed.
+  // add more or less code according to suit your buttons.
+  //
+  debouncer3.update();
+  if(debouncer3.fell()) {
+    buttons_0_6 |= 0b00000001;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer3.rose()) {
+    buttons_0_6 &= ~(0b00000001);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer4.update();
+  if(debouncer4.fell()) {
+    buttons_0_6 |= 0b00000010;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer4.rose()) {
+    buttons_0_6 &= ~(0b00000010);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer5.update();
+  if(debouncer5.fell()) {
+    buttons_0_6 |= 0b00000100;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer5.rose()) {
+    buttons_0_6 &= ~(0b00000100);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer6.update();
+  if(debouncer6.fell()) {
+    buttons_0_6 |= 0b00001000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer6.rose()) {
+    buttons_0_6 &= ~(0b00001000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer7.update();
+  if(debouncer7.fell()) {
+    buttons_0_6 |= 0b00010000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer7.rose()) {
+    buttons_0_6 &= ~(0b00010000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer8.update();
+  if(debouncer8.fell()) {
+    buttons_0_6 |= 0b00100000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer8.rose()) {
+    buttons_0_6 &= ~(0b00100000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer9.update();
+  if(debouncer9.fell()) {
+    buttons_0_6 |= 0b01000000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer9.rose()) {
+    buttons_0_6 &= ~(0b01000000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer10.update();
+  if(debouncer10.fell()) {
+    buttons_7_13 |= 0b00000001;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer10.rose()) {
+    buttons_7_13 &= ~(0b00000001);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer11.update();
+  if(debouncer11.fell()) {
+    buttons_7_13 |= 0b00000010;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer11.rose()) {
+    buttons_7_13 &= ~(0b00000010);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer12.update();
+  if(debouncer12.fell()) {
+    buttons_7_13 |= 0b00000100;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer12.rose()) {
+    buttons_7_13 &= ~(0b00000100);
+    Serial1.write(buttons_7_13);
+  }
+}
+
+
+
+void InitialiseIO(){
+  pinMode(btStatus, INPUT);
+  pinMode(3, INPUT_PULLUP);
+  pinMode(4, INPUT_PULLUP);
+  pinMode(5, INPUT_PULLUP);
+  pinMode(6, INPUT_PULLUP);
+  pinMode(7, INPUT_PULLUP);
+  pinMode(8, INPUT_PULLUP);
+  pinMode(9, INPUT_PULLUP);
+  pinMode(10, INPUT_PULLUP);
+  pinMode(11, INPUT_PULLUP);
+  pinMode(12, INPUT_PULLUP);
+  pinMode(teensyLed, OUTPUT);
+  pinMode(batteryLed, OUTPUT);
+  pinMode(connectionLed, OUTPUT);
+  pinMode(batteryADC, INPUT);
+  digitalWriteFast(teensyLed, LOW);
+  digitalWriteFast(connectionLed, LOW);
+  digitalWriteFast(batteryLed, LOW); // By default the battery is not empty at startup.
+
+  analogReadRes(12);
+  analogReadAveraging(5);
+  analogReference(INTERNAL);
+
+  // By default, all pins are inputs.
+  // Unused inputs in an electrically noisy environment will consume many
+  // mA of power. This is because their voltage floats to a value which makes the input state
+  // switch, and all switching of digital circuitry consumes power.
+  // Please be double sure that you have not connected anything to these pins,
+  // as errors here might fry you Teensy.
+
+  #ifdef POWERSAVING_WITH_PINS_AS_OUTPUTS
+  // list your unused digital pins here
+  pinMode(14, OUTPUT);
+  pinMode(15, OUTPUT);
+  pinMode(16, OUTPUT);
+  pinMode(17, OUTPUT);
+  pinMode(18, OUTPUT);
+  pinMode(19, OUTPUT);
+  pinMode(20, OUTPUT);
+  pinMode(24, OUTPUT);
+  pinMode(25, OUTPUT);
+  pinMode(26, OUTPUT);
+  pinMode(27, OUTPUT);
+  pinMode(28, OUTPUT);
+  pinMode(29, OUTPUT);
+  pinMode(30, OUTPUT);
+  pinMode(31, OUTPUT);
+  pinMode(32, OUTPUT);
+  pinMode(33, OUTPUT);
+  #endif
+}
+


fix to the angu ino

fix to the angu ino

--- angu/angu.ino
+++ angu/angu.ino
@@ -3,11 +3,11 @@
 const int ledPin = 3; // set ledPin to on-board LED
 //                                                        V
 //ID IS A TEST. IT WAS 19B10010-E8F2-537E-4F6C-D104768A1214<<<<<
-BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service
+BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1215"); // create service

 // create switch characteristic and allow remote device to read and write
-BLECharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 20);
+BLECharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1215", BLERead | BLEWrite, 20);

 void setup() {
   Serial.begin(9600);
@@ -47,7 +47,7 @@
     Serial.println(ledCharacteristic.valueLength());
     const byte* val = ledCharacteristic.value();

-    String valueStr = String((const char *)val).substring(ledCharacteristic.valueLength());
+    String valueStr = String((const char *)val).substring(0,ledCharacteristic.valueLength());
     Serial.println("---" + valueStr + "---");
     /**
     12345678901234567890 1234567890


Include timestamps in metrics

Include timestamps in metrics

--- temperature-relay.ino
+++ temperature-relay.ino
@@ -45,18 +45,18 @@
   /* server.httpSuccess(); */
   server.httpSuccess("text/plain; version=0.0.4");
   if (type != WebServer::HEAD) {
-    char s_temp[75];
-    char s_average_temp[100];
-    char s_power[40];
-    char s_freemem[100];
+    char s_temp[85];
+    char s_average_temp[110];
+    char s_power[50];
+    char s_freemem[110];
     uint32_t freemem;

     freemem = System.freeMemory();

-    snprintf(s_temp, 75,"# TYPE temp_degrees gauge\ntemp_degrees %.4f\n\n", temperature);
-    snprintf(s_average_temp, 100, "# TYPE average_temp_degrees gauge\naverage_temp_degrees %.4f\n\n", minuteAverage);
-    snprintf(s_power, 40, "# TYPE heater gauge\nheater %i\n\n", power);
-    snprintf(s_freemem, 100, "# Type free_mem_bytes\nfree_mem_bytes %i\n\n", freemem);
+    snprintf(s_temp, 85,"# TYPE temp_degrees gauge\ntemp_degrees %.4f %li000\n\n", temperature, Time.now());
+    snprintf(s_average_temp, 110, "# TYPE average_temp_degrees gauge\naverage_temp_degrees %.4f %li000\n\n", minuteAverage, Time.now());
+    snprintf(s_power, 50, "# TYPE heater gauge\nheater %i %li000\n\n", power, Time.now());
+    snprintf(s_freemem, 110, "# Type free_mem_bytes\nfree_mem_bytes %lu %li000\n\n", freemem, Time.now());

     server << s_temp;
     server << s_average_temp;
@@ -121,7 +121,7 @@
 void publishTemp(float temp) {
   char publishString[20];

-  snprintf(publishString, 20,"%f", temp);
+  snprintf(publishString, 20,"%.4f", temp);
   Particle.publish("temperature", publishString);
   Serial.print("Temp: ");
   Serial.println(publishString);
@@ -130,7 +130,7 @@
 void publishAverage(float temp) {
   char publishString[20];

-  snprintf(publishString, 20,"%f", temp);
+  snprintf(publishString, 20,"%.4f", temp);
   Particle.publish("minute_average", publishString);
   Serial.print("Average: ");
   Serial.println(publishString);


include mpr121.h

include mpr121.h

--- Finalproject.ino
+++ Finalproject.ino
@@ -1,5 +1,5 @@
 /*Copyright (c) 2010 bildr community
- Permission is hereby granted, free of charge, to any person obtaining a copy
+ Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell


Link to doc

Link to doc

--- examples/Basics/Knob/Knob.ino
+++ examples/Basics/Knob/Knob.ino
@@ -12,6 +12,7 @@
 	 - connect one of the outer pins of the potentiometer to the 3V3 (power)
 	 - connect the other outer pin of the potentiometer to the GND (ground)

+   An image & more info on the setup is at https://github.com/theapi/denbit/blob/master/docs/examples/Basics/Knob.md
 */

 // Include the Denbit library.


Write data to a USB stick.

Write data to a USB stick.

--- ArduinoPondArea/ArduinoPondArea.ino
+++ ArduinoPondArea/ArduinoPondArea.ino
@@ -1,8 +1,21 @@
+// ############################################
+// CONFIG SECTION
+bool veryVerboseDebug = true;
+
 int pinA = 3;  // Connected to CLK on KY-040
 int pinB = 4;  // Connected to DT on KY-040

 int rotaryTicks = 0;
 int lastRotaryTicks = 0;
+
+const String usbFileName = "PONDS.PD";
+
+// every n writes we manually close the file and reopen to prevent data
+// loss. Lower n = slower perf, but safer
+const int USB_WRITE_MANUAL_FLUSH_RATE = 2;
+
+// END CONFIG SECT
+// ############################################

 int lastRotaryValue; // 1/0 read from rotary

@@ -18,38 +31,71 @@
 int rollingAveragePotent();

+bool isUsbStickPluggedIn();
+
+// open a filename
+void usbOpenFile4Write(const String& filename);
+// write some data to an open file
+void write2file(const String& data);
+
 // util functions for writing in CSV format
 void writeCsvLabel();
 void writeCsvRow(int rotaryTickCount, int potentTickCount, double x, double y);

-
-// hacky because for some reason we can print in the setup() fxn
-bool wroteCsvHeader;
+// read all the input coming back from the usb controller
+String dumpUsbOutput();
+
+// this is just to add some dealy so that the usb device can start up
+// before we do operations on it
+long int started;
+bool usbDeviceWasSetup;
+// Write data to the usb device. If command must have the \r on it!
+void usbDeviceWrite(const String& data);
+// same as usbDeviceWrite but doesn't read all the response input after writing
+// to the device
+void usbDeviceWriteUnbuffered(const String& data);
+
+// setup the connection to the usb device
+void setupUsbDevice();
+void setupUsbStickForWrite(); // open files and add new section delimeter
+
+// alias to make clear that Serial1 is the usb device
+HardwareSerial& usbDev = Serial1;
+
+// whether the current usb stick has been 'prepd' for writing data
+// basically whether the file is open for writing and some other stuff
+bool usbStickIsPrepped = false;

 void setup() {
-    pinMode(pinA,INPUT);
-    pinMode(pinB,INPUT);
+    pinMode(pinA, INPUT);
+    pinMode(pinB,  INPUT);
     /* Read Pin A
     Whatever state it's in will reflect the last position
     */
     lastRotaryValue = digitalRead(pinA);
     initialPotentiometerReading = analogRead(A0);
-    wroteCsvHeader = false;
     Serial.begin (9600);
     Serial.println("Now running!");
-}
-
- void loop() {
-  // if they disconnect from reading the output stream, resend the header data on reconnec
-  if (!Serial) {
-    wroteCsvHeader = false;
-  }
-
-  if (!wroteCsvHeader && Serial) // if(Serial) only available on Leonardo: detects if tty connected
-  {
+
+    started = millis();
+    usbDeviceWasSetup = false;
+}
+
+void loop() {
+  dumpUsbOutput();
+
+  if (millis() - started < 1000) {
+    Serial.println("skipped");
+    return;
+  }
+
+  if (!usbDeviceWasSetup) {
+    usbDeviceWasSetup = true;
+    setupUsbDevice();
+    setupUsbStickForWrite();
     delay(150); // 150ms for the client to prepare for display cause clients were slow & dropping label packets
     writeCsvLabel();
-    wroteCsvHeader = true;
+    dumpUsbOutput();
   }

    int newRotaryValue = digitalRead(pinA);
@@ -76,9 +122,12 @@
     }
    }

-
-    Serial.print("rotary="); Serial.print(rotaryTicks);
-    Serial.print(", potent = "); Serial.println(newPotentiometerValue);
+
+
+    if (Serial) {
+      Serial.print("rotary="); Serial.print(rotaryTicks);
+      Serial.print(", potent = "); Serial.println(newPotentiometerValue);
+    }

     writeCsvRow(rotaryTicks, newPotentiometerValue);

@@ -112,15 +161,148 @@
   // we write the read sensor values first to preserve the raw data and then our interpreted/calculated x,y points
   // in the cartesian plane
   // so it's (r, theta, x, y)
-  Serial.println("LABEL,RotaryEncoder,Potentiometer");
+  String header = "RotaryEncoder,Potentiometer,MillisSinceStart\n";
+  if (Serial) {
+    Serial.print("LABEL,");
+    Serial.println(header);
+  }
+
+  write2file(header);
 }

 void writeCsvRow(int rotaryTickCount, int potentTickCount)
 {
-  // these need to be in the same order as writeCsvLabel()'s implementation
-  Serial.print("DATA");
-  Serial.print(","); Serial.print(rotaryTickCount);
-  Serial.print(","); Serial.print(potentTickCount);
-  Serial.println();
-}
-
+  // these need to be in the same order as writeCsvLabel()'s implementatio
+  if (Serial) {
+    Serial.print("DATA");
+    Serial.print(","); Serial.print(rotaryTickCount);
+    Serial.print(","); Serial.print(potentTickCount);
+  }
+
+  String dataLine = "";
+  dataLine += rotaryTickCount;
+  dataLine += ',';
+  dataLine += potentTickCount;
+  dataLine += ',';
+  dataLine += millis();
+  dataLine += '\n';
+
+  if (veryVerboseDebug)
+  {
+    Serial.print("-----------Would have written: (");
+    Serial.print(dataLine.length());
+    Serial.println(" characters)");
+    Serial.println(dataLine);
+    Serial.println("----------------------");
+  }
+
+  write2file(dataLine);
+}
+
+void usbDeviceWriteUnbuffered(const String& data)
+{
+  if (veryVerboseDebug) {
+    Serial.println("DEBUG: WRITING 2 USB:");
+    Serial.println(data);
+  }
+  usbDev.write(data.c_str(), data.length());
+  delay(data.length());
+  usbDev.flush();
+  delay(data.length());
+}
+
+void usbDeviceWrite(const String& data)
+{
+  usbDeviceWriteUnbuffered(data);
+  dumpUsbOutput();
+}
+
+void setupUsbDevice()
+{
+  usbDev.begin(9600);
+  dumpUsbOutput();
+  usbDeviceWrite("failingspacercommand\r");
+  usbDeviceWrite("IPA\r");
+  usbDeviceWrite("ECS\r");
+  delay(100);
+
+
+}
+
+void setupUsbStickForWrite()
+{
+  // open a file for writing
+  usbOpenFile4Write(usbFileName);
+  // special delimeter for mathematica to know that
+  // this is a new section of the file
+  write2file("########## NEW SECTION ##########\n");
+  usbDeviceWrite("plzfail\r");
+}
+
+
+int write2fileCount = 0;
+
+void write2file(const String& data) {
+  String writeCommand = "WRF ";
+  writeCommand += data.length();
+  writeCommand += '\r';
+  writeCommand += data;
+  usbDeviceWrite(writeCommand);
+
+  if (++write2fileCount >= USB_WRITE_MANUAL_FLUSH_RATE) {
+    Serial.println("Manually closing & reopening datafile.");
+    write2fileCount = 0;
+    usbDeviceWrite("CLF\r");
+    usbOpenFile4Write(usbFileName);
+  }
+}
+
+String dumpUsbOutput()
+{
+    if (usbDev.available() && Serial) {
+    String fromUsb = "";
+    while (usbDev.available()) {
+      char readC = usbDev.read();
+      fromUsb += readC;
+    }
+
+    // wait 10ms to see if anything else comes
+    bool delayWorked = true;
+    while (delayWorked) {
+      delayWorked = false;
+      delay(20);
+      while (usbDev.available()) {
+        delayWorked = true;
+        char readC = usbDev.read();
+        fromUsb += readC;
+      }
+    }
+
+
+    Serial.println("###########################");
+    Serial.println("From USB STICK:");
+    Serial.println(fromUsb);
+    Serial.println("###########################");
+
+    return fromUsb;
+  }
+
+  return "";
+}
+
+void usbOpenFile4Write(const String& filename)
+{
+  usbDeviceWrite("OPW " + filename + "\r");
+  delay(100);
+  dumpUsbOutput();
+}
+
+bool isUsbStickPluggedIn()
+{
+  usbDeviceWriteUnbuffered("DVL\r");
+  delay(100);
+  String response = dumpUsbOutput();
+  return response != "No Device blalbla";
+}
+
+


NFCReader with []field of NFC ID and > as comment

--- NFCReader/NFCReader.ino
+++ NFCReader/NFCReader.ino
@@ -1,47 +1,100 @@
-#include "SPI.h"
-#include "MFRC522.h"
+/**************************************************************************/
+/*!
+    @file     iso14443a_uid.pde
+    @author   Adafruit Industries
+    @license  BSD (see license.txt)

-#define SS_PIN 10
-#define RST_PIN 9
-#define SP_PIN 8
+    This example will attempt to connect to an ISO14443A
+    card or tag and retrieve some basic information about it
+    that can be used to determine what type of card it is.
+
+    Note that you need the baud rate to be 115200 because we need to print
+    out the data and read from the card at the same time!

-MFRC522 rfid(SS_PIN, RST_PIN);
+    This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+    This library works with the Adafruit NFC breakout
+    ----> https://www.adafruit.com/products/364
+
+    Check out the links above for our tutorials and wiring diagrams
+    These chips use I2C to communicate, 4 pins required to interface:
+    SDA (I2C Data) and SCL (I2C Clock), IRQ and RESET (any digital line)

-MFRC522::MIFARE_Key key;
+    Adafruit invests time and resources providing this open source code,
+    please support Adafruit and open-source hardware by purchasing
+    products from Adafruit!
+*/
+/**************************************************************************/
+#include <Wire.h>
+#include <Adafruit_NFCShield_I2C.h>

-void setup() {
-  Serial.begin(9600);
-  SPI.begin();
-  rfid.PCD_Init();
+#define IRQ   (2)
+#define RESET (3)  // Not connected by default on the NFC Shield
+
+Adafruit_NFCShield_I2C nfc(IRQ, RESET);
+
+void setup(void) {
+  Serial.begin(115200);
+  Serial.println(">http://www.github.com/awangga/NFCReader");
+
+  nfc.begin();
+
+  uint32_t versiondata = nfc.getFirmwareVersion();
+  if (! versiondata) {
+    Serial.print(">Didn't find PN53x board, please close and open serial monitor. If problem still exist please check your wiring");
+    while (1); // halt
+  }
+
+  // Got ok data, print it out!
+  Serial.print(">Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
+  Serial.print(">Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
+  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
+
+  // Set the max number of retry attempts to read from a card
+  // This prevents us from waiting forever for a card, which is
+  // the default behaviour of the PN532.
+  nfc.setPassiveActivationRetries(0xFF);
+
+  // configure board to read RFID tags
+  nfc.SAMConfig();
+
+  //Serial.println("Waiting for an ISO14443A card");
 }

-void loop() {
-  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
-    return;
-
-     Serial.print(F("PICC type: "));
-  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
-     Serial.println(rfid.PICC_GetTypeName(piccType));
-
-  // Check is the PICC of Classic MIFARE type
-  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
-    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
-    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
-    Serial.println(F("Your tag is not of type MIFARE Classic."));
-    return;
+void loop(void) {
+  boolean success;
+  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
+  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
+
+  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
+  // 'uid' will be populated with the UID, and uidLength will indicate
+  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
+  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
+
+  if (success) {
+    //Serial.println("Found a card!");
+    //Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
+    //Serial.print("UID Value: ");
+    Serial.print("[");
+    for (uint8_t i=0; i < uidLength; i++)
+    {
+      //Serial.print(uid[i], HEX);
+      if (uid[i] < 16)
+      {
+        Serial.print("0");
+      }
+      Serial.print(uid[i], HEX);
+      if (i<uidLength-1)
+      {
+        Serial.print(':');
+      }
+    }
+    Serial.println("]");
+    // Wait 1 second before continuing
+    delay(1000);
   }
-
-  String strID = "";
-  for (byte i = 0; i < 4; i++) {
-    strID +=
-    (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
-    String(rfid.uid.uidByte[i], HEX) +
-    (i!=3 ? ":" : "");
-  }
-  strID.toUpperCase();
-  Serial.print("Tap card key: ");
-  Serial.println(strID);
-
-  rfid.PICC_HaltA();
-  rfid.PCD_StopCrypto1();
+  //else
+  //{
+    // PN532 probably timed out waiting for a card
+    //Serial.println("Timed out waiting for a card");
+  //}
 }


Update rx5808-pro-diversityGc9n.ino

Update rx5808-pro-diversityGc9n.ino

--- rx5808-pro-diversityGc9n/rx5808-pro-diversityGc9n.ino
+++ rx5808-pro-diversityGc9n/rx5808-pro-diversityGc9n.ino
@@ -40,31 +40,31 @@

 #include "settings.h"

+
 // uncomment depending on the display you are using.
 // this is an issue with the arduino preprocessor

 #ifdef OLED_128x64_ADAFRUIT_SCREENS

   #ifdef SH1106
-    #include <Adafruit_SH1106.h>
-  #else
+   #include <Adafruit_SH1106.h>
+ #else
     #include <Adafruit_SSD1306.h>
-  #endif
+ #endif
     #include <Adafruit_GFX.h>
     #include <Wire.h>
     #include <SPI.h>
 #endif
-#ifdef OLED_128x64_U8G_SCREENS
+//#ifdef OLED_128x64_U8G_SCREENS
 //    #include <U8glib.h>
-#endif
-//const byte PARTHENIA = 0x92;
+//#endif
 #include "screens.h"
 screens drawScreen;

 #define EEPROM_ADR_TUNE_FAV_LAST 108
-#define EEPROM_ADR_TUNE_FAV_LAST_SEARCH 109
+
 int EEPROM_ADR_TUNE_FAV[10]  = {100, 101, 102, 103, 104, 105, 106,107,110,111};
-int temp_EEPROM_ADR_TUNE_FAV[10]  = {255, 255, 255, 255, 255, 255, 255,255,255,255};
+int temp_EEPROM_ADR_TUNE_FAV[10] = {255, 255, 255, 255, 255, 255, 255,255,255,255};
 //setting the 10 favorite channels memory blocks George Chatzisavvidis GC9N

@@ -171,12 +171,18 @@
 bool HaveFav = false;
 bool RefreshFav = false;
 uint8_t FirstFav =0;
-bool FATSHARK_BUTTON_PUSHED=false;
-int  LAST_FATSHARK_BUTTON_STATE=0;
+//bool FATSHARK_BUTTON_PUSHED=false;
+//int  LAST_FATSHARK_BUTTON_STATE=0;
 int lfavs=0;
 // SETUP ----------------------------------------------------------------------------
 void setup()
-{ Serial.begin(9600);
+{
+
+  #ifdef Debug
+  //Serial.begin(9600);
+  #endif
+
+    //
     // IO INIT
     // initialize digital pin 13 LED as an output.
     pinMode(led, OUTPUT); // status pin for TV mode errors
@@ -541,11 +547,11 @@
             #ifdef USE_DIVERSITY
                             EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
             #endif
-
+
+            ///////////////////////FAVORITIES SAVE Gc9n
             if (last_state!=STATE_SETUP_MENU  && state_last_used!=STATE_FAVORITE ) // if you didnt came from menu setup  save favorite
             {
-                // //Serial.println("bike sto vasiko");
-                 if ( EEPROM.read(EEPROM_ADR_TUNE_FAV[10]) != 255) //ALL FAVS full gc9n
+                if ( EEPROM.read(EEPROM_ADR_TUNE_FAV[10]) != 255) //ALL FAVS full gc9n
                   {
                     int lfav;
                     lfav=EEPROM.read(EEPROM_ADR_TUNE_FAV_LAST);
@@ -559,8 +565,7 @@
                     }
                     EEPROM.write(EEPROM_ADR_TUNE_FAV[lfav],255); // rotate the favs if full
                     EEPROM.write(EEPROM_ADR_TUNE_FAV_LAST,lfav);
-
-                  }
+                   }
                 for(int i = 0; i<10; i++)
                 {
                       if ( EEPROM.read(EEPROM_ADR_TUNE_FAV[i]) == 255) //not used  gc9n
@@ -575,7 +580,6 @@
             }
             if (last_state==STATE_SETUP_MENU)
             {
-
              drawScreen.save(state_last_used, channelIndex, pgm_read_word_near(channelFreqTable + channelIndex), call_sign,-99);
             }

@@ -584,9 +588,10 @@
             {
               EEPROM.write(EEPROM_ADR_TUNE_FAV[lfavs],255);
               drawScreen.FavDelete(   pgm_read_word_near(channelFreqTable + channelIndex), lfavs+1);
-              RefreshFav=false;
+
               for(int i = 0; i<10; i++) {temp_EEPROM_ADR_TUNE_FAV[i] =255;   }  //empty temp
-              //--REORGANIZE FAVS
+
+              //--REORGANIZE FAVS  GC9n
                   byte MaxFav=0;
                   for(int i = 0; i<10; i++)
                     {
@@ -602,12 +607,20 @@
                        for(int i = 0; i<10; i++)
                         {
                           EEPROM.write(EEPROM_ADR_TUNE_FAV[i],temp_EEPROM_ADR_TUNE_FAV[i] );
-                          RefreshFav=false;
+
                         }
                         beep(100); // beep
-                         delay(1000);
+
+                        //DELETED SUCCESFULLY AND GO TO FIRST FAV (IF EXISTS)
                         drawScreen.FavReorg(MaxFav);
-
+                        RefreshFav=false;
+                        delay(500);
+                        EEPROM.write(EEPROM_ADR_TUNE_FAV_LAST,0);
+                        channelIndex=EEPROM.read(EEPROM_ADR_TUNE_FAV[0]) ;
+                        drawScreen.FavSel(1);
+                        channel=channel_from_index(channelIndex);
+                        EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
+                        //drawScreen.screenSaver(diversity_mode, pgm_read_byte_near(channelNames + channelIndex), pgm_read_word_near(channelFreqTable + channelIndex), call_sign);
             }
            ///END LONG PRESS IN FAVORITES WILL DELETE THE CURRENT FAVORITE CHANNEL
                 for (uint8_t loop=0;loop<5;loop++)
@@ -632,7 +645,7 @@
                     time_screen_saver=0; // dont show screen saver until we found a channel.
                 }

-                drawScreen.FavMode(state,FirstFav);
+                //drawScreen.FavMode(state,FirstFav);

                 // return user to their saved channel after bandscan
                 if(state_last_used == STATE_SCAN ||state_last_used == STATE_FAVORITE  || last_state == STATE_RSSI_SETUP) {
@@ -741,19 +754,19 @@
                         }
                 }
                 RefreshFav=true;
-        //channel=channel_from_index(channelIndex); // get 0...48 index depending of current channel
+               //channel=channel_from_index(channelIndex); // get 0...48 index depending of current channel
          }  // handling of keys
             if( digitalRead(buttonUp) == LOW)        // channel UP
             {
               delay(KEY_DEBOUNCE); // debounce
                   lfavs++;
                   if (lfavs>FirstFav){lfavs=0;}
-                 //Serial.println  ("UPEEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ");
-                 //Serial.print  (EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) );
-                 //Serial.print  (" lfavs");
-                 //Serial.println  (lfavs );
-                  //Serial.print  (" FirstFav");
-                 //Serial.println  (FirstFav );
+//                 Serial.println  ("UPEEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ");
+//                 Serial.print  (EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) );
+//                 Serial.print  (" lfavs");
+//                 Serial.println  (lfavs );
+//                 Serial.print  (" FirstFav");
+//                 Serial.println  (FirstFav );
                     channelIndex=EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ;
                     if (channelIndex!=255)
                      {
@@ -767,7 +780,7 @@
                         {
                             channelIndex = CHANNEL_MIN_INDEX;
                         }
-                        drawScreen.seekMode(state);
+                       // drawScreen.seekMode(state);
                         EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
                         //Serial.println(channelIndex);
                     }
@@ -802,7 +815,7 @@
                         channelIndex = CHANNEL_MAX_INDEX;
                     }

-                  drawScreen.seekMode(state);
+                  //drawScreen.seekMode(state);
                   EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
                 }
                 else
@@ -812,11 +825,15 @@
         if (HaveFav==false)
         {drawScreen.NoFav(state);

-        }   // IF YOU DINT HAVE FAVS
-
-
+        }   // IF YOU DONT HAVE FAVS
+
         else
-        {drawScreen.updateSeekMode(state, channelIndex, channel, rssi, pgm_read_word_near(channelFreqTable + channelIndex), rssi_seek_threshold, seek_found);}// IF YOU HAVE FAVS
+        {
+          //delay(KEY_DEBOUNCE); // debounce
+          //state = STATE_SCREEN_SAVER;
+           drawScreen.screenSaver(diversity_mode, pgm_read_byte_near(channelNames + channelIndex), pgm_read_word_near(channelFreqTable + channelIndex), call_sign);
+          // drawScreen.updateScreenSaver(active_receiver, rssi, readRSSI(useReceiverA), readRSSI(useReceiverB));
+        }// IF YOU HAVE FAVS

     }

@@ -1220,6 +1237,14 @@
 #ifdef USE_DIVERSITY
         rssiB += analogRead(rssiPinB);//random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
 #endif
+
+#ifdef Debug
+  rssiB +=  random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
+
+  rssiA +=  random(RSSI_MAX_VAL-50, RSSI_MAX_VAL);
+
+#endif
+
     }
     rssiA = rssiA/RSSI_READS; // average of RSSI_READS readings


Don't reset the variable before you pass it in to game.reset() ...

--- Pingduino/Pingduino.ino
+++ Pingduino/Pingduino.ino
@@ -128,10 +128,10 @@
     }

     if (requestReset > 0) {
+      game.restart(requestReset);
+      victorySong.reset();
       p1Score = p2Score = 0;
       requestReset = 0;
-      game.restart(requestReset);
-      victorySong.reset();
     }
   }


Write speed increased to 11.5 Hz

Write speed increased to 11.5 Hz

--- Calibration/liveCode/overclockAccel/overclockAccel.ino
+++ Calibration/liveCode/overclockAccel/overclockAccel.ino
@@ -73,20 +73,14 @@
     sdWriteNewline();
   }
 }
-bool sdWriteNewline() {
+void sdWriteNewline() {
   File dataFile = SD.open(FILENAME, FILE_WRITE);
   // if the file is available, write to it:
-  if (dataFile) {
-    dataFile.println("");
-    dataFile.close();
+  dataFile.println("");
+  dataFile.close();
     // print to the serial port too:
-  }
-  // if the file isn't open, pop up an error:
-  else {
-    dataFile.close();
-  }
 }
-
+
 void sdWrite(String data) {
   File dataFile = SD.open(FILENAME, FILE_WRITE);
   // if the file is available, write to it:


RobotDistanceTest okay

RobotDistanceTest okay


spacing

spacing

--- dorm-leds.ino
+++ dorm-leds.ino
@@ -74,7 +74,6 @@
 void loop() {
 	// Run multithreaded system code
 	led_main_loop();
-
 	ctrl_main_loop();

 	Serial.print(F("Free SRAM: "));


don't need to initialize there

don't need to initialize there

--- dorm-leds.ino
+++ dorm-leds.ino
@@ -52,8 +52,8 @@
 #include "util/free_memory.c"

 // Timing
-unsigned long int prev_time = millis();
-unsigned long int cur_time = millis();
+unsigned long int prev_time;
+unsigned long int cur_time;

 // LCD Display
 LiquidCrystal lcd(LCD_E_PIN, LCD_RS_PIN, LCD_D4_PIN, LDC_D5_PIN, LCD_D6_PIN, LCD_D7_PIN);


Works a litte better now

Works a litte better now

--- Stroller_interruptHandling_1/Stroller_interruptHandling_1.ino
+++ Stroller_interruptHandling_1/Stroller_interruptHandling_1.ino
@@ -7,18 +7,25 @@

 #include <avr/sleep.h>
 #include <avr/power.h>
+/*
+ *
+ */

-#define distance 20
+#define distance 895

 long distanceToDate=0;
+int pinOut = 13;
 int pin2 = 2;
 int hadRound=0;
+
 void countRPM(void)
 {
+//      Serial.println("In count");
+
   sleep_disable();
   detachInterrupt(0);
-  hadRound=1;
+  hadRound=1;

 }

@@ -30,21 +37,31 @@
  ***************************************************/
 void enterSleep(void)
 {
+//      Serial.println("Going to sleep");

   /* Setup pin2 as an interrupt and attach handler. */
+   if (digitalRead(2)==HIGH){
   sleep_enable();
+
   attachInterrupt(0, countRPM, LOW);
-  delay(100);
+    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+//  delay(100);
+//  cli();
+//  sleep_bod_disable();
+//sei();

-  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+

-  sleep_mode();
+  sleep_cpu();

   /* The program will continue from here. */

   /* First thing to do is disable sleep. */
   sleep_disable();
+   } else {
+//     Serial.println("not yet going to sleep");
+   }
 }

@@ -64,7 +81,8 @@

   /* Setup the pin direction. */
   pinMode(pin2, INPUT);
-
+  pinMode(pinOut, OUTPUT);
+
   /* Clear the reset flag. */
   MCUSR &= ~(1<<WDRF);

@@ -101,8 +119,11 @@
  ***************************************************/
 ISR(WDT_vect)
 {
-  Serial.print(millis());
-  Serial.println(" Watchdog overrun");
+//  Serial.print(millis());
+//  Serial.println(" Watchdog overrun");
+  Serial.println(" ");
+  Serial.print("Distance: ");
+  Serial.println(distanceToDate);
 }

@@ -121,17 +142,18 @@
 void loop()
 {
   if (hadRound==1) {
-   distanceToDate=distanceToDate+distance;
-  Serial.print("Distance is now: ");
-  Serial.print(distanceToDate);
-  Serial.print(" at  ");
-  Serial.println(millis());
-  hadRound=0;
-  delay(100);
+    distanceToDate=distanceToDate+distance;
+    digitalWrite(pinOut,HIGH);
+//    Serial.print("Distance is now: ");
+//    Serial.print(distanceToDate);
+//    Serial.print(" at  ");
+//    Serial.println(millis());
+    hadRound=0;
+    delay(100);
   }
-    delay(100);
-      Serial.print(millis());
-
-      Serial.println(" going back to sleep");
-    enterSleep();
+   digitalWrite(pinOut,LOW);
+//  Serial.print(millis());
+//  Serial.println("going back to sleep");
+//  delay(50);
+  enterSleep();
 }


Comments modified, again.

Comments modified, again.

--- SlideBright.ino
+++ SlideBright.ino
@@ -2,7 +2,6 @@
 ** SlideBright - Firmware for the overengineered Hexbright flashlight.
 **               Hexbright: http://hexbright.com/
 **                                ~ Tobias Jäger <Tobias.Jaeger@slidetex.de>
-**
 **
 **
 ** Based on darcbright by Robert Quattlebaum <darco@deepdarc.com>


arduino stuff

arduino stuff

--- arduino/src/robotLEDControllerrev2/robotLEDControllerrev2.ino
+++ arduino/src/robotLEDControllerrev2/robotLEDControllerrev2.ino
@@ -3,12 +3,11 @@
 //
 // Functions:
 // -distance from wall (DONE)
-// -shooting animation (NEEDS TO BE TESTED)
-// -when the ball is in the craddle (charging animation)
-// -ground pass
-// -catch
-// -idle: purple, newton's ball, one led going around,
-// -winning dance
+// -shooting animation (DONE)
+// -autonomous (charging animation) (DONE)
+// -ground pass (DONE)
+// -idle: charging (DONE)
+// -winning dance (fireworks) (DONE)
 //
 // Diagrams of robot: (everything here should be flipped(front->back)!!!!!)
 //   =========Front:==========
@@ -38,6 +37,7 @@
 //led string stuff:
 const int ledsNumber = 80; //number of leds on the strip
 CRGB leds[ledsNumber];
+boolean idleStart[ledsNumber];

 //color data
 uint32_t distanceColor = 0xFF0000; //start off with the color being red
@@ -69,22 +69,28 @@
   pinMode(3, INPUT);

   //interupt pin
-  attachInterrupt(0, readSidecar, RISING);
+  attachInterrupt(1, readSidecar, RISING);
+
+  //seed for random stuff
+  randomSeed(analogRead(3));

   //setup the led strip
   FastLED.addLeds<WS2801, RGB>(leds, ledsNumber);

+  //set 54 random leds for the idle animation
+  for(int i = 0; i<35; i++){
+    r = random(0, 79);
+    idleStart[r] = true;
+  }
+
   //clear the LED strip data
   FastLED.clear();

   //Debugging
   Serial.begin(9600);  //For debugging

-  //random stuff
-  randomSeed(analogRead(0));
-
   //set brightness
-  FastLED.setBrightness(20);
+  FastLED.setBrightness(100);
 }

 void loop(){
@@ -102,48 +108,48 @@
   if (Serial.available() > 0) {
     // read the incoming byte:
     incomingByte = Serial.read();
-  }
-  if (incomingByte == 97){ //a
-    dataRecieved[0] = false;
-    dataRecieved[1] = false;
-    dataRecieved[2] = false;
-    dataRecieved[3] = false;
-    //    clearLeds();
-  }
-  else if (incomingByte == 98){ //b
-    dataRecieved[0] = true;
-    dataRecieved[1] = true;
-    dataRecieved[2] = false;
-    dataRecieved[3] = false;
-    //    setRed();
-  }
-  else if (incomingByte == 99){ //c
-    dataRecieved[0] = false;
-    dataRecieved[1] = false;
-    dataRecieved[2] = false;
-    dataRecieved[3] = true;
-    //    setGreen();
-  }
-  else if (incomingByte == 100){ //d
-    dataRecieved[0] = false;
-    dataRecieved[1] = false;
-    dataRecieved[2] = true;
-    dataRecieved[3] = true;
-    //    shootAndCollect();
-  }
-  else if (incomingByte == 101){ //e
-    dataRecieved[0] = false;
-    dataRecieved[1] = true;
-    dataRecieved[2] = false;
-    dataRecieved[3] = false;
-  }
-  else if (incomingByte == 102){ //f
-    dataRecieved[0] = false;
-    dataRecieved[1] = false;
-    dataRecieved[2] = true;
-    dataRecieved[3] = false;
-  }
-
+
+    if (incomingByte == 97){ //a
+      dataRecieved[0] = false;
+      dataRecieved[1] = false;
+      dataRecieved[2] = false;
+      dataRecieved[3] = false;
+      //    clearLeds();
+    }
+    else if (incomingByte == 98){ //b
+      dataRecieved[0] = true;
+      dataRecieved[1] = true;
+      dataRecieved[2] = false;
+      dataRecieved[3] = true;
+      //    setRed();
+    }
+    else if (incomingByte == 99){ //c
+      dataRecieved[0] = false;
+      dataRecieved[1] = false;
+      dataRecieved[2] = false;
+      dataRecieved[3] = true;
+      //    setGreen();
+    }
+    else if (incomingByte == 100){ //d
+      dataRecieved[0] = false;
+      dataRecieved[1] = false;
+      dataRecieved[2] = true;
+      dataRecieved[3] = true;
+      //    shootAndCollect();
+    }
+    else if (incomingByte == 101){ //e
+      dataRecieved[0] = false;
+      dataRecieved[1] = true;
+      dataRecieved[2] = false;
+      dataRecieved[3] = false;
+    }
+    else if (incomingByte == 102){ //f
+      dataRecieved[0] = true;
+      dataRecieved[1] = false;
+      dataRecieved[2] = true;
+      dataRecieved[3] = false;
+    }
+  }
   //Possible cases
   if (dataRecieved[0] == false && dataRecieved[1] == false && dataRecieved[2] == false && dataRecieved[3] == false){
     //clears the strip
@@ -189,11 +195,11 @@
     //play animation during autonomous
     charging();
   }
-  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
+  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
     //if the alliance color is blue
     allianceColor = CRGB::Blue;
   }
-  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == true && dataRecieved[3] == false){
+  else if (dataRecieved[0] == true && dataRecieved[1] == true && dataRecieved[2] == false && dataRecieved[3] == true){
     //if the alliance color is red
     allianceColor = CRGB::Red;
   }
@@ -215,14 +221,14 @@
 void readSidecar(){
   //reads the data coming from the sidecar when the interrupt is detected
   delayMicroseconds(5000);
-  dataRecieved[0] = digitalRead(3);
+  dataRecieved[0] = digitalRead(12);
   delayMicroseconds(10000);
-  dataRecieved[1] = digitalRead(3);
+  dataRecieved[1] = digitalRead(12);
   delayMicroseconds(10000);
-  dataRecieved[2] = digitalRead(3);
-  delayMicroseconds(100000);
-  dataRecieved[3] = digitalRead(3);
-  delayMicroseconds(100000);
+  dataRecieved[2] = digitalRead(12);
+  delayMicroseconds(10000);
+  dataRecieved[3] = digitalRead(12);
+  delayMicroseconds(10000);

   Serial.print(dataRecieved[0]);
   Serial.print(dataRecieved[1]);
@@ -532,20 +538,66 @@
 void idle(){
   //plays when the robot isn't doing anything specific, but is just driving, defending, etc.
   FastLED.clear();
-  for(int i = 1; i<25; i++){
-    r = random(0, 79);
-    leds[r] = allianceColor;
-  }
-
-}
-
-
-
-
-
-
-
-
-
-
-
+
+  //start with random leds lit
+  for(int i = 0; i < 80; i++){
+    if(idleStart[i] == true){
+      leds[i] = allianceColor;
+    }
+  }
+  FastLED.show();
+  for(int timesPlayed = 0; timesPlayed < 20; timesPlayed++){
+    //make the leds go down the strip
+    for(int i = 0; i < 19; i++){
+      leds[i].r = leds[i+1].r;
+      leds[i].g = leds[i+1].g;
+      leds[i].b = leds[i+1].b;
+    }
+    leds[19].r = leds[0].r;
+    leds[19].g = leds[0].g;
+    leds[19].b = leds[0].b;
+
+    for(int i = 39; i >= 21; i--){
+      leds[i].r = leds[i-1].r;
+      leds[i].g = leds[i-1].g;
+      leds[i].b = leds[i-1].b;
+    }
+    leds[20].r = leds[39].r;
+    leds[20].g = leds[39].g;
+    leds[20].b = leds[39].b;
+    for(int i = 40; i < 59; i++){
+      leds[i].r = leds[i+1].r;
+      leds[i].g = leds[i+1].g;
+      leds[i].b = leds[i+1].b;
+    }
+    leds[59].r = leds[40].r;
+    leds[59].g = leds[40].g;
+    leds[59].b = leds[40].b;
+    for(int i = 79; i >= 61; i--){
+      leds[i].r = leds[i-1].r;
+      leds[i].g = leds[i-1].g;
+      leds[i].b = leds[i-1].b;
+    }
+    leds[60].r = leds[79].r;
+    leds[60].g = leds[79].g;
+    leds[60].b = leds[79].b;
+    FastLED.show();
+    delay(100);
+    Serial.println("hi");
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


Add AutoAck,USBInterface Prototype

Add AutoAck,USBInterface Prototype

--- ArduinoSensorBoard/ArduinoSensorBoard.ino
+++ ArduinoSensorBoard/ArduinoSensorBoard.ino
@@ -2,13 +2,14 @@
 #include "nRF24L01.h"
 #include "RF24.h"
 #include "DHT.h"
-//#include "printf.h"
+#include "printf.h"

 #define DHTPIN 2
 #define DHTTYPE DHT11

 RF24 radio(8,9);
 DHT dht(DHTPIN, DHTTYPE);
+byte incomingByte = 0;

 const uint64_t pipes[2] = {
   0xF0F0F0F001LL, 0xF0F0F0F002LL };
@@ -28,7 +29,7 @@
   dht.begin();
   radio.begin();

-  radio.setAutoAck(false);
+  radio.setAutoAck(true);
   radio.setRetries(15,15);
   radio.setPALevel(RF24_PA_MAX);
   radio.openReadingPipe(1,pipes[1]);
@@ -48,6 +49,17 @@
   byte command[32] ;
   byte *ptr = &command[0];
   uint8_t pipenum = 0;
+   if (Serial.available() > 0) {  //если есть доступные данные
+        // считываем байт
+        incomingByte = Serial.read();
+
+        // отсылаем то, что получили
+        Serial.println(incomingByte);
+        switch(incomingByte){
+        case 49: Serial.println("Test");
+
+        }
+    }
   if ( radio.available(&pipenum))
   {


changed distance between two ticks

changed distance between two ticks

--- arduino/kurbel/kurbel.ino
+++ arduino/kurbel/kurbel.ino
@@ -24,7 +24,8 @@
 long last_value = 0;
 long act_value = 0;

-int distance = 10; // how many ticks until keypress is fired, 10 seemed to result in ~8 keys per round
+//int distance = 10; // how many ticks until keypress is fired, 10 seemed to result in ~8 keys per round
+int distance = 6; // how many ticks until keypress is fired, 10 seemed to result in ~8 keys per round

 void loop() {


script arduino led

script arduino led

--- bp_led.ino
+++ bp_led.ino
@@ -52,5 +52,5 @@
 // turn LED Off:
 void turnOff(){
   digitalWrite(ledPin, LOW);
-  Serial.println(CONST_ID+":"+CONST_TYPE+":2");
+  Serial.println(CONST_ID+":"+CONST_TYPE+":0");
 }


aAdded second termometer

aAdded second termometer

--- hacks/rf_temp_sensor/rf_temp_sensor_sensor/rf_temp_sensor_sensor.ino
+++ hacks/rf_temp_sensor/rf_temp_sensor_sensor/rf_temp_sensor_sensor.ino
@@ -22,9 +22,11 @@
 OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
 DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
 DeviceAddress firstThermometer = { 0x28, 0xFF, 0xAD, 0x82, 0x61, 0x15, 0x02, 0xE8 }; // Assign the addresses of your 1-Wire temp sensors.
+DeviceAddress secondThermometer = { 0x28, 0xFF, 0x6A, 0xB3, 0x64, 0x15, 0x01, 0x8B }; // Assign the addresses of your 1-Wire temp sensors.
 String messageString = "";
 int messageId = 0;
-float tempC = -127.00; //-127.00 is the error temp
+float temp1C = -127.00; //-127.00 is the error temp
+float temp2C = -127.00; //-127.00 is the error temp
 float vIn = 0.00;

 void setup() {
@@ -50,7 +52,8 @@
   // Get and print temperature
   Serial.println("Getting temperatures...");
   sensors.requestTemperatures();
-  tempC = sensors.getTempC(firstThermometer);
+  temp1C = sensors.getTempC(firstThermometer);
+  temp2C = sensors.getTempC(secondThermometer);

   // Get and print battery voltage
   Serial.println("Getting voltage...");
@@ -60,12 +63,19 @@
   // Make message, e.g. "I:1 T:22.50 \n"
   messageString = "I:";
   messageString = messageString + String(messageId, DEC);
-  messageString = messageString + " T:";
-  if (tempC == -127.00) {
+  messageString = messageString + " T1:";
+  if (temp1C == -127.00) {
     Serial.println("Error getting temperature");
     messageString = messageString + "E";
   } else {
-    messageString = messageString + String(tempC, 2);
+    messageString = messageString + String(temp1C, 2);
+  }
+  messageString = messageString + " T2:";
+  if (temp2C == -127.00) {
+    Serial.println("Error getting temperature");
+    messageString = messageString + "E";
+  } else {
+    messageString = messageString + String(temp2C, 2);
   }
   messageString = messageString + " V:";
   messageString = messageString + String(vIn, 2);


ok funzionane

ok funzionane

--- prova/src/provavoltage.ino
+++ prova/src/provavoltage.ino
@@ -13,7 +13,7 @@
 #define TWI_RX_BUFFER_SIZE ( 16 )
 #endif
 int pinLed = 1;
-int watch_dog_counter = 2;
+int watch_dog_counter = 50;
 volatile byte reg_position = 0;
 const byte reg_size = sizeof(cv.dati); //dati son il valore della tensione vedi checkvoltage.ino
 void setup(){
@@ -28,7 +28,7 @@
   TinyWireS.onRequest(requestEvent);
 }
 void loop(){
-  if (watch_dog_counter>=2) {  // 90*8 sec =13 min : wait for timed out watchdog / flag is set when a watchdog timeout occurs
+  if (watch_dog_counter>=50) {  // 90*8 sec =13 min : wait for timed out watchdog / flag is set when a watchdog timeout occurs
     watch_dog_counter=0;        // reset flag
     digitalWrite(pinLed,HIGH);  // let led blink -> esp-01 power on
   }


Move SD card setup out of functions

Move SD card setup out of functions

--- RouterReset.ino
+++ RouterReset.ino
@@ -59,9 +59,7 @@
   pinMode(greenLed, OUTPUT);
   pinMode(yellowLed, OUTPUT);

-  //Initialize serial and wait for port to open:
   flash_3leds(redLed, greenLed, yellowLed, 5, 100);
-  flash_3leds(redLed, greenLed, yellowLed, 5, 400);

   // check for the presence of the shield:
   if (WiFi.status() == WL_NO_SHIELD) {
@@ -82,7 +80,17 @@
   delay(500);
   if( Udp.parsePacket() ) get_and_set_time();

-  open_file();
+  // setup SD card and log file
+  pinMode(10, OUTPUT);
+  while(!SD.begin(chipSelect)) flash_3leds(redLed, greenLed, yellowLed, 5, 400);
+  char filename[] = "wifi_log.txt";
+  logfile = SD.open(filename, FILE_WRITE);
+  time_to_string(now(), time_as_string);
+  logfile.print("\nStart up - ");
+  logfile.println(time_as_string);
+  logfile.flush();
+
+  flash_3leds(redLed, greenLed, yellowLed, 5, 100);
 }

 void loop() {
@@ -97,7 +105,6 @@
     digitalWrite(yellowLed, HIGH);
     connect_to_server();
     digitalWrite(yellowLed, LOW);
-
   }

   if(canConnect) {
@@ -108,12 +115,16 @@
     digitalWrite(greenLed, LOW);
     digitalWrite(redLed, HIGH);
   }
+
+  // log change in connection status
   if(canConnect != canConnect_prev) {
     time_to_string(now(), time_as_string);
     logfile.print(time_as_string);
     logfile.print(" - ");
-    if(canConnect) logfile.println("connected.");
-    else logfile.println("NOT CONNECTED!");
+    if(canConnect)
+      logfile.println("connected.");
+    else
+      logfile.println("NOT CONNECTED!");
     logfile.flush();

     canConnect_prev = canConnect;
@@ -151,7 +162,7 @@
   }
 }

-// send an NTP request to the time server at the given address
+// send an NTP request to the time server
 unsigned long sendNTPpacket(IPAddress& address)
 {
   memset(packetBuffer, 0, NTP_PACKET_SIZE);
@@ -186,12 +197,3 @@
           month(epoch), day(epoch), year(epoch),
           hour(epoch), minute(epoch), second(epoch));
 }
-
-void open_file(void) {
-  char filename[] = "log_****-11-11_12:59:59.csv";
-
-  sprintf(filename, "log_%4d-%02d-%02d_%02d:%02d:%02d.csv",
-          year(), month(), day(), hour(), minute(), second());
-
-  logfile = SD.open(filename, FILE_WRITE);
-}


NemoWeight : 0

NemoWeight : 0

--- _03-hx711-scale/_03-hx711-scale-v3-adaptor/_03-hx711-scale-esp-12/_03-hx711-scale-esp-12.ino
+++ _03-hx711-scale/_03-hx711-scale-v3-adaptor/_03-hx711-scale-esp-12/_03-hx711-scale-esp-12.ino
@@ -159,6 +159,8 @@

   payload = "{\"WeightPoop\":";
   payload += ( measured_poop - measured_empty );
+  payload += ",\"NemoWeight\":";
+  payload += 0;
   payload += "}";

   sendHx711toMqtt(payload, topicEvery);