Improve button intialization and updates

--- midicontroller.ino
+++ midicontroller.ino
@@ -18,13 +18,30 @@
 const int ledPin = 13;

 const byte channelButtonStart = 0;
-//const byte channelButtonLedStart = 14;
 const byte numberOfChannelButtons = 2;
 const byte ledPins[] = {/*10, 11, 12,*/ 14, 15, 16};
 Bounce channelButtons[numberOfChannelButtons];
 boolean channelButtonStates[numberOfChannelButtons];
 boolean channelButtonDown[numberOfChannelButtons];

+const byte bankDownPin = 6;
+const byte bankUpPin = 7;
+Bounce bankDownButton = Bounce();
+Bounce bankUpButton = Bounce();
+boolean bankDownState;
+boolean bankDownDown;
+boolean bankUpState;
+boolean bankUpDown;
+
+const byte stopPin = 8;
+const byte playPin = 9;
+Bounce stopButton = Bounce();
+Bounce playButton = Bounce();
+boolean stopState;
+boolean stopDown;
+boolean playState;
+boolean playDown;
+
 const byte bpmLed = 22;

@@ -54,12 +71,20 @@

 void setupButtons() {
   for (byte i = 0; i < numberOfChannelButtons; i++) {
-    pinMode(channelButtonStart + i, INPUT_PULLUP);
-    channelButtons[i].attach(channelButtonStart + i);
-    channelButtons[i].interval(10);
-    channelButtonStates[i] = false;
-    channelButtonDown[i] = false;
-  }
+    initButton(channelButtonStart + i, &channelButtons[i], &channelButtonStates[i], &channelButtonDown[i]);
+  }
+  initButton(bankDownPin, &bankDownButton, &bankDownState, &bankDownDown);
+  initButton(bankUpPin, &bankUpButton, &bankUpState, &bankUpDown);
+  initButton(stopPin, &stopButton, &stopState, &stopDown);
+  initButton(playPin, &playButton, &playState, &playDown);
+}
+
+void initButton(byte pin, Bounce *button, boolean *state, boolean *down) {
+  pinMode(pin, INPUT_PULLUP);
+  (*button).attach(pin);
+  (*button).interval(10);
+  *state = false;
+  *down = false;
 }

 void setupLeds() {
@@ -105,18 +130,27 @@

 void updateButtons() {
   for (byte i = 0; i < numberOfChannelButtons; i++) {
-    if (channelButtons[i].update()) {
-      if (channelButtons[i].read() == LOW) {
-        channelButtonDown[i] = true;
-      } else if (channelButtonDown[i]) {
-        channelButtonStates[i] = 1 - channelButtonStates[i];
-        channelButtonDown[i] = false;
-        if (channelButtonStates[i]) {
-          digitalWrite(ledPins[i], HIGH);
-        } else {
-          digitalWrite(ledPins[i], LOW);
-        }
-      }
+    updateButtonState(channelButtonStart + i, &channelButtons[i], &channelButtonStates[i], &channelButtonDown[i]);
+  }
+  updateButtonState(bankDownPin, &bankDownButton, &bankDownState, &bankDownDown);
+  updateButtonState(bankUpPin, &bankUpButton, &bankUpState, &bankUpDown);
+  updateButtonState(stopPin, &stopButton, &stopState, &stopDown);
+  updateButtonState(playPin, &playButton, &playState, &playDown);
+}
+
+void updateButtonState(byte pin, Bounce *button, boolean *state, boolean *down) {
+  if ((*button).update()) {
+    if ((*button).read() == LOW) {
+      *down = true;
+      Serial.print("Button ");
+      Serial.print(pin);
+      Serial.println(" down");
+    } else if (*down) {
+      Serial.print("Button ");
+      Serial.print(pin);
+      Serial.println(" up");
+      *state = 1 - *state;
+      *down = false;
     }
   }
 }
@@ -125,6 +159,19 @@
 {
   usbMIDI.read();
   updateButtons();
+  updateLeds();
+
+
+}
+
+void updateLeds() {
+  for (byte i = 0; i < numberOfChannelButtons; i++) {
+    if (channelButtonStates[i]) {
+      digitalWrite(ledPins[i], HIGH);
+    } else {
+      digitalWrite(ledPins[i], LOW);
+    }
+  }
 }

 void RealTimeSystem(byte realtimebyte) {


Added files via upload

Added files via upload

--- FeatherChorder/FeatherChorder.ino
+++ FeatherChorder/FeatherChorder.ino
@@ -1,8 +1,11 @@
 /*
  * Arduino code for a Bluetooth version of the Chorder.
  * @author: clc@clcworld.net
- * some additional code by: priestdo@budgardr.org
+ * additional code by: priestdo@budgardr.org
  * This version tested on/with the Adafruit Feather 32u4 Bluefruit LE
+ *
+ * It is a new arduino based chorder inspired by the SpiffChorder
+ * which can be found at http://symlink.dk/projects/spiffchorder/
  */

 #include <Arduino.h>


MQTT hangs on WIFI disconnect fix

MQTT hangs on WIFI disconnect fix

Added software reset.

Redacted my connection info this time

--- bruh_mqtt_multisensor_github/bruh_mqtt_multisensor_github.ino
+++ bruh_mqtt_multisensor_github/bruh_mqtt_multisensor_github.ino
@@ -19,7 +19,9 @@
       - Adafruit unified sensor
       - PubSubClient
       - ArduinoJSON
-
+
+	Update by Knutella 5-16-2017 Fixed MQTT disconnects when wifi drops by moving around Reconnect and adding a software reset of MCU
+
 */

@@ -35,11 +37,11 @@

 /************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/
-#define wifi_ssid "YourSSID" //type your WIFI information inside the quotes
-#define wifi_password "YourWIFIpassword"
-#define mqtt_server "your.mqtt.server.ip"
-#define mqtt_user "yourMQTTusername"
-#define mqtt_password "yourMQTTpassword"
+#define wifi_ssid "REDACTED" //type your WIFI information inside the quotes
+#define wifi_password "REDACTED"
+#define mqtt_server "REDACTED"
+#define mqtt_user "REDACTED"
+#define mqtt_password "REDACTED"
 #define mqtt_port 1883

@@ -186,7 +188,7 @@
   Serial.println("Ready");
   Serial.print("IPess: ");
   Serial.println(WiFi.localIP());
-
+  reconnect();
 }

@@ -402,17 +404,16 @@
 }

-
 /********************************** START MAIN LOOP***************************************/
 void loop() {

   ArduinoOTA.handle();
-
+
   if (!client.connected()) {
-    reconnect();
+    // reconnect();
+    software_Reset();
   }
   client.loop();
-

   if (!inFade) {

@@ -592,3 +593,9 @@
   return val;
 }

+/****reset***/
+void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
+{
+Serial.print("resetting");
+ESP.reset();
+}


Change to always adjust RTC when compiling

--- NeoPixelNightLight/NeoPixelNightLight.ino
+++ NeoPixelNightLight/NeoPixelNightLight.ino
@@ -20,8 +20,9 @@
 // neopixel
 #include "NeoPixelWheel.h"

+#define NEOPIXEL_LEDS 12
+
 #define NEOPIXEL_DATA_PIN 6
-#define NEOPIXEL_LEDS 12
 #define ANALOG_COLOR_PIN A0
 #define ANALOG_BRIGHTNESS_PIN A1

@@ -146,21 +147,22 @@
       delay(1000);
     }
   }
-
-  DateTime now = rtc.now();
-  Serial.print( F("Rtc now is "));
-  Serial.print(now.unixtime(),HEX);
-  Serial.print(F(" which is "));
-  Processor::printTime(now);
-  Serial.println("");
-
-  haveRtc = now.hour() <= 24 || now.minute() <= 60 || now.month() <= 12; // all above succeeds

-  if (!rtc.isrunning()) {
-    Serial.println(F("RTC is NOT running!"));
+  if ( rtc.isrunning() ) {
     // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(compileTime);
+
+    DateTime now = rtc.now();
+    Serial.print( F("Rtc now is "));
+    Serial.print(now.unixtime(),HEX);
+    Serial.print(F(" which is "));
+    Processor::printTime(now);
+    Serial.println("");
+
+    haveRtc = now.hour() <= 24 || now.minute() <= 60 || now.month() <= 12; // all above succeeds
   }
-
+  else {
+    Serial.println(F("RTC is NOT running!"));
+  }
 }


some cleanup, and the ability to hold down buttons from USB

--- teensy/teensy.ino
+++ teensy/teensy.ino
@@ -24,7 +24,6 @@

 #include "crc_table.h"
 #include <SdFatConfig.h>
-#include <FreeStack.h>
 #include <MinimumSerial.h>
 #include <SdFat.h>
 #include <BlockDriver.h>
@@ -82,6 +81,9 @@
 static volatile bool bufferHasData;
 static void updateInputBuffer();

+static bool hold = false;
+static bool finished = false;
+
 static size_t getNextRegion(size_t& size) {
   size_t currentPos = bufferPos;
   if ((currentPos == bufferEndPos || (currentPos == 0 && bufferEndPos == INPUT_BUFFER_SIZE)) && bufferHasData) {
@@ -108,6 +110,8 @@
 {
   size_t pos = bufferPos + bytes;
   if (pos == bufferEndPos) {
+    if (hold)
+      return;
     bufferHasData = false;
     bufferPos = pos;
     return;
@@ -126,8 +130,15 @@
     size_t writePos = getNextRegion(writeLen);
     if (writeLen > dataLeft)
       writeLen = dataLeft;
-    memcpy(inputBuffer + writePos, data.c_str() + totalWritten, writeLen);
-    totalWritten += writeLen;
+    if (writeLen) {
+      memcpy(inputBuffer + writePos, data.c_str() + totalWritten, writeLen);
+      totalWritten += writeLen;
+      noInterrupts();
+      finished = false;
+      bufferEndPos = writePos + writeLen;
+      bufferHasData = true;
+      interrupts();
+    }
   } while (writeLen > 0);
   return totalWritten;
 }
@@ -135,8 +146,6 @@
 static FatFile m64File;
 static bool m64OpenSuccess = false;
 static bool openM64(const String& path);
-
-static bool finished = false;

 //static unsigned int progressPos = 0;
 static unsigned long numFrames = 0, curFrame = 0;
@@ -314,6 +323,8 @@
   } else if (cmd.startsWith("IN:")) {
     size_t len = appendInputs(hextobin(cmd.substring(3)));
     lockedPrintln("IN:", len);
+  } else if (cmd.startsWith("HL:")) {
+    hold = cmd[3] == '1';
   } else if (cmd.startsWith("CL:")) {
     writeFile.close();
     lockedPrintln("CL:OK");
@@ -384,11 +395,8 @@
     startTimer();
     volatile uint32_t *config = portConfigRegister(N64_PIN);
     uint32_t oldConfig = *config;
+    bool haveFrame;
 //    unsigned int curPos;
-
-    // Bail if file open failed
-    if (!m64OpenSuccess)
-        goto end;

     *config &= ~0x000F0000;

@@ -421,18 +429,20 @@
             Serial.println("P:");
             break;
         case 0x01:
+            haveFrame = (!finished && bufferHasData);
             // If the TAS is finished, there's nothing left to do.
-            if (finished || !bufferHasData)
+            if (haveFrame)
+              memcpy(output_buffer, inputBuffer + bufferPos, 4);
+            else
               memset(output_buffer, 0, 4);
-            else
-              memcpy(output_buffer, inputBuffer + bufferPos, 4);

             // blast out the pre-assembled array in output_buffer
             n64_send(output_buffer, 4, 1);

-            if (finished) {
+            if (!haveFrame)
               break;
-            }
+
+            curFrame++;

             logFrame();

@@ -443,15 +453,12 @@
             Serial.print(F(" Data: "));
             Serial.println(inputBuffer[bufferPos]);*/

-            if (curFrame == numFrames && !finished) {
+            if (curFrame == numFrames) {
               Serial.println("C:");
               finished = true;
             }

-            curFrame++;
-
-            if (!finished && bufferHasData)
-              advanceBuffer(4);
+            advanceBuffer(4);

 //            while (Serial.availableForWrite() && readTimer() < 10 * 1000 * MICRO_CYCLES && N64_QUERY);

@@ -555,7 +562,6 @@
             break;
     }

-end:
     *config = oldConfig;

     interrupts();
@@ -614,7 +620,7 @@
     m64File.seekSet(0x018);

     // Open header
-    int32_t newNumFrames;
+    uint32_t newNumFrames;
     if (m64File.read(&newNumFrames, 4) != 4) {
         m64File.close();
         Serial.println(F("E:Failed to read frame count"));
@@ -648,7 +654,6 @@

     Serial.write("N:");
     Serial.println(newNumFrames);
-
     Serial.flush();

     // Wait for the line to go idle, then begin listening


Update 2018-Firefighter.ino

Update 2018-Firefighter.ino

--- 2018-Firefighter/2018-Firefighter.ino
+++ 2018-Firefighter/2018-Firefighter.ino
@@ -17,6 +17,8 @@
 #define FRONT_US_TRIG   3
 #define LEFT_US_ECHO   18
 #define LEFT_US_TRIG   19
+#define RIGHT_US_ECHO  20
+#define RIGHT_US_TRIG 21

 Servo leftServo;
 Servo rightServo;
@@ -24,6 +26,7 @@

 Ultrasonic frontUltrasonic(FRONT_US_ECHO, FRONT_US_TRIG, true);
 Ultrasonic leftUltrasonic(LEFT_US_ECHO, LEFT_US_TRIG, true);
+Ultrasonic rightUltrasonic(RIGHT_US_ECHO, RIGH_US_TRIG, true);

 void moveForward() {
   leftServo.write(180);
@@ -68,6 +71,12 @@

 void extinguishFire(){
   while (detectFire()) {
+     if (detectFire()){
+      digitalWrite(FLAME_LED, HIGH);
+     } else {
+     digitalWrite(FLAME_LED, LOW);
+     }
+
     if (frontUltrasonic.getDistance() > 3) {
       moveForward();
     } else {
@@ -125,12 +134,6 @@
   mazeNav();
   extinguishFire();
   delay(100);
-
-  if (detectFire()){
-    digitalWrite(FLAME_LED, HIGH);
-  } else {
-    digitalWrite(FLAME_LED, LOW);
-  }

   if (usingCamera()){
     digitalWrite(CAMERA_LED, HIGH);


通信ポートがソフトシリアルかハードシリアルかの処理の違いをifdefで実現

通信ポートがソフトシリアルかハードシリアルかの処理の違いをifdefで実現

--- WiFiTelnetToSerial/WiFiTelnetToSerial.ino
+++ WiFiTelnetToSerial/WiFiTelnetToSerial.ino
@@ -2,7 +2,7 @@
 #define DEBUG
 #define CONSOLE_MESSAGE
 #define ESP
-
+//#define SOFT_SERIAL

 #define TIMER_THRESHOLD 60
 #define MAX_PASS_RETRY 3
@@ -19,6 +19,10 @@
 #define LOGIN_PASSWD_FILE "pass.txt"
 #define WIFI_SSID_FILE "ssid.txt"
 #define WIFI_PASS_FILE "wifipass.txt"
+
+#define SOFT_SERIAL_RX_PIN 16
+#define SOFT_SERIAL_TX_PIN 4
+
 /*
   状態遷移
     初期状態    STATE_START          0
@@ -53,6 +57,11 @@
 #include <SD.h>
 #include <ESP8266WiFi.h>

+#ifdef SOFT_SERIAL
+#include <EspSoftwareSerial.h>
+EspSoftwareSerial swSer(SOFT_SERIAL_RX_PIN,SOFT_SERIAL_TX_PIN, false, 256);  // Rx ,Tx, inverse_logic, buffSize
+#endif /* SOFT_SERIAL */
+
 char wifi_ssid[MAX_WIFI_SSID_SIZE];
 char wifi_pass[MAX_WIFI_PASS_SIZE];
 char passwd[MAX_USER_PASS_SIZE];
@@ -416,11 +425,28 @@
             promptCommand();
             return STATE_COMMAND;
           default:
+#ifdef SOFT_SERIAL
+            swSer.write(incomingByte);
+#else /* SOFT_SERIAL */
             Serial.write(incomingByte);
+#endif /* SOFT_SERIAL */
         }
       }
     }
   }
+#ifdef SOFT_SERIAL
+  //check UART for data
+  if(swSer.available()){
+    size_t len = swSer.available();
+    uint8_t sbuf[len];
+    swSer.readBytes(sbuf, len);
+    //push UART data to all connected telnet clients
+    if (serverClient && serverClient.connected()) {
+      serverClient.write(sbuf, len);
+      delay(1);
+    }
+  }
+#else /* SOFT_SERIAL */
   //check UART for data
   if(Serial.available()){
     size_t len = Serial.available();
@@ -432,6 +458,7 @@
       delay(1);
     }
   }
+#endif /* SOFT_SERIAL */
   return STATE_RELAY;
 }


Moved random seed to random eval code

Moved random seed to random eval code

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -130,7 +130,6 @@

   }

-  randomSeed(analogRead(0));
   static unsigned long timePassed;
   static int changeVal;
   static int markovShakeState;
@@ -154,6 +153,7 @@
   }

 if(millis() - timePassed >= 1000){
+    randomSeed(analogRead(0));
     changeVal = getMarkovSpeed(changeVal);
     markovShakeState = markovState(10, 20);


Update Sim800/Sim900 example

Update Sim800/Sim900 example

--- examples/Boards_GSM/SIM800_SIM900/SIM800_SIM900.ino
+++ examples/Boards_GSM/SIM800_SIM900/SIM800_SIM900.ino
@@ -78,8 +78,11 @@
   delay(3000);

   // Restart takes quite some time
-  // You can skip it in many cases
+  // To skip it, call init() instead of restart()
   modem.restart();
+
+  // Unlock your SIM card with a PIN
+  //modem.simUnlock("1234");

   Blynk.begin(auth, modem, apn, user, pass);
 }


slight mods on timing to help with leostick leonardo bootloader

--- SimpleBotFirmata/SimpleBotFirmata.ino
+++ SimpleBotFirmata/SimpleBotFirmata.ino
@@ -627,8 +627,12 @@
   */
 }

+
 void setup()
 {
+
+  while (!Serial) {};
+
   Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

   Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);


Update Ecran Début ecrans de debug, manque actualisation des variables

--- Ecran/BotMenu/BotMenu.ino
+++ Ecran/BotMenu/BotMenu.ino
@@ -300,6 +300,31 @@
 };
 M2_VLIST(el_muse_vlist, "c2", muse_list);
 M2_ALIGN(top_el_muse, "-1|1W64H64", &el_muse_vlist);
