Reduced serial rate back to 9600 baud

Reduced serial rate back to 9600 baud

Was missing characters at higher rates

--- Arduino/Mimic_LED_Controller/Mimic_LED_Controller.ino
+++ Arduino/Mimic_LED_Controller/Mimic_LED_Controller.ino
@@ -1,567 +1,568 @@
-#include <Adafruit_NeoPixel.h>
-#include <string.h>
-//Connect USB port to Pi USB Port
-//For serial debugging - connect to the RX1 and TX1 pins
-Adafruit_NeoPixel stbdIEA = Adafruit_NeoPixel(24, 5, NEO_GRB + NEO_KHZ800);
-Adafruit_NeoPixel portIEA = Adafruit_NeoPixel(24, 6, NEO_GRB + NEO_KHZ800);
-Adafruit_NeoPixel moduleLED = Adafruit_NeoPixel(16, 7, NEO_GRB + NEO_KHZ800);
-const int ledRedPin = 13;
-const int ledBluePin = 52;
-const int ledGreenPin = 53;
-int MyBrightness= 100; // up to 255
-String test;
-
-double V1A = 0.00;
-double V1B = 0.00;
-double V3A = 0.00;
-double V3B = 0.00;
-double V2A = 0.00;
-double V2B = 0.00;
-double V4A = 0.00;
-double V4B = 0.00;
-String module = "unset module";
-boolean Disco = false;
-int NULLIFY = 0;
-
-void setup()
-{
-  pinMode(ledRedPin, OUTPUT);
-  pinMode(ledBluePin, OUTPUT);
-  pinMode(ledGreenPin, OUTPUT);
-//  Serial1.begin(9600);
- Serial.begin(57600);
-  Serial.setTimeout(50);
-  portIEA.begin();
-  stbdIEA.begin();
-  moduleLED.begin();
-  portIEA.show();
-  stbdIEA.show();
-  moduleLED.show();
-  allSet_module(moduleLED.Color(MyBrightness,0,0),5);
-}
-
-void loop()
-{
-  digitalWrite(ledRedPin, LOW);
-  digitalWrite(ledGreenPin, LOW);
-  digitalWrite(ledBluePin, LOW);
-  //wSerial1.println("-------");
-  if(Serial.available())
-  {
-    checkSerial();
-  }
-  allSet_module(moduleLED.Color(0,0,0),0);
-  //Serial1.println(module);
-  if(module == "SM")
-  {
-    moduleLED.setPixelColor(0, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("SM");
-  }
-  else if(module == "FGB")
-  {
-    moduleLED.setPixelColor(1, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("FGB");
-  }
-  else if(module == "Node1")
-  {
-    moduleLED.setPixelColor(2, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("Node1");
-  }
-  else if(module == "Node2")
-  {
-    moduleLED.setPixelColor(6, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("Node2");
-  }
-  else if(module == "Node3")
-  {
-    moduleLED.setPixelColor(4, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("Node3");
-  }
-  else if(module == "AL")
-  {
-    moduleLED.setPixelColor(3, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("AL");
-  }
-  else if(module == "USL")
-  {
-    moduleLED.setPixelColor(5, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("USL");
-  }
-  else if(module == "Col")
-  {
-    moduleLED.setPixelColor(7, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("Col");
-  }
-  else if(module == "JEM")
-  {
-    moduleLED.setPixelColor(8, moduleLED.Color(MyBrightness,MyBrightness,MyBrightness));
-    moduleLED.show();
-    //Serial1.println("JEM");
-  }
-  else
-  {
-    allSet_module(moduleLED.Color(0,0,0),0);
-    moduleLED.show();
-  }
-
-  if(V2A < 151.5)
-  {
-    portIEA.setPixelColor(0, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(1, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(2, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(3, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(4, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(5, portIEA.Color(MyBrightness,0,0));
-    portIEA.show();
-  }
-  else if(V2A > 160)
-  {
-    portIEA.setPixelColor(0, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(1, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(2, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(3, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(4, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(5, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.show();
-  }
-  else
-  {
-    portIEA.setPixelColor(0, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(1, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(2, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(3, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(4, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(5, portIEA.Color(0,0,MyBrightness));
-    portIEA.show();
-  }
-
-  if(V4A < 151.5)
-  {
-    portIEA.setPixelColor(6, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(7, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(8, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(9, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(10, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(11, portIEA.Color(MyBrightness,0,0));
-    portIEA.show();
-  }
-  else if(V4A > 160)
-  {
-    portIEA.setPixelColor(6, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(7, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(8, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(9, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(10, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(11, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.show();
-  }
-  else
-  {
-    portIEA.setPixelColor(6, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(7, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(8, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(9, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(10, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(11, portIEA.Color(0,0,MyBrightness));
-    portIEA.show();
-  }
-
-  if(V4B < 151.5)
-  {
-    portIEA.setPixelColor(12, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(13, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(14, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(15, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(16, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(17, portIEA.Color(MyBrightness,0,0));
-    portIEA.show();
-  }
-  else if(V4B > 160)
-  {
-    portIEA.setPixelColor(12, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(13, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(14, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(15, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(16, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(17, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.show();
-  }
-  else
-  {
-    portIEA.setPixelColor(12, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(13, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(14, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(15, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(16, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(17, portIEA.Color(0,0,MyBrightness));
-    portIEA.show();
-  }
-
-  if(V2B < 151.5)
-  {
-    portIEA.setPixelColor(18, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(19, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(20, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(21, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(22, portIEA.Color(MyBrightness,0,0));
-    portIEA.setPixelColor(23, portIEA.Color(MyBrightness,0,0));
-    portIEA.show();
-  }
-  else if(V2B > 160)
-  {
-    portIEA.setPixelColor(18, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(19, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(20, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(21, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(22, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.setPixelColor(23, portIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    portIEA.show();
-  }
-  else
-  {
-    portIEA.setPixelColor(18, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(19, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(20, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(21, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(22, portIEA.Color(0,0,MyBrightness));
-    portIEA.setPixelColor(23, portIEA.Color(0,0,MyBrightness));
-    portIEA.show();
-  }
-  if(V1A < 151.5)
-  {
-    stbdIEA.setPixelColor(0, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(1, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(2, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(3, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(4, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(5, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.show();
-  }
-  else if(V1A > 160)
-  {
-    stbdIEA.setPixelColor(0, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(1, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(2, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(3, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(4, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(5, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.show();
-  }
-  else
-  {
-    stbdIEA.setPixelColor(0, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(1, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(2, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(3, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(4, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(5, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.show();
-  }
-
-  if(V3A < 151.5)
-  {
-    stbdIEA.setPixelColor(6, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(7, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(8, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(9, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(10, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(11, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.show();
-  }
-  else if(V3A > 160)
-  {
-    stbdIEA.setPixelColor(6, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(7, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(8, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(9, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(10, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(11, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.show();
-  }
-  else
-  {
-    stbdIEA.setPixelColor(6, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(7, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(8, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(9, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(10, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(11, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.show();
-  }
-
-  if(V3B < 151.5)
-  {
-    stbdIEA.setPixelColor(12, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(13, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(14, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(15, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(16, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(17, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.show();
-  }
-  else if(V3B > 160)
-  {
-    stbdIEA.setPixelColor(12, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(13, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(14, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(15, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(16, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(17, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.show();
-  }
-  else
-  {
-    stbdIEA.setPixelColor(12, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(13, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(14, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(15, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(16, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(17, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.show();
-  }
-
-  if(V1B < 151.5)
-  {
-    stbdIEA.setPixelColor(18, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(19, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(20, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(21, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(22, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.setPixelColor(23, stbdIEA.Color(MyBrightness,0,0));
-    stbdIEA.show();
-  }
-  else if(V1B > 160)
-  {
-    stbdIEA.setPixelColor(18, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(19, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(20, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(21, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(22, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.setPixelColor(23, stbdIEA.Color(MyBrightness,MyBrightness,MyBrightness));
-    stbdIEA.show();
-  }
-  else
-  {
-    stbdIEA.setPixelColor(18, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(19, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(20, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(21, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(22, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.setPixelColor(23, stbdIEA.Color(0,0,MyBrightness));
-    stbdIEA.show();
-  }
-  if(Disco)
-  {
-    theaterChaseRainbow_portIEA(50);
-    theaterChaseRainbow_stbdIEA(50);
-  }
-  Disco = false;
-}
-void checkSerial()
-{
-  digitalWrite(ledBluePin, HIGH);
-  test = "";
-
-  while(Serial.available() > 0)
-  {
-    test = Serial.readStringUntil('\n');
-    //test = Serial.readString();
-  }
-//  Serial1.println(test);
-
-  char sz[test.length() + 1];
-  char copy[test.length() + 1];
-  strcpy(sz, test.c_str());
-  char *p = sz;
-  char *str;
-  int delimeter = 0;
-  String test2 = "";
-
-  while((str = strtok_r(p," ",&p))!=NULL)
-  {
-    test2 = String(str);
-    delimeter = test2.indexOf('=');
-    if(test2.substring(0,delimeter)=="Disco")
-    {
-      Disco = true;
-    }
-    else if (test2.substring(0, delimeter) == "NULLIFY")
-    {
-      NULLIFY = int((test2.substring(delimeter + 1)).toFloat());
-          Serial.println(" Got the NULL cmd over Serial...");
-    }
-    if(test2.substring(0,delimeter)=="V2A")
-    {
-      V2A = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V2B")
-    {
-      V2B = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V4A")
-    {
-      V4A = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V4B")
-    {
-      V4B = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V1A")
-    {
-      V1A = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V1B")
-    {
-      V1B = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V3A")
-    {
-      V3A = (test2.substring(delimeter+1)).toFloat();
-    }
-    else if(test2.substring(0,delimeter)=="V3B")
-    {
-      V3B = (test2.substring(delimeter+1)).toFloat();
-    }
-    //module Selection
-    else if(test2.substring(0,delimeter)=="ISS")
-    {
-      //Serial1.println("----Module!------");
-      module = (test2.substring(delimeter+1));
-    }
-  }
-//  Serial1.println();
-}
-
-//module led functions
-void allSet_module(uint32_t c, uint8_t wait) {
-  for(uint16_t i=0; i<moduleLED.numPixels(); i++)
-  {
-    moduleLED.setPixelColor(i, c);
-    moduleLED.show();
-    delay(wait);
-  }
-}
-void theaterChaseRainbow_Module(uint8_t wait) {
-  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
-    for (int q=0; q < 3; q++) {
-      for (uint16_t i=0; i < moduleLED.numPixels(); i=i+3) {
-        moduleLED.setPixelColor(i+q, Wheel_Module( (i+j) % MyBrightness));    //turn every third pixel on
-      }
-      moduleLED.show();
-
-      delay(wait);
-
-      for (uint16_t i=0; i < moduleLED.numPixels(); i=i+3) {
-        moduleLED.setPixelColor(i+q, 0);        //turn every third pixel off
-      }
-    }
-  }
-}
-
-// Input a value 0 to MyBrightness to get a color value.
-// The colours are a transition r - g - b - back to r.
-uint32_t Wheel_Module(byte WheelPos) {
-  WheelPos = MyBrightness - WheelPos;
-  if(WheelPos < 85) {
-    return moduleLED.Color(MyBrightness - WheelPos * 3, 0, WheelPos * 3);
-  }
-  if(WheelPos < 170) {
-    WheelPos -= 85;
-    return moduleLED.Color(0, WheelPos * 3, MyBrightness - WheelPos * 3);
-  }
-  WheelPos -= 170;
-  return moduleLED.Color(WheelPos * 3, MyBrightness - WheelPos * 3, 0);
-}
-
-//port IEA led functions
-void allSet_portIEA(uint32_t c, uint8_t wait) {
-  for(uint16_t i=0; i<portIEA.numPixels(); i++)
-  {
-    portIEA.setPixelColor(i, c);
-    portIEA.show();
-    delay(wait);
-  }
-}
-
-void theaterChaseRainbow_portIEA(uint8_t wait) {
-  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
-    for (int q=0; q < 3; q++) {
-      for (uint16_t i=0; i < portIEA.numPixels(); i=i+3) {
-        portIEA.setPixelColor(i+q, Wheel_portIEA( (i+j) % MyBrightness));    //turn every third pixel on
-      }
-      portIEA.show();
-
-      delay(wait);
-
-      for (uint16_t i=0; i < portIEA.numPixels(); i=i+3) {
-        portIEA.setPixelColor(i+q, 0);        //turn every third pixel off
-      }
-    }
-  }
-}
-
-// Input a value 0 to MyBrightness to get a color value.
-// The colours are a transition r - g - b - back to r.
-uint32_t Wheel_portIEA(byte WheelPos) {
-  WheelPos = MyBrightness - WheelPos;
-  if(WheelPos < 85) {
-    return portIEA.Color(MyBrightness - WheelPos * 3, 0, WheelPos * 3);
-  }
-  if(WheelPos < 170) {
-    WheelPos -= 85;
-    return portIEA.Color(0, WheelPos * 3, MyBrightness - WheelPos * 3);
-  }
-  WheelPos -= 170;
-  return portIEA.Color(WheelPos * 3, MyBrightness - WheelPos * 3, 0);
-}
-
-
-//stbd IEA led functions
-void allSet_stbdIEA(uint32_t c, uint8_t wait) {
-  for(uint16_t i=0; i<stbdIEA.numPixels(); i++)
-  {
-    stbdIEA.setPixelColor(i, c);
-    stbdIEA.show();
-    delay(wait);
-  }
-}
-
-void theaterChaseRainbow_stbdIEA(uint8_t wait) {
-  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
-    for (int q=0; q < 3; q++) {
-      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
-        stbdIEA.setPixelColor(i+q, Wheel_stbdIEA( (i+j) % MyBrightness));    //turn every third pixel on
-      }
-      stbdIEA.show();
-
-      delay(wait);
-
-      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
-        stbdIEA.setPixelColor(i+q, 0);        //turn every third pixel off
-      }
-    }
-  }
-}
-
-// Input a value 0 to MyBrightness to get a color value.
-// The colours are a transition r - g - b - back to r.
-uint32_t Wheel_stbdIEA(byte WheelPos) {
-  WheelPos = MyBrightness - WheelPos;
-  if(WheelPos < 85) {
-    return stbdIEA.Color(MyBrightness - WheelPos * 3, 0, WheelPos * 3);
-  }
-  if(WheelPos < 170) {
-    WheelPos -= 85;
-    return stbdIEA.Color(0, WheelPos * 3, MyBrightness - WheelPos * 3);
-  }
-  WheelPos -= 170;
-  return stbdIEA.Color(WheelPos * 3, MyBrightness - WheelPos * 3, 0);
-}
+#include <Adafruit_NeoPixel.h>
+#include <string.h>
+//Connect USB port to Pi USB Port
+//For serial debugging - connect to the RX1 and TX1 pins
+Adafruit_NeoPixel stbdIEA = Adafruit_NeoPixel(24, 5, NEO_GRB + NEO_KHZ800);
+Adafruit_NeoPixel portIEA = Adafruit_NeoPixel(24, 6, NEO_GRB + NEO_KHZ800);
+Adafruit_NeoPixel moduleLED = Adafruit_NeoPixel(16, 7, NEO_GRB + NEO_KHZ800);
+const int ledRedPin = 13;
+const int ledBluePin = 52;
+const int ledGreenPin = 53;
+String test;
+
+double V1A = 0.00;
+double V1B = 0.00;
+double V3A = 0.00;
+double V3B = 0.00;
+double V2A = 0.00;
+double V2B = 0.00;
+double V4A = 0.00;
+double V4B = 0.00;
+String module = "unset module";
+boolean Disco = false;
+int NULLIFY = 0;
+
+void setup()
+{
+  pinMode(ledRedPin, OUTPUT);
+  pinMode(ledBluePin, OUTPUT);
+  pinMode(ledGreenPin, OUTPUT);
+//  Serial1.begin(9600);
+  Serial.begin(9600);
+  Serial.setTimeout(50);
+  portIEA.begin();
+  stbdIEA.begin();
+  moduleLED.begin();
+  allSet_stbdIEA(stbdIEA.Color(0,255,0),0);
+  allSet_portIEA(portIEA.Color(0,255,0),0);
+  portIEA.show();
+  stbdIEA.show();
+  allSet_module(moduleLED.Color(255,0,0),5);
+  moduleLED.show();
+}
+
+void loop()
+{
+  digitalWrite(ledRedPin, LOW);
+  digitalWrite(ledGreenPin, LOW);
+  digitalWrite(ledBluePin, LOW);
+  //wSerial1.println("-------");
+  if(Serial.available())
+  {
+    checkSerial();
+  }
+  allSet_module(moduleLED.Color(0,0,0),0);
+  //Serial1.println(module);
+  if(module == "SM")
+  {
+    moduleLED.setPixelColor(0, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("SM");
+  }
+  else if(module == "FGB")
+  {
+    moduleLED.setPixelColor(1, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("FGB");
+  }
+  else if(module == "Node1")
+  {
+    moduleLED.setPixelColor(2, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("Node1");
+  }
+  else if(module == "Node2")
+  {
+    moduleLED.setPixelColor(6, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("Node2");
+  }
+  else if(module == "Node3")
+  {
+    moduleLED.setPixelColor(4, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("Node3");
+  }
+  else if(module == "AL")
+  {
+    moduleLED.setPixelColor(3, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("AL");
+  }
+  else if(module == "USL")
+  {
+    moduleLED.setPixelColor(5, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("USL");
+  }
+  else if(module == "Col")
+  {
+    moduleLED.setPixelColor(7, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("Col");
+  }
+  else if(module == "JEM")
+  {
+    moduleLED.setPixelColor(8, moduleLED.Color(255,255,255));
+    moduleLED.show();
+    //Serial1.println("JEM");
+  }
+  else
+  {
+    allSet_module(moduleLED.Color(0,0,0),0);
+    moduleLED.show();
+  }
+
+  if(V2A < 151.5)
+  {
+    portIEA.setPixelColor(0, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(1, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(2, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(3, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(4, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(5, portIEA.Color(255,0,0));
+    portIEA.show();
+  }
+  else if(V2A > 160)
+  {
+    portIEA.setPixelColor(0, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(1, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(2, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(3, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(4, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(5, portIEA.Color(255,255,255));
+    portIEA.show();
+  }
+  else
+  {
+    portIEA.setPixelColor(0, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(1, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(2, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(3, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(4, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(5, portIEA.Color(0,0,255));
+    portIEA.show();
+  }
+
+  if(V4A < 151.5)
+  {
+    portIEA.setPixelColor(6, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(7, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(8, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(9, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(10, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(11, portIEA.Color(255,0,0));
+    portIEA.show();
+  }
+  else if(V4A > 160)
+  {
+    portIEA.setPixelColor(6, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(7, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(8, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(9, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(10, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(11, portIEA.Color(255,255,255));
+    portIEA.show();
+  }
+  else
+  {
+    portIEA.setPixelColor(6, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(7, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(8, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(9, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(10, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(11, portIEA.Color(0,0,255));
+    portIEA.show();
+  }
+
+  if(V4B < 151.5)
+  {
+    portIEA.setPixelColor(12, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(13, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(14, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(15, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(16, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(17, portIEA.Color(255,0,0));
+    portIEA.show();
+  }
+  else if(V4B > 160)
+  {
+    portIEA.setPixelColor(12, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(13, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(14, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(15, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(16, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(17, portIEA.Color(255,255,255));
+    portIEA.show();
+  }
+  else
+  {
+    portIEA.setPixelColor(12, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(13, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(14, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(15, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(16, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(17, portIEA.Color(0,0,255));
+    portIEA.show();
+  }
+
+  if(V2B < 151.5)
+  {
+    portIEA.setPixelColor(18, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(19, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(20, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(21, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(22, portIEA.Color(255,0,0));
+    portIEA.setPixelColor(23, portIEA.Color(255,0,0));
+    portIEA.show();
+  }
+  else if(V2B > 160)
+  {
+    portIEA.setPixelColor(18, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(19, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(20, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(21, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(22, portIEA.Color(255,255,255));
+    portIEA.setPixelColor(23, portIEA.Color(255,255,255));
+    portIEA.show();
+  }
+  else
+  {
+    portIEA.setPixelColor(18, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(19, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(20, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(21, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(22, portIEA.Color(0,0,255));
+    portIEA.setPixelColor(23, portIEA.Color(0,0,255));
+    portIEA.show();
+  }
+  if(V1A < 151.5)
+  {
+    stbdIEA.setPixelColor(0, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(1, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(2, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(3, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(4, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(5, stbdIEA.Color(255,0,0));
+    stbdIEA.show();
+  }
+  else if(V1A > 160)
+  {
+    stbdIEA.setPixelColor(0, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(1, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(2, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(3, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(4, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(5, stbdIEA.Color(255,255,255));
+    stbdIEA.show();
+  }
+  else
+  {
+    stbdIEA.setPixelColor(0, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(1, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(2, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(3, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(4, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(5, stbdIEA.Color(0,0,255));
+    stbdIEA.show();
+  }
+
+  if(V3A < 151.5)
+  {
+    stbdIEA.setPixelColor(6, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(7, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(8, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(9, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(10, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(11, stbdIEA.Color(255,0,0));
+    stbdIEA.show();
+  }
+  else if(V3A > 160)
+  {
+    stbdIEA.setPixelColor(6, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(7, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(8, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(9, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(10, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(11, stbdIEA.Color(255,255,255));
+    stbdIEA.show();
+  }
+  else
+  {
+    stbdIEA.setPixelColor(6, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(7, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(8, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(9, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(10, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(11, stbdIEA.Color(0,0,255));
+    stbdIEA.show();
+  }
+
+  if(V3B < 151.5)
+  {
+    stbdIEA.setPixelColor(12, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(13, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(14, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(15, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(16, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(17, stbdIEA.Color(255,0,0));
+    stbdIEA.show();
+  }
+  else if(V3B > 160)
+  {
+    stbdIEA.setPixelColor(12, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(13, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(14, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(15, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(16, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(17, stbdIEA.Color(255,255,255));
+    stbdIEA.show();
+  }
+  else
+  {
+    stbdIEA.setPixelColor(12, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(13, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(14, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(15, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(16, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(17, stbdIEA.Color(0,0,255));
+    stbdIEA.show();
+  }
+
+  if(V1B < 151.5)
+  {
+    stbdIEA.setPixelColor(18, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(19, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(20, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(21, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(22, stbdIEA.Color(255,0,0));
+    stbdIEA.setPixelColor(23, stbdIEA.Color(255,0,0));
+    stbdIEA.show();
+  }
+  else if(V1B > 160)
+  {
+    stbdIEA.setPixelColor(18, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(19, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(20, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(21, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(22, stbdIEA.Color(255,255,255));
+    stbdIEA.setPixelColor(23, stbdIEA.Color(255,255,255));
+    stbdIEA.show();
+  }
+  else
+  {
+    stbdIEA.setPixelColor(18, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(19, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(20, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(21, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(22, stbdIEA.Color(0,0,255));
+    stbdIEA.setPixelColor(23, stbdIEA.Color(0,0,255));
+    stbdIEA.show();
+  }
+  if(Disco)
+  {
+    theaterChaseRainbow_portIEA(50);
+    theaterChaseRainbow_stbdIEA(50);
+  }
+  Disco = false;
+}
+void checkSerial()
+{
+  digitalWrite(ledBluePin, HIGH);
+  test = "";
+
+  while(Serial.available() > 0)
+  {
+    test = Serial.readStringUntil('\n');
+    //test = Serial.readString();
+  }
+  //Serial.println(test);
+
+  char sz[test.length() + 1];
+  char copy[test.length() + 1];
+  strcpy(sz, test.c_str());
+  char *p = sz;
+  char *str;
+  int delimeter = 0;
+  String test2 = "";
+
+  while((str = strtok_r(p," ",&p))!=NULL)
+  {
+    test2 = String(str);
+    delimeter = test2.indexOf('=');
+    if(test2.substring(0,delimeter)=="Disco")
+    {
+      Disco = true;
+    }
+    else if (test2.substring(0, delimeter) == "NULLIFY")
+    {
+      NULLIFY = int((test2.substring(delimeter + 1)).toFloat());
+      //Serial.println(" Got the NULL cmd over Serial...");
+    }
+    if(test2.substring(0,delimeter)=="V2A")
+    {
+      V2A = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V2B")
+    {
+      V2B = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V4A")
+    {
+      V4A = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V4B")
+    {
+      V4B = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V1A")
+    {
+      V1A = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V1B")
+    {
+      V1B = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V3A")
+    {
+      V3A = (test2.substring(delimeter+1)).toFloat();
+    }
+    else if(test2.substring(0,delimeter)=="V3B")
+    {
+      V3B = (test2.substring(delimeter+1)).toFloat();
+    }
+    //module Selection
+    else if(test2.substring(0,delimeter)=="ISS")
+    {
+      //Serial1.println("----Module!------");
+      module = (test2.substring(delimeter+1));
+    }
+  }
+//  Serial1.println();
+}
+
+//module led functions
+void allSet_module(uint32_t c, uint8_t wait) {
+  for(uint16_t i=0; i<moduleLED.numPixels(); i++)
+  {
+    moduleLED.setPixelColor(i, c);
+    moduleLED.show();
+    delay(wait);
+  }
+}
+void theaterChaseRainbow_Module(uint8_t wait) {
+  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
+    for (int q=0; q < 3; q++) {
+      for (uint16_t i=0; i < moduleLED.numPixels(); i=i+3) {
+        moduleLED.setPixelColor(i+q, Wheel_Module( (i+j) % 255));    //turn every third pixel on
+      }
+      moduleLED.show();
+
+      delay(wait);
+
+      for (uint16_t i=0; i < moduleLED.numPixels(); i=i+3) {
+        moduleLED.setPixelColor(i+q, 0);        //turn every third pixel off
+      }
+    }
+  }
+}
+
+// Input a value 0 to 255 to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel_Module(byte WheelPos) {
+  WheelPos = 255 - WheelPos;
+  if(WheelPos < 85) {
+    return moduleLED.Color(255 - WheelPos * 3, 0, WheelPos * 3);
+  }
+  if(WheelPos < 170) {
+    WheelPos -= 85;
+    return moduleLED.Color(0, WheelPos * 3, 255 - WheelPos * 3);
+  }
+  WheelPos -= 170;
+  return moduleLED.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
+}
+
+//port IEA led functions
+void allSet_portIEA(uint32_t c, uint8_t wait) {
+  for(uint16_t i=0; i<portIEA.numPixels(); i++)
+  {
+    portIEA.setPixelColor(i, c);
+    portIEA.show();
+    delay(wait);
+  }
+}
+
+void theaterChaseRainbow_portIEA(uint8_t wait) {
+  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
+    for (int q=0; q < 3; q++) {
+      for (uint16_t i=0; i < portIEA.numPixels(); i=i+3) {
+        portIEA.setPixelColor(i+q, Wheel_portIEA( (i+j) % 255));    //turn every third pixel on
+      }
+      portIEA.show();
+
+      delay(wait);
+
+      for (uint16_t i=0; i < portIEA.numPixels(); i=i+3) {
+        portIEA.setPixelColor(i+q, 0);        //turn every third pixel off
+      }
+    }
+  }
+}
+
+// Input a value 0 to 255 to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel_portIEA(byte WheelPos) {
+  WheelPos = 255 - WheelPos;
+  if(WheelPos < 85) {
+    return portIEA.Color(255 - WheelPos * 3, 0, WheelPos * 3);
+  }
+  if(WheelPos < 170) {
+    WheelPos -= 85;
+    return portIEA.Color(0, WheelPos * 3, 255 - WheelPos * 3);
+  }
+  WheelPos -= 170;
+  return portIEA.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
+}
+
+
+//stbd IEA led functions
+void allSet_stbdIEA(uint32_t c, uint8_t wait) {
+  for(uint16_t i=0; i<stbdIEA.numPixels(); i++)
+  {
+    stbdIEA.setPixelColor(i, c);
+    stbdIEA.show();
+    delay(wait);
+  }
+}
+
+void theaterChaseRainbow_stbdIEA(uint8_t wait) {
+  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
+    for (int q=0; q < 3; q++) {
+      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
+        stbdIEA.setPixelColor(i+q, Wheel_stbdIEA( (i+j) % 255));    //turn every third pixel on
+      }
+      stbdIEA.show();
+
+      delay(wait);
+
+      for (uint16_t i=0; i < stbdIEA.numPixels(); i=i+3) {
+        stbdIEA.setPixelColor(i+q, 0);        //turn every third pixel off
+      }
+    }
+  }
+}
+
+// Input a value 0 to 255 to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel_stbdIEA(byte WheelPos) {
+  WheelPos = 255 - WheelPos;
+  if(WheelPos < 85) {
+    return stbdIEA.Color(255 - WheelPos * 3, 0, WheelPos * 3);
+  }
+  if(WheelPos < 170) {
+    WheelPos -= 85;
+    return stbdIEA.Color(0, WheelPos * 3, 255 - WheelPos * 3);
+  }
+  WheelPos -= 170;
+  return stbdIEA.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
+}


Update spark-as-client.ino

Update spark-as-client.ino

--- spark-as-client/spark-as-client.ino
+++ spark-as-client/spark-as-client.ino
@@ -1,5 +1,9 @@
 TCPClient client;
 byte server[] = { 74, 125, 224, 72 }; // Google
+
+// found somewhere  IPAddress server(192, 168, 1, 122); instead of the above line
+
+
 void setup()
 {


Fixed encoder decrement bug on Constant Resistance and Constant Power mode

--- ElectronicLoadController/ElectronicLoadController.ino
+++ ElectronicLoadController/ElectronicLoadController.ino
@@ -73,7 +73,7 @@

  if(mode == CONSTANT_RESISTANCE) {
-    byte encoderPos = getEncoderMovement();       //getEncoderMovement() returns either -1, 0 or 1
+    int encoderPos = getEncoderMovement();       //getEncoderMovement() returns either -1, 0 or 1
     if(encoderPos > 0 && ISetVal < ISET_CR_MAX)   //Encoder incremented
       ISetVal+=ISET_CR_STEP;
     else if (encoderPos < 0 && ISetVal >= ISET_CR_MIN)   //Encoder decremented
@@ -87,7 +87,7 @@

  if(mode == CONSTANT_POWER) {
-    byte encoderPos = getEncoderMovement();       //getEncoderMovement() returns either -1, 0 or 1
+    int encoderPos = getEncoderMovement();       //getEncoderMovement() returns either -1, 0 or 1
     if(encoderPos > 0 && ISetVal < ISET_CP_MAX)   //Encoder incremented
       ISetVal+=ISET_CP_STEP;
     else if (encoderPos < 0 && ISetVal >= ISET_CP_STEP)   //Encoder decremented
@@ -372,7 +372,3 @@
 delay(100);

 }
-
-
-
-


Cleaned up code indenting and comments.

Cleaned up code indenting and comments.

--- VernierAnalogStore/VernierAnalogStore.ino
+++ VernierAnalogStore/VernierAnalogStore.ino
@@ -1,12 +1,19 @@
 /*
 VernierAnalogStore
-Reads a Vernier analog (BTA) Sensor connected to pin A0 of the Arduino and and stores  the data in the non-volatile EEPROM memory of the Arduino.
+Reads a Vernier analog (BTA) Sensor connected to pin A0 of the Arduino
+and and stores  the data in the non-volatile EEPROM memory of the Arduino.
 This sketch displays the time and sensor readings on the Serial Monitor.
 As written, the readings will be displayed every half second.
 Change the variable TimeBetweenReadings to change the rate.
 Change the variable NumberOfReadings to change the number of data points to take.
- See www.vernier.com/arduino for more information, especially for information on how this sketch can be used to collect remote data with the Arduino away from a computer.
- Thanks to B. Huang, for help on this program, especially the structure of a program to store and retrieve data.
+Change the info between //////// lines to change sensors.
+
+See www.vernier.com/arduino for more information, especially for information
+on how this sketch can be used to collect remote data with the Arduino away
+from a computer.
+
+Thanks to Brian Huang, for help on this program, especially the structure of a
+program to store and retrieve data.
 */
 int buttonPin= 12; // analog input pin to use as a digital input
 int ledPin1= 13; // digital output pin for LED 1 indicator
@@ -22,7 +29,7 @@
 long btnUpTime; // time the button was released
 boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered
 boolean ledVal1 = false; // state of LED 1
-int AnalogDataPin = A1; // this may be changed depending on circuit wiring
+int AnalogDataPin = A0; // this may be changed depending on circuit wiring
 int Count;
 float Voltage;
 float SensorReading;
@@ -39,43 +46,44 @@
 ///////////////////////////////////
 void setup()
 {
-// Set button input pin
-pinMode(buttonPin, INPUT);
-digitalWrite(buttonPin, HIGH);
-pinMode(AnalogDataPin, INPUT);
-pinMode(ledPin1, OUTPUT);// Set LED output pin
-Serial.begin(9600);
-Serial.println("VernierAnalogStore sketch");
-Serial.println("Press and hold to collect new data");
-Serial.println("Press button briefly to read data stored in EEPROM");
-Serial.println("and send it to the Serial Monitor");
-Serial.println(" ");
+  // Set button input pin
+  pinMode(buttonPin, INPUT);
+  digitalWrite(buttonPin, HIGH);
+  pinMode(AnalogDataPin, INPUT);
+  pinMode(ledPin1, OUTPUT);// Set LED output pin
+  Serial.begin(9600);
+  Serial.println("VernierAnalogStore sketch");
+  Serial.println("Press and hold to collect new data");
+  Serial.println("Press button briefly to read data stored in EEPROM");
+  Serial.println("and send it to the Serial Monitor");
+  Serial.println(" ");
 }
 void loop()
 {
-digitalWrite(ledPin1, false);
-// Read the state of the button
-buttonVal = digitalRead(buttonPin);// button down is low
-// Test for button pressed and store the down time
-if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce))
-{ //button pressed
-  btnDnTime = millis();// note time of press
-}
-// Test for button release and store the up time
-if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnDnTime) > long(debounce))
-{
-  if (ignoreUp == false) ReadEEPROMData();// read data from EEPROM and send to Serial Monitor
-  else ignoreUp = false;
-btnUpTime = millis();// note time of button release
-}
-// Test for button held down for longer than the hold time
-if (buttonVal == LOW && (millis() - btnDnTime) > long(holdTime))
-{
-CollectData(); //collect new data
-ignoreUp = true;
-btnDnTime = millis(); // get new button down time
-}
-buttonLast = buttonVal;
+  digitalWrite(ledPin1, false);
+  // Read the state of the button
+  buttonVal = digitalRead(buttonPin);// button down is low
+  // Test for button pressed and store the down time
+  if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce))
+    {
+      //button pressed
+       btnDnTime = millis();// note time of press
+     }
+  // Test for button release and store the up time
+  if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnDnTime) > long(debounce))
+    {
+       if (ignoreUp == false) ReadEEPROMData();// read data from EEPROM and send to Serial Monitor
+       else ignoreUp = false;
+       btnUpTime = millis();// note time of button release
+     }
+  // Test for button held down for longer than the hold time
+  if (buttonVal == LOW && (millis() - btnDnTime) > long(holdTime))
+    {
+      CollectData(); //collect new data
+      ignoreUp = true;
+      btnDnTime = millis(); // get new button down time
+    }
+  buttonLast = buttonVal;
 }
 //=================================================
 // Events to trigger by click and press+hold
@@ -107,31 +115,32 @@
   Serial.println(Units);
   for (i = 0; i <(NumberOfPointsRead)*2; i+=2)
    {
-    Count = EEPROM.read(base+2 + i) | EEPROM.read(base+2 + i + 1) << 8;
-    //the print below does the division first to avoid overflows
-    Serial.print(i/2/1000.0*TimeBetweenReadings);
-    Serial.print("\t");                // print a tab character
-    Voltage = Count  * (5.0/ 1024);
-    SensorReading= Intercept + Voltage * Slope;
-    Serial.println(SensorReading);
-  }
-Serial.println(" ");
-Serial.println("Press and hold button to collect new data ");
-Serial.println(" ");
-digitalWrite(ledPin1, false); //turn off LED
-//end of send data to Serial Monitor
+      Count = EEPROM.read(base+2 + i) | EEPROM.read(base+2 + i + 1) << 8;
+      //the print below does the division first to avoid overflows
+      Serial.print(i/2/1000.0*TimeBetweenReadings);
+      Serial.print("\t");                // print a tab character
+      Voltage = Count  * (5.0/ 1024);
+      SensorReading= Intercept + Voltage * Slope;
+      Serial.println(SensorReading);
+   }
+  Serial.println(" ");
+  Serial.println("Press and hold button to collect new data ");
+  Serial.println(" ");
+  digitalWrite(ledPin1, false); //turn off LED
+  //end of send data to Serial Monitor
 }
+
 void CollectData() //Collect Data
 {
-ledVal1 = !ledVal1;
-Serial.begin(9600);
-Serial.println("Collecting Data...");
-Serial.println(" ");
-int Sample = 0;// local variable
-unsigned long StartTime =0;
-int addr = base+ 2; //starting address of memory for data storage
-//note addr is later incremented
- Serial.println( "Vernier Format 2");
+  ledVal1 = !ledVal1;
+  Serial.begin(9600);
+  Serial.println("Collecting Data...");
+  Serial.println(" ");
+  int Sample = 0;// local variable
+  unsigned long StartTime =0;
+  int addr = base+ 2; //starting address of memory for data storage
+  //note addr is later incremented
+  Serial.println( "Vernier Format 2");
   Serial.print(NumberOfPoints);
   Serial.print(" readings taken with a Vernier ");
   Serial.println(SensorName);
@@ -153,31 +162,32 @@
   Serial.println(Units);
   StartTime = millis();// time of last reading in ms
   for (Sample=0;Sample<NumberOfPoints;Sample++)
-  {digitalWrite(ledPin1, true);
-    Serial.print(Sample);
-    Serial.print("\t");
-    //the print below does the division first to avoid overflows
-    Serial.print(Sample/1000.0*TimeBetweenReadings);
-    Serial.print("\t");
-    Count= analogRead(A1);
-    Voltage = Count * (5.0/ 1024);
-    SensorReading = Intercept + Voltage * Slope;
-    Serial.println(SensorReading);
-    EEPROM.write(addr, lowByte(Count));
-    EEPROM.write(addr + 1, highByte(Count));
-    addr +=2;  //increment address pointer twice
-   delay (TimeBetweenReadings/2);//these lines are to give a blink to the LED
-   digitalWrite(ledPin1, false);
-   delay (TimeBetweenReadings/2);
-  }
-//the number of points is stored at base and base+1;
-//data starts at the next two bytes (base=2 and base+3, etc);
-EEPROM.write(base+ 0, lowByte(NumberOfPoints));
-EEPROM.write(base + 1, highByte(NumberOfPoints));
-Serial.println(" ");
-Serial.println("Press button briefly to send data to Serial Monitor");
-Serial.println("Press and hold to collect new data");
-Serial.println(" ");
-digitalWrite(ledPin1, false);
+   {
+     digitalWrite(ledPin1, true);
+     Serial.print(Sample);
+     Serial.print("\t");
+     //the print below does the division first to avoid overflows
+     Serial.print(Sample/1000.0*TimeBetweenReadings);
+     Serial.print("\t");
+     Count= analogRead(A1);
+     Voltage = Count * (5.0/ 1024);
+     SensorReading = Intercept + Voltage * Slope;
+     Serial.println(SensorReading);
+     EEPROM.write(addr, lowByte(Count));
+     EEPROM.write(addr + 1, highByte(Count));
+     addr +=2;  //increment address pointer twice
+     delay (TimeBetweenReadings/2);//these lines are to give a blink to the LED
+     digitalWrite(ledPin1, false);
+     delay (TimeBetweenReadings/2);
+    }
+  //the number of points is stored at base and base+1;
+  //data starts at the next two bytes (base=2 and base+3, etc);
+  EEPROM.write(base+ 0, lowByte(NumberOfPoints));
+  EEPROM.write(base + 1, highByte(NumberOfPoints));
+  Serial.println(" ");
+  Serial.println("Press button briefly to send data to Serial Monitor");
+  Serial.println("Press and hold to collect new data");
+  Serial.println(" ");
+  digitalWrite(ledPin1, false);
 };//end of Data Collect
-
+


Update 9_Loop.ino

Update 9_Loop.ino

增加sigfox封包確認訊息

--- WaterBox_v1/9_Loop.ino
+++ WaterBox_v1/9_Loop.ino
@@ -1,332 +1,331 @@
-/*
-   usr 按鈕檢查
-   超過5秒返回 true : 儲存資料
-   否則返回false:     狀態 + 1
-*/
-int chapter = 0;                          //  大項目：0~1(校正設定,時間設定)
-int item = 0;                             //  子項目：0~3(準備,參數1設定,參數2設定,參數3設定)
-bool config_state = true;                 //  true時只能顯示目前設定，flase時可以改設定
-int _YY, _year_1, _year_2, _MM, _DD, _HH, _mm; //  時間日期調整用
-
-void loop() {
-  bool _switch_mode = digitalRead(switch_pin);
-
-  DateTime now = rtc.now();          // 取得目前時間
-  int _year = now.year();
-  int _month = now.month();
-  int _day = now.day();
-  String _days = daysOfTheWeek[now.dayOfTheWeek()];
-  int _hour = now.hour();
-  int _minute = now.minute();
-  bool _SD_save = now.unixtime() % SD_save_interval == 0;     //  5分鐘存檔一次
-  bool _upload = now.unixtime() % Upload_interval == 0;       // 20分鐘上傳一次
-  // Upload_interval
-
-  if (_switch_mode) // 分析模式
-  {
-    SerialUSB.println("分析模式");
-
-    float temperature = temp_value();
-    int EC = EC_value(temperature, EC_slop, EC_intercept);
-    float pH_mV = _pH_mV(pH_slop, pH_intercept);                             // 實際輸出電壓(mV)，校正用來校正電壓
-    float pH_Value = 3.5 * pH_mV * 0.001;                                   // 分壓(5V->2.5V)後，用電壓換算成pH (斜率3.5的出處待確認)
-    float DO, ORP;                                                        // 預留但不會用到
-
-    OLED_header("  >> Water Box <<  ");
-    OLED_content((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day), 1);
-    OLED_content("<< " + _days + " >>", 1);
-    OLED_content("T: " + (String)temperature, 2);
-    display.display();
-    display.clearDisplay();
-    delay(1000);
-
-    OLED_header("  >> Water Box <<  ");
-    OLED_content(convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
-    OLED_content("EC: " + (String)EC + " us", 2);
-    OLED_content("pH: " + (String)pH_Value, 2);
-    OLED_content("pH(mV): " + (String)pH_mV, 1);
-    display.display();
-    display.clearDisplay();
-    delay(500);
-
-    String _Msg = "";
-
-    if (_SD_save)  {
-      OLED_header("  >> Water Box <<  ");
-      OLED_content(convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
-      OLED_content("Save Data", 2);
-      display.display();
-      display.clearDisplay();
-      delay(500);
-      save2SD(_year, _month, _day, _hour, _minute, temperature, pH_Value, EC, pH_mV);
-      delay(500);
-    }
-    else delay(1000);
-
-    if (_upload) {                 // 上傳前先用JSON打包訊息
-      SerialUSB.print("上傳資料");
-
-      /*
-         int App_ID = 0x6;                       // App ID 給LASS後端辨識用
-        int Temperature_filed[2] = {1,7};         // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
-        int pH_filed[2] = {1,8};                 // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
-        int EC_filed[2] = {1,18};                // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
-        int DO_filed[2] = {0,7};                 // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
-        int ORP_filed[2] = {0,11};               // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
-        const int Filed_length_limit = 52;             // Filed length limit (在設定時檢查是否超過長度，16*4(sigfox) - 4(app id)- 8(FiledDefinition) =52)
-      */
-
-      long long _buffer[2] = {App_ID, 0};  // 打包資料用buffer  (第一個)
-      int _packets_size[2] = {12, 0};      // 封包大小初始值為12bits，後面再依測項增加長度
-
-      byte _DataFiled = 0b1;             // byte 為8 bits剛好可以塞_DataFiled
-      _DataFiled = _DataFiled << 1;
-      _DataFiled |= Temperature_filed[0];// add Temperature filed
-      _DataFiled = _DataFiled << 1;
-      _DataFiled |= pH_filed[0];        // add pH filed
-      _DataFiled = _DataFiled << 1;
-      _DataFiled |= EC_filed[0];        // add EC filed
-      _DataFiled = _DataFiled << 1;
-      _DataFiled |= DO_filed[0];        // add DO filed
-      _DataFiled = _DataFiled << 1;
-      _DataFiled |= ORP_filed[0];       // add ORP filed
-      _DataFiled = _DataFiled << 2;     // add last 2 reserved filed
-
-      SerialUSB.println("_DataFiled: " + (String)_DataFiled);   // 確認打包OK
-      SerialUSB.println(_DataFiled, BIN);
-
-      _buffer[0] = _buffer[0] << 8;
-      _buffer[0] |= _DataFiled;                // add Data Filed
-
-      SerialUSB.print("第1段封包");
-      _printOut1(_buffer[0], sizeof(_buffer[0]));  // 0000 0000 0000 0000 0000 0110 1111 0000
-      SerialUSB.print("第2段封包");
-      _printOut1(_buffer[1], sizeof(_buffer[1]));  // 0000 0000 0000 0000 0000 0000 0000 0000
-
-      if (Temperature_filed[0]) {
-        int _temperature_temp = int(temperature) + 200;                     // -20.0~80.0 修正成 0-100
-        _bale(_temperature_temp, Temperature_filed, _buffer, _packets_size);   // 打包資料
-        SerialUSB.print("第1段封包");
-        _printOut1(_buffer[0], sizeof(_buffer[0]));
-        // 0000 0000 0000 0110 1111 0000 1110 0110
-        // 0000 0000 0000 0110 1111 0000 1110 0110
-        // 0110 1111 0000 1110 0110 0010 1111 0000
-      } else SerialUSB.println("無安裝溫度模組");
-      if (pH_filed[0]) {
-        int _pH_temp = int(pH_Value * 10);                                     // -20.0~80.0 修正成 0-100
-        _bale(_pH_temp, pH_filed, _buffer, _packets_size);                  // 打包資料
-      } else SerialUSB.println("無安裝pH模組");
-      if (EC_filed[0]) {
-        int _EC_temp = int(EC);                                          // -20.0~80.0 修正成 0-100
-        _bale(_EC_temp, EC_filed, _buffer, _packets_size);                  // 打包資料
-      } else SerialUSB.println("無安裝EC模組");
-      if (DO_filed[0]) {
-        int _DO_temp = int(DO * 10);                                      // 0.0~10.0 修正成 0-100
-        _bale(_DO_temp, DO_filed, _buffer, _packets_size);                   // 打包資料
-      } else SerialUSB.println("無安裝DO模組");
-      if (ORP_filed[0]) {
-        int _ORP_temp = int(ORP) + 1000;                                  // -20.0~80.0 修正成 0-100
-        _bale(_ORP_temp, ORP_filed, _buffer, _packets_size);                // 打包資料
-      } else SerialUSB.println("無安裝ORP模組");
-
-      _buffer[0] = _buffer[0] << ( 32 - _packets_size[0] );                 // 把資料往左補滿，空格再右
-      _buffer[1] = _buffer[1] << ( 32 - _packets_size[1] );                 // 把資料往左補滿，空格再右
-
-      SerialUSB.print("第1段封包(" + (String)(32 - _packets_size[0]) + ")\t");
-      _printOut1(_buffer[0], sizeof(_buffer[0]));                           // 0000 0000 0000 0011 0111 1000 1110 1000
-      SerialUSB.print("第2段封包(" + (String)(32 - _packets_size[1]) + ")\t");
-      _printOut1(_buffer[1], sizeof(_buffer[1]));                           // 0000 0000 0000 0000 0000 0000 0000 0000
-
-      String _str_balle = _bale2Hex(_buffer);
-      send_to_sigfox(_str_balle);
-    }
-    SerialUSB.println((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day) + "\t<<" + _days + ">>");
-    SerialUSB.print("pH: ");
-    SerialUSB.print(pH_Value);
-    SerialUSB.print("(");
-    SerialUSB.print(pH_mV);
-    SerialUSB.print(")");
-    SerialUSB.print("\tEC: ");
-    SerialUSB.print(EC);
-    SerialUSB.print("\t溫度: ");
-    SerialUSB.print(temperature);
-    SerialUSB.println("\n\r");
-
-  } // end of if (_switch_mode)
-  else {  // 設定模式
-    unsigned long printTime = millis();                            // Serial印出時間計時器
-    float _time = pull_time(USR_pin, 3);                           // 設定按鈕計時器
-    String _state_str, _config_str;                                // Serial輸出用
-    String _state_OLDE_1, _state_OLDE_2, _state_str_OLED;          // OLED 顯示用
-
-    if (printTime % print_interval <= print_interval * 0.05) {
-      SerialUSB.println("設定模式");
-    }
-
-    if (_time > 0 && _time < 1) {       // 切換子項目
-      if (item == 3) item = 0;          // 到最後一項時跳回第一項
-      else item += 1;                   // 跳到下一項
-    }
-    else if (_time > 1 && _time < 2) {  // 切換大項目
-      if (chapter == 1) chapter = 0;    // 到最後一項時跳回第一項
-      else chapter += 1;                // 跳到下一項
-    }
-    else if (_time >= 3) {              // 切換設定顯示/調整
-      if (config_state) config_state = false;                          // 切換到設定調整狀態
-      else  {                                                          // 切回設定顯示狀態
-        config_state = true;
-        _config(false);                                                // 儲存目前的設定
-        if (_YY != 0 && _MM != 0 && _DD != 0 && _HH != 0 && _mm != 0)  rtc.adjust(DateTime(_YY, _MM, _DD, _HH, _mm, 0)); // 設定時間
-      }
-    }
-    if (printTime % print_interval <= print_interval * 0.05) {
-      if (config_state) {
-        SerialUSB.println("顯示目前設定");
-      }
-      else {
-        SerialUSB.println("調整設定");
-      }
-    }
-    // 顯示目前的項目
-    switch (item) {
-      case 0:
-        if (chapter) {
-          _state_str = "時間設定頁面";
-          _state_str_OLED = "Setting Time";
-        }
-        else {
-          _state_str = "參數設定頁面";
-          _state_str_OLED = "Setting Parameters";
-        }
-        break;
-      case 1:
-        if (chapter) {          // 年份的設定
-          if (config_state) {   // 顯示年分
-            _state_str = "系統年分";
-            _config_str = (String) _year;
-            _state_str_OLED = "This Year";
-            _state_OLDE_1 = (String)_year;
-          }
-          else {                // 用可變電阻調整目前年分
-            _state_str = "設定年分";
-            int _year_1 = (int)_analog_convert(Rotary_Pin_1, 9);
-            int _year_2 = (int)_analog_convert(Rotary_Pin_2, 9);
-            _YY = 2000 + _year_1 * 10 + _year_2;
-            _config_str = (String) _YY;
-            _state_str_OLED = "Setting Year";
-            _state_OLDE_1 = (String)_YY;
-          }
-        }
-        else {                  // pH斜率截距的設定
-          if (config_state) {   // 顯示目前設定
-            _state_str = "pH 目前的斜率截距";
-            _config_str = "pH slope:" + (String)pH_slop + "\t pH intercept：" + (String)pH_intercept;
-            _state_str_OLED = "pH's config";
-            _state_OLDE_1 = "pH's slop: " + (String)pH_slop;
-            _state_OLDE_2 = "pH's intercept: " + (String)pH_intercept;
-          }
-          else {                // 用可變電阻設定參數
-            _state_str = "設定pH斜率截距";
-            pH_slop = 0.8 + _analog_convert(Rotary_Pin_1, 400) * 0.001;
-            pH_intercept = -0.5 + _analog_convert(Rotary_Pin_2, 100) * 0.01;
-            _config_str = "pH slope:" + (String)pH_slop + "\t pH intercept：" + (String)pH_intercept;
-            _state_str_OLED = "Setting pH's config";
-            _state_OLDE_1 = "pH's slop: " + (String)pH_slop;
-            _state_OLDE_2 = "pH's intercept: " + (String)pH_intercept;
-          }
-        }
-        break;
-      case 2:
-        if (chapter) {          // 日期的設定
-          if (config_state) {   // 顯示目前日期
-            _state_str = "日期顯示";
-            _config_str = convert_2digits(_month) + "/" + convert_2digits(_day);
-            _state_str_OLED = "Date Now";
-            _state_OLDE_1 = "Month: " + convert_2digits(_month);
-            _state_OLDE_2 = "Day: " + convert_2digits(_day);
-          }
-          else {                // 用可變電阻調整日期
-            _state_str = "日期設定(MM/DD)";
-            _MM = (int)_analog_convert(Rotary_Pin_1, 11) + 1;
-            _DD = (int)_analog_convert(Rotary_Pin_2, 30) + 1;
-            _config_str = convert_2digits(_MM) + "/" + convert_2digits(_DD);
-            _state_str_OLED = "Setting Date";
-            _state_OLDE_1 = "Month: " + convert_2digits(_MM);
-            _state_OLDE_2 = "Day: " + convert_2digits(_DD);
-          }
-        }
-        else {                  // EC斜率截距的設定
-          if (config_state) {   // 顯示目前設定
-            _state_str = "EC目前的斜率截距";
-            _config_str = "EC斜率:" + (String)EC_slop + "\t EC截距：" + (String)EC_intercept;
-            _state_str_OLED = "EC's config";
-            _state_OLDE_1 = "EC's slop: " + (String)EC_slop;
-            _state_OLDE_2 = "EC's intercept: " + (String)EC_intercept;
-          }
-          else {                // 用可變電阻設定參數
-            _state_str = "設定EC斜率截距";
-            EC_slop = 0.8 + _analog_convert(Rotary_Pin_1, 400) * 0.001;
-            EC_intercept = _analog_convert(Rotary_Pin_2, 1000) - 500;
-            _config_str = "EC斜率:" + (String)EC_slop + "\t EC截距：" + (String)EC_intercept;
-            _state_str_OLED = "Setting EC's config";
-            _state_OLDE_1 = "EC's slop: " + (String)EC_slop;
-            _state_OLDE_2 = "EC's intercept: " + (String)EC_intercept;
-          }
-        }
-        break;
-      case 3:
-        if (chapter) {          // 時間的設定
-          if (config_state) {   // 顯示目前時間
-            _state_str = "時間顯示";
-            _config_str = convert_2digits(_hour) + ":" + convert_2digits(_minute);
-            _state_str_OLED = "Time Now";
-            _state_OLDE_1 = "Hours Now: " + (String)_hour;
-            _state_OLDE_2 = "Minutes Now: " + (String)_minute;
-          }
-          else {                // 用可變電阻調整目前時間
-            _state_str = "時間設定(HH:MM)";
-            _HH = (int)_analog_convert(Rotary_Pin_1, 23);
-            _mm = (int)_analog_convert(Rotary_Pin_2, 59) + 1;
-            _config_str = convert_2digits(_HH) + ":" + convert_2digits(_mm);
-            _state_str_OLED = "SettingTime(HH:MM)";
-            _state_OLDE_1 = "Hours: " + (String)_HH;
-            _state_OLDE_2 = "Minutes: " + (String)_mm;
-          }
-        }
-        else {                  // 偵測警報設定
-          if (config_state) {
-            _state_str = "上下限顯示";
-            _config_str = "pH上下限:±" + (String)pH_alarm + "\t EC上限：" + (String)EC_alarm;
-            _state_str_OLED = "Show the limit";
-            _state_OLDE_1 = "pH's limit: " + (String)(7 - pH_alarm) + "-" + (String)(7 + pH_alarm);
-            _state_OLDE_2 = "EC's limit: " + (String)EC_alarm;
-          }
-          else {
-            _state_str = "上下限設定";
-            pH_alarm = _analog_convert(Rotary_Pin_1, 20) * 0.1;
-            EC_alarm = _analog_convert(Rotary_Pin_2, 1000);
-            _config_str = "pH上下限:7.00±" + (String)pH_alarm + "\t EC上限：" + (String)EC_alarm;
-            _state_str_OLED = "Setting limit";
-            _state_OLDE_1 = "pH's limit: " + (String)(7 - pH_alarm) + "-" + (String)(7 + pH_alarm);
-            _state_OLDE_2 = "EC's limit: " + (String)EC_alarm;
-          }
-        }
-        break;
-    }
-
-    if (printTime % print_interval <= print_interval * 0.05 ) {
-      SerialUSB.println("目前頁面:" + (String)chapter + "-" + (String)item);
-      SerialUSB.println("\t " + _state_str);
-      SerialUSB.println("\t 目前設定：" + _config_str);
-      SerialUSB.println("*******************************\n\r\n\r ");
-    }
-
-    OLED_header("  >> Water Box <<  ");
-    OLED_content((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day) + " " + convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
-    OLED_content(_state_str_OLED, 1);
-    OLED_state(_state_OLDE_1, _state_OLDE_2);
-    OLED_content(_firwareVersion, 1);
-    display.display();
-    display.clearDisplay();
-  } //end of 設定模式
+/*
+   usr 按鈕檢查
+   超過5秒返回 true : 儲存資料
+   否則返回false:     狀態 + 1
+*/
+int chapter = 0;                          //  大項目：0~1(校正設定,時間設定)
+int item = 0;                             //  子項目：0~3(準備,參數1設定,參數2設定,參數3設定)
+bool config_state = true;                 //  true時只能顯示目前設定，flase時可以改設定
+int _YY, _year_1, _year_2, _MM, _DD, _HH, _mm; //  時間日期調整用
+
+void loop() {
+  bool _switch_mode = digitalRead(switch_pin);
+
+  DateTime now = rtc.now();          // 取得目前時間
+  int _year = now.year();
+  int _month = now.month();
+  int _day = now.day();
+  String _days = daysOfTheWeek[now.dayOfTheWeek()];
+  int _hour = now.hour();
+  int _minute = now.minute();
+  bool _SD_save = now.unixtime() % SD_save_interval == 0;     //  5分鐘存檔一次
+  bool _upload = now.unixtime() % Upload_interval == 0;       // 20分鐘上傳一次
+  // Upload_interval
+
+  if (_switch_mode) // 分析模式
+  {
+    SerialUSB.println("分析模式");
+
+    float temperature = temp_value();
+    int EC = EC_value(temperature, EC_slop, EC_intercept);
+    float pH_mV = _pH_mV(pH_slop, pH_intercept);                             // 實際輸出電壓(mV)，校正用來校正電壓
+    float pH_Value = 3.5 * pH_mV * 0.001;                                   // 分壓(5V->2.5V)後，用電壓換算成pH (斜率3.5的出處待確認)
+    float DO, ORP;                                                        // 預留但不會用到
+
+    OLED_header("  >> Water Box <<  ");
+    OLED_content((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day), 1);
+    OLED_content("<< " + _days + " >>", 1);
+    OLED_content("T: " + (String)temperature, 2);
+    display.display();
+    display.clearDisplay();
+    delay(1000);
+
+    OLED_header("  >> Water Box <<  ");
+    OLED_content(convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
+    OLED_content("EC: " + (String)EC + " us", 2);
+    OLED_content("pH: " + (String)pH_Value, 2);
+    OLED_content("pH(mV): " + (String)pH_mV, 1);
+    display.display();
+    display.clearDisplay();
+    delay(500);
+
+    String _Msg = "";
+
+    if (_SD_save)  {
+      OLED_header("  >> Water Box <<  ");
+      OLED_content(convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
+      OLED_content("Save Data", 2);
+      display.display();
+      display.clearDisplay();
+      delay(500);
+      save2SD(_year, _month, _day, _hour, _minute, temperature, pH_Value, EC, pH_mV);
+      delay(500);
+    }
+    else delay(1000);
+
+    if (_upload) {                 // 上傳前先用JSON打包訊息
+      SerialUSB.print("上傳資料");
+
+      /*
+         int App_ID = 0x6;                       // App ID 給LASS後端辨識用
+        int Temperature_filed[2] = {1,7};         // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
+        int pH_filed[2] = {1,8};                 // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
+        int EC_filed[2] = {1,18};                // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
+        int DO_filed[2] = {0,7};                 // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
+        int ORP_filed[2] = {0,11};               // [0]:啟用狀態(1:yes; 0:no), [1]:資料長度(bits)
+        const int Filed_length_limit = 52;             // Filed length limit (在設定時檢查是否超過長度，16*4(sigfox) - 4(app id)- 8(FiledDefinition) =52)
+      */
+
+      long long _buffer[2] = {App_ID, 0};  // 打包資料用buffer  (第一個)
+      int _packets_size[2] = {12, 0};      // 封包大小初始值為12bits，後面再依測項增加長度
+
+      byte _DataFiled = 0b1;             // byte 為8 bits剛好可以塞_DataFiled
+      _DataFiled = _DataFiled << 1;
+      _DataFiled |= Temperature_filed[0];// add Temperature filed
+      _DataFiled = _DataFiled << 1;
+      _DataFiled |= pH_filed[0];        // add pH filed
+      _DataFiled = _DataFiled << 1;
+      _DataFiled |= EC_filed[0];        // add EC filed
+      _DataFiled = _DataFiled << 1;
+      _DataFiled |= DO_filed[0];        // add DO filed
+      _DataFiled = _DataFiled << 1;
+      _DataFiled |= ORP_filed[0];       // add ORP filed
+      _DataFiled = _DataFiled << 2;     // add last 2 reserved filed
+
+      SerialUSB.println("_DataFiled: " + (String)_DataFiled);   // 確認打包OK
+      SerialUSB.println(_DataFiled, BIN);
+
+      _buffer[0] = _buffer[0] << 8;
+      _buffer[0] |= _DataFiled;                // add Data Filed
+
+      SerialUSB.print("第1段封包");
+      _printOut1(_buffer[0], sizeof(_buffer[0]));  // 0000 0000 0000 0000 0000 0110 1111 0000
+      SerialUSB.print("第2段封包");
+      _printOut1(_buffer[1], sizeof(_buffer[1]));  // 0000 0000 0000 0000 0000 0000 0000 0000
+
+      if (Temperature_filed[0]) {
+        int _temperature_temp = int(temperature) + 200;                     // -20.0~80.0 修正成 0-100
+        _bale(_temperature_temp, Temperature_filed, _buffer, _packets_size);   // 打包資料
+      } else SerialUSB.println("無安裝溫度模組");
+      if (pH_filed[0]) {
+        int _pH_temp = int(pH_Value * 10);                                     // -20.0~80.0 修正成 0-100
+        _bale(_pH_temp, pH_filed, _buffer, _packets_size);                  // 打包資料
+      } else SerialUSB.println("無安裝pH模組");
+      if (EC_filed[0]) {
+        int _EC_temp = int(EC);                                          // -20.0~80.0 修正成 0-100
+        _bale(_EC_temp, EC_filed, _buffer, _packets_size);                  // 打包資料
+      } else SerialUSB.println("無安裝EC模組");
+      if (DO_filed[0]) {
+        int _DO_temp = int(DO * 10);                                      // 0.0~10.0 修正成 0-100
+        _bale(_DO_temp, DO_filed, _buffer, _packets_size);                   // 打包資料
+      } else SerialUSB.println("無安裝DO模組");
+      if (ORP_filed[0]) {
+        int _ORP_temp = int(ORP) + 1000;                                  // -20.0~80.0 修正成 0-100
+        _bale(_ORP_temp, ORP_filed, _buffer, _packets_size);                // 打包資料
+      } else SerialUSB.println("無安裝ORP模組");
+
+      SerialUSB.println("封包空間已使用量:" + (String)_packets_size[0] + "-" + (String)_packets_size[1]);
+       _buffer[0] = _buffer[0] << ( 32 - _packets_size[0] );                 // 把資料往左補滿，空格再右
+      _buffer[1] = _buffer[1] << ( 32 - _packets_size[1] );                 // 把資料往左補滿，空格再右
+
+      SerialUSB.print("第1段封包(" + (String)(32 - _packets_size[0]) + ")\t");
+      _printOut1(_buffer[0], sizeof(_buffer[0]));                           // 0000 0000 0000 0011 0111 1000 1110 1000
+      SerialUSB.print("第2段封包(" + (String)(32 - _packets_size[1]) + ")\t");
+      _printOut1(_buffer[1], sizeof(_buffer[1]));                           // 0000 0000 0000 0000 0000 0000 0000 0000
+
+      String _str_balle = _bale2Hex(_buffer);
+      SerialUSB.println("上傳資料(HEX): " + _str_balle);
+      send_to_sigfox(_str_balle);
+    }
+    SerialUSB.println((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day) + "\t<<" + _days + ">>");
+    SerialUSB.println(convert_2digits(_hour) + ":" + convert_2digits(_minute) + ":" + convert_2digits(now.second()));
+    SerialUSB.println("存SD卡:" + (String)_SD_save + "\t上傳:" + (String)_upload);
+    SerialUSB.print("pH: ");
+    SerialUSB.print(pH_Value);
+    SerialUSB.print("(");
+    SerialUSB.print(pH_mV);
+    SerialUSB.print(")");
+    SerialUSB.print("\tEC: ");
+    SerialUSB.print(EC);
+    SerialUSB.print("\t溫度: ");
+    SerialUSB.print(temperature);
+    SerialUSB.println("\n\r");
+
+  } // end of if (_switch_mode)
+  else {  // 設定模式
+    unsigned long printTime = millis();                            // Serial印出時間計時器
+    float _time = pull_time(USR_pin, 3);                           // 設定按鈕計時器
+    String _state_str, _config_str;                                // Serial輸出用
+    String _state_OLDE_1, _state_OLDE_2, _state_str_OLED;          // OLED 顯示用
+
+    if (printTime % print_interval <= print_interval * 0.05) {
+      SerialUSB.println("設定模式");
+    }
+
+    if (_time > 0 && _time < 1) {       // 切換子項目
+      if (item == 3) item = 0;          // 到最後一項時跳回第一項
+      else item += 1;                   // 跳到下一項
+    }
+    else if (_time > 1 && _time < 2) {  // 切換大項目
+      if (chapter == 1) chapter = 0;    // 到最後一項時跳回第一項
+      else chapter += 1;                // 跳到下一項
+    }
+    else if (_time >= 3) {              // 切換設定顯示/調整
+      if (config_state) config_state = false;                          // 切換到設定調整狀態
+      else  {                                                          // 切回設定顯示狀態
+        config_state = true;
+        _config(false);                                                // 儲存目前的設定
+        if (_YY != 0 && _MM != 0 && _DD != 0 && _HH != 0 && _mm != 0)  rtc.adjust(DateTime(_YY, _MM, _DD, _HH, _mm, 0)); // 設定時間
+      }
+    }
+    if (printTime % print_interval <= print_interval * 0.05) {
+      if (config_state) {
+        SerialUSB.println("顯示目前設定");
+      }
+      else {
+        SerialUSB.println("調整設定");
+      }
+    }
+    // 顯示目前的項目
+    switch (item) {
+      case 0:
+        if (chapter) {
+          _state_str = "時間設定頁面";
+          _state_str_OLED = "Setting Time";
+        }
+        else {
+          _state_str = "參數設定頁面";
+          _state_str_OLED = "Setting Parameters";
+        }
+        break;
+      case 1:
+        if (chapter) {          // 年份的設定
+          if (config_state) {   // 顯示年分
+            _state_str = "系統年分";
+            _config_str = (String) _year;
+            _state_str_OLED = "This Year";
+            _state_OLDE_1 = (String)_year;
+          }
+          else {                // 用可變電阻調整目前年分
+            _state_str = "設定年分";
+            int _year_1 = (int)_analog_convert(Rotary_Pin_1, 9);
+            int _year_2 = (int)_analog_convert(Rotary_Pin_2, 9);
+            _YY = 2000 + _year_1 * 10 + _year_2;
+            _config_str = (String) _YY;
+            _state_str_OLED = "Setting Year";
+            _state_OLDE_1 = (String)_YY;
+          }
+        }
+        else {                  // pH斜率截距的設定
+          if (config_state) {   // 顯示目前設定
+            _state_str = "pH 目前的斜率截距";
+            _config_str = "pH slope:" + (String)pH_slop + "\t pH intercept：" + (String)pH_intercept;
+            _state_str_OLED = "pH's config";
+            _state_OLDE_1 = "pH's slop: " + (String)pH_slop;
+            _state_OLDE_2 = "pH's intercept: " + (String)pH_intercept;
+          }
+          else {                // 用可變電阻設定參數
+            _state_str = "設定pH斜率截距";
+            pH_slop = 0.8 + _analog_convert(Rotary_Pin_1, 400) * 0.001;
+            pH_intercept = -0.5 + _analog_convert(Rotary_Pin_2, 100) * 0.01;
+            _config_str = "pH slope:" + (String)pH_slop + "\t pH intercept：" + (String)pH_intercept;
+            _state_str_OLED = "Setting pH's config";
+            _state_OLDE_1 = "pH's slop: " + (String)pH_slop;
+            _state_OLDE_2 = "pH's intercept: " + (String)pH_intercept;
+          }
+        }
+        break;
+      case 2:
+        if (chapter) {          // 日期的設定
+          if (config_state) {   // 顯示目前日期
+            _state_str = "日期顯示";
+            _config_str = convert_2digits(_month) + "/" + convert_2digits(_day);
+            _state_str_OLED = "Date Now";
+            _state_OLDE_1 = "Month: " + convert_2digits(_month);
+            _state_OLDE_2 = "Day: " + convert_2digits(_day);
+          }
+          else {                // 用可變電阻調整日期
+            _state_str = "日期設定(MM/DD)";
+            _MM = (int)_analog_convert(Rotary_Pin_1, 11) + 1;
+            _DD = (int)_analog_convert(Rotary_Pin_2, 30) + 1;
+            _config_str = convert_2digits(_MM) + "/" + convert_2digits(_DD);
+            _state_str_OLED = "Setting Date";
+            _state_OLDE_1 = "Month: " + convert_2digits(_MM);
+            _state_OLDE_2 = "Day: " + convert_2digits(_DD);
+          }
+        }
+        else {                  // EC斜率截距的設定
+          if (config_state) {   // 顯示目前設定
+            _state_str = "EC目前的斜率截距";
+            _config_str = "EC斜率:" + (String)EC_slop + "\t EC截距：" + (String)EC_intercept;
+            _state_str_OLED = "EC's config";
+            _state_OLDE_1 = "EC's slop: " + (String)EC_slop;
+            _state_OLDE_2 = "EC's intercept: " + (String)EC_intercept;
+          }
+          else {                // 用可變電阻設定參數
+            _state_str = "設定EC斜率截距";
+            EC_slop = 0.8 + _analog_convert(Rotary_Pin_1, 400) * 0.001;
+            EC_intercept = _analog_convert(Rotary_Pin_2, 1000) - 500;
+            _config_str = "EC斜率:" + (String)EC_slop + "\t EC截距：" + (String)EC_intercept;
+            _state_str_OLED = "Setting EC's config";
+            _state_OLDE_1 = "EC's slop: " + (String)EC_slop;
+            _state_OLDE_2 = "EC's intercept: " + (String)EC_intercept;
+          }
+        }
+        break;
+      case 3:
+        if (chapter) {          // 時間的設定
+          if (config_state) {   // 顯示目前時間
+            _state_str = "時間顯示";
+            _config_str = convert_2digits(_hour) + ":" + convert_2digits(_minute);
+            _state_str_OLED = "Time Now";
+            _state_OLDE_1 = "Hours Now: " + (String)_hour;
+            _state_OLDE_2 = "Minutes Now: " + (String)_minute;
+          }
+          else {                // 用可變電阻調整目前時間
+            _state_str = "時間設定(HH:MM)";
+            _HH = (int)_analog_convert(Rotary_Pin_1, 23);
+            _mm = (int)_analog_convert(Rotary_Pin_2, 59) + 1;
+            _config_str = convert_2digits(_HH) + ":" + convert_2digits(_mm);
+            _state_str_OLED = "SettingTime(HH:MM)";
+            _state_OLDE_1 = "Hours: " + (String)_HH;
+            _state_OLDE_2 = "Minutes: " + (String)_mm;
+          }
+        }
+        else {                  // 偵測警報設定
+          if (config_state) {
+            _state_str = "上下限顯示";
+            _config_str = "pH上下限:±" + (String)pH_alarm + "\t EC上限：" + (String)EC_alarm;
+            _state_str_OLED = "Show the limit";
+            _state_OLDE_1 = "pH's limit: " + (String)(7 - pH_alarm) + "-" + (String)(7 + pH_alarm);
+            _state_OLDE_2 = "EC's limit: " + (String)EC_alarm;
+          }
+          else {
+            _state_str = "上下限設定";
+            pH_alarm = _analog_convert(Rotary_Pin_1, 20) * 0.1;
+            EC_alarm = _analog_convert(Rotary_Pin_2, 1000);
+            _config_str = "pH上下限:7.00±" + (String)pH_alarm + "\t EC上限：" + (String)EC_alarm;
+            _state_str_OLED = "Setting limit";
+            _state_OLDE_1 = "pH's limit: " + (String)(7 - pH_alarm) + "-" + (String)(7 + pH_alarm);
+            _state_OLDE_2 = "EC's limit: " + (String)EC_alarm;
+          }
+        }
+        break;
+    }
+
+    if (printTime % print_interval <= print_interval * 0.05 ) {
+      SerialUSB.println("目前頁面:" + (String)chapter + "-" + (String)item);
+      SerialUSB.println("\t " + _state_str);
+      SerialUSB.println("\t 目前設定：" + _config_str);
+      SerialUSB.println("*******************************\n\r\n\r ");
+    }
+
+    OLED_header("  >> Water Box <<  ");
+    OLED_content((String)_year + "/" + convert_2digits(_month) + "/" + convert_2digits(_day) + " " + convert_2digits(_hour) + ":" + convert_2digits(_minute), 1);
+    OLED_content(_state_str_OLED, 1);
+    OLED_state(_state_OLDE_1, _state_OLDE_2);
+    OLED_content(_firwareVersion, 1);
+    display.display();
+    display.clearDisplay();
+  } //end of 設定模式
 }


move the servo gradually

move the servo gradually

--- servometer/servometer.ino
+++ servometer/servometer.ino
@@ -60,6 +60,7 @@
 String display2Value = SURE_STRING;
 String currentHealth = "";
 int servoAngle = SERVO_MAX;
+int currentServoAngle = SERVO_MAX;
 int noDataCount = 0;

 /*
@@ -99,6 +100,7 @@
     display2Value = formatValueForSegmentDisplay(getValueFromResponse(receivedData, ':', 1));
     currentHealth = getValueFromResponse(receivedData, ':', 2);
     servoAngle = findServoAngle(display1Value);
+    Serial.println("new servo angle: " + servoAngle);
     noDataCount = 0;
   }
   else
@@ -134,10 +136,23 @@
   // update matrix for health display
   updateHealthMatrix(currentHealth);

-  // write servo angle for meter
-  servo.write(servoAngle);
+  // move servo angle for meter
+  moveServo();

   delay(500);
+}
+
+void moveServo() {
+  if(servoAngle == currentServoAngle) {
+    return;
+  }
+  else {
+    while(currentServoAngle != servoAngle) {
+      currentServoAngle += (servoAngle > currentServoAngle ? 1 : -1);
+      servo.write(currentServoAngle);
+      delay(50);
+    }
+  }
 }

 void updateHealthMatrix(String health)


Serial input works, and so does one-dimentional G-Code-like parsing

--- miscr.ino
+++ miscr.ino
@@ -83,7 +83,7 @@
   bool update;
   Command command;
   int incr;
-
+
   Stepper(int stepPinIn, int dirPinIn, int enablePinIn,
           int minPinIn, int maxPinIn) {
     stepPin = stepPinIn;
@@ -129,53 +129,79 @@
 /* bool yswitch() {} */
 /* bool zswitch() {} */

+int getIndex(char code, String in) {
+  int codeIndex = in.indexOf(code);
+  int spaceIndex = in.indexOf(" ");
+  bool toEnd = false;
+
+  if(spaceIndex == -1) {
+    toEnd = true;
+    Serial.println("toEnd is true!");
+  }
+
+  if(codeIndex == -1) {
+    Serial.println("nope not found");
+    Serial.println("code = " + code);
+    return -1;
+  }
+
+  if(!toEnd) {
+    String toconvert = in.substring(codeIndex + 1, spaceIndex - 1);
+    Serial.println("convert :: " + toconvert);
+    return toconvert.toInt();
+  } else {
+    String toconvert = in.substring(codeIndex + 1);
+    Serial.println("convert :: " + toconvert);
+    return toconvert.toInt();
+  }
+
+  return -2;
+}
+
+int strtoint(String in) {return in.toInt();}
+
 /*
  * This function does not yet have any GCode parsing functionality,
  * it is currently only used for testing...
+ *
+ * Thanks to the blog post at:
+ * https://www.marginallyclever.com/2013/08/how-to-build-an-2-axis-arduino-cnc-gcode-interpreter/
+ * for helping me writing this function!
  */
 bool parseGCode(String in) {
-  if(in == "stopall") {
-    Serial.println("TODO Implement");
-    return true;
-  } else if(in == "startall") {
-    sX.testSpin(true, 360);
-    return true;
-  } else if(in == "?") {
-    Serial.println("TODO Display info...");
-    return true;
-  }
-  return false;
-}
-
+  int index = getIndex('X', in);
+  if(index != -1) {
+    sX.testSpin(true, index);
+  } else
+    return false;
+}
+
+String serialStr = "";

 /*
  * Gets user serial input to be put into the parseGCode() function.
  */
 void getSerialInput() {
-  String out = "";
-  char c;
-
-  while(Serial.available()) {
-      c = Serial.read();
-      out.concat(c);
-  }
-
-  if(out != "") {
-    if(!parseGCode(out)) {
-      Serial.println("Invalid GCode entered!");
+  if(Serial.available() > 0) {
+    serialStr = Serial.readString();
+    serialStr.trim();
+    if(Serial.read() == -1) {
+      Serial.println(serialStr);
+      if(!parseGCode(serialStr))
+        Serial.println("Invalid GCode entered!");
     }
   }
 }

 void setup() {
   // Begin serial connection
-  Serial.begin(9600);
+  Serial.begin(115200);

   // Print welcome message
-  Serial.println("miscr v0.1 [enter \"?\" for commands and \"$\" for status]\n\n");
+  Serial.println("miscr v0.1 [enter \"?\" for commands and \"$\" for status]\n");

   sX.begin();
-  sY.begin();
+  //sY.begin();
 }

 void loop() {
@@ -197,4 +223,4 @@
   }

   // TODO other motors
-}+}


Final Arduino Scetch

Final Arduino Scetch

Full Input controller
Full UART transiver
LCD addition

--- arduino/input_controller.ino
+++ arduino/input_controller.ino
@@ -0,0 +1,265 @@
+/*
+Materials are took from "Exploring Arduino"
+*/
+
+//LCD text with incrementing number
+//Include the library code:
+
+#include <LiquidCrystal.h>
+#include <math.h>
+
+//Initialize the library with the numbers of the interface pins
+LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
+
+
+//Number of Light Sensors on analog pins
+const uint8_t l_EntranceToOffice = 0; //  Entrance to office
+const uint8_t l_EntranceToBedroom = 1; //  Entrance to bedroom
+const uint8_t l_ExitFromOffice = 2; //  Exit from office
+const uint8_t l_ExitFromBedroom = 3; //  Exit from bedroom
+//  Предназначения этих аналоговых входов пока что не определены
+const uint8_t LIGHT4 = 4;
+const uint8_t LIGHT5 = 5;
+
+
+//  variables to hold current analog reading
+uint8_t v_ToOffice = 0;
+uint8_t v_ToBedroom = 0;
+uint8_t v_FromOffice = 0;
+uint8_t v_FromBedroom = 0;
+uint8_t value4 = 0;
+uint8_t value5 = 0;
+//  variables to hold last analog reading
+uint8_t v_old_ToOffice = 0;
+uint8_t v_old_ToBedroom = 0;
+uint8_t v_old_FromOffice = 0;
+uint8_t v_old_FromBedroom = 0;
+uint8_t old_value4 = 0;
+uint8_t old_value5 = 0;
+
+//  Is sending flag - blocks repeating sending,
+//  when data is already sent and analog value is still < THRESHOLD
+boolean isSending0 = false;
+boolean isSending1 = false;
+boolean isSending2 = false;
+boolean isSending3 = false;
+boolean isSending4 = false;
+boolean isSending5 = false;
+
+typedef unsigned short int USHORT;
+const uint8_t DIFFERENCE = 30;
+const uint8_t THRESHOLD = 500;
+
+//  Buffer for displaying data on lcd screen
+char buf[4];
+
+/*--------------------------------------------------------------------*/
+
+// Variables for buttons
+
+
+//  Buttons ports
+const uint8_t button[6] = {
+  8, 9, 10, 11, 12, 13
+};
+
+//  Current button states
+boolean current_state[6] = {
+  LOW, LOW, LOW, LOW, LOW, LOW
+};
+
+//  Last button states
+boolean last_state[6] = {
+  LOW, LOW, LOW, LOW, LOW, LOW
+};
+
+//  Strings to send
+char buttonString[][6] = {
+  "B1",
+  "B2",
+  "B3",
+  "B4",
+  "B5",
+  "B6"
+};
+
+
+/*--------------------------------------------------------------------------*/
+
+//  Function that defines how many '0' print before integer in 4-digit representation
+char & GetBufByValue(const int & _val)
+{
+  if (_val < 1000 && _val > 99) {
+    sprintf(buf, "0%d", _val);
+  } else if (_val < 100 && _val > 9){
+    sprintf(buf, "00%d", _val);
+  } else if (_val < 10) {
+    sprintf(buf, "000%d", _val);
+  }
+  return *buf;
+}
+
+//  Function to display raw analog 8-bit input data
+//  by position for 4-digit places
+void PrintByIndex(int _place, int _value) {
+  lcd.setCursor(_place * 5 % 15, (_place) / 3);
+  *buf = GetBufByValue(_value);
+  lcd.print(buf);
+}
+
+//  Overloaded function to display 4-character string by position
+void PrintByIndex(int _place, const char * _value) {
+  lcd.setCursor(_place * 5 % 15, (_place) / 3);
+  lcd.print(_value);
+}
+
+
+///////////////////////////////////////////////////////////
+
+
+void setup()
+{
+  Serial.begin(9600);
+  for (USHORT i = 0; i < 6; ++i) {
+    pinMode(button[i], INPUT);
+  }
+  //Set up the LCD's number of columns and rows:
+  lcd.begin(16, 2);
+
+  //  Set lcd to default values
+  lcd.setCursor(0,0);
+  lcd.print("---- ---- ----  ");
+  lcd.setCursor(0,1);
+  lcd.print("---- ---- ----  ");
+
+
+}
+
+boolean debounce(boolean _current, boolean _last, uint8_t _port) {
+  boolean current = digitalRead(_port); //Read the button state
+  if (_last != _current) {
+    delay(5); //wait 5ms
+    _current = digitalRead(_port); //read it again
+  }
+  return current; //return the current value
+}
+
+void loop()
+{
+  //  Опрос кнопок с использованием антидребезговой системы
+  for (USHORT i = 0; i < 6; ++i) {
+    current_state[i] = debounce(current_state[i], last_state[i], button[i]);
+    if (last_state[i] == LOW && current_state[i] == HIGH)
+      Serial.print(buttonString[i]);
+  }
+
+  /*---------------------------------------------------------------------------------------*/
+  // Реализация опроса фотосенсоров
+
+  v_ToOffice = analogRead(l_EntranceToOffice);
+  v_ToBedroom = analogRead(l_EntranceToBedroom);
+  v_FromOffice = analogRead(l_ExitFromOffice);
+  v_FromBedroom = analogRead(l_ExitFromBedroom);
+  value4 = analogRead(LIGHT4);
+  value5 = analogRead(LIGHT5);
+
+  //  Обработка полученных данных с фотосенсоров
+  if (abs(v_ToOffice - v_old_ToOffice) > DIFFERENCE) {
+    if (v_ToOffice < THRESHOLD) {
+      if (!isSending0) {
+        //  Sending string "S0_1" to Raspberry via UART
+        //  "S0_1" means that sensor behind the office detected movement (1 like "On")
+        Serial.print("S0_1");
+        //  Set sending flag to true to omit repeating sendings of the same string
+        isSending0 = true;
+        //  Print sending value on the lcd screen
+        PrintByIndex(0, "S0_1");
+      }
+    } else {
+      //  If value of analog is more than THRESHOLD
+      //  and detected state was sent - then send "S0_0" once.
+      if (isSending0) {
+        Serial.print("S0_0");
+        PrintByIndex(0, "S0_0");
+        isSending0 = false;
+      }
+    }
+  }
+  if (abs(v_ToBedroom - v_old_ToBedroom) > DIFFERENCE) {
+    if (v_ToBedroom < THRESHOLD) {
+      if (!isSending1) {
+        Serial.print("S1_1");
+        isSending1 = true;
+        //  Print '1' on the lcd display in place 1 if detection is seen
+        PrintByIndex(1, "S1_1");
+      }
+    } else {
+      if (isSending1) {
+        Serial.print("S1_0");
+        PrintByIndex(1, "S1_0");
+        isSending1 = false;
+      }
+    }
+  }
+  if (abs(v_FromOffice - v_old_FromOffice) > DIFFERENCE) {
+    if (v_FromOffice < THRESHOLD) {
+      if (!isSending2) {
+        Serial.print("S2_1");
+        isSending2 = true;
+        PrintByIndex(2, "S2_1");
+      }
+
+    } else {
+      Serial.print("S2_0");
+      PrintByIndex(2, "S2_0");
+      isSending2 = false;
+    }
+  }
+  if (abs(v_FromBedroom - v_old_FromBedroom) > DIFFERENCE) {
+    if (v_FromBedroom < THRESHOLD) {
+      if (!isSending3) {
+        Serial.print("S3_1");
+        isSending3 = true;
+        PrintByIndex(3, "S3_1");
+      }
+    } else {
+      Serial.print("S3_0");
+      PrintByIndex(3, "S3_0");
+      isSending3 = false;
+    }
+  }
+  if (abs(value4 - old_value4) > DIFFERENCE) {
+    if (value4 < THRESHOLD) {
+      if (!isSending3) {
+        Serial.print("S4_1");
+        isSending4 = true;
+        PrintByIndex(4, "S4_1");
+      }
+    } else {
+      Serial.print("S4_0");
+      PrintByIndex(4, "S4_0");
+      isSending4 = false;
+    }
+  }
+  if (abs(value5 - old_value5) > DIFFERENCE) {
+    if (value5 < THRESHOLD) {
+      Serial.print("S5_1");
+       isSending5 = true;
+       PrintByIndex(5, "S5_1");
+    } else {
+      Serial.print("S5_0");
+      PrintByIndex(5, "S5_0");
+      isSending5 = false;
+    }
+  }
+
+  v_ToOffice = v_old_ToOffice;
+  v_old_ToBedroom = v_ToBedroom;
+  v_old_FromOffice = v_FromOffice;
+  v_old_FromBedroom = v_FromBedroom;
+  old_value4 = value4;
+  old_value5 = value5;
+
+  //  Ask sensors every 100 miliseconds
+  delay(100);
+}


fixing merge bullshit

fixing merge bullshit

--- animus/animus_main.ino
+++ animus/animus_main.ino
@@ -15,10 +15,7 @@
 // key states
 int KeyState[COL][ROW];
 int PreviousState[COL][ROW];
-<<<<<<< HEAD
 int LayerState[COL][ROW];
-=======
->>>>>>> refs/remotes/origin/master

 // slave states
 boolean IS_MASTER = true;
@@ -61,19 +58,12 @@
         {
           if (KeyState[j][i] == HIGH)
           {
-<<<<<<< HEAD
             LayerState[j][i] = TempLayer;
-=======
->>>>>>> refs/remotes/origin/master
             PressKey(GetValEEPROM(j, i, TempLayer), GetTypeEEPROM(j, i, TempLayer));
           }
           else
           {
-<<<<<<< HEAD
             ReleaseKey(GetValEEPROM(j, i, LayerState[j][i]), GetTypeEEPROM(j, i, LayerState[j][i]));
-=======
-            ReleaseKey(GetValEEPROM(j, i, TempLayer), GetTypeEEPROM(j, i, TempLayer));
->>>>>>> refs/remotes/origin/master
           }
         }

@@ -103,21 +93,13 @@
     else if (type == 1)
     {
       TempLayer = val;
-<<<<<<< HEAD
       //ReleaseAllKey();
-=======
-      ReleaseAllKey();
->>>>>>> refs/remotes/origin/master
     }
     else if (type == 2) // DEPRECIATED
     {
       PressedKey = false;
       TempLayer = val;
-<<<<<<< HEAD
       //ReleaseAllKey();  // DEPRECIATED END
-=======
-      ReleaseAllKey();  // DEPRECIATED END
->>>>>>> refs/remotes/origin/master
     }
     else if (type == 3)
     {
@@ -145,11 +127,7 @@
       {
         TempLayer = val;
       }
-<<<<<<< HEAD
       //ReleaseAllKey();
-=======
-      ReleaseAllKey();
->>>>>>> refs/remotes/origin/master
     }
     else if (type == 11)
     {
@@ -221,11 +199,7 @@
     else if (type == 1)
     {
       TempLayer = KeyLayer;
-<<<<<<< HEAD
       //ReleaseAllKey();
-=======
-      ReleaseAllKey();
->>>>>>> refs/remotes/origin/master
     }
     else if (type == 2) //DEPRECIATED
     {
@@ -234,11 +208,7 @@
         Keyboard.write(44);
       }
       TempLayer = KeyLayer;
-<<<<<<< HEAD
       //ReleaseAllKey(); // DEPRECIATED END
-=======
-      ReleaseAllKey(); // DEPRECIATED END
->>>>>>> refs/remotes/origin/master
     }
     else if (type == 11)
     {
@@ -347,11 +317,7 @@
   {
     KeyLayer = Lay - 1;
   }
-<<<<<<< HEAD
   //ReleaseAllKey();
-=======
-  ReleaseAllKey();
->>>>>>> refs/remotes/origin/master
 }

@@ -396,11 +362,7 @@
   }

   KeyLayer = newLayer;
-<<<<<<< HEAD
   //ReleaseAllKey();
-=======
-  ReleaseAllKey();
->>>>>>> refs/remotes/origin/master
 }


added broadcast logic

added broadcast logic


Fixed api.setup call

Fixed api.setup call

--- examples/Led/Led.ino
+++ examples/Led/Led.ino
@@ -111,7 +111,7 @@
 void IotsaLedControlMod::serverSetup() {
   // Setup the web server hooks for this module.
   server.on("/led", std::bind(&IotsaLedControlMod::handler, this));
-  apiSetup("/api/led", true, true);
+  api.setup("/api/led", true, true);
 }

 String IotsaLedControlMod::info() {


Select color once instead of once per LED

--- arduino/blinkytape_orb.ino
+++ arduino/blinkytape_orb.ino
@@ -84,12 +84,14 @@
   }

   for (uint8_t v = val; v != next_val; v += incr) {
+    CRGB color;
+    if (current.color == COLOR_WHITE) {
+      color = CRGB(v, v, v);
+    } else {
+      color = CHSV(colors[current.color], 255, v);
+    }
     for (uint8_t i = 0; i < NUM_LEDS; i++) {
-      if (current.color == COLOR_WHITE) {
-        leds[i] = CRGB(v, v, v);
-      } else {
-        leds[i] = CHSV(colors[current.color], 255, v);
-      }
+      leds[i] = color;
     }
     FastLED.show();


i2c communication working

i2c communication working

--- trivia_box/trivia_box.ino
+++ trivia_box/trivia_box.ino
@@ -1,4 +1,5 @@
 #include <arduino.h>
+#include <stdarg.h>
 #include <Wire.h>

 #define SLAVE_ADDRESS 0x04
@@ -13,6 +14,23 @@

 int winning_team = -1;
 int winning_player = -1;
+
+// IMPORTANT!
+// DO NOT CALL Serial.print() withing these callbacks!
+// They are interrupt driven and will give you a bad day.
+void receive_data(int byte_count) {
+    while(Wire.available()) {
+      int number = Wire.read();
+    }
+}
+
+void send_data() {
+      byte x[2];
+      x[0] = winning_team;
+      x[1] = winning_player;
+      Wire.write(x, 2);
+}
+

 void setup() {
   Serial.begin(115200);
@@ -35,19 +53,6 @@
   Wire.onReceive(receive_data);
   Wire.onRequest(send_data);

-}
-
-void receive_data(int byte_count) {
-    while(Wire.available()) {
-      number = Wire.read();
-      Serial.print("data received: ");
-      Serial.println(number);
-    }
-}
-
-void send_data() {
-  Wire.write(winning_team);
-  Wire.write(winning_player);
 }

 void loop() {


Support for the new @AUTO# Serial API command.

--- DiveIno.ino
+++ DiveIno.ino
@@ -449,6 +449,19 @@
 		outputStream->println("@");
 		settings.printSettings(outputStream);
 		outputStream->println("#");
+	} else if (message.startsWith(F("AUTO")) || message.startsWith(F("auto"))) {
+		sensor.readSensor();
+		float pressureInMillibar = sensor.pressure();
+		if (980 <= pressureInMillibar && pressureInMillibar <= 1100) {
+			seaLevelPressureSetting = pressureInMillibar;
+			responseMessage += F("AUTO - ");
+			responseMessage += seaLevelPressureSetting;
+			responseMessage += F("#");
+			saveSettings();
+		} else {
+			responseMessage += F("ERROR: Invalid argument - Must be between 980 and 1100 millibar!#");
+		}
+		outputStream->println(responseMessage);
 	} else if (message.startsWith(F("SOUND")) || message.startsWith(F("sound"))) {
 		String state = message.substring(5);
 		state.trim();
@@ -475,14 +488,14 @@
 		outputStream->println(responseMessage);
 	} else if (message.startsWith(F("PRESSURE")) || message.startsWith(F("pressure"))) {
 		float seaLevelPressure = message.substring(8).toFloat();
-		if (seaLevelPressure > 900 && seaLevelPressure < 1200) {
+		if (980 <= seaLevelPressure && seaLevelPressure <= 1100) {
 			seaLevelPressureSetting = seaLevelPressure;
 			responseMessage += F("PRESSURE - ");
 			responseMessage += seaLevelPressureSetting;
 			responseMessage += F("#");
 			saveSettings();
 		} else {
-			responseMessage += F("ERROR: Invalid argument - Must be between 900 and 1200 millibar!#");
+			responseMessage += F("ERROR: Invalid argument - Must be between 980 and 1100 millibar!#");
 		}
 		outputStream->println(responseMessage);
 	} else if (message.startsWith(F("OXYGEN")) || message.startsWith(F("oxygen"))) {
@@ -494,7 +507,7 @@
 			responseMessage += F("#");
 			saveSettings();
 		} else {
-			responseMessage += F("ERROR: Invalid argument - Must be between 0.16 and 0.50!#");
+			responseMessage += F("ERROR: Invalid argument - Must be between 0.21 and 0.40!#");
 		}
 		outputStream->println(responseMessage);
 	} else if (message.startsWith(F("DEFAULT")) || message.startsWith(F("default"))) {