+
+
+//____________________________________________________________________________________________________
+/*=== Debug menu ===*/
+uint32_t global_value_01 = 245;
+uint32_t global_value_02 = 126;
+//M2_U32NUM(el_u8_cb, "c6", &global_value);
+//M2tk m2(&el_u8_cb, NULL, NULL, m2_gh_u8g_bfs);
+
+M2_LABEL(el_num_label_debug_01, NULL, "Var_1:");
+M2_U32NUM(el_num_debug_01, "c3r1", &global_value_01);
+
+M2_LABEL(el_num_label_debug_02, NULL, "Var_2:");
+M2_U32NUM(el_num_debug_02, "c3r1", &global_value_02);
+
+
+M2_LIST(num_list_debug) = {
+    &el_num_label_debug_01, &el_num_debug_01, &el_num_label_debug_02, &el_num_debug_02,
+    &el_num_label_debug_01, &el_num_debug_01, &el_num_label_debug_02, &el_num_debug_02,
+    &el_num_label_debug_01, &el_num_debug_01, &el_num_label_debug_02, &el_num_debug_02,
+    &el_num_label_debug_01, &el_num_debug_01, &el_num_goto_top
+};
+
+M2_GRIDLIST(el_num_list_debug, "c4", num_list_debug);
+M2_ALIGN(el_top_num_menu_debug, "-1|1W64H64", &el_num_list_debug);

 //____________________________________________________________________________________________________
@@ -379,7 +404,9 @@
   { ". Test Pince", &el_top_num_menu_2},
   { ". Test Moteur", &top_el_muse},
   //{ ". File Select", &el_top_fs },
-  { "Debug ", &top_el_muse },
+  { "Debug ", NULL },
+  { ". Debug Moteur", &el_top_num_menu_debug},
+  { ". Debug Autre", &el_top_num_menu_debug},
   { "Top", &top_el_expandable_menu },
   { NULL, NULL },
 };


sketch again

sketch again

--- CAN_Pipe/ArduinoSketch/ArduinoSketch.ino
+++ CAN_Pipe/ArduinoSketch/ArduinoSketch.ino
@@ -17,7 +17,6 @@
 void setup()
 {
     Serial.begin(115200);
-    //pinMode(LED,OUTPUT);
     Serial.println("0|0 0 0 0 0 0 0 0");

     while (CAN_OK != CAN.begin(CAN_500KBPS))              // init can bus : baudrate = 500k


Small fix ups

Small fix ups

--- arduino/moodbeam.ino
+++ arduino/moodbeam.ino
@@ -15,12 +15,11 @@
 #include <Adafruit_NeoPixel.h>
 #include "moodbeam.h"

-
-
 ThreadController controller = ThreadController();
 Thread flashColorThread = Thread();
 Thread alternateColorsThread = Thread();
 Thread fadeThread = Thread();
+Thread rainbowThread = Thread();

 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(
 	NUM_PIXELS,
@@ -29,14 +28,14 @@
 );

 String cmd;
-
 byte colorOne[3];
 byte colorTwo[3];
 byte fadeBrightness;
+int rainbowCounter;

 bool isFlashColor = false;
 bool isColorOne = false;
-bool rainbowRunning = false;
+bool isRainbowRunning = false;
 bool isFadingDown = true;

 void setup()
@@ -50,9 +49,13 @@
 	fadeThread.onRun(fade);
 	fadeThread.enabled = false;

+	rainbowThread.onRun(showRainbow);
+	rainbowThread.enabled = false;
+
 	controller.add(&flashColorThread);
 	controller.add(&alternateColorsThread);
 	controller.add(&fadeThread);
+	controller.add(&rainbowThread);

 	delay(2000);
 	Serial.begin(9600);
@@ -60,7 +63,7 @@
 	pixels.begin();
 	pixels.show();

-	Timer1.initialize(5000);
+	Timer1.initialize(10000);
 	Timer1.attachInterrupt(timerCallback);
 	Timer1.start();
 }
@@ -74,78 +77,76 @@
 {
 	while (!Serial.available());

-	delay(25);
+	delay(5);

 	while(Serial.available())
 	{
-		if (Serial.available() > 0)
-		{
-			char data = (char)Serial.read();
-			cmd += data;
-
-			if(data == 0x0A) {
-
-				flashColorThread.enabled = false;
-				alternateColorsThread.enabled = false;
-				fadeThread.enabled = false;
-
-				setBrightness(255);
-
-				switch (cmd[0])
-				{
-					case (char)SHOW_COLOR:
-						setColor(-1, cmd[1], cmd[2], cmd[3]);
-						break;
-
-					case (char)SET_BRIGHTNESS:
-						setBrightness(cmd[1]);
-						break;
-
-					case (char)TWO_COLOR:
-						setColor(0, cmd[1], cmd[2], cmd[3]);
-						setColor(1, cmd[4], cmd[5], cmd[6]);
-						break;
-
-					case (char)ALTERNATE_COLORS:
-						colorOne[0] = cmd[1];
-						colorOne[1] = cmd[2];
-						colorOne[2] = cmd[3];
-
-						colorTwo[0] = cmd[4];
-						colorTwo[1] = cmd[5];
-						colorTwo[2] = cmd[6];
-
-						alternateColorsThread.setInterval(cmd[7] * 100);
-						alternateColorsThread.enabled = true;
-						break;
-
-					case (char)FLASH_COLOR:
-						colorOne[0] = cmd[1];
-						colorOne[1] = cmd[2];
-						colorOne[2] = cmd[3];
-
-						flashColorThread.setInterval(cmd[4] * 100);
-						flashColorThread.enabled = true;
-						break;
-
-					case (char)SHOW_RAINBOW:
-						showRainbow(cmd[1]);
-						break;
-
-					case (char)FADE:
-						setColor(-1, cmd[1], cmd[2], cmd[3]);
-						fadeBrightness = 255;
-						isFadingDown = true;
-
-						Serial.println(cmd[4] * 1);
-
-						fadeThread.setInterval(cmd[4] * 1);
-						fadeThread.enabled = true;
-						break;
-				}
+		char data = (char)Serial.read();
+		cmd += data;
+
+		if(data == 0x0A) {
+
+			flashColorThread.enabled = false;
+			alternateColorsThread.enabled = false;
+			fadeThread.enabled = false;
+			rainbowThread.enabled = false;
+
+			setBrightness(255);
+
+			switch (cmd[0])
+			{
+				case (char)SHOW_COLOR:
+					colorOne[0] = cmd[1];
+					colorOne[1] = cmd[2];
+					colorOne[2] = cmd[3];
+
+					setColor(-1, cmd[1], cmd[2], cmd[3]);
+					break;
+
+				case (char)SET_BRIGHTNESS:
+					setBrightness(cmd[1]);
+					break;
+
+				case (char)TWO_COLOR:
+					setColor(0, cmd[1], cmd[2], cmd[3]);
+					setColor(1, cmd[4], cmd[5], cmd[6]);
+					break;
+
+				case (char)ALTERNATE_COLORS:
+					colorOne[0] = cmd[1];
+					colorOne[1] = cmd[2];
+					colorOne[2] = cmd[3];
+
+					colorTwo[0] = cmd[4];
+					colorTwo[1] = cmd[5];
+					colorTwo[2] = cmd[6];
+
+					alternateColorsThread.setInterval(cmd[7] * 50);
+					alternateColorsThread.enabled = true;
+					break;
+
+				case (char)FLASH_COLOR:
+					flashColorThread.setInterval(cmd[1] * 50);
+					flashColorThread.enabled = true;
+					break;
+
+				case (char)SHOW_RAINBOW:
+					rainbowCounter = 0;
+
+					rainbowThread.setInterval(cmd[1] * 1);
+					rainbowThread.enabled = true;
+					break;
+
+				case (char)FADE:
+					fadeBrightness = 255;
+					isFadingDown = true;
+
+					fadeThread.setInterval(cmd[1] * 1);
+					fadeThread.enabled = true;
+					break;
+			}

-				cmd = "";
-			}
+			cmd = "";
 		}
 	}
 }
@@ -227,28 +228,26 @@
 		}
 	}

-	Serial.println(fadeBrightness);
 	setBrightness(fadeBrightness);
 }

-void showRainbow(byte wait)
-{
-	uint16_t i;
-	uint16_t j;
-
-	for(j = 0; j < 256 * 5; j++)
-	{
-		for(i = 0; i < pixels.numPixels(); i++)
-		{
-			pixels.setPixelColor(i, Wheel(( i + j) & 255));
-		}
-
-		pixels.show();
-		delay(wait);
-	}
-}
-
-uint32_t Wheel(byte WheelPos)
+void showRainbow()
+{
+	rainbowCounter++;
+	if(rainbowCounter >= 256 * 5)
+	{
+		rainbowCounter = 0;
+	}
+
+	for(int i = 0; i < pixels.numPixels(); i++)
+	{
+		pixels.setPixelColor(i, Wheel(( i + rainbowCounter) & 255));
+	}
+
+	pixels.show();
+}
+
+uint16_t Wheel(byte WheelPos)
 {
 	WheelPos = 255 - WheelPos;


fixed order in how the commands were executed

--- libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino
+++ libraries/Robot_Control/examples/explore/R02_Line_Follow/R02_Line_Follow.ino
@@ -33,12 +33,6 @@

   Robot.drawBMP("lf.bmp", 0, 0); // display background image

-  // These are some general values that work for line following
-  Robot.lineFollowConfig(11, 5, 50, 10);
-
-  //set the motor board into line-follow mode
-  Robot.setMode(MODE_LINE_FOLLOW);
-
   Robot.playFile("chase.sqm");  // play a song from the SD card

   // add the instructions
@@ -46,6 +40,12 @@
   Robot.text("Press the middle\n button to start...", 5, 61);
   Robot.waitContinue();

+  // These are some general values that work for line following
+  Robot.lineFollowConfig(11, 5, 50, 10);
+
+  //set the motor board into line-follow mode
+  Robot.setMode(MODE_LINE_FOLLOW);
+
   // start
   Robot.fill(255, 255, 255);
   Robot.stroke(255, 255, 255);


Linearly changing hue between randomised values

--- GameOfLife/GameOfLife.ino
+++ GameOfLife/GameOfLife.ino
@@ -1,9 +1,19 @@
 #include "FastSPI_LED2.h"

+// Game of Life parameters

+// Loop time of main loop in ms (20 default -> 50 Hz)
 #define LOOP_TIME 20
+// Time between GoL steps in ms (5000 default -> one step every 5 s)
 #define UPDATE_TIME 5000
-#define SEED_DELAY 10000
+// How long to wait with seeding a new field after a stall or period-2 oscillations (ms)
+#define SEED_DELAY 15000
+// Hue is linearly interpolated between randomised values
+// the speed of the interpolation is 255 * HUE_SLOWDOWN * LOOP_TIME ~= 5s * HUE_SLOWDOWN
+#define HUE_SLOWDOWN 10
+
+// End of GoL parameters, do not change below
+

 #define ROWS 10
 #define COLS 10
@@ -39,7 +49,7 @@
   return 0;
 }

-uint8_t hue; //all living cells have a slowly changing colour
+uint8_t hue, from_hue, to_hue; //all living cells have a slowly changing colour
 void GoLseed(){
   // seed initial cells
   for(uint8_t y=0; y!=ROWS; ++y){
@@ -98,9 +108,6 @@
   memcpy(prev,alive,sizeof(alive));
   memcpy(alive,next,sizeof(next));

-  // Generate a new hue
-  hue += (10-random(0,20));
-
   // Finally, update the newleds array
   for(uint8_t y=0; y!=ROWS; ++y){
     for(uint8_t x=0; x!=COLS; ++x){
@@ -113,11 +120,31 @@
   }
 }

+uint16_t hue_i = 0;
 void sendColors(){
-  // simple FO low-pass between newleds and leds
-  for(uint8_t i_led=0; i_led!=NUM_LEDS; ++i_led)
+  // interpolate between from_hue and to_hue
+  if(++hue_i == HUE_SLOWDOWN*255){
+    //select a new hue
+    from_hue = to_hue;
+    to_hue = random(0,255);
+  }
+  hue = lerp8by8(from_hue,to_hue,hue_i/HUE_SLOWDOWN);
+
+  // Update the hue for the ALIVE leds
+  for(uint8_t y=0; y!=ROWS; ++y){
+    for(uint8_t x=0; x!=COLS; ++x){
+      if(alive[y][x]){
+        newleds[xy2i(x,y)].setHSV(hue, 255, 255);
+      } else {
+        newleds[xy2i(x,y)] = CRGB::Black;
+      }
+    }
+  }
+
+  for(uint8_t i_led=0; i_led!=NUM_LEDS; ++i_led){
     for(uint8_t i=0; i!=3; ++i)
       leds[i_led][i] = (uint8_t) (((uint16_t) leds[i_led][i]*24 + newleds[i_led][i])/25);
+  }

   LEDS.show();
 }
@@ -137,8 +164,9 @@

   randomSeed(analogRead(A3));
-  // generate initial hue
-  hue = random(0,255);
+  // generate initial hues
+  from_hue = random(0,255);
+  to_hue = random(0,255);
   // seed the first cells
   GoLseed();
 }


Flip alt and regular id bridgepin output, clean up send timings so status LED does not fire at same time as IR LED

--- CoreIR.ino
+++ CoreIR.ino
@@ -13,7 +13,7 @@
 //CONFIGURABLE SECTION - SET TRANSPONDER ID
 //Change transponder ID # by setting a different transponder number for tx_id
 //WARNING: IDs set by CoreIR-Uplink tool will override these numbers
-long tx_id = 4242424;
+long tx_id = 1111111;
 long tx_alt_id = 8901234;

 // Enable debug info on serial output
@@ -34,8 +34,8 @@
 //TODO, set pins for attiny85 boards
 #ifdef micro
   // Set up alternate ID jumper bridge, shift pins because micro is special and uses pin 5 for IR output
-  #define bridgePinIn 15
-  #define bridgePinOut 14
+  #define bridgePinIn 14
+  #define bridgePinOut 15
   // Change the status LED location to the proper pin for the atmega32U4
   const int ledPin = 17;
 #else
@@ -62,7 +62,7 @@

 // Set up status LED
 int ledState = LOW;
-const long interval = 100; // Blink LED faster for regular id by default
+long interval = 0;
 unsigned long previousMillis = 0; // Allow status LED to blink without sacraficing a timer

 void setup() {
@@ -92,17 +92,18 @@
   #endif
   if (digitalRead(bridgePinIn)) {
     #ifdef debug
+      Serial.print("STD ");
+      Serial.println(tx_id);
+    #endif
+    interval = 155; // Blink LED faster for regular id by default
+    makeOutputCode(tx_id); // use alternate ID if unbridged
+  } else {
+    #ifdef debug
       Serial.print("ALT ");
       Serial.println(tx_alt_id);
     #endif
-    const long interval = 1000; // Blink LED slower for alt id
-    makeOutputCode(tx_alt_id); // use alternate ID if unbridged
-  } else {
-    #ifdef debug
-      Serial.print("STD ");
-      Serial.println(tx_id);
-    #endif
-    makeOutputCode(tx_id); // use standard ID otherwise
+    interval = 1005; // Blink LED slower for alt id
+    makeOutputCode(tx_alt_id); // use standard ID otherwise
   }

   // Set up for blinking the status LED
@@ -112,7 +113,7 @@
 void loop() {
   //Send the IR signal, then wait the appropriate amount of time before re-sending
   irsend.sendRaw(outputcode, codeLen, khz);
-  delayMicroseconds(2600);
+  delayMicroseconds(500);

   // -----Status LED blink code start -----
     unsigned long currentMillis = millis();
@@ -129,4 +130,5 @@
       digitalWrite(ledPin, ledState);
     // -----LED blink code end -----
   }
+  delayMicroseconds(800);
 }


darn github app, it keeps checking in deselected files!

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -4,7 +4,7 @@

 // this version adds flash memory support, 2009-11-19

-#define RF69_COMPAT 1 // define this to use the RF69 driver i.s.o. RF12
+#define RF69_COMPAT 0 // define this to use the RF69 driver i.s.o. RF12
 #include <JeeLib.h>
 #include <util/crc16.h>
 #include <util/parity.h>


add weblog url, better back-off logic

add weblog url, better back-off logic

--- examples/RF12/syncRecv/syncRecv.ino
+++ examples/RF12/syncRecv/syncRecv.ino
@@ -1,13 +1,15 @@
 /// @dir syncRecv
 /// Try to receive periodic transmissions with minimal power consumption.
+/// @see http://jeelabs.org/2012/11/02/synchronised-reception/
 // 2012-10-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

 #include <JeeLib.h>

-#define SEND_ID 9      // wait for packets from node 9
+#define SEND_ID 9       // wait for packets from node 9

-word estimate = 3000;  // packet expected every 3s
-word window = 512;     // start with a +/- 17 % window
+word estimate = 3000;   // packet expected every 3s
+word window = 512;      // start with +/- 17 % window, power of 2
+byte missed;            // count how often in a row receive failed

 ISR(WDT_vect) { Sleepy::watchdogEvent(); }

@@ -15,7 +17,7 @@
   return rf12_recvDone() && rf12_crc == 0 && rf12_hdr == SEND_ID;
 }

-// the since watchdog timer is inaccurate, tune the estimate first
+// since the watchdog timer is inaccurate, we must estimate
 static bool estimateWithWatchdog () {
   // first wait indefinitely for a packet to come in
   while (!isDesiredPacket())
@@ -39,7 +41,8 @@
   } while (!isDesiredPacket());

   int offset = window - (diff - lowEstimate);
-  estimate = diff & ~0x0F; // truncate down to a 16 ms multiple
+  // the new estimate shouldn't be too close to the exact time
+  estimate = (diff + 2) & ~0x0F; // truncate down to 16 ms multiple

   Serial.print(" ok at "); Serial.print(diff);
   Serial.print(", window = "); Serial.print(window);
@@ -55,7 +58,14 @@
 }

 void loop () {
-  // gradually improve the estimate each time reception succeeds
-  if (estimateWithWatchdog() && window >= 32)
-    window /= 2;
+  if (estimateWithWatchdog()) {
+    // gradually narrow down the window whenever reception succeeds
+    if (window >= 32)
+      window /= 2;
+    missed = 0;
+  } else {
+    // but widen the window again if reception fails for too long
+    if (window <= 512 && ++missed % 10 == 0)
+      window *= 4; // increase window x4 at every 10 packets missed
+  }
 }


TODO-1033: WIP

TODO-1033: WIP

--- Arduino/V0p2_Main/V0p2_Main.ino
+++ Arduino/V0p2_Main/V0p2_Main.ino
@@ -60,9 +60,9 @@
   for( ; ; )
     {
     OTV0P2BASE::LED_HEATCALL_ON();
-    OTRadValve::ModeButtonAndPotActuatorPhysicalUI::tinyPause();
+    OTV0P2BASE::nap(WDTO_15MS);
     OTV0P2BASE::LED_HEATCALL_OFF();
-    OTRadValve::ModeButtonAndPotActuatorPhysicalUI::bigPause();
+    OTV0P2BASE::nap(WDTO_120MS);
     }
   }

@@ -111,7 +111,7 @@
     for(int i = position; --i >= 0; )
       {
       OTV0P2BASE::LED_HEATCALL_ON();
-      OTRadValve::ModeButtonAndPotActuatorPhysicalUI::tinyPause();
+      OTV0P2BASE::nap(WDTO_15MS);
       OTV0P2BASE::LED_HEATCALL_OFF();
       OTV0P2BASE::sleepLowPowerMs(PP_OFF_MS); // TODO: use this time to gather entropy.
       }


TODO-851: make secondary radio panic explicit

--- Arduino/V0p2_Main/V0p2_Main.ino
+++ Arduino/V0p2_Main/V0p2_Main.ino
@@ -329,7 +329,7 @@
   DEBUG_SERIAL_PRINTLN_FLASHSTRING("R2");
 #endif
   // Check that the radio is correctly connected; panic if not...
-  if(!SecondaryRadio.configure(1, &SecondaryRadioConfig) || !SecondaryRadio.begin()) { panic(); }
+  if(!SecondaryRadio.configure(1, &SecondaryRadioConfig) || !SecondaryRadio.begin()) { panic(F("r2")); }
   // Assume no RX nor filtering on secondary radio.
 #endif // ENABLE_RADIO_SECONDARY_MODULE


Set to 5 minutes

Set to 5 minutes

--- Micro_Temp/Micro_Temp.ino
+++ Micro_Temp/Micro_Temp.ino
@@ -24,10 +24,10 @@
 void connectWifi();
 void checkTempHumid();

-#define UPDATE_FREQUENCY 60 // Time to sleep (in seconds)
-#define DHTTYPE DHT11       // DHT 11
-const int DHTPin = 2;       // Should be D4 on the Wemos D1 Mini
-bool fahrenheit = true;     // Yes, report fahrenheit
+#define UPDATE_FREQUENCY 300 // Time to sleep (in seconds)
+#define DHTTYPE DHT11        // DHT 11
+const int DHTPin = 2;        // Should be D4 on the Wemos D1 Mini
+bool fahrenheit = true;      // Yes, report fahrenheit
 DHT dht(DHTPin, DHTTYPE);

 //Wifi settings
@@ -54,6 +54,7 @@
 void loop() {
   delay(1000);  //Sometimes the MQTT doesn't seem to go through before sleep begins....
   yield();
+  Serial.println("Going into deep sleep for 5 minutes");
   ESP.deepSleep(UPDATE_FREQUENCY * 1000000);
 }


[mm] Switch to LidCountdown display if active

--- arduino/MeterMonitor/MeterMonitor.ino
+++ arduino/MeterMonitor/MeterMonitor.ino
@@ -38,20 +38,30 @@
 {
   --g_HmTempsChanged;

+  bool isLid = hm.state.LidCountdown > 0;
   for (uint8_t i = 0; i < TEMP_COUNT; ++i)
   {
     //if (i == 1) { leds[1]->showNumberDec(ESP.getFreeHeap() / 10); continue; }
     if (g_HmTempsChanged == 0)
       g_LastTemps[i] = hm.state.Probes[i].Temperature;

-    if (hm.state.Probes[i].HasTemperature)
+    // If Lid mode, show "Lid Mode" in LED[1,2] and the countdown in LED[3]
+    if (isLid && i == 1)
+      leds[1]->setSegments(new uint8_t[4]{ TM1637_L, TM1637_I, TM1637_D, 0 });
+    else if (isLid && i == 2)
+      leds[2]->setSegments(new uint8_t[4]{ TM1637_M, TM1637_O, TM1637_D, TM1637_E });
+    else if (isLid && i == 3)
+      leds[3]->showNumberDecEx(hm.state.LidCountdown, 0);
+
+    else if (hm.state.Probes[i].HasTemperature)
     {
       // LERP from the last temperature just to make it seem like there's more going on here
       float t = g_LastTemps[i] + ((4 - g_HmTempsChanged) / 4.0f) * (hm.state.Probes[i].Temperature - g_LastTemps[i]);
-      leds[i]->showNumberDecEx(int32_t(t * 10.0f), 0b00100000, false);
+      leds[i]->showNumberDecEx(int32_t(t * 10.0f), 0b00100000);
     }
     else
       leds[i]->clear();
+
     yield();
   }
 }


i tried to clean up the code and everything broke and now i'm going to the pub

--- arduino/modularsynth/modularsynth.ino
+++ arduino/modularsynth/modularsynth.ino
@@ -1,7 +1,8 @@
-byte incomingByte;
-byte note;
-byte velocity;
-int action=2; //0 =note off ; 1=note on ; 2= nada
+byte commandByte;
+byte noteByte;
+byte velocityByte;
+byte midiChannel;
+byte midiCommand;

 // pins for selecting mux channel for reading
 const int READ_SELECT_1 = 2;
@@ -39,7 +40,7 @@

 void loop() {
   // put your main code here, to run repeatedly:
-  int i,j;
+  /*int i,j;
   for(i=0;i<8;i++) {
     digitalWrite(WRITE_SELECT_1,bitRead(i,0));
     digitalWrite(WRITE_SELECT_2,bitRead(i,1));
@@ -57,43 +58,19 @@
         }
       }
     }
+  }*/
+  if(Serial1.available()) {
+    noteByte = Serial1.read();
+    if(noteByte == 60) Serial.println("YUP");
   }
+  //while (Serial1.available() > 2){
+   // commandByte = Serial1.read();//read first byte
+    //noteByte = Serial1.read();//read next byte
+    //velocityByte = Serial1.read();//read final byte
+    //midiChannel = commandByte & B00001111;
+    //midiCommand = commandByte & B11110000;
+    //if(noteByte == 60) Serial.println("YEAH");
+    //if(midiCommand == 144) Serial.println(noteByte);
+  //}
   //Serial.println("DONE");
-  if (Serial1.available() > 0) {
-   // read the incoming byte:
-   incomingByte = Serial1.read();
-
-   // wait for as status-byte, channel 1, note on or off
-   if (incomingByte== 144){ // note on message starting starting
-     action=1;
-   }else if (incomingByte== 128){ // note off message starting
-     action=0;
-   }else if (incomingByte== 208){ // aftertouch message starting
-      //not implemented yet
-   }else if (incomingByte== 160){ // polypressure message starting
-      //not implemented yet
-   }else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
-     note=incomingByte;
-     playNote(note, 0);
-     note=0;
-     velocity=0;
-     action=2;
-   }else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
-     note=incomingByte;
-   }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
-     velocity=incomingByte;
-     playNote(note, velocity);
-     note=0;
-     velocity=0;
-     action=0;
-   }else{
-     //nada
-   }
-  }
-  //delay(100);
 }
-
-void playNote(byte note, byte velocity){
-  Serial.println("PLAYED NOTE");
-  Serial.println(note);
-}


Added working lamp store/recall for debug modes

--- GVG200.ino
+++ GVG200.ino
@@ -790,6 +790,8 @@
 uint8_t previousLamp[255] = {0};
 uint8_t previousDim[9] = {0};

+uint8_t storedLamp[255] = {0};
+
 uint8_t previousButtons_XPT[22] = {0};
 uint8_t previousButtons_DSK[8] = {0};
 uint8_t previousButtons_DSK_SEC[5] = {0};
@@ -1332,6 +1334,22 @@
   }
 }

+void storeandclearLamps() {
+  memcpy(storedLamp,previousLamp,256);
+  for(int i=0;i<397;i++) writeLamp(i,0);
+}
+
+void restoreLamps() {
+  // 0 all lamps
+  for(int i=0;i<397;i++) writeLamp(i,0);
+  // now write out to addresses that have data in (then we don't accidentally set displays/dimmers
+  for(int i=0;i<256;i++) {
+    if(storedLamp[i]) {
+      sendData(i,storedLamp[i]);
+    }
+  }
+}
+
 void setup() {
   Serial.begin(115200);

@@ -1453,9 +1471,21 @@
           break;
       }
     } else {
-      if(buffer[0]=='a') {
-        Serial.println(readAnalog(atoi(buffer+1)));
-      } else if(buffer[0]=='!') resetFunc();
+      // things that don't require two values
+      switch(buffer[0]) {
+        case 'a':
+          Serial.print("a");Serial.print(atoi(buffer+1));Serial.print(",");Serial.println(readAnalog(atoi(buffer+1)));
+          break;
+        case '!':
+          resetFunc();
+        case '~':
+          Serial.println("Analog Calibrate mode");
+          storeandclearLamps();
+          Serial.println("Waiting...");
+          waitSerial();
+          restoreLamps();
+          break;
+      }
     }
     memset(buffer, 0, BUFFER_SIZE);
   }


improved stability

improved stability

--- Master.ino
+++ Master.ino
@@ -20,7 +20,7 @@
 #define recal "MODE_recal" // keyword for start sync seq (receiver side)
 #define partyM "MODE_party" // keyword for party mode (eastern egg)
 #define crdM "MODE_credits" // keyword to show contributors
-#define initDelay 500 //(ms) synchronization sequence delay
+#define initDelay 200 //(ms) synchronization sequence delay
 #define redONtime 5 //(ms)
 #define redOFFtime 5 //(ms)
 #define trnsDELAY 0 //(ms)
@@ -267,17 +267,14 @@

   detect_rgb(r, g, b, th_Val, buff[9], buff[10], buff[11]);

-  digitalWrite(redLED, HIGH);
-  delay(redONtime);
-  digitalWrite(redLED, LOW);
-  delay(redOFFtime);
-
   checkParity(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11], buff[0], buff[1], buff[3], buff[7], err);

   ch = decodeASCII(buff[2], buff[4], buff[5], buff[6], buff[8], buff[9], buff[10], buff[11]);

   if(ch != NULL)
   {
+    digitalWrite(redLED, HIGH);
+    delay(redONtime);
     Serial.print(ch);
      writtenCH++;
      if(writtenCH == 80)
@@ -285,6 +282,8 @@
        Serial.print("\n");
        writtenCH = 0;
      }
+     digitalWrite(redLED, LOW);
+     delay(redOFFtime);
      goto loopSTART;
   }


Don't use internal if we are at power-up/reset but seeing good external GPS data.

--- mega/mega.ino
+++ mega/mega.ino
@@ -1470,7 +1470,8 @@
           debug_info(F("--GPS BUF RMC--"));
           debug_info(gps_read_buffer);
           #endif
-          if(millis() - nmea_rmc_timestamp > nmea_sample_interval || millis() < nmea_sample_interval)
+          if(millis() - nmea_rmc_timestamp > nmea_sample_interval ||
+            (millis() < nmea_sample_interval && nmea_rmc_timestamp == 0))
 	  {
             #ifdef GPS_SOURCE_DEBUG_ON
             debug_info(F("GPS RMC INTERNAL"));
@@ -1485,7 +1486,8 @@
           debug_info(F("--GPS BUF GGA--"));
           debug_info(gps_read_buffer);
           #endif
-          if(millis() - nmea_gga_timestamp > nmea_sample_interval || millis() < nmea_sample_interval)
+          if(millis() - nmea_gga_timestamp > nmea_sample_interval ||
+            (millis() < nmea_sample_interval && nmea_gga_timestamp == 0))
 	  {
             #ifdef GPS_SOURCE_DEBUG_ON
             debug_info(F("GPS GGA INTERNAL"));


v5.0 Major cleanup

v5.0 Major cleanup

--- WeatherDisplay.ino
+++ WeatherDisplay.ino
@@ -19,8 +19,8 @@
 WiFiClient client;
 String serverName = "api.openweathermap.org"; // Remote server we will connect to
 String result;
-boolean night = false;
-bool toggleDisplay = digitalRead(TOGGLEDISPLAY_SW);
+bool night = false;
+bool toggleDisplay = HIGH;
 bool pastToggleDisplay = toggleDisplay;

 Adafruit_ST7735 tft(TFT_CS, TFT_DC, TFT_RST);
@@ -184,11 +184,12 @@
   String windSpeed = root["list"]["wind"]["speed"];
   String windDirection = root["list"]["wind"]["deg"];

+  bool DST = false;
   int riseI, setI, monthI, dayI, yearI;
   String timeUTC = timeS;
   timeUTC = timeUTC.substring(timeUTC.length() - 8, timeUTC.length()); // Strip out the time (XX:XX:XX)
   timeS = convertGMTTimeToLocal(timeS, latitude, longitude,
-                                &riseI, &setI, &monthI, &dayI, &yearI);
+                                &riseI, &setI, &monthI, &dayI, &yearI, &DST);
   String dateS = String(monthI) + '/' + String(dayI) + '/' + String(yearI);

   int length = temperature.length();
@@ -197,7 +198,11 @@
     temperature.remove(length - 1);
   }
 #ifdef DEBUG
+  Serial.println();
+  Serial.println(dateS);
   Serial.println("Today is " + getDayOfWeek(dayOfWeek(yearI, monthI, dayI)));
+  Serial.println((DST) ? "It's DST" : "It's ST");
+  Serial.println((night) ? "It is Night time" : "It is Day time");
   Serial.print("City ");
   Serial.println(location);
   Serial.print("Weather Icon ID ");
@@ -248,7 +253,8 @@
                  timeUTC,
                  dayI,
                  monthI,
-                 yearI);
+                 yearI,
+                 DST);
   }
   else {
     // Display the main weather
@@ -275,7 +281,8 @@
                   String timeUTC,
                   int dayI,
                   int monthI,
-                  int yearI)
+                  int yearI,
+                  bool DST)
 {
   static long lastRandomNumber;
   long randomColor;
@@ -339,6 +346,7 @@
   tft.print("Sunset: ");
   tft.print(set);
   tft.println(":00pm");
+  tft.println((DST) ? "It's DST" : "It's ST");
   tft.println("Today is " + getDayOfWeek(dayOfWeek(yearI, monthI, dayI)));
   tft.println((night) ? "It is Night time" : "It is Day time");
 }
@@ -445,7 +453,7 @@
 }

 String convertGMTTimeToLocal(String timeS, String latitude, String longitude,
-                             int* riseI, int* setI, int* monthI, int* dayI, int* yearI)
+                             int* riseI, int* setI, int* monthI, int* dayI, int* yearI, bool* DST)
 {
   double rise, set;

@@ -478,22 +486,12 @@
 #endif

   // Convert UTC time & date to local time & date
-  bool DST = convertToLocal(&time, &year, &month,
-                            &day, (double)longitude.toFloat(), true); // true means date and DST conversion
+  *DST = convertToLocal(&time, &year, &month,
+                        &day, (double)longitude.toFloat(), true); // true means date and DST conversion

   *monthI = month;
   *dayI = day;
   *yearI = year;
-
-#ifdef DEBUG
-  Serial.print("\nDate ");
-  Serial.print(month);
-  Serial.print("/");
-  Serial.print(day);
-  Serial.print("/");
-  Serial.println(year);
-  Serial.println((DST) ? "It's DST" : "It's ST");
-#endif

   // Get sunrise and sunset time in UTC
   int rs = sun_rise_set(year, month, day,
@@ -504,12 +502,12 @@
   *setI = (int)round(set);

   // Convert UTC sunrise time to local sunrise time
-  bool notUsed1 = convertToLocal(riseI, &year, &month,
-                                 &day, (double)longitude.toFloat(), false); // false means no date or DST conversion
+  (void) convertToLocal(riseI, &year, &month,
+                        &day, (double)longitude.toFloat(), false); // false means no date or DST conversion

   // Convert UTC sunset time to local sunset time
-  bool notUsed2 = convertToLocal(setI, &year, &month,
-                                 &day, (double)longitude.toFloat(), false); // false means no date or DST conversion
+  (void) convertToLocal(setI, &year, &month,
+                        &day, (double)longitude.toFloat(), false); // false means no date or DST conversion

   // Determine night or day
   night = (time > *setI ||  time < *riseI);
@@ -520,10 +518,6 @@
   if (*setI >= 12) { // Convert to 12 hour format
     if (*setI > 12) *setI -= 12;
   }
-
-#ifdef DEBUG
-  Serial.println((night) ? "It is Night time" : "It is Day time");
-#endif

   char AMPM[] = "am";
   if (time >= 12) { // Convert to 12 hour format


Update E00_KY-040_RotaryEncoder.ino

Update E00_KY-040_RotaryEncoder.ino

--- RotaryEncoder/examples/E00_KY-040_RotaryEncoder/E00_KY-040_RotaryEncoder.ino
+++ RotaryEncoder/examples/E00_KY-040_RotaryEncoder/E00_KY-040_RotaryEncoder.ino
@@ -1,108 +1,108 @@
-//  Getting Started: E00 KY-040 RotaryEncoder Demo
-//
-//  Search string:
-//    "ky-040 rotary decoder encoder module for arduino"
-//
-//  Functions:
-//    Rotate CW:   count up         0..15, 0
-//    Rotate CCW:  count down       0, 15..0
-//    Push Button: reset counter to 0
-//
-//
-//  Wiring:
-//         KY-040                 Arduino AVR (UNO, Nano, etc.)
-//    +-------------+
-//    |             |--- CLK  >   o Pin 3
-//    |             |--- DAT  >   o Pin 2
-//    |   top view  |--- SW   >   o Pin A1
-//    |             |--- VCC  >   o 5.0V
-//    |             |--- GND  >   o GND
-//    +-------------+
-//
-//     No external RC- or R-parts are used. Debouncing will be supported by Rotary Encoder library 'RotaryEncoder.h'
-//
-//  Copyright (c) 2015 Thomas Walloschke (artkeller at gmx.de). All rights reserved.
-//
-//  Permission is hereby granted, free of charge, to any person obtaining a copy
-//  of this software and associated documentation files (the "Software"), to deal
-//  in the Software without restriction, including without limitation the rights
-//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-//  copies of the Software, and to permit persons to whom the Software is
-//  furnished to do so, subject to the following conditions:
-//
-//  The above copyright notice and this permission notice shall be included in
-//  all copies or substantial portions of the Software.
-//
-//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-//  THE SOFTWARE.
-
-// ***************************************************************
-
-#if ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-// This implementation based on
-// "Another Interrupt Library THAT REALLY WORKS" by rafbuff
-// http://playground.arduino.cc/Main/RotaryEncoders
-
-enum PinAssignments {                                           // CW = count up, CCW = count down
-  encoderPinA = 3,                                              // DAT
-  encoderPinB = 2,                                              // CLK
-  clearButton = A1                                              // BUTTON
-};
-
-volatile byte encoderPos = 0;                                   // a counter for the dial
-byte lastReportedPos = 1;                                       // change management
-static bool rotating = false;                                   // debounce management
-
-// ***************************************************************
-
-void setup() {
-
-  // Set input and urn on pullup resistors
-  pinMode(encoderPinA, INPUT_PULLUP);
-  pinMode(encoderPinB, INPUT_PULLUP);
-  pinMode(clearButton, INPUT_PULLUP);
-
-  // Encoder pins on interrupt
-  attachInterrupt(digitalPinToInterrupt(encoderPinA), doEncoderA, CHANGE);
-  attachInterrupt(digitalPinToInterrupt(encoderPinB), doEncoderB, CHANGE);
-
-  // Initialize Serial
-  Serial.begin(115200);
-  Serial.print(F("E00 KY-040 RotaryEncoder Demo"));
-  Serial.println(F(" (compiled " __DATE__ " " __TIME__ ")"));
-}
-
-// ***************************************************************
-
-// Main loop
-// Work is done by interrupt service routines, this one prints stuff
-void loop() {
-
-  rotating = true;                                              // reset the debouncer
-
-  // Reset counter if button has ben pushed
-  if ( ( clearButton < A0 )                                     // check analog or digital pin
-       ? ( not digitalRead(clearButton) )                       // undebounced (!)
-       : ( analogRead(clearButton) < 100 ) )                    // threshold approx. 10% of VCC
-    encoderPos = 0;                                             // reset encoder position
-
-  // Print changes
-  if (lastReportedPos != encoderPos) {                          // verify if encoder position has changed
-    Serial.print(F("Position: "));
-    Serial.println(encoderPos % 16, DEC);                       // print counter for the dial (values 0..15)
-    lastReportedPos = encoderPos;                               // update new position
-  }
-}
-
-// ***************************************************************
+//  Getting Started: E00 KY-040 RotaryEncoder Demo
+//
+//  Web Search String:
+//    "ky-040 rotary decoder encoder module for arduino"
+//
+//  Functions:
+//    Rotate CW:   count up         0..15, 0
+//    Rotate CCW:  count down       0, 15..0
+//    Push Button: reset counter to 0
+//
+//
+//  Wiring:
+//         KY-040                 Arduino AVR (UNO, Nano, etc.)
+//    +-------------+
+//    |             |--- CLK  >   o Pin 3
+//    |             |--- DAT  >   o Pin 2
+//    |   top view  |--- SW   >   o Pin A1
+//    |             |--- VCC  >   o 5.0V
+//    |             |--- GND  >   o GND
+//    +-------------+
+//
+//     No external RC- or R-parts are used. Debouncing will be supported by Rotary Encoder library 'RotaryEncoder.h'
+//
+//  Copyright (c) 2015 Thomas Walloschke (artkeller at gmx.de). All rights reserved.
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.

+// ***************************************************************
+
+#if ARDUINO >= 100
+#include "Arduino.h"
+#else
+#include "WProgram.h"
+#endif
+
+// This implementation based on
+// "Another Interrupt Library THAT REALLY WORKS" by rafbuff
+// http://playground.arduino.cc/Main/RotaryEncoders
+
+enum PinAssignments {                                           // CW = count up, CCW = count down
+  encoderPinA = 3,                                              // DAT
+  encoderPinB = 2,                                              // CLK
+  clearButton = A1                                              // BUTTON
+};
+
+volatile byte encoderPos = 0;                                   // a counter for the dial
+byte lastReportedPos = 1;                                       // change management
+static bool rotating = false;                                   // debounce management
+
+// ***************************************************************
+
+void setup() {
+
+  // Set input and urn on pullup resistors
+  pinMode(encoderPinA, INPUT_PULLUP);
+  pinMode(encoderPinB, INPUT_PULLUP);
+  pinMode(clearButton, INPUT_PULLUP);
+
+  // Encoder pins on interrupt
+  attachInterrupt(digitalPinToInterrupt(encoderPinA), doEncoderA, CHANGE);
+  attachInterrupt(digitalPinToInterrupt(encoderPinB), doEncoderB, CHANGE);
+
+  // Initialize Serial
+  Serial.begin(115200);
+  Serial.print(F("E00 KY-040 RotaryEncoder Demo"));
+  Serial.println(F(" (compiled " __DATE__ " " __TIME__ ")"));
+}
+
+// ***************************************************************
+
+// Main loop
+// Work is done by interrupt service routines, this one prints stuff
+void loop() {
+
+  rotating = true;                                              // reset the debouncer
+
+  // Reset counter if button has ben pushed
+  if ( ( clearButton < A0 )                                     // check analog or digital pin
+       ? ( not digitalRead(clearButton) )                       // undebounced (!)
+       : ( analogRead(clearButton) < 100 ) )                    // threshold approx. 10% of VCC
+    encoderPos = 0;                                             // reset encoder position
+
+  // Print changes
+  if (lastReportedPos != encoderPos) {                          // verify if encoder position has changed
+    Serial.print(F("Position: "));
+    Serial.println(encoderPos % 16, DEC);                       // print counter for the dial (values 0..15)
+    lastReportedPos = encoderPos;                               // update new position
+  }
+}
+
+// ***************************************************************
+


GPRS interface

GPRS interface

--- Lab_s1e5.ino
+++ Lab_s1e5.ino
@@ -5,17 +5,12 @@
 #include <SoftwareSerial.h>

 typedef struct{
-  String fisrt_name;
-  String last_name;
+  String name;
   String phone_number;
 } Contact;

-void constact_set_first_name(String first_name, Contact* contact){
-  contact->fisrt_name = first_name;
-}
-
-void constact_set_last_name(String last_name, Contact* contact){
-  contact->last_name = last_name;
+void constact_set_name(String name, Contact* contact){
+  contact->name = name;
 }

 void constact_set_phone_num(String number, Contact* contact){
@@ -28,14 +23,35 @@
   delay(3000); // takes time to accept PIN
 }

-void GPRS_send_sms(String text){
-
+// Send SMS Message
+void GPRS_sms_send(String text){
+  Serial.write("AT+CMGF=1\r");
+  delay(3000);
+  Serial.write("AT+CMGS=\"0401959797\",129\r");
+  delay(3000);
+  Serial.write("Hello, World\r");
+  delay(3000);
 }

+// Select Phonebook Memory Storage
+void GPRS_phonebook_memory(){
+  Serial.write("AT+CPBS?\r");
+  delay(3000);
+}

-void GPRS_send_sms(String text){
+// Write Phonebook Entry
+void GPRS_phonebook_write(String text){
+  Serial.write("AT+CPBW=<index1>[, <number>,[<type>,[<text>]]]\r");
+  delay(3000);
+}

+// Read Current Phonebook Entries
+void GPRS_phonebook_read(){
+  Serial.write("AT+CPBR=?\r");
+  delay(3000);
 }
+
+//

 #define N_ENTRIES 2


End-of-line normalization, see dtwilliamson:ctrl 6335dcc

--- BinaryKeyboard.ino
+++ BinaryKeyboard.ino
@@ -1,384 +1,384 @@
-/*
-Chris Johnston Apr 13 2017
-Binary Keyboard for Arduino Pro Micro
-*/
-
-// libraries
-#include <Keyboard.h>
-#include <Wire.h>
-#include <SPI.h>
-#include <Adafruit_GFX.h>
-#include <Adafruit_SSD1306.h>
-
-// pixel art for 1/0 mode w/ animations
-#include "PixelArt.h"
-
-// flag for reading/entering right to left or left to right
-// true = right to left (least significant bit to most)
-// false = left to right (most significant bit to least)
-#define USE_RIGHT_TO_LEFT false
-
-// button pins
-#define BUTTON_ZERO 8
-#define BUTTON_ONE 9
-
-#define LED_ZERO 5
-#define LED_ONE 6
-
-#define SCREEN_ROTATION 2
-
-#define X_RESOLUTION 128
-#define Y_RESOLUTION 32
-
-// constant characters for zero and one (for single button press mode)
-// hey osu players, you should look at these, do X for ZERO, Z for ONE
-#define CHAR_ZERO '0' // right
-#define CHAR_ONE '1' // left
-
-// set up display
-#define OLED_RESET 4
-Adafruit_SSD1306 display(OLED_RESET);
-
-// timer
-unsigned long debounceTimer = 0;
-unsigned int debounceDelay = 5;
-// switch mode delay
-unsigned long switchModeTimerStartPress = 0;
-// increased switch mode delay
-unsigned int switchModeDelay = 2000;
-// display last timer
-unsigned long lastPrintTime = 0;
-// this should be long enough so that people can tell what it says
-unsigned int showDelay = 1500;
-// last switch time
-unsigned long switchTime = 0;
-
-// used for one/zero mode timing
-unsigned long timerOne = 0, timerZero = 0;
-
-// flag for what mode it will start in
-bool mode = false; // false = binary mode, true = single button press mode
-
-char lastPrinted = ' ';
-
-// keystroke value
-byte keyStroke = 0; //B01010101;
-int index = 0;
-
-bool buttonStateZero, buttonStateOne;
-// PWM values for each led
-int ledZero, ledOne;
-int ledDecayRate = 10;
-
-void setup() {
-
-	if (USE_RIGHT_TO_LEFT)
-	{
-		index = 0;
-	}
-	else
-	{
-		index = 7;
-	}
-
-	//Serial.begin(9600);
-	Keyboard.begin();
-
-	// leds
-	pinMode(LED_ZERO, OUTPUT);
-	pinMode(LED_ONE, OUTPUT);
-
-	// buttons
-	pinMode(BUTTON_ZERO, INPUT);
-	pinMode(BUTTON_ONE, INPUT);
-
-	// display
-	display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
-	// set screen rotation
-	display.setRotation(SCREEN_ROTATION);
-
-	// do some fancy screen stuff on boot
-	display.clearDisplay();
-	display.setCursor(0, 0);
-	display.setTextColor(WHITE);
-	display.print("Binary Keyboard!\ngithub.com/\n     Chris-Johnston");
-	display.display();
-	delay(1000);
-	// wipes the screen away with an effect
-	display.setCursor(0, 0);
-	int width = 15;
-	for (int i = 0; i < X_RESOLUTION / 6 + width + Y_RESOLUTION / 8; i++)
-	{
-		analogWrite(LED_ZERO, millis() / 2 % 255);
-		analogWrite(LED_ONE, millis() / 2 % 255);
-
-		// iterate horizontally
-		for (int j = 0; j < Y_RESOLUTION / 8; j++)
-		{
-			//iterate vertically
-			char c = ((i + j) % 2) ? '1' : '0';
-			if (i == 2 && j == 2)
-			{
-				c = '2'; // wonder if anyone will notice? EDIT: Yes, people did. LOL
-				/*
-				* Bender:	Whoa, what an awful dream. Ones and zeroes everywhere. And I thought I saw a two.
-				* Fry:		It was just a dream Bender. There's no such thing as two.
-				*/
-			}
-			display.drawChar(i * 6, j * 8, c, WHITE, BLACK, 1);
-			display.drawChar((i - width) * 6, j * 8, ' ', WHITE, BLACK, 1);
-		}
-		delay(10);
-		display.display();
-	}
-
-	analogWrite(LED_ZERO, 0);
-	analogWrite(LED_ONE, 0);
-}
-
-// deals with a keypress
-void keypress(int val)
-{
-
-	if (USE_RIGHT_TO_LEFT)
-	{
-		// clear the keystroke only when starting to type once again
-		if (index == 0) { keyStroke = 0; }
-
-		keyStroke += val << index;
-		// index increments from 0 -> 7 when RTL
-		index++;
-
-		if (index > 7)
-		{
-			sendVal((char)keyStroke);
-			index = 0;
-		}
-	}
-	else
-	{
-		// clear the keystroke only when starting to type once again
-		if (index == 7) { keyStroke = 0; }
-
-		keyStroke += (val << index);
-
-		// index decrements from 0->7 when LTR
-		index--;
-
-		if (index < 0)
-		{
-			sendVal((char)keyStroke);
-			index = 7;
-		}
-	}
-
-
-}
-
-void sendVal(char val)
-{
-	Keyboard.write(val);
-	lastPrintTime = millis();
-	lastPrinted = val;
-}
-
-void loop() {
-	bool previousZero = buttonStateZero;
-	bool previousOne = buttonStateOne;
-
-	buttonStateOne = digitalRead(BUTTON_ONE);
-	buttonStateZero = digitalRead(BUTTON_ZERO);
-
-	// write LED values
-	analogWrite(LED_ZERO, ledZero);
-	analogWrite(LED_ONE, ledOne);
-
-	ledZero = max(0, ledZero - ledDecayRate);
-	ledOne = max(0, ledOne - ledDecayRate);
-
-	display.clearDisplay();
-
-	// do drawing stuff
-	if (mode)
-	{
-		// single button press mode
-		// draw black rectangle behind text
-		//display.setTextSize(2);
-		//display.setTextColor(WHITE, BLACK);
-		//display.setCursor(61, 8); // roughly centered text
-		//display.print(lastPrinted);
-
-
-		// removing this for now, it gets in the way of the bitmaps
-		/*if (((millis() - switchTime) < switchModeDelay))
-		{
-			display.setCursor(0, 0);
-			display.setTextSize(1);
-			display.print("Press & Hold Both To Return");
-		}*/
-	}
-	else
-	{
-		if ((millis() - lastPrintTime) < showDelay)
-		{
-			display.setCursor(0, 0);
-			display.setTextSize(1);
-			display.print("Last: ");
-			display.print(lastPrinted);
-		}
-
-		// minimalist style
-		display.setTextSize(2);
-		display.setTextColor(WHITE, BLACK);
-		display.setCursor(16, 8);
-		for (int i = 7; i >= 0; i--)
-		{
-			display.print(bitRead(keyStroke, i));
-		}
-		display.drawLine((8 - index - 1) * 12 + 16, 24, (8 - index) * 12 + 16, 24, WHITE);
-	}
-
-	// do backlighting stuff
-	if (buttonStateOne)
-	{
-		ledOne = 255;
-	}
-	if (buttonStateZero)
-	{
-		ledZero = 255;
-	}
-
-	// handle switching between modes
-	if (buttonStateZero && buttonStateOne)
-	{
-		if (switchModeTimerStartPress == 0)
-		{
-			switchModeTimerStartPress = millis();
-		}
-		else if (((millis() - switchModeTimerStartPress) > switchModeDelay) && previousOne && previousZero)
-		{
-			switchModeTimerStartPress = millis();
-			mode = !mode;
-			switchTime = millis();
-			lastPrinted = '0';
-		}
-
-		int width = map(millis() - switchModeTimerStartPress, 0, switchModeDelay, 0, 128);
-
-		// draw a 'progress bar' indicating when this will switch over
-		display.drawRect(0, 30, width, 2, WHITE);
-	}
-	else
-	{
-		switchModeTimerStartPress = 0;
-	}
-
-	// in single button press mode, ignore the debounce timers
-	if (mode)
-	{
-		if (buttonStateOne)
-		{
-			//display.drawRect(1, 1, 62, 30, WHITE);
-			Keyboard.press(CHAR_ONE);
-		}
-		else
-		{
-			timerOne = millis();
-			Keyboard.release(CHAR_ONE);
-		}
-
-		// do animation for button one (left)
-		if (!buttonStateOne)
-		{
-			display.drawChar(TEXT_X_1, TEXT_Y_0, CHAR_ONE, WHITE, BLACK, 2);
-			display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_0, ART_WIDTH, ART_HEIGHT, WHITE);
-		}
-		else
-		{
-			int v = (millis() - timerOne);// / FRAME_DELAY_MS;
-			if (v <= FRAME_DELAY_MS * 1)
-			{
-				display.drawChar(TEXT_X_1, TEXT_Y_1, CHAR_ONE, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_1, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else if (v <= FRAME_DELAY_MS * 2)
-			{
-				display.drawChar(TEXT_X_1, TEXT_Y_2, CHAR_ONE, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_2, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else if (v <= FRAME_DELAY_MS * 3)
-			{
-				display.drawChar(TEXT_X_1, TEXT_Y_3, CHAR_ONE, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_3, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else
-			{
-				display.drawChar(TEXT_X_1, TEXT_Y_4, CHAR_ONE, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_4, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-		}
-
-		if (buttonStateZero)
-		{
-			Keyboard.press(CHAR_ZERO);
-		}
-		else
-		{
-			timerZero = millis();
-			Keyboard.release(CHAR_ZERO);
-		}
-
-		// do animation for button zero (right)
-		if (!buttonStateZero)
-		{
-			display.drawChar(TEXT_X_2, TEXT_Y_0, CHAR_ZERO, WHITE, BLACK, 2);
-			display.drawBitmap(KEY_X_1, KEY_Y_0, FRAME_0, ART_WIDTH, ART_HEIGHT, WHITE);
-		}
-		else
-		{
-			int v = (millis() - timerZero);// / FRAME_DELAY_MS;
-			if (v <= FRAME_DELAY_MS * 1)
-			{
-				display.drawChar(TEXT_X_2, TEXT_Y_1, CHAR_ZERO, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_1, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else if (v <= FRAME_DELAY_MS * 2)
-			{
-				display.drawChar(TEXT_X_2, TEXT_Y_2, CHAR_ZERO, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_2, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else if (v <= FRAME_DELAY_MS * 3)
-			{
-				display.drawChar(TEXT_X_2, TEXT_Y_3, CHAR_ZERO, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_3, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-			else
-			{
-				display.drawChar(TEXT_X_2, TEXT_Y_4, CHAR_ZERO, WHITE, BLACK, 2);
-				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_4, ART_WIDTH, ART_HEIGHT, WHITE);
-			}
-		}
-
-	}
-	else // in normal binary keyboard mode
-	{
-		// debounce
-		if ((millis() - debounceTimer) > debounceDelay)
-		{
-			// zero pressed
-			if (buttonStateZero && !buttonStateOne && !previousZero)
-			{
-				keypress(0);
-				debounceTimer = millis();
-			}
-			// one pressed
-			else if (!buttonStateZero && buttonStateOne && !previousOne)
-			{
-				keypress(1);
-				debounceTimer = millis();
-			}
-		}
-	}
-
-	display.display();
+/*
+Chris Johnston Apr 13 2017
+Binary Keyboard for Arduino Pro Micro
+*/
+
+// libraries
+#include <Keyboard.h>
+#include <Wire.h>
+#include <SPI.h>
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1306.h>
+
+// pixel art for 1/0 mode w/ animations
+#include "PixelArt.h"
+
+// flag for reading/entering right to left or left to right
+// true = right to left (least significant bit to most)
+// false = left to right (most significant bit to least)
+#define USE_RIGHT_TO_LEFT false
+
+// button pins
+#define BUTTON_ZERO 8
+#define BUTTON_ONE 9
+
+#define LED_ZERO 5
+#define LED_ONE 6
+
+#define SCREEN_ROTATION 2
+
+#define X_RESOLUTION 128
+#define Y_RESOLUTION 32
+
+// constant characters for zero and one (for single button press mode)
+// hey osu players, you should look at these, do X for ZERO, Z for ONE
+#define CHAR_ZERO '0' // right
+#define CHAR_ONE '1' // left
+
+// set up display
+#define OLED_RESET 4
+Adafruit_SSD1306 display(OLED_RESET);
+
+// timer
+unsigned long debounceTimer = 0;
+unsigned int debounceDelay = 5;
+// switch mode delay
+unsigned long switchModeTimerStartPress = 0;
+// increased switch mode delay
+unsigned int switchModeDelay = 2000;
+// display last timer
+unsigned long lastPrintTime = 0;
+// this should be long enough so that people can tell what it says
+unsigned int showDelay = 1500;
+// last switch time
+unsigned long switchTime = 0;
+
+// used for one/zero mode timing
+unsigned long timerOne = 0, timerZero = 0;
+
+// flag for what mode it will start in
+bool mode = false; // false = binary mode, true = single button press mode
+
+char lastPrinted = ' ';
+
+// keystroke value
+byte keyStroke = 0; //B01010101;
+int index = 0;
+
+bool buttonStateZero, buttonStateOne;
+// PWM values for each led
+int ledZero, ledOne;
+int ledDecayRate = 10;
+
+void setup() {
+
+	if (USE_RIGHT_TO_LEFT)
+	{
+		index = 0;
+	}
+	else
+	{
+		index = 7;
+	}
+
+	//Serial.begin(9600);
+	Keyboard.begin();
+
+	// leds
+	pinMode(LED_ZERO, OUTPUT);
+	pinMode(LED_ONE, OUTPUT);
+
+	// buttons
+	pinMode(BUTTON_ZERO, INPUT);
+	pinMode(BUTTON_ONE, INPUT);
+
+	// display
+	display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
+	// set screen rotation
+	display.setRotation(SCREEN_ROTATION);
+
+	// do some fancy screen stuff on boot
+	display.clearDisplay();
+	display.setCursor(0, 0);
+	display.setTextColor(WHITE);
+	display.print("Binary Keyboard!\ngithub.com/\n     Chris-Johnston");
+	display.display();
+	delay(1000);
+	// wipes the screen away with an effect
+	display.setCursor(0, 0);
+	int width = 15;
+	for (int i = 0; i < X_RESOLUTION / 6 + width + Y_RESOLUTION / 8; i++)
+	{
+		analogWrite(LED_ZERO, millis() / 2 % 255);
+		analogWrite(LED_ONE, millis() / 2 % 255);
+
+		// iterate horizontally
+		for (int j = 0; j < Y_RESOLUTION / 8; j++)
+		{
+			//iterate vertically
+			char c = ((i + j) % 2) ? '1' : '0';
+			if (i == 2 && j == 2)
+			{
+				c = '2'; // wonder if anyone will notice? EDIT: Yes, people did. LOL
+				/*
+				* Bender:	Whoa, what an awful dream. Ones and zeroes everywhere. And I thought I saw a two.
+				* Fry:		It was just a dream Bender. There's no such thing as two.
+				*/
+			}
+			display.drawChar(i * 6, j * 8, c, WHITE, BLACK, 1);
+			display.drawChar((i - width) * 6, j * 8, ' ', WHITE, BLACK, 1);
+		}
+		delay(10);
+		display.display();
+	}
+
+	analogWrite(LED_ZERO, 0);
+	analogWrite(LED_ONE, 0);
+}
+
+// deals with a keypress
+void keypress(int val)
+{
+
+	if (USE_RIGHT_TO_LEFT)
+	{
+		// clear the keystroke only when starting to type once again
+		if (index == 0) { keyStroke = 0; }
+
+		keyStroke += val << index;
+		// index increments from 0 -> 7 when RTL
+		index++;
+
+		if (index > 7)
+		{
+			sendVal((char)keyStroke);
+			index = 0;
+		}
+	}
+	else
+	{
+		// clear the keystroke only when starting to type once again
+		if (index == 7) { keyStroke = 0; }
+
+		keyStroke += (val << index);
+
+		// index decrements from 0->7 when LTR
+		index--;
+
+		if (index < 0)
+		{
+			sendVal((char)keyStroke);
+			index = 7;
+		}
+	}
+
+
+}
+
+void sendVal(char val)
+{
+	Keyboard.write(val);
+	lastPrintTime = millis();
+	lastPrinted = val;
+}
+
+void loop() {
+	bool previousZero = buttonStateZero;
+	bool previousOne = buttonStateOne;
+
+	buttonStateOne = digitalRead(BUTTON_ONE);
+	buttonStateZero = digitalRead(BUTTON_ZERO);
+
+	// write LED values
+	analogWrite(LED_ZERO, ledZero);
+	analogWrite(LED_ONE, ledOne);
+
+	ledZero = max(0, ledZero - ledDecayRate);
+	ledOne = max(0, ledOne - ledDecayRate);
+
+	display.clearDisplay();
+
+	// do drawing stuff
+	if (mode)
+	{
+		// single button press mode
+		// draw black rectangle behind text
+		//display.setTextSize(2);
+		//display.setTextColor(WHITE, BLACK);
+		//display.setCursor(61, 8); // roughly centered text
+		//display.print(lastPrinted);
+
+
+		// removing this for now, it gets in the way of the bitmaps
+		/*if (((millis() - switchTime) < switchModeDelay))
+		{
+			display.setCursor(0, 0);
+			display.setTextSize(1);
+			display.print("Press & Hold Both To Return");
+		}*/
+	}
+	else
+	{
+		if ((millis() - lastPrintTime) < showDelay)
+		{
+			display.setCursor(0, 0);
+			display.setTextSize(1);
+			display.print("Last: ");
+			display.print(lastPrinted);
+		}
+
+		// minimalist style
+		display.setTextSize(2);
+		display.setTextColor(WHITE, BLACK);
+		display.setCursor(16, 8);
+		for (int i = 7; i >= 0; i--)
+		{
+			display.print(bitRead(keyStroke, i));
+		}
+		display.drawLine((8 - index - 1) * 12 + 16, 24, (8 - index) * 12 + 16, 24, WHITE);
+	}
+
+	// do backlighting stuff
+	if (buttonStateOne)
+	{
+		ledOne = 255;
+	}
+	if (buttonStateZero)
+	{
+		ledZero = 255;
+	}
+
+	// handle switching between modes
+	if (buttonStateZero && buttonStateOne)
+	{
+		if (switchModeTimerStartPress == 0)
+		{
+			switchModeTimerStartPress = millis();
+		}
+		else if (((millis() - switchModeTimerStartPress) > switchModeDelay) && previousOne && previousZero)
+		{
+			switchModeTimerStartPress = millis();
+			mode = !mode;
+			switchTime = millis();
+			lastPrinted = '0';
+		}
+
+		int width = map(millis() - switchModeTimerStartPress, 0, switchModeDelay, 0, 128);
+
+		// draw a 'progress bar' indicating when this will switch over
+		display.drawRect(0, 30, width, 2, WHITE);
+	}
+	else
+	{
+		switchModeTimerStartPress = 0;
+	}
+
+	// in single button press mode, ignore the debounce timers
+	if (mode)
+	{
+		if (buttonStateOne)
+		{
+			//display.drawRect(1, 1, 62, 30, WHITE);
+			Keyboard.press(CHAR_ONE);
+		}
+		else
+		{
+			timerOne = millis();
+			Keyboard.release(CHAR_ONE);
+		}
+
+		// do animation for button one (left)
+		if (!buttonStateOne)
+		{
+			display.drawChar(TEXT_X_1, TEXT_Y_0, CHAR_ONE, WHITE, BLACK, 2);
+			display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_0, ART_WIDTH, ART_HEIGHT, WHITE);
+		}
+		else
+		{
+			int v = (millis() - timerOne);// / FRAME_DELAY_MS;
+			if (v <= FRAME_DELAY_MS * 1)
+			{
+				display.drawChar(TEXT_X_1, TEXT_Y_1, CHAR_ONE, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_1, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else if (v <= FRAME_DELAY_MS * 2)
+			{
+				display.drawChar(TEXT_X_1, TEXT_Y_2, CHAR_ONE, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_2, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else if (v <= FRAME_DELAY_MS * 3)
+			{
+				display.drawChar(TEXT_X_1, TEXT_Y_3, CHAR_ONE, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_3, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else
+			{
+				display.drawChar(TEXT_X_1, TEXT_Y_4, CHAR_ONE, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_0, KEY_Y_0, FRAME_4, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+		}
+
+		if (buttonStateZero)
+		{
+			Keyboard.press(CHAR_ZERO);
+		}
+		else
+		{
+			timerZero = millis();
+			Keyboard.release(CHAR_ZERO);
+		}
+
+		// do animation for button zero (right)
+		if (!buttonStateZero)
+		{
+			display.drawChar(TEXT_X_2, TEXT_Y_0, CHAR_ZERO, WHITE, BLACK, 2);
+			display.drawBitmap(KEY_X_1, KEY_Y_0, FRAME_0, ART_WIDTH, ART_HEIGHT, WHITE);
+		}
+		else
+		{
+			int v = (millis() - timerZero);// / FRAME_DELAY_MS;
+			if (v <= FRAME_DELAY_MS * 1)
+			{
+				display.drawChar(TEXT_X_2, TEXT_Y_1, CHAR_ZERO, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_1, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else if (v <= FRAME_DELAY_MS * 2)
+			{
+				display.drawChar(TEXT_X_2, TEXT_Y_2, CHAR_ZERO, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_2, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else if (v <= FRAME_DELAY_MS * 3)
+			{
+				display.drawChar(TEXT_X_2, TEXT_Y_3, CHAR_ZERO, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_3, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+			else
+			{
+				display.drawChar(TEXT_X_2, TEXT_Y_4, CHAR_ZERO, WHITE, BLACK, 2);
+				display.drawBitmap(KEY_X_1, KEY_Y_1, FRAME_4, ART_WIDTH, ART_HEIGHT, WHITE);
+			}
+		}
+
+	}
+	else // in normal binary keyboard mode
+	{
+		// debounce
+		if ((millis() - debounceTimer) > debounceDelay)
+		{
+			// zero pressed
+			if (buttonStateZero && !buttonStateOne && !previousZero)
+			{
+				keypress(0);
+				debounceTimer = millis();
+			}
+			// one pressed
+			else if (!buttonStateZero && buttonStateOne && !previousOne)
+			{
+				keypress(1);
+				debounceTimer = millis();
+			}
+		}
+	}
+
+	display.display();
 }


Update DigitalPotControl.ino

Update DigitalPotControl.ino

Fixing SPI communication with a delay as pointe out in #6395

--- hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
+++ hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino
@@ -63,9 +63,11 @@
 void digitalPotWrite(int address, int value) {
   // take the SS pin low to select the chip:
   digitalWrite(slaveSelectPin, LOW);
+  delay(100);
   //  send in the address and value via SPI:
   SPI.transfer(address);
   SPI.transfer(value);
+  delay(100);
   // take the SS pin high to de-select the chip:
   digitalWrite(slaveSelectPin, HIGH);
 }


update sketch

update sketch

--- teensytty/teensytty.ino
+++ teensytty/teensytty.ino
@@ -133,8 +133,9 @@

 // You can tweak the baud rate very slightly here, but it's better to use 110 and
 // fix whatever timing/alignment issues in hardware
-#define BAUDRATE 109
-
+#define BAUDRATE 111
+
+#define SNOOZETIME 5000
 elapsedMillis millisSinceActivity;

@@ -184,9 +185,7 @@
   HWSERIAL.begin(BAUDRATE); //, SERIAL_8N2);
 #endif

-  millisSinceActivity = 0;
-
-  delay(100);
+  millisSinceActivity = SNOOZETIME;
   readOptions();
 }

@@ -198,36 +197,29 @@

   if (isTestMode) {
     // print a test sequence
-    digitalWrite(PIN_INTERNAL_LED, HIGH);
     selfTest();
   }
-  digitalWrite(PIN_INTERNAL_LED, LOW);
-
-  if (HWSERIAL.available() > 0) {
+
+  if (Serial.available() > 0) {
+    // Print something to tty
+    incomingByte = Serial.read();
+    incomingByte = processUSBByte(incomingByte);
+    sendToTTY(incomingByte);
     millisSinceActivity = 0;
-    waitAlign();
+  } else if (HWSERIAL.available() > 0) {
+    // Read something from tty
     incomingByte = HWSERIAL.read();
     incomingByte = processTTYByte(incomingByte);
-  }
-
-  if (Serial.available() > 0) {
     millisSinceActivity = 0;
-    waitAlign();
-    incomingByte = Serial.read();
-    incomingByte = processUSBByte(incomingByte);
-  }
-
-  if (millisSinceActivity > 1000) {
-    waitAlign();
+  } else if (millisSinceActivity > SNOOZETIME) {
+    // Stop the open-line chattering
     HWSERIAL.setBreak();
-  }
-
-}
-
-
-void waitAlign() {
-  // align to 10th of a second to spare the clutch
-  while ((millisSinceActivity % 100) != 0) {}
+  } else {
+    // Keep the line open so timing errors are minimized
+    sendToTTY(0);
+  }
+
+
 }

@@ -286,7 +278,7 @@
   }

   prevUSBByte = b;
-  sendToTTY(b);
+  //sendToTTY(b);
   return b;
 }

@@ -308,16 +300,16 @@
   }

 #ifdef DEBUG_ALL
-  Serial.print("Sending to TTY: ");
-  Serial.write(b);
-  Serial.print(" = 0x");
-  Serial.println(b, HEX);
+  if(b!=0) {
+    Serial.print("Sending to TTY: ");
+    Serial.write(b);
+    Serial.print(" = 0x");
+    Serial.println(b, HEX);
+  }
 #endif

   // Print the received byte at the teletype
   // HWSERIAL.flush();
-  while (HWSERIAL.isReading()) {}
-  HWSERIAL.write((uint8_t)0);
   digitalWrite(PIN_INTERNAL_LED, HIGH);
   HWSERIAL.write(b);
   while (HWSERIAL.isWriting()) {}
@@ -330,12 +322,10 @@
       // Add delay after carriage return (200m or more)
       sendToTTY(0);
       sendToTTY(0);
-      //sendToTTY(0);
     }
     if (b==LF) {
       // Add delay after line feed
       sendToTTY(0);
-      //sendToTTY(0);
     }
   }

@@ -362,6 +352,7 @@

     // Ryemove the parity bit
     b = b & 0x7F;
+    c = b;

     if(isTxUCLC) {
       // TTY produces uppercase alpha, fold them to lowercase


Tibi and Jim got the code to work!

Tibi and Jim got the code to work!

--- Arduino/Optical_tachometer_using_proximity_sensor/tach_schmitt_interrupts.ino
+++ Arduino/Optical_tachometer_using_proximity_sensor/tach_schmitt_interrupts.ino
@@ -1,10 +1,11 @@
 const byte TACH = 2;
+const byte DURATION = 1;
 volatile boolean revolution_occured = false;
-int revolution_count = 0;
-int current_time = 0
-int previous_time = 0;
-int rpm = 0;
-int duration = 1; // in seconds
+unsigned int revolution_count = 0;
+unsigned int current_time = 0;
+unsigned int previous_time = 0;
+unsigned int rpm = 0;
+//unsigned int duration = 1; // in seconds

 // Interrupt Service Routine (ISR)
 void revolution ()
@@ -15,24 +16,26 @@
 void setup ()
 {
   Serial.begin(115200);
-  pinMode (LED, OUTPUT);  // so we can update the LED
+
   digitalWrite (TACH, HIGH);  // internal pull-up resistor built in :-)
-  attachInterrupt (0, revolution, RISING);  // attach interrupt handler
+  attachInterrupt (digitalPinToInterrupt(2), revolution, RISING);  // attach interrupt handler
 }  // end of setup

 void loop ()
 {
-  if (revolution) {
-    revolution_count += 1;
-    revolution_occured = false;
+  if (revolution_occured) {
+    revolution_count ++;
+    revolution_occured = !revolution_occured;
   }

   current_time = millis();
   if (current_time - previous_time >= 1000) {
-    rpm = (revolution_count / duration * 60);
-	Serial.println (rpm);
-	revolution_count = 0;
-	previous_time = current_time;
-  }
-}
-
+    rpm = (revolution_count / DURATION * 60);
+    Serial.print ("rpm = ");
+    Serial.println (rpm);
+    Serial.print ("counts = ");
+    Serial.println (revolution_count);
+    previous_time = current_time;
+    revolution_count = 0;
+  }
+}


increase threshold

increase threshold

--- sensor_clock_2.ino
+++ sensor_clock_2.ino
@@ -25,7 +25,7 @@
 #define SLEEP_INTERVAL 250 //0.25s
 #define SLEEP_LONG_INTERVAL 45000 //45s

-#define LIGHT_THRESHOLD 140
+#define LIGHT_THRESHOLD 120

 #define OFF_HOUR 00
 #define OFF_MIN 00


renamed motorStart to motorVelocitySettings

--- Firmware/Robot.ino
+++ Firmware/Robot.ino
@@ -110,7 +110,7 @@
 {
     robot_velocityMode(wheel);
     robot_motorPowerOn(wheel);
-    robot_motorStart(wheel);
+    robot_motorVelocitySettings(wheel);
 }

 void robot_velocityMode(uint8_t wheel)
@@ -123,7 +123,7 @@
         {0x2B, 0x40, 0x60, 0x00, 0x0F, 0x00, 0x00, 0x00},  // CONTROLWORD RES:0 RES:0 RES:0 RES:0 RES:0 RES:0 MS5:0 HAT:0 FTR:0 MS3:0 MS2:0 MS1:0 ENO:1 QUS:1 ENV:1 SWO:1
         {0x2F, 0x60, 0x60, 0x00, 0x02, 0x00, 0x00, 0x00}   // MODE OF OPERATION
     };
-    for (int i = 0; i < 3; i++)
+    for (int i = 0; i < 2; i++)
     {
         robot_command(wheel, cmd[i]);
     }
@@ -146,7 +146,7 @@
     }
 }

-void robot_motorStart(uint8_t wheel)
+void robot_motorVelocitySettings(uint8_t wheel)
 {
     #if DEBUGMODE
     Serial.println("# Motor start");


Spacing Fix

Spacing Fix

--- firmware/examples/BMP280.ino
+++ firmware/examples/BMP280.ino
@@ -39,7 +39,7 @@

 void checkEnvironment() {

-    Particle.publish("EnvironmentData", String::format("Temp: %.1f °C / %.1f °F, Pressure %.1f mbar, Humidity %.1f %%", cTemp, fTemp, pressure, humidity), PRIVATE);
+  Particle.publish("EnvironmentData", String::format("Temp: %.1f °C / %.1f °F, Pressure %.1f mbar, Humidity %.1f %%", cTemp, fTemp, pressure, humidity), PRIVATE);
 }

 float cToF(float c) {


Update HC-SR04.ino

Update HC-SR04.ino

--- Device/HC-SR04.ino
+++ Device/HC-SR04.ino
@@ -1,192 +1,201 @@
+/*********************************************************************************
+SMART PARKING LOT SYSTEM
+*********************************************************************************/
 //Reference Value to Get The Status of Parking
-#define parked 100
-#define fault 4500
+#define g_distanceMinimum 100
+#define g_faultValue 4500

 //Pin Setting for the 3 Ultrasonic Sensors
-#define trigPin 13
-#define echoPin 12
-#define trigPin2 4
-#define echoPin2 5
-#define trigPin3 8
-#define echoPin3 9
-/*
-//Deducting the Low Pulse fromm the Echo Pin
-unsigned long echoDeduct(uint8_t pin, uint8_t state, unsigned long timeout)
-{
-        uint8_t bit = digitalPinToBitMask(pin);
-        uint8_t port = digitalPinToPort(pin);
-        uint8_t stateMask = (state ? bit : 0);
-        unsigned long width = 0;
-        unsigned long numloops = 0;
-        unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
-
-        while ((*portInputRegister(port) & bit) == stateMask)
-                if (numloops++ == maxloops)
-                        return 0;
-
-        while ((*portInputRegister(port) & bit) != stateMask)
-                if (numloops++ == maxloops)
-                        return 0;
-
-        while ((*portInputRegister(port) & bit) == stateMask)
-                width++;
-
-        return clockCyclesToMicroseconds(width * 10 + 16);
+#define g_trigPin 13
+#define g_echoPin 12
+#define g_trigPin2 4
+#define g_echoPin2 5
+#define g_trigPin3 8
+#define g_echoPin3 9
+
+/**************************************************************************************
+Function Name 		:	setup
+Description		:	Initialize the Sensor Trigger Pin as Output and
+                                echo pin as Input and begin the serial communication
+                                with 9600 BAUD
+Parameters 		:	void
+Return 			:	void
+**************************************************************************************/
+//Initialize the Pins and BAUD rate
+void setup(void) {
+        Serial.begin (9600);
+        pinMode(g_trigPin, OUTPUT);
+        pinMode(g_echoPin, INPUT);
+        pinMode(g_trigPin2, OUTPUT);
+        pinMode(g_echoPin2, INPUT);
+        pinMode(g_trigPin3, OUTPUT);
+        pinMode(g_echoPin3, INPUT);
 }
-*/
-//Initialize the Pins and BAUD rate
-void setup() {
-  Serial.begin (9600);
-  pinMode(trigPin, OUTPUT);
-  pinMode(echoPin, INPUT);
-  pinMode(trigPin2, OUTPUT);
-  pinMode(echoPin2, INPUT);
-  pinMode(trigPin3, OUTPUT);
-  pinMode(echoPin3, INPUT);
-}
-
-//
-void loop() {
-  long duration, distance,duration2, distance2,duration3, distance3;
-  digitalWrite(trigPin, LOW);
+
+/**************************************************************************************
+Function Name 		:	loop
+Description		:	Generate a Trigger signal and wait for the echo on
+                                HC-SR04 Ultrasonic Sensor and calculate the distance.
+Parameters 		:	void
+Return 			:	void
+**************************************************************************************/
+void loop(void) {
+  //Variables to calculate the distance using the duration taken for 1 cycle of trigger and echo
+  long l_duration,l_distance,l_duration2,l_distance2,l_duration3,l_distance3;
+  //Distance form the Ultrasonic Sensor 1
+  //Generate a high pulse on Trigger Pin with 10 micro seconds delay and wait for the echo
+  digitalWrite(g_trigPin, LOW);
   delayMicroseconds(2);
-  digitalWrite(trigPin, HIGH);
+  digitalWrite(g_trigPin, HIGH);
   delayMicroseconds(10);
-  digitalWrite(trigPin, LOW);
-  duration = pulseIn(echoPin, HIGH);
-  distance = (duration/2) / 29.1;
+  digitalWrite(g_trigPin, LOW);
+  //Once received the Echo calculate the distance from the duration
+  l_duration = pulseIn(g_echoPin, HIGH);
+  l_distance = (l_duration/2) / 29.1;
   delay(300);

-  digitalWrite(trigPin2, LOW);
+  //Distance form the Ultrasonic Sensor 2
+  digitalWrite(g_trigPin2, LOW);
   delayMicroseconds(2);
-  digitalWrite(trigPin2, HIGH);
+  digitalWrite(g_trigPin2, HIGH);
   delayMicroseconds(10);
-  digitalWrite(trigPin2, LOW);
-  duration2 = pulseIn(echoPin2, HIGH);
-  distance2 = (duration2/2) / 29.1;
+  digitalWrite(g_trigPin2, LOW);
+  l_duration2 = pulseIn(g_echoPin2, HIGH);
+  l_distance2 = (l_duration2/2) / 29.1;
   delay(300);
-  digitalWrite(trigPin3, LOW);
+
+  //Distance form the Ultrasonic Sensor 3
+  digitalWrite(g_trigPin3, LOW);
   delayMicroseconds(2);
-  digitalWrite(trigPin3, HIGH);
+  digitalWrite(g_trigPin3, HIGH);
   delayMicroseconds(10);
-  digitalWrite(trigPin3, LOW);
-  duration3 = pulseIn(echoPin3, HIGH);
-  distance3 = (duration3/2) / 29.1;
+  digitalWrite(g_trigPin3, LOW);
+  l_duration3 = pulseIn(g_echoPin3, HIGH);
+  l_distance3 = (l_duration3/2) / 29.1;
   delay(300);
-
-  if(distance < fault && distance2 < fault && distance3 < fault) {
-  if(distance <= parked && distance2 <= parked && distance3 <= parked)
+
+  //Check if the Sensor has any fault
+  /*DATA SENT by UART to RPi is  1,2,3
+		1	-	Parking LOT is Free
+		2	-	Parking LOT is Filled
+		3	-	Fault in the Sensor	*/
+  if(l_distance < g_fault && l_distance2 < g_fault && l_distance3 < g_fault)
   {
-    Serial.write("222");
+        if(l_distance <= g_parked && l_distance2 <= g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("222");
+        }
+        else if(l_distance <= g_parked && l_distance2 <= g_parked && l_distance3 > g_parked)
+        {
+                Serial.write("221");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("212");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_parked && l_distance3 > g_parked)
+        {
+                Serial.write("211");
+        }
+        else if(l_distance > g_parked && l_distance2 <= g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("122");
+        }
+        else if(l_distance > g_parked && l_distance2 <= g_parked && l_distance3 > g_parked)
+        {
+                Serial.write("121");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("112");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_parked && l_distance3 > g_parked)
+        {
+                Serial.write("111");
+        }
   }
-  else if(distance <= parked && distance2 <= parked && distance3 > parked)
+  else
   {
-    Serial.write("221");
+        if(l_distance > g_fault && l_distance2 <= g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("322");
+        }
+        else if(l_distance > g_fault && l_distance2 <= g_parked && l_distance3 > g_parked)
+        {
+                Serial.write("321");
+        }
+        else if(l_distance > g_fault && l_distance2 > g_parked && l_distance3 <= g_parked)
+        {
+                Serial.write("312");
+        }
+        else if(distance > g_fault && distance2 > g_parked && distance3 > g_parked)
+        {
+                Serial.write("311");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_fault && l_distance3 <= g_parked)
+        {
+                Serial.write("232");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_fault && l_distance3 > g_parked)
+        {
+                Serial.write("231");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_fault && l_distance3 <= g_parked)
+        {
+                Serial.write("132");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_fault && l_distance3 > g_parked)
+        {
+                Serial.write("131");
+        }
+        else if(l_distance <= g_parked && l_distance2 <= g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("223");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("213");
+        }
+        else if(l_distance > g_parked && l_distance2 <= g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("123");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("113");
+        }
+        else if(l_distance > g_fault && l_distance2 > g_fault && l_distance3 <= g_parked)
+        {
+                Serial.write("332");
+        }
+        else if(l_distance > g_fault && l_distance2 > g_fault && l_distance3 > g_parked)
+        {
+                Serial.write("331");
+        }
+        else if(l_distance <= g_parked && l_distance2 > g_fault && l_distance3 > g_fault)
+        {
+                Serial.write("233");
+        }
+        else if(l_distance > g_parked && l_distance2 > g_fault && l_distance3 > g_fault)
+        {
+                Serial.write("133");
+        }
+        else if(l_distance > g_fault && l_distance2 <= g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("323");
+        }
+        else if(l_distance > g_fault && l_distance2 > g_parked && l_distance3 > g_fault)
+        {
+                Serial.write("313");
+        }
+        else if(l_distance > g_fault && l_distance2 > g_fault && l_distance3 > g_fault)
+        {
+                Serial.write("333");
+        }
   }
-  else if(distance <= parked && distance2 > parked && distance3 <= parked)
-  {
-    Serial.write("212");
-  }
-  else if(distance <= parked && distance2 > parked && distance3 > parked)
-  {
-    Serial.write("211");
-  }
-  else if(distance > parked && distance2 <= parked && distance3 <= parked)
-  {
-    Serial.write("122");
-  }
-  else if(distance > parked && distance2 <= parked && distance3 > parked)
-  {
-    Serial.write("121");
-  }
-  else if(distance > parked && distance2 > parked && distance3 <= parked)
-  {
-    Serial.write("112");
-  }
-  else if(distance > parked && distance2 > parked && distance3 > parked)
-  {
-    Serial.write("111");
-  }
-  }
-  else{
-  if(distance > fault && distance2 <= parked && distance3 <= parked)
-  {
-    Serial.write("322");
-  }
-  else if(distance > fault && distance2 <= parked && distance3 > parked)
-  {
-    Serial.write("321");
-  }
-  else if(distance > fault && distance2 > parked && distance3 <= parked)
-  {
-    Serial.write("312");
-  }
-  else if(distance > fault && distance2 > parked && distance3 > parked)
-  {
-    Serial.write("311");
-  }
-  else if(distance <= parked && distance2 > fault && distance3 <= parked)
-  {
-    Serial.write("232");
-  }
-  else if(distance <= parked && distance2 > fault && distance3 > parked)
-  {
-    Serial.write("231");
-  }
-  else if(distance > parked && distance2 > fault && distance3 <= parked)
-  {
-    Serial.write("132");
-  }
-  else if(distance > parked && distance2 > fault && distance3 > parked)
-  {
-    Serial.write("131");
-  }
-  else if(distance <= parked && distance2 <= parked && distance3 > fault)
-  {
-    Serial.write("223");
-  }
-  else if(distance <= parked && distance2 > parked && distance3 > fault)
-  {
-    Serial.write("213");
-  }
-  else if(distance > parked && distance2 <= parked && distance3 > fault)
-  {
-    Serial.write("123");
-  }
-  else if(distance > parked && distance2 > parked && distance3 > fault)
-  {
-    Serial.write("113");
-  }
-  else if(distance > fault && distance2 > fault && distance3 <= parked)
-  {
-    Serial.write("332");
-  }
-  else if(distance > fault && distance2 > fault && distance3 > parked)
-  {
-    Serial.write("331");
-  }
-  else if(distance <= parked && distance2 > fault && distance3 > fault)
-  {
-    Serial.write("233");
-  }
-  else if(distance > parked && distance2 > fault && distance3 > fault)
-  {
-    Serial.write("133");
-  }
-  else if(distance > fault && distance2 <= parked && distance3 >fault)
-  {
-    Serial.write("323");
-  }
-  else if(distance > fault && distance2 > parked && distance3 >fault)
-  {
-    Serial.write("313");
-  }
-  else if(distance > fault && distance2 > fault && distance3 > fault)
-  {
-    Serial.write("333");
-  }
-  }
+  //Provide a Delay for every 5 Seconds once data sent to the RPi
   delay(5000);
 }

 //End of the Program
+/***************************************************************************************************/


Add missing license notice

Add missing license notice

--- Kleineswetter/Kleineswetter.ino
+++ Kleineswetter/Kleineswetter.ino
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 Lakoja on github.com
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include <Arduino.h>
 #include <Adafruit_BME280.h>
 #include <ESP8266WiFi.h>
@@ -5,7 +21,6 @@
 Adafruit_BME280 bme;
 bool bme_ok = false;

-// TODO center in server awake window
 // TODO save last temp and only connect when necessary

 void setup() {


Fixed data type of authorization

Fixed data type of authorization

--- module/module.ino
+++ module/module.ino
@@ -30,12 +30,12 @@
 void loop() {
 	// some variables
 	bool isStaff = false;
+  bool authorization = false;
 	bool isValidResponse = false;
 	unsigned int userID, totalTime = 0;
 	unsigned long existingTime, elapsedTime = 0;
 	unsigned long lastSend = millis();
 	unsigned char readData[bufferSize];
-	unsigned char authorization = 0x00;
 	// ----------------------------------------------------------------------
 	// Turn LED off and lock laser cutter
 	digitalWrite(ledPin, LOW);


Tuning around 868MHz defaults

Tuning around 868MHz defaults

--- examples/RF12/RF12tune3/RF12tune3.ino
+++ examples/RF12/RF12tune3/RF12tune3.ino
@@ -7,7 +7,7 @@
 /// 2013-10-04 <john<AT>o-hare<DOT>net> http://opensource.org/licenses/mit-license.php
 ////
 const char NodeConfiguration[] PROGMEM =
-   "1640o 8b 209g 9i Harvington Node";
+   "1600o 8b 212g 9i RF12Tune3";
 ////0....5....10...5....20...5....30...5....40...5....50...5....60..

 /// Recommended fuse settings:
@@ -66,6 +66,9 @@

 #if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
 #define SERIAL_BAUD 9600
+/// Serial support (output only) for Tiny supported by TinyDebugSerial
+/// http://www.ernstc.dk/arduino/tinycom.html
+/// Connect Tiny85 PB0 to USB-BUB RXD
 #else
 #define SERIAL_BAUD 57600
 #endif