Various updates

Various updates

Added license header, updated documentation. Also, added a new feature
that prevents multiple hits when holding down a laser. Previously, it
would play the sound over and over, which is OK for a wind instrument,
but horrible for string and piano instruments.

This commit adds a variable and related code to keep track of the last
hit laser, which causes it to play the sound once, even if the laser is
held down.

Also added are some #ifndefs that disable the new code when #define WIND
is uncommented. This reverts this program back to the old behavior.

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -1,12 +1,21 @@
 /* Code for laser guzheng
  * Copyright (C) 2016 Jason Lu
  *
+ * Licensed under the MIT License
  */
+
+/* Uncomment the define if you are using a wind instrument, such
+ * as a trumpet or flute. It will disable several things that
+ * are specific to string and percussion instruments. DO NOT
+ * uncomment it if you are using a piano or string instrument! */
+// #define WIND

-// Some defines
+// Port I/O defines
 #define THRESHOLD 500
+#define LASTPORT 4
+
+// MIDI property defines
 #define VOLUME 0x7F
-#define LASTPORT 4
 #define DELAY 10

 // MIDI command defines
@@ -14,7 +23,10 @@
 #define NOTEOFF 0x80
 #define CHANGEINSTRUMENT 0xC0

+#define INSTRUMENT 0x39
+
 // Values for different notes
+// Currently a C scale, starting from middle C (C4)
 int note8 = 0x48;
 int note7 = 0x47;
 int note6 = 0x45;
@@ -24,7 +36,17 @@
 int note2 = 0x3E;
 int note1 = 0x3C;

+// Variable to keep track of which set of notes (lower or upper 4)
+// Needed to work around limited lasers
 int noteSet = 1;
+/* Variable to keep track of the last played instrument. Used to
+ * prevent continuous striking sounds on string and piano instruments
+ * . Set to -1 when all strings have not been blocked, and 314 when
+ * the noteSet laser is pressed. Otherwise, it is set to the last
+ * playing laser, which will cause the Arduino to ignore the laser
+ * until it is released again, thus preventing multiple hits */
+// TODO: Switch to a bit flag, and support multiple strings
+int lastNote = -1;

 void setup()
 {
@@ -36,7 +58,7 @@
   // 0xC0 is the change instrument command
   // 0x39 is the instrument ID in hex
   Serial.write(CHANGEINSTRUMENT);
-  Serial.write(0x68);
+  Serial.write(INSTRUMENT);
 }

 // Function for playing note based on ID
@@ -116,18 +138,35 @@
   // 5 ports, from 0 to 4
   for (int i = 0; i <= LASTPORT; i++) {
     if(analogRead(i) > THRESHOLD) {
-      // Beam has been cut
-      // i+1 is because i is 0 indexed, but the ID starts with 1
-      if (i < 4) {
-        musicOn(i + 1);
-      } else {
-        if (noteSet == 1) {
-          noteSet = 2;
+#ifndef WIND
+      if (lastNote != i || lastNote != 314) {
+#endif
+        // Beam has been cut
+        // i+1 is because i is 0 indexed, but the ID starts with 1
+        if (i < 4) {
+          musicOn(i + 1);
+#ifndef WIND
+          lastNote = i;
+#endif
         } else {
-          noteSet = 1;
+          if (noteSet == 1) {
+            noteSet = 2;
+          } else {
+            noteSet = 1;
+          }
+#ifndef WIND
+          lastNote = 314;
+#endif
         }
+#ifndef WIND
       }
+#endif
     } else {
+#ifndef WIND
+      if (lastNote == i) {
+        lastNote = -1;
+      }
+#endif
       // Hand is gone. Stop the sound
       musicOff(i + 1);
     }


Made ShellCommands example more physical

--- hardware/arduino/avr/libraries/Bridge/examples/ShellCommands/ShellCommands.ino
+++ hardware/arduino/avr/libraries/Bridge/examples/ShellCommands/ShellCommands.ino
@@ -3,18 +3,21 @@
  Running shell coommands using Process class.

  This sketch demonstrate how to run linux shell commands
- using an Arduino Yún.
-
+ using an Arduino Yún. It runs the wifiCheck script on the linino side
+ of the Yun, then uses grep to get just the signal strength line.
+ Then it uses parseInt() to read the wifi signal strength as an integer,
+ and finally uses that number to fade an LED using analogWrite().
+
  The circuit:
- * Arduino Yun
+ * Arduino Yun with LED connected to pin 9

  created 12 Jun 2013
  by Cristian Maglie
- modified 21 June 2013
+ modified 25 June 2013
  by Tom Igoe

  This example code is in the public domain.
-
+
  */

 #include <Process.h>
@@ -27,15 +30,23 @@

 void loop() {
   Process p;
-  // This command line prints the name of the wireless network
-  // that the board is connected to, or the network which the board has created:
-  p.runShellCommand(F("lua /usr/lib/lua/pretty_wifi_info.lua | grep SSID"));
+  // This command line runs the wifiCheck script, (lua /arduino/pretty...), then
+  // sends the result to the grep command to look for a line containing the word
+  // "Signal:"  the result is passed to this sketch:
+  p.runShellCommand("lua /arduino/pretty_wifi_info.lua | grep Signal");

-  // Read command output
+  // do nothing until the process finishes, so you get the whole output:
+  while(p.running());
+
+  // Read command output. runShellCommand() should have passed "Signal: xx&":
   while (p.available()) {
-    char c = p.read();
-    Serial.print(c);
+    int result = p.parseInt();                // look for an integer
+    int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255
+    analogWrite(9, signal);                   // set the brightness of LED on pin 9
+    Serial.println(result);                   // print the number as well
   }
-  while (true);    // do nothing more
+  delay(5000);    // wait 5 seconds before you do it again
 }

+
+


Pin renames

Pin renames

--- examples/TMC2130_Simple/TMC2130_Simple.ino
+++ examples/TMC2130_Simple/TMC2130_Simple.ino
@@ -1,27 +1,26 @@
 #define EN_PIN    38  // Nano v3:	16 Mega:	38	//enable (CFG6)
 #define DIR_PIN   55  //			19			55	//direction
 #define STEP_PIN  54  //			18			54	//step
-#define CS_PIN    64  //			17			64	//chip select
+#define CS_PIN    40  //			17			64	//chip select

 bool dir = false;

 #include <TMC2130Stepper.h>
-TMC2130Stepper TMC2130 = TMC2130Stepper(pinEN, pinDIR, pinStep, pinCS);
+TMC2130Stepper TMC2130 = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);

 void setup() {
 	Serial.begin(9600);
 	TMC2130.begin();
 	TMC2130.SilentStepStick2130(1000);

-	digitalWrite(pinEN, LOW);
-	Serial.println(TMC2130.external_ref());
+	digitalWrite(EN_PIN, LOW);
 }

 void loop() {
-	digitalWrite(pinStep, HIGH);
+	digitalWrite(STEP_PIN, HIGH);
 	delayMicroseconds(10);
-	digitalWrite(pinStep, LOW);
+	digitalWrite(STEP_PIN, LOW);
 	delayMicroseconds(10);
 	uint32_t ms = millis();
 	static uint32_t last_time = 0;


using String as a recv buffer

using String as a recv buffer

--- MyReceiver_softSPI/MyReceiver_softSPI.ino
+++ MyReceiver_softSPI/MyReceiver_softSPI.ino
@@ -26,17 +26,14 @@
     return;
   }

-  receiver.read();
+  if( ! receiver.read()) {
+    return;
+  }

-  char c;
-  receiver.rxPL(c);
-
-  if(c != 0) {
-    while(c != 0) {
-      Serial.print(c);
-      receiver.rxPL(c);
-    }
-    Serial.println();
+  String s = String("");
+  receiver.rxPL(s);
+  if(s.length() > 0) {
+    Serial.println(s);
   }
 }


turned on pixel-y mode as default

turned on pixel-y mode as default

--- HexaWS2811/HexaWS2811.ino
+++ HexaWS2811/HexaWS2811.ino
@@ -260,7 +260,7 @@
   for (int s=0; s < NUM_STRIPS; s++) {
     for (int i=0; i < LEDS_PER_STRIP; i++) {
       int pix;
-#if 0
+#if 1
   //fade mode
       pix=*pixelPtr;
       if (pix){
@@ -286,7 +286,7 @@
           pix=ft; //0x00;
         pix&=0xff;

-        pix=(ft+i)&0x7f;  //trails
+        pix=(ft+i)&0xff;  //trails

 //        if (pix>0x80)pix=0x80;


intermediate steps to bluetooth control

intermediate steps to bluetooth control

--- controllable_robot/controllable_robot.ino
+++ controllable_robot/controllable_robot.ino
@@ -16,7 +16,7 @@
   Serial.begin(57600);
   mySerial.begin(9600);
   Serial.println("Do it.");
-  /*
+
   // //Setup Channel A
   pinMode(12, OUTPUT); //Initiates Motor Channel A pin
   pinMode(9, OUTPUT); //Initiates Brake Channel A pin
@@ -24,7 +24,7 @@
   // //Setup Channel B
   pinMode(13, OUTPUT); //Initiates Motor Channel B pin
   pinMode(8, OUTPUT);  //Initiates Brake Channel B pin
-
+  /*
   digitalWrite(9, HIGH);   //Disengage the Brake for Channel A
   digitalWrite(8, HIGH);   //Disengage the Brake for Channel B
   */
@@ -68,16 +68,16 @@
     }
     else if (cmd ==  "bck") {
       digitalWrite(12, HIGH);
-      digitalWrite(12, HIGH);
+      digitalWrite(13, HIGH);
     }
     else if (cmd ==  "rgt") {
-      digitalWrite(12, HIGH);
       digitalWrite(12, LOW);
+      digitalWrite(13, HIGH);
     }

     else if (cmd == "lft") {
-      digitalWrite(12, LOW);
       digitalWrite(12, HIGH);
+      digitalWrite(13, LOW);
     }


correct bug where cannot stop on alarm when lcd is set to off

--- vibrate_alarm_clock.ino
+++ vibrate_alarm_clock.ino
@@ -256,10 +256,11 @@

   Serial.println("Alarm Set Button Pressed");

-  if(!showLCD){
+  //Do not process button if not active
+  if(!showLCD && currentState != ALARM){
     return;
   }
-
+
   switch(currentState)
   {
     case ALARM: stopAlarm();
@@ -305,7 +306,8 @@

   Serial.println("Time Set Button Pressed");

-  if(!showLCD){
+  //Do not process button if not active
+  if(!showLCD && currentState != ALARM){
     return;
   }


solve push button problem NC to NO

solve push button problem NC to NO

--- coni/arduino/main/remote/last.ino
+++ coni/arduino/main/remote/last.ino
@@ -2,7 +2,7 @@
 #define SEL_A 28 //0 su 1
 #define SEL_B 31 //0 su 2
 #define BT_A A14 //0 premuto
-#define BT_B A8 //1 premuto
+#define BT_B A8 //0 premuto
 #define SEL_Gp A5 //0 su G e 1 su p

 #define passetto 10
@@ -31,7 +31,7 @@
     pinMode(channels[i], OUTPUT);
   }

-  Serial.begin(9600);
+  //Serial.begin(9600);

   Serial2.begin(4800);
 }
@@ -48,16 +48,16 @@
     digitalWrite(channels[15],LOW);
     if (act == 0) {
       t0 = millis();
-      Serial.println("ACT 0");
+      //Serial.println("ACT 0");
       inviatop = false;
       inviatoG = false;
       act++;
       att1 = 0;
       att2 = 0;
-      Serial.print(digitalRead(SEL_A));
-      Serial.print(" ");
-      Serial.print(digitalRead(SEL_B));
-      Serial.println(" ");
+      //Serial.print(digitalRead(SEL_A));
+      //Serial.print(" ");
+      //Serial.print(digitalRead(SEL_B));
+      //Serial.println(" ");
     }
     if ((digitalRead(SEL_A) == 0) && (digitalRead(SEL_B) == 1)) //A
     {
@@ -85,8 +85,8 @@
     // P 2000       >> set velocity of little cone to 2000
     // g 90 -90 90  >> move big cone
     // G 4000       >> set velocity of big cone
-    if (Serial.available() > 0) {
-      Serial2.write(Serial.read());
+    if (//Serial.available() > 0) {
+      Serial2.write(//Serial.read());
     }

     // Check button
@@ -101,16 +101,16 @@
     if (inviatoG == false) {
       att1 = muovi(let_G, vel_G, posG_a, posG_b, posG_c);
       digitalWrite(channels[act-1], HIGH);
-      Serial.println("mando scena G");
-      Serial.println(act);
+      //Serial.println("mando scena G");
+      //Serial.println(act);
       inviatoG = true;
       tdd = millis();
     }
     if ((inviatop == false) && ((long)(millis() - tdd) > dd)) {
       att2 = muovi(let_p, vel_p, posp_a, posp_b);
       digitalWrite(channels[act-1], LOW);
-      Serial.println("mando scena p");
-      Serial.println(act);
+      //Serial.println("mando scena p");
+      //Serial.println(act);
       inviatop = true;
     }
     if ((long)(millis() - t0) > (long)(magg(att1, att2) + pausa)) {
@@ -143,34 +143,34 @@
 void show_due() {

   //intro
-  attore(1, 'g', 2000, -180,  -180,  180, 'p', 2000, -150, 180,  8000); //def
-  attore(2, 'g', 2000, 0,  -180,  -180, 'p', 2500, 150, -180,  8000); //def
-  attore(3, 'g', 2000, 0,  80,  110, 'p', 3400, -130, 180,  8000); //def
-  attore(4, 'g', 3000, 180,  -250,  -110, 'p', 1800, 130, -180,  5000); //def
+  attore(1, 'g', 2200, -90,  -160,  180, 'p', 2000, -150, 180,  8000); //def
+  attore(2, 'g', 2000, -90,  160,  -180, 'p', 2500, 150, -180,  8000); //def
+  attore(3, 'g', 2000, 0,  110,  110, 'p', 3400, -130, 180,  8000); //def
+  attore(4, 'g', 3000, 180,  -280,  -110, 'p', 1800, 130, -180,  5000); //def

   //dance
   attore(5, 'g', 4000, -640,  300,  -720, 'p', 2800, 540, -540,  13000); //def
-  attore(6, 'g', 4000, 110,  -310,  -190, 'p', 3000, -360, 360,  6000); //def
+  attore(6, 'g', 4000, 90,  -290,  -180, 'p', 3000, -360, 360,  6000); //def

   //outro
-  attore(7, 'g', 2000, 160,  170,  180, 'p', 1500, 175, -170,  6000); //def
+  attore(7, 'g', 2000, 180,  150,  170, 'p', 1500, 175, -170,  6000); //def

 }

 void show_tre() {

   //intro
-  attore(1, 'g', 2000, -180,  -180,  180, 'p', 2000, -150, 180,  8000); //def
-  attore(2, 'g', 2000, 0,  -180,  -180, 'p', 2500, 150, -180,  8000); //def
-  attore(3, 'g', 2000, 0,  80,  110, 'p', 3400, -130, 180,  8000); //def
-  attore(4, 'g', 3000, 180,  -250,  -110, 'p', 1800, 130, -180,  8000); //def
+  attore(1, 'g', 2200, -90,  -160,  180, 'p', 2000, -150, 180,  8000); //def
+  attore(2, 'g', 2000, -90,  160,  -180, 'p', 2500, 150, -180,  8000); //def
+  attore(3, 'g', 2000, 0,  110,  110, 'p', 3400, -130, 180,  8000); //def
+  attore(4, 'g', 3000, 180,  -280,  -110, 'p', 1800, 130, -180,  5000); //def

   //dance
-  attore(5, 'g', 4000, -640,  300,  -720, 'p', 3000, 540, -540,  15000); //def
-  attore(6, 'g', 4000, 110,  -310,  -190, 'p', 3000, -360, 360,  6000); //def
+  attore(5, 'g', 4000, -640,  300,  -720, 'p', 2800, 540, -540,  13000); //def
+  attore(6, 'g', 4000, 90,  -290,  -180, 'p', 3000, -360, 360,  6000); //def

   //outro
-  attore(7, 'g', 2000, 160,  170,  180, 'p', 1500, 175, -170,  6000); //def
+  attore(7, 'g', 2000, 180,  150,  170, 'p', 1500, 175, -170,  6000); //def

 }

@@ -248,94 +248,141 @@
 void checkButton() {
   if ((digitalRead(SEL_A) == 0) && (digitalRead(SEL_B) == 1)) //A
   {
-    if (digitalRead(BT_A) == 0)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore A orario");
+    if ((digitalRead(BT_A) == 0) && (digitalRead(BT_B) == 1)) //premuto A e non B
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore A orario");
         muovi('p', vel_passetti, passetto, 0);
       }
       else
       {
-        Serial.println("motore C orario");
+        //Serial.println("motore C orario");
         muovi('g', vel_passetti, passetto,0);
       }
       delay(1000);
     }
-    else if (digitalRead(BT_B) == 1)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore A antiorario");
+    else if ((digitalRead(BT_B) == 0) && (digitalRead(BT_A) == 1)) //premuto B e non A
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore A antiorario");
         muovi('p', vel_passetti, -passetto, 0);
       }
       else
       {
-        Serial.println("motore C antiorario");
+        //Serial.println("motore C antiorario");
         muovi('g',vel_passetti,-passetto, 0, 0);
       }
       delay(1000);
     }
+    else if ((digitalRead(BT_B) == 0) && (digitalRead(BT_A) == 0)) //premuto B e A
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore A giro");
+        muovi('p', 4000, 360, 0);
+      }
+      else
+      {
+        //Serial.println("motore C giro");
+        muovi('g', 4000, 360, 0, 0);
+      }
+      delay(20000);
+    }
   }
   else if ((digitalRead(SEL_A) == 1) && (digitalRead(SEL_B) == 1)) //B
   {
-    if (digitalRead(BT_A) == 0)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore B orario");
+    if ((digitalRead(BT_A) == 0) && (digitalRead(BT_B) == 1))  //premuto
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore B orario");
         muovi('p',vel_passetti,0, passetto);
       }
       else
       {
-        Serial.println("motore D orario");
+        //Serial.println("motore D orario");
         muovi('g',vel_passetti,0, passetto, 0);
       }
       delay(1000);
     }
-    else if (digitalRead(BT_B) == 1)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore B antiorario");
+    else if ((digitalRead(BT_B) == 0) && (digitalRead(BT_A) == 1)) //premuto
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore B antiorario");
         muovi('p',vel_passetti,0, -passetto);
       }
       else
       {
-        Serial.println("motore D antiorario");
+        //Serial.println("motore D antiorario");
         muovi('g',vel_passetti,0, -passetto, 0);
       }

       delay(1000);
     }
+    else if ((digitalRead(BT_B) == 0) && (digitalRead(BT_A) == 0)) //premuto B e A
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore B giro");
+        muovi('p', 4000, 0, 360);
+      }
+      else
+      {
+        //Serial.println("motore D giro");
+        muovi('g', 4000, 0, 360, 0);
+      }
+      delay(20000);
+    }
   }
   else if ((digitalRead(SEL_A) == 1) && (digitalRead(SEL_B) == 0)) //C
   {
-    if (digitalRead(BT_A) == 0)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore inesistente");
-      }
-      else
-      {
-        Serial.println("motore E orario");
+    if ((digitalRead(BT_A) == 0) && (digitalRead(BT_B) == 1))  //premuto
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("tutti in senso orario");
+        muovi('g',2000,180, 0, 0);
+        delay(100);
+        muovi('p',2000,0, -180);
+      }
+      else
+      {
+        //Serial.println("motore E orario");
         muovi('g',vel_passetti,0, 0, passetto);
       }
       delay(1000);
     }
-    else if (digitalRead(BT_B) == 1)  //premuto
-    {
-      if (digitalRead(SEL_Gp)) //1 è piccolo
-      {
-        Serial.println("motore inesistente");
-      }
-      else
-      {
-        Serial.println("motore E antiorario");
+    else if ((digitalRead(BT_B) == 0)  && (digitalRead(BT_A) == 1)) //premuto
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("tutti in senso antiorario");
+        muovi('g',2000,-180, 0, 0);
+        delay(100);
+        muovi('p',2000,0, 180);
+      }
+      else
+      {
+        //Serial.println("motore E antiorario");
         muovi('g',vel_passetti,0, 0, -passetto);
       }
       delay(1000);
     }
-  }
-}
+    else if ((digitalRead(BT_B) == 0) && (digitalRead(BT_A) == 0)) //premuto B e A
+    {
+      if (digitalRead(SEL_Gp)) //1 è piccolo
+      {
+        //Serial.println("motore inesistente");
+      }
+      else
+      {
+        //Serial.println("motore E giro");
+        muovi('g', 4000, 0, 0, 360);
+      }
+      delay(20000);
+    }
+  }
+}


IT'S ALIVE

IT'S ALIVE

--- crypt-gears/gear_arduino/gear_arduino.ino
+++ crypt-gears/gear_arduino/gear_arduino.ino
@@ -20,11 +20,10 @@
                     390, 280,
                     190, 70,
                     50, 24,
-                    12, 0};
+                    12, 5};

 // above this = white; below = black (unlodged is undefined)
-// TODO(benkraft): Recompute after we move them.
-int photoresistor_thresholds[3] = {28, 6, 15};
+int photoresistor_thresholds[3] = {90, 50, 70};

 // STATE OF THE WORLD

@@ -49,8 +48,8 @@
 // gear position.  When we transition to state 2 we use this to populate
 // gear_types and gear_orientations.
 // NOTE: The photoresistor is positioned down.
-int photoresistor_totals[3][7];
-int photoresistor_counts[3][7];
+long int photoresistor_totals[3][7];
+long int photoresistor_counts[3][7];

 // The state of the ith gear, if we know it.  This is not its current position,
 // but rather the position corresponding to selector gear 0!  Only meaningful
@@ -95,11 +94,11 @@
 // SETTINGS

 // How long in ms we wait between loops
-int FRAME_SPEED = 50; // 20 fps
+int FRAME_SPEED = 10; // 100 fps
 // How many frames to wait before toggling blinking lights
-int BLINK_SPEED = 10; // 0.5s
+int BLINK_SPEED = 50; // 0.5s
 // How many frames to wait before logging debug data, or 0 for never
-int DEBUG_FREQ = 20; // 1s
+int DEBUG_FREQ = 100; // 1s

 // MAIN TOPLEVEL STUFF

@@ -114,24 +113,17 @@
     pinMode(output_lights[i], OUTPUT);
     digitalWrite(output_lights[i], LOW);
   }
+
 }

 // this is run continuously after setup has completed
 void loop()
 {
   delay(FRAME_SPEED);
+
+  printState();

   int selector_pos = getSelectorGearPosition();
-  if (selector_pos == -2)
-  {
-    sendCastleErrorMessage();
-    return;
-  }
-  else if (selector_pos == -1)
-  {
-    // we haven't made it to a new position yet, do nothing.
-    return;
-  }

   // LE GRAND STATE MACHINE
   // NOTE: with some exceptions the state machine falls through: if we advance
@@ -139,7 +131,11 @@
   if (state == 0)
   {
     setCalibration(false);
-    if (selector_pos == 0 && buttonPressed())
+    if (selector_pos < 0)
+    {
+      return;
+    }
+    else if (selector_pos == 0 && buttonPressed())
     {
       // We have started calibrating!
       state = 1;
@@ -158,14 +154,14 @@
   if (state == 1)
   {
     blinkCalibration();
-    if (selector_pos < last_selector_pos
-        || selector_pos > last_selector_pos + 1)
+    if (selector_pos >= 0 && (selector_pos < last_selector_pos
+        || selector_pos > last_selector_pos + 1))
     {
       // They have gone backwards or too fast.
       state = 0;
       resetLights();
     }
-    else
+    else if (selector_pos >= 0)
     {
       // Fill in new photoresistor states.
       for (int i=0; i<3; i++)
@@ -173,58 +169,63 @@
         photoresistor_totals[i][selector_pos] += getRawPhotoresistor(i);
         photoresistor_counts[i][selector_pos]++;
       }
-
-      // If we are at the end, move on to state 2.
-      if (selector_pos == 6)
-      {
-        state = 2;
-        // This fills in gear_types and gear_orientations.
-        // We check that it passes each time, and that
-        // we see one of each gear type.
-        int failed = false;
-        int types_seen = 0;
-        for (int i=0; i<3; i++)
-        {
-          if (!computeGearPosition(i))
-          {
-            failed = true;
-            printGearRead(i, true);
-          }
-          else
-          {
-            types_seen |= 1 << gear_types[i];
-            printGearRead(i, false);
-          }
-        }
-
-        if (types_seen != 7)
+    }
+    // If we are at the end, move on to state 2.
+    else if (selector_pos < 0 && last_selector_pos == 6)
+    {
+      // This fills in gear_types and gear_orientations.
+      // We check that it passes each time, and that
+      // we see one of each gear type.
+      int failed = false;
+      int types_seen = 0;
+      for (int i=0; i<3; i++)
+      {
+        if (!computeGearPosition(i))
         {
           failed = true;
-        }
-
-
-        if (failed)
-        {
-          state = 0;
-          resetLights();
+          printGearRead(i, true);
         }
         else
         {
-          for (int i=0; i<7; i++)
-          {
-            correct_positions[i] = false;
-          }
+          types_seen |= 1 << gear_types[i];
+          printGearRead(i, false);
         }
       }
+
+      if (types_seen != 7)
+      {
+        failed = true;
+      }
+
+
+      if (failed)
+      {
+        state = 0;
+        resetLights();
+      }
+      else
+      {
+        state = 2;
+        for (int i=0; i<7; i++)
+        {
+          correct_positions[i] = false;
+        }
+      }
+    }
+    else
+    {
+      return;
+
     }
   }

   if (state == 2)
   {
     setCalibration(true);
-    if (selector_pos > last_selector_pos
-        || selector_pos < last_selector_pos - 1)
-    {
+    if (selector_pos >= 0 && (selector_pos > last_selector_pos
+        || selector_pos < last_selector_pos - 1))
+    {
+      Serial.println("RESET");
       // They have gone backwards or too fast.
       state = 0;
       resetLights();
@@ -237,27 +238,31 @@
       {
         showCorrect(selector_pos);
       }
-
-      if (selector_pos == 0)
-      {
-        // If we are back to the beginning, and have won, yay!
-        boolean winning = true;
-        for (int i=0; i<7; i++)
+    }
+    else if (last_selector_pos == 0)
+    {
+      // If we are back to the beginning, and have won, yay!
+      boolean winning = true;
+      for (int i=0; i<7; i++)
+      {
+        if (!correct_positions[i])
         {
-          if (!correct_positions[i])
-          {
-            winning = false;
-            break;
-          }
+          winning = false;
+          break;
         }
-
-        if (winning)
-        {
-          state = 3;
-          winning_blink_state = 0;
-          sendCastleSuccessMessage();
-        }
-      }
+      }
+
+      if (winning)
+      {
+        state = 3;
+        winning_blink_state = 0;
+        sendCastleSuccessMessage();
+      }
+
+    }
+    else if (selector_pos < 0)
+    {
+      return;
     }
   }

@@ -273,6 +278,7 @@
     {
       blinkWinningLights();
     }
+    return;
   }

   last_selector_pos = selector_pos;
@@ -290,7 +296,7 @@
   // Hold on tight; this is kinda bespoke and messy.

   // First, figure out what, on average, we saw.
-  int photoresistor_history[7];
+  boolean photoresistor_history[7];
   int positions_white = 0;
   for (int j=0; j<7; j++)
   {
@@ -299,7 +305,8 @@
     // apart, set a dynamic threshold halfway between.
     photoresistor_history[j] = (
       photoresistor_totals[i][j] / photoresistor_counts[i][j]
-      < photoresistor_thresholds[i]);
+      > photoresistor_thresholds[i]);
+    Serial.print(photoresistor_history[j]);

     positions_white += photoresistor_history[j];
   }
@@ -613,16 +620,16 @@
   {
     // print out position of the pot
     Serial.print("pot: ");
-    Serial.println(getSelectorGearPosition());
+    Serial.print(getSelectorGearPosition());
+    Serial.print(" (");
+    Serial.print(analogRead(pot));
+    Serial.println(")");
     // print out the three photoresistors.
     Serial.print("photoresistors:");
     for (int i=0; i<3; i++)
     {
       Serial.print(" ");
       Serial.print(getRawPhotoresistor(i));
-      Serial.print(" (");
-      Serial.print(analogRead(photoresistors[i]));
-      Serial.print(")");
     }
     Serial.println("");

@@ -677,12 +684,14 @@
       Serial.print("history ");
       Serial.print(i);
       Serial.print(":");
-      for (int j=0; j<=last_selector_pos; j++)
+      for (int j=0; j<7; j++)
       {
         Serial.print(" ");
         Serial.print(photoresistor_totals[i][j]);
         Serial.print("/");
         Serial.print(photoresistor_counts[i][j]);
+        Serial.print("=");
+        Serial.print(photoresistor_totals[i][j] / photoresistor_counts[i][j]);
       }
       Serial.println("");
     }


Moved debounce delay to #define

Moved debounce delay to #define

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -11,6 +11,8 @@
 #include "MusicPlayer.h"
 #include "star.h"

+#define DEBOUNCE_DELAY 100
+
 // TODO highScore should be replaced with table in EEPROM
 unsigned int score, highScore = 0;
 byte livesRemaining = 4;
@@ -49,7 +51,6 @@
   byte selectedItem = TITLE_PLAY_GAME;
   unsigned short totalDelay = 0;
   long lastDebounceTime = 0;  // the last time the button was pressed
-  long debounceDelay = 100;
   arduboy.clear();
   printText("TITLE", 25, 20, 2);
   arduboy.drawRect(2, 47, 26, 13, 1);
@@ -66,14 +67,14 @@
     }

     if (arduboy.pressed(LEFT_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > debounceDelay) {
+      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = titleMenuLeftButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
     }

     if (arduboy.pressed(RIGHT_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > debounceDelay) {
+      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = titleMenuRightButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
@@ -187,7 +188,6 @@
 void settingsScreen() {
   // TODO, this is a placeholder
   long lastDebounceTime = 0;  // the last time the button was pressed
-  long debounceDelay = 100;
   bool exit_settings_menu = false;
   byte selectedItem;

@@ -201,21 +201,21 @@

   while (!exit_settings_menu) {
     if (arduboy.pressed(DOWN_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > debounceDelay) {
+      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = settingMenuDownButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
     }

     if (arduboy.pressed(UP_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > debounceDelay) {
+      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = settingMenuUpButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
     }

     if (arduboy.pressed(A_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > debounceDelay) {
+      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         switch (selectedItem) {

           case SETTINGS_EXIT:


implemented a turn() method

implemented a turn() method

turn() method was written without testing
mazeSolve is mostly dummy code

--- MazeSolver/MazeSolver.ino
+++ MazeSolver/MazeSolver.ino
@@ -2,10 +2,22 @@
 #include "Direction.h"

 const int numberOfSensors = 6;
+// pid loop vars
 const float proportionalConst = 0.1f;
 const float derivateConst = 1.0f;
 const int calibrationSeconds = 4;
 const int twoHundred = 200;
+
+int speed_a = 3;  //speed control for motor outputs 1 and 2 is on digital pin 10  (Right motor)
+int speed_b = 11; //speed control for motor outputs 3 and 4 is on digital pin 11  (Left motor)
+int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12  (Right motor)
+int dir_b = 13;  //direction control for motor outputs 3 and 4 is on digital pin 13  (Left motor)
+
+// motor tuning vars for maze navigating
+int turnSpeed = 200;  // tune value motors will run while turning (0-255) NOT TESTED
+int turnSpeedSlow = 125;  // tune value motors will run as they slow down from turning cycle to avoid overrun (0-255) NOT TESTED
+int drivePastDelay = 300; // tune value in mseconds motors will run past intersection to align wheels for turn NOT TESTED
+

 unsigned char pins[6] = { 0, 1, 2, 3, 4, 5 };
 QTRSensorsAnalog qtra(pins, numberOfSensors, 4, 2);
@@ -121,3 +133,152 @@

 	Serial.println((int)position - 2500);
 }
+// Turns to the sent variable of
+// 'L' (left), 'R' (right), 'S' (straight), or 'B' (back)
+// To Do: Tune 'turnSpeed'
+void turn(char dir)
+{
+  switch(dir)
+  {
+    // Turn left 90deg
+    case 'L':
+      digitalWrite(dir_a, HIGH);
+      analogWrite(speed_a, turnSpeed);
+      digitalWrite(dir_b, LOW);
+      analogWrite(speed_b, turnSpeed);
+
+      position = qtrra.readLine(sensorValues);
+
+
+      while (sensorValues[5] <300)  // wait for outer most sensor to find the line
+      {
+        position = qtrra.readLine(sensorValues);
+      }
+
+      // slow down speed
+      analogWrite(speed_a, turnSpeedSlow);
+      analogWrite(speed_b, turnSpeedSlow);
+
+      // find center
+      while (position > 3000)  // tune - wait for line position to find near center
+      {
+        position = qtrra.readLine(sensorValues); //possible bug: libary uses position to calculate the next val
+      }
+
+      // stop both motors
+      analogWrite(speed_b, 0);  // stop right motor first to better avoid over run
+      analogWrite(speed_a, 0);
+      break;
+
+    // Turn right 90deg
+    case 'R':
+      digitalWrite(dir_a, LOW);
+      analogWrite(speed_a, turnSpeed);
+      digitalWrite(dir_b, HIGH);
+      analogWrite(speed_b, turnSpeed);
+
+      line_position = qtrra.readLine(sensorValues);
+
+      while (sensorValues[1] <300)  // wait for outer most sensor to find the line
+      {
+        position = qtrra.readLine(sensorValues);
+      }
+
+      // slow down speed
+      analogWrite(speed_a, turnSpeedSlow);
+      analogWrite(speed_b, turnSpeedSlow);
+
+      // find center
+      while (position < 3000)  // tune - wait for line position to find near center
+      {
+        position = qtrra.readLine(sensorValues);
+      }
+
+      // stop both motors
+      analogWrite(speed_a, 0);
+      analogWrite(speed_b, 0);
+      break;
+
+    // Turn right 180deg to go back
+    case 'B':
+      digitalWrite(dir_a, LOW);
+      analogWrite(speed_a, turnSpeed);
+      digitalWrite(dir_b, HIGH);
+      analogWrite(speed_b, turnSpeed);
+
+      position = qtrrc.readLine(sensorValues);
+
+      while (sensorValues[1] <300)  // wait for outer most sensor to find the line
+      {
+        position = qtrra.readLine(sensorValues);
+      }
+
+      // slow down speed
+      analogWrite(speed_a, turnSpeedSlow);
+      analogWrite(speed_b, turnSpeedSlow);
+
+      // find center
+      while (position < 300)  // tune - wait for line position to find near center
+      {
+        position = qtrrc.readLine(sensorValues);
+      }
+
+      // stop both motors
+      analogWrite(speed_a, 0);
+      analogWrite(speed_b, 0);
+      break;
+
+    // Straight ahead
+    case 'S':
+      // do nothing
+      break;
+  }
+} // end turn
+
+void MazeSolve()
+{
+  while(1)
+  {
+
+    follow_line();
+
+    // Drive straight a bit.
+    digitalWrite(dir_a, LOW);
+    analogWrite(pwm_a, 200);
+    digitalWrite(dir_b, LOW);
+    analogWrite(pwm_b, 200);
+    delay(25);
+
+    // These variables record whether the robot has seen a line to the
+    // left, straight ahead, and right, whil examining the current
+    // intersection.
+    unsigned char found_left=0;
+    unsigned char found_straight=0;
+    unsigned char found_right=0;
+
+    // Now read the sensors and check the intersection type.
+    line_position = qtrra.readLine(sensorValues);
+
+    // Check for left and right exits.
+    if(sensorValues[0] > 400)
+    found_right = 1;
+    if(sensorValues[5] > 400)
+    found_left = 1;
+
+    // Drive straight a bit more
+    digitalWrite(dir_a, LOW);
+    analogWrite(pwm_a, 200);
+    digitalWrite(dir_b, LOW);
+    analogWrite(pwm_b, 200);
+    delay(drivePastDelay);
+
+    line_position = qtrra.readLine(sensorValues);
+   // if(sensorValues[1] > 200 || sensorValues[2] > 200 || sensorValues[3] > 200 || sensorValues[4] > 200) //To Do: Which sensor values indicate a straight
+   // found_straight = 1;
+
+   // unsigned char dir = select_turn(found_left, found_straight, found_right); //To Do: this method
+
+    // Make the turn indicated by the path.
+    turn(dir);
+    //To Do: End of the maze
+  }


Fix bugs in hearbeat logic

Fix bugs in hearbeat logic

--- WirelessTrigger.ino
+++ WirelessTrigger.ino
@@ -35,7 +35,7 @@
 Switch triggerButton = Switch(triggerButtonPin);
 Switch resetButton = Switch(resetButtonPin);

-uint8_t heartbeatLEDPin = 13;
+uint8_t heartbeatLEDPin = 4;

 unsigned long lastHeartbeat = 0;
 bool isCommHealthy = false;
@@ -89,7 +89,8 @@
         }
         else {
             radio.read(&recvByte, 1);
-            Serial.print("Received ack byte " + recvByte);
+            Serial.print("Received ack byte ");
+            Serial.println((int)recvByte);
         }
     }
     else {
@@ -101,8 +102,10 @@
 }

 void validateAck(byte ackResponse) {
-    if (ackResponse == ackVal)
+    if (ackResponse == ackVal) {
         isCommHealthy = true;
+        Serial.println("Comms healthy");
+    }
     else {
         isCommHealthy = false;
         Serial.println("Bad ack received! This probably means that the connection is unstable.");
@@ -128,7 +131,7 @@
     }
     else if (millis() - lastHeartbeat >= HEARTBEAT_THRESH_MILLIS) {
         // Re-use ack byte for heartbeat
-        validateAck(sendByte(triggerVal));
+        validateAck(sendByte(ackVal));
     }

     digitalWrite(heartbeatLEDPin, isCommHealthy);


upd: change wifi led behavior

upd: change wifi led behavior

--- ArduinoFirmwareEsp/ArduinoFirmwareEsp.ino
+++ ArduinoFirmwareEsp/ArduinoFirmwareEsp.ino
@@ -12,7 +12,7 @@

 int ledState = LOW;             // used to set the LED state
 long previousMillis = 0;        // will store last time LED was updated
-long bl_interval = 200;
+long ap_interval = 50;         //blink interval in ap mode
 IPAddress default_IP(192,168,240,1);  //defaul IP Address
 String HOSTNAME = DEF_HOSTNAME;

@@ -63,21 +63,34 @@

   unsigned long currentMillis = millis();
   int wifi_status = WiFi.status();
-  if ((WiFi.getMode() == 1 || WiFi.getMode() == 3) && wifi_status == WL_CONNECTED) {
-    if (currentMillis - previousMillis > bl_interval) {
+  if ((WiFi.getMode() == 1 || WiFi.getMode() == 3) && wifi_status == WL_CONNECTED) {    //wifi LED in STA MODE
+    if (currentMillis - previousMillis > ap_interval) {
       previousMillis = currentMillis;
-      if (ledState == LOW)
+      if (ledState == LOW){
         ledState = HIGH;
-      else
+        ap_interval = 200;    //time wifi led ON
+      }
+      else{
         ledState = LOW;
+        ap_interval = 2800;   //time wifi led OFF
+      }
       digitalWrite(WIFI_LED, ledState);
     }
   }
-  else if (WiFi.softAPgetStationNum() > 0 ) {   //LED on in AP mode
-    digitalWrite(WIFI_LED, HIGH);
+  else{ //if (WiFi.softAPgetStationNum() > 0 ) {   //wifi LED on in AP mode
+    if (currentMillis - previousMillis > ap_interval) {
+      previousMillis = currentMillis;
+      if (ledState == LOW){
+        ledState = HIGH;
+        ap_interval = 950;
+      }
+      else{
+        ledState = LOW;
+        ap_interval = 50;
+      }
+      digitalWrite(WIFI_LED, ledState);
+    }
   }
-  else //if (wifi_status !=WL_CONNECTED){
-    digitalWrite(WIFI_LED, LOW);

 }


Recalibrated

Recalibrated


Simpler tdi/tdo storage.

Simpler tdi/tdo storage.

--- JTAGWhisperer.ino
+++ JTAGWhisperer.ino
@@ -19,10 +19,14 @@
     Serial.println();                               \
   }

-#if 1
-#define DEBUG(fmt, ...)  { }
-#define DEBUG_BYTES(s, p, n)  { }
+#if 0
+#define DEBUG_STATE(s) { Serial.print("D State -> "); \
+    Serial.print(state_name(s)); }
 #else
+#define DEBUG_STATE(s) {}
+#endif
+
+#if 0
 #define DEBUG(fmt, ...)  { Serial.print("D ");  \
     p(fmt, ## __VA_ARGS__);                     \
     Serial.println();                           \
@@ -31,12 +35,14 @@
     print_bytes(p, n);                                                \
     Serial.println();                                                 \
   }
+#else
+#define DEBUG(fmt, ...)  { }
+#define DEBUG_BYTES(s, p, n)  { }
 #endif

 void print_bytes(uint8_t* pb, uint8_t count) {
-  pb += count;
   while (count--) {
-    p("%02x", *--pb);
+    p("%02x", *pb++);
   }
 }

@@ -400,9 +406,8 @@
   }

   void get_next_bytes(uint8_t* data, uint8_t count) {
-    data += count;
     while (count--) {
-      *--data = get_next_byte();
+      *data++ = get_next_byte();
     }
   }

@@ -492,7 +497,7 @@
     int byte_count = BYTE_COUNT(data_length_bits);

     for (int i = 0; i < byte_count; ++i) {
-      uint8_t byte_out = data[i];
+      uint8_t byte_out = data[byte_count - 1 - i];
       uint8_t tdo_byte = 0;
       for (int j = 0; j < 8 && data_length_bits-- > 0; ++j) {
         if (data_length_bits == 0 && is_end) {
@@ -509,7 +514,7 @@
         bool tdo = twiddler_.pulse_clock_and_read_tdo();
         tdo_byte |= tdo << j;
       }
-      tdo_[i] = tdo_byte;
+      tdo_[byte_count - 1 - i] = tdo_byte;
     }
   }

@@ -559,7 +564,7 @@

   void set_state(int state) {
     if (current_state_ != state) {
-      DEBUG("Switching to state %s.", state_name(state));
+      DEBUG_STATE(state);
     }
     current_state_ = state;
   }


update, use DS1307RTC library to set time

--- RTC_DS1307/RTC_DS1307.ino
+++ RTC_DS1307/RTC_DS1307.ino
@@ -66,7 +66,15 @@
       pf("Wrong\n");
       break;
   }
-  setTime(h, m, s, d, M, y);
+  //setTime(h, m, s, d, M, y);
+  tmElements_t tm;
+  tm.Year = y - 1970;
+  tm.Month = M;
+  tm.Day = d;
+  tm.Hour = h;
+  tm.Minute = m;
+  tm.Second = s;
+  RTC.set(makeTime(tm));
 }


default to 115200

default to 115200

--- BrewManiac.ino
+++ BrewManiac.ino
@@ -49,7 +49,11 @@
 const byte SoftwareSerialTx = 11;
 #endif

+#if UseSoftwareSerial == true
 #define WiFiSerialBaudRate 38400
+#else
+#define WiFiSerialBaudRate 115200
+#endif

 /* this option is not used if  UseSoftwareSerial == true */
 #define WirelessHardwarePort Serial
@@ -68,7 +72,7 @@
 #define ButtonEnterPin  A0
 // use Serial1
 #define UseSoftwareSerial false
-#define WirelessHardwarePort Serial
+#define WirelessHardwarePort Serial1
 #endif

 #if BOARD == UNOTEST
@@ -3063,7 +3067,7 @@

 	buzzPlaySoundRepeat(SoundIdWaitUserInteraction);

-	if(readSetting(PS_PidPipe) == 1 && readSetting(PS_SensorType) == 0)
+	if(!(readSetting(PS_PidPipe) == 1 && readSetting(PS_SensorType) == 0))
 		heatProgramOff(); // heat off, programming

 	#if WirelessSupported == true


add new config

add new config

--- BrewManiac.ino
+++ BrewManiac.ino
@@ -27,9 +27,11 @@
 #define UNOTEST 1
 // MRE168 is MEGA, HD44780s LCD
 #define MRE168 2
+// Setting from default Open ArdBir
+#define Pcb_ArdBir_DanielXan 3
 //////////////////////////

-#define BOARD MRE168
+#define BOARD Pcb_ArdBir_DanielXan
 // not usingI2C_LCD by default
 #define I2C_LCD false

@@ -37,6 +39,10 @@

 //hardware setup
 const byte SensorPin=7;
+#define PumpControlPin  6
+#define BuzzControlPin 8
+#define HeatControlPin  9
+

 #if BOARD == MRE168
 #define ButtonUpPin    A3
@@ -49,20 +55,22 @@

 // overwrite I2C_LCD setting
 #define I2C_LCD true
-
 #define ButtonUpPin    A2
 #define ButtonDownPin   A3
 #define ButtonStartPin  A0
 #define ButtonEnterPin  A1
 #endif

-#define PumpControlPin  6
-#define BuzzControlPin 8
-#define HeatControlPin  9
+
+#if BOARD == Pcb_ArdBir_DanielXan
+#define ButtonUpPin    A2
+#define ButtonDownPin   A3
+#define ButtonStartPin  A0
+#define ButtonEnterPin  A1
+#endif

 #define BluetoothSupported true
 #define UseSoftwareSerial true
-

 #if UseSoftwareSerial == true
 const byte SoftwareSerialRx = 10;
@@ -76,10 +84,12 @@
 //debug
 //should be false
 #define SerialDebug false
-#define CHANG_BAUDRATE true
+#define CHANG_BAUDRATE false
+
 #if UseSoftwareSerial != true
 #define SerialDebug false
 #endif
+
 // should be false
 #define FakeHeating false
 #if FakeHeating == true
@@ -92,7 +102,6 @@

 #define ElectronicOnly true
-
 #define PerformanceProfiling false

 #define NoPrint true
@@ -101,7 +110,7 @@

 #define BT_AutoBaudRate true
 #define BT_MODULE_INITIALIZATION true
-#define BT_Menu true
+#define BT_Menu false

 #if BT_MODULE_INITIALIZATION != true
 #define BT_Menu false


Explicitly declaring large number as unsigned longs

--- control_board/firmware/vasttrapi.ino
+++ control_board/firmware/vasttrapi.ino
@@ -29,7 +29,7 @@
 const boolean powerOnState = HIGH; // The rpiPwrPin state that turns the power on to the RPi

 volatile unsigned long timeToSleep = 0;
-const unsigned long awakePeriod = 600000; // Time in milliseconds to remain awake on every new touch
+const unsigned long awakePeriod = 600000UL; // Time in milliseconds to remain awake on every new touch
 const unsigned long shutdownTime = 12000; // Time in milliseconds to wait for the RPi to shutdown

 enum PowerState {


added write function

added write function

--- MF_ACM/MF_ACM.ino
+++ MF_ACM/MF_ACM.ino
@@ -14,22 +14,26 @@
 #define CMD_INCREMENT 0x24
 #define CMD_GET_SNR 0x25

-/* RFID Reader
-   Uses RDM880 breakout board with RX connected to pin 2 and TX connected to pin 3.
-   Another serial interface is added by including the Software Serial library.
-   Dummy signal from 3.3 V is connected to pin 4.
+/*
+RFID Reader
+  Uses RDM880 breakout board with RX connected to pin 2 and TX connected to pin 3.
+  Another serial interface is added by including the Software Serial library.
+  Dummy signal from 3.3 V is connected to pin 4.

-   Input:
-      RFID tags
-      Signal from Pin 4
+Input:
+  RFID tags
+  Signal from Pin 4

-   Output:
-      Serial number of tag scanned
-      Elapsed time
+Output:
+  Serial number of tag scanned
+  Elapsed time

-   Operation:
-      Reader waits until a tag is scanned, then prints the serial number of the tag.
-      Reader now waits for "control" signal, and when that signal goes high, counts time.
+Operation:
+  Reader waits until a tag is scanned, then prints the serial number of the tag.
+  Reader now waits for "control" signal, and when that signal goes high, counts time.
+
+Notes:
+  Consult ISO14443 documentation on command/receive packet structures

 */

@@ -109,6 +113,7 @@
   }
 }

+// Prints serial number to monitor, sets flag if a packet other than idle is detected
 unsigned char getResponse(bool responseFlag) {
   int i = 0;
   unsigned char response[bufferSize];
@@ -127,6 +132,7 @@
     return false;
 }

+// calculates checksum by XOR-ing all bytes except STX and ETX
 unsigned char checksum(unsigned char A[], int numElements) {
   int i = 0;
   unsigned char BCC = A[0];
@@ -138,12 +144,14 @@
   return BCC;
 }

+// Get serial number of detected card, prints serial number of selected card if > 1 near reader
 void MF_GET_SNR(unsigned char DADD) {
   BCC = checksum( { DADD, 0x03, CMD_GET_SNR, 0x26, 0x00 }, 5);
   unsigned char CMD[] = { STX, DADD, 0x03, CMD_GET_SNR, 0x26, 0x00, BCC, ETX};
-  RDM880.write(CMD, 8);
+  RDM880.write(CMD, sizeof(CMD)/sizeof(CMD[0]));
 }

+// Read up to 4 blocks (16 bytes each) from sectors 0 - 63
 void MF_READ(unsigned char numBlocks, unsigned char startSector) {
   int i = 0;
   BCC = checksum( { 0x00, 0x0A, CMD_READ, 0x01, numBlocks, startSector, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, 12);
@@ -151,6 +159,10 @@
                           0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, BCC, ETX };
   unsigned char response[bufferSize];

+  // send command
+  RDM880.write(CMD, sizeof(CMD)/sizeof(CMD[0]));
+
+  // get response packet and print
   while(RDM880.available()) {
     response[i] = RDM880.read();
     Serial.print(response[i], HEX);
@@ -160,3 +172,19 @@

 }

+// Write a block at a sector with 16 bytes (can do up to 4 blocks)
+void MF_WRITE(unsigned char numBlocks, unsigned char startSector, unsigned char time) {
+  BCC = checksum({ 0x00, 0x1A, CMD_WRITE, 0x01, 0x01, startSector,
+                    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                    time }, 28);
+  unsigned char CMD[] = { STX, 0x00, 0x1A, CMD_WRITE, 0x01, 0x01, startSector,
+                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                          time, BCC, ETX };
+  unsigned char response[bufferSize];
+
+  // send command
+  RDM880.write(CMD, sizeof(CMD)/sizeof(CMD[0]));
+
+}


Replace sendData() with shiftOut()

Replace sendData() with shiftOut()

--- arduino/fillbrick.ino
+++ arduino/fillbrick.ino
@@ -6,29 +6,17 @@
 const int DATAPIN = 13;
 // Number of pins
 const int BOARDHEIGHT = 5;
-// Delay
+// Refresh rate
 const int DELAY = 200;

-void sendData(byte data) {
-  // 001010
-  for (int i = 0; i < boardHeight; i++) {
-    digitalWrite(LATCHPIN, LOW);
-    // shift out the bits:
-    digitalWrite(DATAPIN, data[i]);
-    //take the latch pin high so the LEDs will light up:
-    digitalWrite(LATCHPIN, HIGH);
-    Serial.print(bitRead(data, i));
-  }
-  //digitalWrite(0);
-  Serial.print(0);
-  Serial.println();
-}
+// Test pattern smiley face
+const int data[10] = {7,1,13,1,1,13,1,7,0,0};

 void diagonalLines() {
   // count from 1 (0x00001) to 32 (0x10000)
   // note: the furthest right pin is disconnected; drop the right most digit in binary
-  for (byte a = 1; a< 32;a*=2) {
-    sendData(a);
+  for (byte a = 1; a < 8; a++) {
+    shiftOut(DATAPIN, CLOCKPIN, LSBFIRST, a);
     delay(DELAY);
   }
 }
@@ -41,5 +29,12 @@
 }

 void loop() {
-  diagonalLines()
+  for (int a = 0; a < 10; a++) {
+    // Bit shift twice because the first pin on each shift register is unused
+    int b = data[a] << 2;
+    digitalWrite(LATCHPIN, LOW);
+    shiftOut(DATAPIN, CLOCKPIN, LSBFIRST, b);
+    digitalWrite(LATCHPIN, HIGH);
+    delay(DELAY);
+  }
 }


Fix example

Fix example

--- examples/More/Stroboscope/Stroboscope.ino
+++ examples/More/Stroboscope/Stroboscope.ino
@@ -45,6 +45,12 @@
 SimpleTimer timer;
 int t1;

+// Toggle LED
+void ledBlynk()
+{
+  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
+}
+
 // Enable/disable blinking using virtual pin 1
 BLYNK_WRITE(V1)
 {
@@ -68,12 +74,6 @@
   }
 }

-// Toggle LED
-void ledBlynk()
-{
-  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
-}
-
 void setup()
 {
   // Configure Blynk


Fixed a bug.

Fixed a bug.

--- Tests/FSM/FSM.ino
+++ Tests/FSM/FSM.ino
@@ -40,8 +40,8 @@
 bool buttonPressed;
 int numberOfStates = 4;
 int currentState = 0;
-bool foundBlack = false;
-bool foundCylinder = false;
+bool foundBlack;
+bool foundCylinder;
 int galvReading = 0;

@@ -87,6 +87,8 @@
   if (currentState == 0) {
     // Initilization, robot stays idle
     stopMovement();
+    bool foundBlack = false;
+    bool foundCylinder = false;

   } else if (currentState == 1) {
     // Stop on black


Add pins 4 and 5 for connection status and A/C power status LEDs.

--- CloudComfort/CloudComfort.ino
+++ CloudComfort/CloudComfort.ino
@@ -45,6 +45,8 @@
 long lastConnectionTime = 0;        // last time you connected to the server, in milliseconds
 boolean lastConnected = false;      // state of the connection last time through the main loop
 const int postingInterval = 10000;  // delay between updates to the cloud
+const int PIN_ONLINE_LED = 4;
+const int PIN_AC_POWER_LED = 5;

 boolean static isIPValid = false;

@@ -57,6 +59,8 @@
   Serial.begin(9600);
   Serial.println("BOOT");

+  pinMode(PIN_ONLINE_LED, OUTPUT);
+  pinMode(PIN_AC_POWER_LED, OUTPUT);
   // Give the Ethernet Shield time to initialize.
   delay(1000);

@@ -68,6 +72,7 @@
   } else {
     Serial.println("IP Found");
   }
+  digitalWrite(PIN_ONLINE_LED, HIGH);
   airConditioner.setupTemp();
   ACTemp = 19;
 }
@@ -159,6 +164,7 @@
     if (acStatus != newAcStatus) {
       acStatus = newAcStatus;
       airConditioner.setPower(acStatus);
+      digitalWrite(PIN_AC_POWER_LED, acStatus ? HIGH : LOW);
     }
     if (ACTemp != newTempc) {
       ACTemp = newTempc;
@@ -205,3 +211,5 @@
   // return the number of digits:
   return digits;
 }
+
+


initialise_eeprom 2

initialise_eeprom 2

--- _09_ir_tx_rx/_09_ir_tx_rx.ino
+++ _09_ir_tx_rx/_09_ir_tx_rx.ino
@@ -11,6 +11,7 @@
 #define eeprom_read(dst, eeprom_field) eeprom_read_to(&dst, eeprom_field, sizeof(dst))
 #define eeprom_write_from(src_p, eeprom_field, src_size) eeprom_write_block(src_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(src_size, sizeof((__eeprom_data*)0)->eeprom_field))
 #define eeprom_write(src, eeprom_field) { typeof(src) x = src; eeprom_write_from(&x, eeprom_field, sizeof(x)); }
+#define MIN(x,y) (x > y ? y : x)

 // Change this any time the EEPROM content changes
 const long magic_number = 0x0326;
@@ -117,7 +118,7 @@
   // initialize eeprom
   long magic;
   eeprom_read(magic, magic);
-  if ((magic != magic_number) || ( setUpStatus == 0 ) {
+  if ((magic != magic_number) || ( setUpStatus == 0 )) {
      run_initialise_setup();
   }

@@ -270,4 +271,4 @@
  */
   // initialise_eeprom();

-}+}


Update K_Nearest_Template.ino

Update K_Nearest_Template.ino

Made some changes

--- K_Nearest_Template/K_Nearest_Template.ino
+++ K_Nearest_Template/K_Nearest_Template.ino
@@ -1,178 +1,219 @@
-#include <Arduino.h>
-#include <math.h>
-// FIXME: Add the libraries needed for each pin
-
-#include "Object.h"
-
-// Define Pins for each sensor
-// Distance Sensor (Height)
-
-int test = 0;
-
-// Define anything else needed for sensors
-
-// K Nearest Neighbors
-// FIXME: Change when necessary
-const int K = [number];
-
-// FIXME: Change when necessary
-const size_t NUM_OF_KNOWN_OBJECTS = [number];
-const size_t NUM_OF_OBJECT_TYPES = [number];
-
-// FIXME: Change object types
-String Known_Object_Types[[number]] = {[object types]};
-const int STRUCT_FIELDS = [number];
-
-// Define max height/weight/etc.
-// FIXME: For each feature
-const int [feature]_MAX = [number];
-const int [feature]_MIN = [number];
-
-// Computes the euclidean distance between the known and the current object's rgb values
-float ComputeDistanceofColors(Object currObject, Object knownObject) {
-  float red = currObject.red - knownObject.red;
-  float green = currObject.green - knownObject.green;
-  float blue = currObject.blue - knownObject.blue;
-  float dist = pow(red, 2) + pow(green, 2) + pow(blue, 2);
-  dist = roundf(dist* 100.0) / 100.0;
-  return dist;
-}
-
-// Computes the euclidean distance between the known and the current object's features
-// Can add or remove features
-float ComputeDistanceofObjects(Object currObject, Object knownObject) {
-  // FIXME: For non-color features
-  float [feature] = ((currObject.[feature] - knownObject.[feature]) - [feature]_MIN) / ([feature]_MAX - [feature]_MIN);
-
-  // FIXME (optional): For color feature
-  float colorDistance = ComputeDistanceofColors(currObject, knownObject);
-
-  // FIXME: For each feature
-  float dist = pow([feature 1], 2) + pow([feature 2], 2) + pow([feature 3], 2);
-  dist = sqrt(dist);
-
-  // Nearest 100ths place
-  dist = roundf(dist * 100.0) / 100.0;
-
-  return dist;
-}
-
-// Takes the features from the current object and converts them to strings and integers
-void ObjectFeatureExtraction(Object &currObject) {
-  int currDistance;
-  // Define necessary variables for height/weight/etc.
-
-  // Read features from sensors (ex: sonar.ping_cm())
-
-  // Assign each of those features to currObject.
-}
-
-// Finds the patterns from the current object and compares them to patterns from the given objects
-String PatternRecognition(Object currObject, Object knownObjects[], size_t NUM_OF_KNOWN_OBJECTS) {
-
-  Object kNearestObjects[K];
-
-  // The first K Object differences are added to the kNearestObjects array
-  for(int i = 0; i < K; ++i) {
-    kNearestObjects[i].type = knownObjects[i].type;
-    // FIXME: For each feature
-    kNearestObjects[i].[feature] = abs(knownObjects[i].[feature] - currObject.[feature]);
-  }
-
-  // Now, determine if each remaining object is among the K closest, and if so insert into array (thus dropping one obj)
-  for(int i = K; i < NUM_OF_KNOWN_OBJECTS; ++i) { // For each remaining known object
-
-    // Find the current max difference (CHANGE TO DISTANCE, EVERYWHERE) in the K nearest objects
-    float max_diff = 0;
-    int max_index = 0;
-    // FIXME: For each feature
-    int temp_[feature] = 0;
-
-    for(int j = 0; j < K; ++j) {
-      temp_dist = ComputeDistanceofObjects(currObject, kNearestObjects[j]);
-
-      if(temp_dist > max_diff) { // Update max
-        max_diff = temp_dist;
-        max_index = j;
-      }
-    }
-
-    // If the current known object's difference < the max difference in the current K nearest neighbors
-    // For each feature
-    temp_[feature] = abs(knownObjects[i].[feature] - currObject.[feature]);
-    temp_dist = ComputeDistanceofObjects(currObject, knownObjects[i]);
-
-    if(temp_dist < max_diff) {
-      // Replace the existing neighbor having max_diff, by the current known object, in the K nearest neighbors array
-      kNearestObjects[max_index].type = knownObjects[i].type;
-      // FIXME: For each feature
-      kNearestObjects[max_index].[feature] = temp_[feature];
-      max_diff = temp_dist;
-    }
-  }
-
-  int count = 0;
-  int max_count = 0;
-  String max_type;
-  // Find out which object type occurs the most
-  for(int i = 0; i < NUM_OF_OBJECT_TYPES; ++i) {
-    count = 0;
-    for(int j = 0; j < K; ++j) {
-      if(kNearestObjects[j].type == Known_Object_Types[i]) {
-        count++;
-      }
-    }
-    if(count > max_count) {
-      max_count = count;
-      max_type = Known_Object_Types[i];
-    }
-  }
-
-  return max_type;
-}
-
-// Prints the type of object that is being passed through the project
-void Actuation(String object) {
-  if(object != "") {
-    Serial.print("\t");
-    Serial.println(object);
-  }
-}
-
-void setup() {
-  Serial.begin(9600);
-
-  // Setup any features that need it
-}
-
-void loop() {
-  // Turns both LEDs off before each reading
-
-  // Should put feature extraction and pattern recognition in one multi-second for loop to
-    //give the box time to go through the sensors.
-  // FIXME: Change number if needed
-  const size_t NUM_OF_KNOWN_OBJECTS = 9;
-
-  // FIXME: Add known objects
-  Object knownObjects[NUM_OF_KNOWN_OBJECTS] = { {"[type]", [Put features in here]]},
-                                                ...};
-
-  // FIXME: Change number if needed
-  const size_t NUM_OF_TEST_OBJECTS = 9;
-
-  // FIXME: Add test objects
-  Object testObjects[NUM_OF_KNOWN_OBJECTS] = { {"", [Put features in here]]},
-                                                ...};
-
-  Object currObject;
-  String closestObject;
-
-  ObjectFeatureExtraction(currObject);
-
-  closestObject = PatternRecognition(currObject, knownObjects, NUM_OF_KNOWN_OBJECTS);
-
-  Actuation(closestObject);
-
-  delay(1000);
-}
-
+#include <Arduino.h>
+#include <math.h>
+// FIXME: Add the libraries needed for each pin
+
+#include "Object.h"
+
+// FIXME: Can change pin number
+#define IR_SENSOR_PIN_1 6
+
+// Define Pins for each sensor
+// Distance Sensor (Height)
+
+int test = 0;
+bool wait = false;
+
+// Define anything else needed for sensors
+
+// K Nearest Neighbors
+// FIXME: Change when necessary
+const int K = [number];
+
+// FIXME: Change when necessary
+const size_t NUM_OF_KNOWN_OBJECTS = [number];
+const size_t NUM_OF_OBJECT_TYPES = [number];
+
+// FIXME: Change object types
+String Known_Object_Types[NUM_OF_OBJECT_TYPES] = {[object types]};
+
+Object knownObjects[NUM_OF_KNOWN_OBJECTS];
+
+// Define max height/weight/etc.
+// FIXME: For each feature
+const int [feature]_MAX = [number];
+const int [feature]_MIN = [number];
+
+// Takes the features from the current object and converts them to strings and integers
+// **
+void ObjectFeatureExtraction(Object &currObject) {
+  // Define necessary variables for height/weight/etc.
+
+  // Read features from sensors (ex: sonar.ping_cm())
+
+  // Assign each of those features to currObject.
+}
+
+float RescaleValue(float value, const float min, const float max) {
+  return (value-min)/(max-min);
+}
+
+// Rescale object features to 1-0 range
+void RescaleObject(Object *object) {
+  // FIXME: For each feature
+  object->[feature] = RescaleValue(object->[feature], [feature]_MIN, [feature]_MAX);
+}
+
+//  Computes the euclidean distance between the known and the current object's rgb values
+// FIXME: Remove if there are no colors
+float ComputeDistanceofColors(Object currObject, Object knownObject) {
+  float red = currObject.r - knownObject.r;
+  float green = currObject.g - knownObject.g;
+  float blue = currObject.b - knownObject.b;
+  float dist = pow(red, 2) + pow(green, 2) + pow(blue, 2);
+  dist = roundf(dist* 100.0) / 100.0;
+  return dist;
+}
+
+// Computes the euclidean distance between the known and the current object's features
+float ComputeDistanceofObjects(Object currObject, Object knownObject) {
+  // FIXME: For each feature
+  float [feature]_dist = (currObject.[feature] - knownObject.[feature]);
+  // FIXME: Remove if there are no colors
+  float color_dist = ComputeDistanceofColors(currObject, knownObject);
+  // FIXME: For each feature, remove color_dist if there are no colors
+  float dist = [feature]_dist*[feature]_dist + color_dist*color_dist;
+
+  return dist;
+}
+
+// Finds the patterns from the current object and compares them to patterns from the given objects
+// **
+String ObjectPatternRecognition(Object currObject, Object knownObjects[]) {
+  int count = 0;
+  int max_count = 0;
+  String most_frequent_type;
+
+  Object kNearestObjects[K];
+
+  // First K known objects are the closest K, obviously, so just fill array
+  for(int i = 0; i < K; ++i) {
+    kNearestObjects[i].type = knownObjects[i].type;
+    // FIXME: For each feature
+    kNearestObjects[i].[feature] = knownObjects[i].[feature];
+  }
+
+  // Now, determine if each remaining object is among the K closest, and if so insert into array (thus dropping one obj)
+  for(int i = K; i < NUM_OF_KNOWN_OBJECTS; ++i) { // For each remaining known object
+    int j;
+
+    // Find the current max difference in the K nearest objects
+    float max_diff_of_K_nearest = 0;
+    int max_index = 0;
+    float temp_dist = 0;
+
+    for(j = 0; j < K; ++j) {
+      // kNearest Objects is the difference between the currObject and the knownObjects
+      // ComputeDistanceofObjects should compute the total distance for kNearestObjects[j]
+      // May just add this to the above
+      temp_dist = ComputeDistanceofObjects(currObject, kNearestObjects[j]);
+
+      if(temp_dist > max_diff_of_K_nearest) { // Update max
+        max_diff_of_K_nearest = temp_dist;
+        max_index = j;
+      }
+    }
+
+    // If the current known object's difference < the max difference in the current K nearest neighbors
+    temp_dist = ComputeDistanceofObjects(currObject, knownObjects[i]);
+
+    if(temp_dist < max_diff_of_K_nearest) {
+      // Replace the existing neighbor having max_diff_of_K_nearest, by the current known object, in the K nearest neighbors array
+      kNearestObjects[max_index].type = knownObjects[i].type;
+      // FIXME: For each feature
+      kNearestObjects[max_index].[feature] = knownObjects[i].[feature];
+  }
+
+  // For testing purposes
+  for(int i = 0; i < K; ++i) {
+    Serial.println(kNearestObjects[i].type);
+    // FIXME: For each feature
+    Serial.println(kNearestObjects[i].[feature]);
+  }
+
+  // Find out which object type occurs most frequently
+  for(int i = 0; i < NUM_OF_OBJECT_TYPES; ++i) {
+    int j;
+    count = 0;
+    for(j = 0; j < K; ++j) {
+      if(kNearestObjects[j].type == Object_Types[i]) {
+        count++;
+      }
+    }
+    if(count > max_count) {
+      max_count = count;
+      most_frequent_type = Object_Types[i];
+    }
+  }
+
+  return most_frequent_type;
+}
+
+// Prints the type of object that is being passed through the project
+// **
+void Actuation(String object) {
+  if(object != "") {
+    Serial.print("\t");
+    Serial.println(object);
+  }
+}
+
+void PopulateKnownObjects() {
+  // Change values and measure
+  // FIXME: For each feature
+  // FIXME: Add as many known objects as needed
+  knownObjects[0].type = "[Object type]";
+  knownObjects[0].[feature] = [feature value];
+}
+
+
+void setup() {
+  Serial.begin(9600);
+
+  PopulateKnownObjects();
+
+  pinMode(IR_SENSOR_PIN_1, INPUT);
+  digitalWrite(IR_SENSOR_PIN_1, HIGH);
+
+  // Setup any features that need it
+
+  String closestObject;
+}
+
+void loop() {
+  bool IR_Sensor1;
+  String closestObject;
+
+  IR_Sensor1 = digitalRead(IR_SENSOR_PIN_1);
+
+  // Sensor was tripped and wasn't right before.
+  if(IR_Sensor1 == LOW && !wait) {
+    // FIXME: Can change what the object is (ex: Box, Fruit, etc.)
+    Serial.println("[Object] Detected");
+
+    delay(1000);
+
+    digitalWrite(LED_BUILTIN, HIGH);
+
+    Object currObject;
+
+    ObjectFeatureExtraction(currObject);
+
+    closestObject = ObjectPatternRecognition(currObject, knownObjects);
+
+    Actuation(closestObject);
+
+    wait = true;
+
+    delay(1000);
+  }
+  // Sensor was tripped and was right before.
+  else if(IR_Sensor1 == LOW && wait) {
+    digitalWrite(LED_BUILTIN, LOW);
+  }
+  // Sensor was not tripped.
+  else if(IR_Sensor1 == HIGH){
+    digitalWrite(LED_BUILTIN, LOW);
+    wait = false;
+  }
+
+}


check driver condition before switches

check driver condition before switches

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -319,25 +319,27 @@
   Serial.println(elapsedMillis);
 */

-  debounceMillis += elapsedMillis;
-  if (debounceMillis >= debounceInterval) {
-    debounceMillis = 0;
-
-    debounce(switchTrigger, &swTrigger, &swTriggerDebounce);
-    debounce(switchFront, &swFront, &swFrontDebounce);
-    debounce(switchBack, &swBack, &swBackDebounce);
-  }

   // fast debounce driver error signals to filter short glitches
   debounce(motorDiagAPin, &motorDiagA, &motorDiagADebounce);
   debounce(motorDiagBPin, &motorDiagB, &motorDiagBDebounce);

-  // The WAM's overheating!
+  // The WAM is overheating!
   if ((motorDiagA == LOW || motorDiagB == LOW) && doorState != doorError) {
     motorFree();
     debug(currentMillis, F("Motor driver error condition - door disabled\r\n"));
     setLeds1(red, ledFade);
     doorState = doorError;
+  }
+
+
+  debounceMillis += elapsedMillis;
+  if (debounceMillis >= debounceInterval) {
+    debounceMillis = 0;
+
+    debounce(switchTrigger, &swTrigger, &swTriggerDebounce);
+    debounce(switchFront, &swFront, &swFrontDebounce);
+    debounce(switchBack, &swBack, &swBackDebounce);
   }


moved acceleration profile to config block

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -2,7 +2,7 @@

 /* config */

-// MAXPIX+EXTRAPIX must fit into uint8_t
+// MAXPIX must fit uint8_t loop variable in ledFade, ledBlink
 #define MAXPIX 20  // LED stripe length
 #define EXTRAPIX 3 // animation buffer, read window moves back and forth EXTRAPIX pixels

@@ -18,7 +18,7 @@
 const int motorInBPin = 8;
 const int motorPWMPin = 9;

-// switch inputs, active-low
+// end-stop switches, active-low
 const int switchFront = 3; // front is at the closed position
 const int switchFrontIRQ = 1; // TODO: maybe use interrupts & sleep

@@ -33,61 +33,6 @@

 // on-board status LED
 const int statusLED = 13;
-
-
-/* WS2812 LEDs */
-
-cRGB leds[MAXPIX+EXTRAPIX];
-cRGB tmp_leds[MAXPIX]; // temp array for fading and blinking
-cRGB *ledptr; // read pointer for WS2812 library, points to start of window
-
-// requires custom changes to accept uint8_t** argument
-WS2812 LED(MAXPIX, &ledptr);
-
-enum ledModes { ledSolid, ledFade, ledBlink, ledForward, ledBackward } ledMode;
-
-// mode-dependent state
-union ledState {
-  unsigned int ledidx;
-  signed int fader;
-  bool blink_on;
-} ledState;
-
-// pre-defined colors. GRB order, g++ doesn't implement out-of-order initializers
-const cRGB traktor = {g: 0xB8/7, r: 0x67/7, b: 0xDC/7}; // https://wiki.attraktor.org/Corporate_Identity
-const cRGB black = {g: 0x00, r: 0x00, b: 0x00};
-const cRGB white = {g: 0x1F, r: 0x1F, b: 0x1F};
-const cRGB red = {g: 0x00, r: 0x1F, b: 0x00};
-const cRGB yellow = {g: 0x1F, r: 0x1F, b: 0x00};
-const cRGB green = {g: 0x1F, r: 0x00, b: 0x00};
-const cRGB blue = {g: 0x00, r: 0x00, b: 0x1F};
-
-// macro instead of inline function. TODO: compare generated code again
-// fill LED buffer with solid color, reset state, set mode
-#define setLeds1(color1, mode) {\
-  for (uint8_t i = 0; i < MAXPIX+EXTRAPIX; i++) {\
-    leds[i] = (color1);\
-  }\
-  memset(&ledState, 0x00, sizeof(ledState));\
-  ledMode = (mode);\
-}
-
-// fill LED buffer with alternating colors every modulo pixels, reset state, set mode
-#define setLeds2(color1, color2, modulo, mode) {\
-  for (uint8_t i = 0; i < MAXPIX+EXTRAPIX; i++) {\
-    leds[i] = (i % (modulo)) ? ((color2)) : ((color1));\
-  }\
-  memset(&ledState, 0x00, sizeof(ledState));\
-  ledMode = (mode);\
-ledMoveInterval = 250;\
-}
-
-
-/* motor driver */
-
-// global motor direction variable, required for PWM-brake & coasting
-// TODO: PWM-brake is never used, maybe refactor & remove
-enum motorDir { forward, backward } motorDir;

 // ad-hoc acceleration profile
 // TODO: self-calibration by means of driveTotalMillis
@@ -199,8 +144,63 @@
   },
 */

+
+/* motor driver */
+
+// global motor direction variable, required for PWM-brake & coasting
+// TODO: PWM-brake is never used, maybe refactor & remove
+enum motorDir { forward, backward } motorDir;
+
 const struct accelProfile *accelProfile; // pointer to current profile
 int accelProfileIdx = 0;
+
+
+/* WS2812 LEDs */
+
+cRGB leds[MAXPIX+EXTRAPIX];
+cRGB tmp_leds[MAXPIX]; // temp array for fading and blinking
+cRGB *ledptr; // read pointer for WS2812 library, points to start of window
+
+// requires custom changes to accept uint8_t** argument
+WS2812 LED(MAXPIX, &ledptr);
+
+enum ledModes { ledSolid, ledFade, ledBlink, ledForward, ledBackward } ledMode;
+
+// mode-dependent state
+union ledState {
+  unsigned int ledidx;
+  signed int fader;
+  bool blink_on;
+} ledState;
+
+// pre-defined colors. GRB order, g++ doesn't implement out-of-order initializers
+const cRGB traktor = {g: 0xB8/7, r: 0x67/7, b: 0xDC/7}; // https://wiki.attraktor.org/Corporate_Identity
+const cRGB black = {g: 0x00, r: 0x00, b: 0x00};
+const cRGB white = {g: 0x1F, r: 0x1F, b: 0x1F};
+const cRGB red = {g: 0x00, r: 0x1F, b: 0x00};
+const cRGB yellow = {g: 0x1F, r: 0x1F, b: 0x00};
+const cRGB green = {g: 0x1F, r: 0x00, b: 0x00};
+const cRGB blue = {g: 0x00, r: 0x00, b: 0x1F};
+
+// macro instead of inline function. TODO: compare generated code again
+// fill LED buffer with solid color, reset state, set mode
+#define setLeds1(color1, mode) {\
+  for (uint8_t i = 0; i < MAXPIX+EXTRAPIX; i++) {\
+    leds[i] = (color1);\
+  }\
+  memset(&ledState, 0x00, sizeof(ledState));\
+  ledMode = (mode);\
+}
+
+// fill LED buffer with alternating colors every modulo pixels, reset state, set mode
+#define setLeds2(color1, color2, modulo, mode) {\
+  for (uint8_t i = 0; i < MAXPIX+EXTRAPIX; i++) {\
+    leds[i] = (i % (modulo)) ? ((color2)) : ((color1));\
+  }\
+  memset(&ledState, 0x00, sizeof(ledState));\
+  ledMode = (mode);\
+ledMoveInterval = 250;\
+}

 /* unsorted variables below. TODO: refactor & cleanup */
@@ -649,7 +649,7 @@
         ledMillis = 0;

         if (!ledState.blink_on) {
-  //          memset(&tmp_leds, 0x00, sizeof(tmp_leds));
+//          memset(&tmp_leds, 0x00, sizeof(tmp_leds));
           for (uint8_t i = 0; i < MAXPIX; i++) {
             tmp_leds[i] = black;
           }


Fixed calculation of uv intensity

Fixed calculation of uv intensity

--- files/template_home/template_home.ino
+++ files/template_home/template_home.ino
@@ -118,7 +118,7 @@
   sleep(1);
   if (Wire.available()) lsb = Wire.read();
   uvValue = (msb << 8) | lsb;
-  return uvValue * 5;
+  return uvValue * 5.625;
 }

 int printHexToStream(const uint8_t *data, uint8_t length, Print &stream) // prints 8-bit data in hex


Firmware ~ Display any colour on RGB LED

--- arduino/TLamp/TLamp.ino
+++ arduino/TLamp/TLamp.ino
@@ -1,8 +1,15 @@
-#define PIN_LED LED_BUILTIN
+#define PIN_RED 3
+#define PIN_GREEN 5
+#define PIN_BLUE 6

 void setup() {
-  pinMode(PIN_LED, OUTPUT);
-  digitalWrite(PIN_LED, LOW);
+  pinMode(PIN_RED, OUTPUT);
+  pinMode(PIN_GREEN, OUTPUT);
+  pinMode(PIN_BLUE, OUTPUT);
+
+  digitalWrite(PIN_RED, LOW);
+  digitalWrite(PIN_GREEN, LOW);
+  digitalWrite(PIN_BLUE, LOW);

   Serial.begin(9600);
 }
@@ -42,14 +49,9 @@
 }

 void setColor(int r, int g, int b) {
-  // Debug
-    if (r == 255) {
-      blink(PIN_LED, 1);
-    } else if (g == 255) {
-      blink(PIN_LED, 2);
-    } else if (b == 255) {
-      blink(PIN_LED, 3);
-    }
+  analogWrite(PIN_RED, r);
+  analogWrite(PIN_GREEN, g);
+  analogWrite(PIN_BLUE, b);
 }

 void blink(int pin) {


_05_kidSerie_sketch_01.DHTServer.ino 05#kidSerie

_05_kidSerie_sketch_01.DHTServer.ino 05#kidSerie

--- _05_kidSerie_sketch_01.DHTServer.ino
+++ _05_kidSerie_sketch_01.DHTServer.ino
@@ -22,7 +22,7 @@
    DHT11:                PRODUCT ID: 386               https://www.adafruit.com/product/386

    Connections:
-      See Official youtube channel vids:
+      See Official youtube channel vids: https://youtu.be/cwYix_Oyui4
    Based on:   Tony DiCola for Adafruit Industries - see below!

    This program is free software: you can redistribute it and/or modify


Removed some PSTR() statements.

Removed some PSTR() statements.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -122,14 +122,16 @@
   LIGHTS_OFF, LIGHTS_ON, LIGHTS_AUTO
 };

+const char * lightStr[] = { " LIGHTS OFF", "LIGHTS ON", "LIGHTS AUTO" };
+
 const char *lightStatusToString( const lightStatus_t status )
 {
   switch ( status )
   {
-    case LIGHTS_OFF:   return PSTR(" LIGHTS OFF");
-    case LIGHTS_ON:    return PSTR(" LIGHTS ON ");
-    case LIGHTS_AUTO:  return PSTR("LIGHTS AUTO");
-    default:           return PSTR(" UNDEFINED ");
+    case LIGHTS_OFF:   return lightStr[LIGHTS_OFF];
+    case LIGHTS_ON:    return lightStr[LIGHTS_ON];
+    case LIGHTS_AUTO:  return lightStr[LIGHTS_AUTO];
+    default:           return " UNDEFINED ";
   }
 }


Hammer Servo library with position updates

--- arduino/mearm.ino
+++ arduino/mearm.ino
@@ -49,8 +49,6 @@
     char c = Serial.read();
     controller.parseChar(c);
   };
-  if (dt >= 20) {
-    controller.update(dt * 0.001);
-    t0 += dt;
-  };
+  controller.update(dt * 0.001);
+  t0 += dt;
 }


version string

version string

--- analogjson.ino
+++ analogjson.ino
@@ -74,7 +74,7 @@

 // version string
 // since this is always served in JSON dictionary form, that's included here
-const char revision_json[] PROGMEM = "\"serverVersion\": \"20161104.1\"";
+const char revision_json[] PROGMEM = "\"serverVersion\": \"20161121.1\"";

 // this counter is for statistics; reported via status API
 unsigned long requests_processed = 0;


docs: disable config save for example adv sketch

--- examples/advertising/setBeanName.ino
+++ examples/advertising/setBeanName.ino
@@ -1,5 +1,7 @@
 void setup() {
-  // We don't need to set anything up here
+  // Disable writing to NVRAM to preserve its lifespan,
+  // since we are setting a new Bean name every 15 seconds
+  Bean.enableConfigSave(false);
 }

 void loop() {


Updated header

Updated header

--- ZXKBFirmware/ZXKBFirmware.ino
+++ ZXKBFirmware/ZXKBFirmware.ino
@@ -1,6 +1,8 @@
-//  ZXKBFirmware v1.0
-//  Copyright 2016 Mike Daley
-
+//  Name:     ZXKBFirmware
+//  Version:  1.0
+//  Author:   Mike Daley
+//  Date:     January 2016
+//-------------------------------------------------------------------------
 #include <Keyboard.h>
 #include "keys.h"


Removed lower case chars from hi scores.

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -596,7 +596,7 @@

     if (arduboy.pressed(UP_BUTTON)) {
        if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
-          if (currInitials[currPos] == 126) {
+          if (currInitials[currPos] == 96) {
             currInitials[currPos] = 32;
           } else {
             currInitials[currPos]++;
@@ -611,7 +611,7 @@
     if (arduboy.pressed(DOWN_BUTTON)) {
        if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
           if (currInitials[currPos] == 32) {
-            currInitials[currPos] = 126;
+            currInitials[currPos] = 96;
           } else {
             currInitials[currPos]--;
           }


Fixed issue with deprecated clearDisplay();

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -258,7 +258,7 @@
   // Loop to simulate a game that ends with score being
   // close to value of randomScore
   while (score < randomScore) {
-    arduboy.clearDisplay();
+    arduboy.clear();
     sprintf(textBuf, "SCORE %u", score);
     printText(textBuf, 0, 0, 1);
     score += random(0, 50);


analytics are sent successfully via bluetooth

--- src/rfduino/serial_reporter/serial_reporter.ino
+++ src/rfduino/serial_reporter/serial_reporter.ino
@@ -71,7 +71,8 @@
 int loops = 0;

 void setup() {
-  Serial.begin(9600, 1, 0);
+  /* RX is Pin 0, TX is Pin 1 */
+  Serial.begin(9600, 0, 1);
   RFduinoBLE.begin();
 }


Only output pos if it changed.

Only output pos if it changed.

--- brotherKH930_arduino.ino
+++ brotherKH930_arduino.ino
@@ -8,14 +8,20 @@
   Serial.println("Ready.");
 }

+int old_pos = 0;
+
 void loop() {
   Direction dir = brother.direction();
   int pos = brother.position();

-  Serial.print("@");
-  Serial.print(pos);
-  Serial.print("  ");
-  if (dir == LEFT) Serial.print("<-");
-  else Serial.print("->");
-  Serial.println();
+  if (old_pos != pos) {
+    Serial.print("@");
+    Serial.print(pos);
+    Serial.print("  ");
+    if (dir == LEFT) Serial.print("<-");
+    else Serial.print("->");
+    Serial.println();
+  }
+
+  delay(30);
 }


-More priority levels for tasks.

-More priority levels for tasks.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -222,13 +222,13 @@
 const char* defaultTimerFile   = "/default.aqu";

 /* task priorities */
-const uint8_t dimmerTaskPriority       = 7;
-const uint8_t webserverTaskPriority    = 5;
-const uint8_t tempTaskPriority         = 6;
-const uint8_t tftTaskPriority          = 2;
-const uint8_t ntpTaskPriority          = 1;
-const uint8_t oledTaskPriority         = 1;
-const uint8_t wifiTaskPriority         = 1;
+const uint8_t dimmerTaskPriority       = 8;
+const uint8_t tempTaskPriority         = 7;
+const uint8_t webserverTaskPriority    = 6;
+const uint8_t tftTaskPriority          = 5;
+const uint8_t ntpTaskPriority          = 4;
+const uint8_t oledTaskPriority         = 3;
+const uint8_t wifiTaskPriority         = 2;
 const uint8_t loggerTaskPriority       = 1;
 const uint8_t spiffsTaskPriority       = 0;

@@ -283,9 +283,8 @@
   pinMode( I2C_SDA_PIN, INPUT_PULLUP );

   btStop();
-
   //Serial.begin( 115200 );
-  ESP_LOGI( TAG, "aquacontrol32 %s", SKETCH_VERSION );
+  ESP_LOGI( TAG, "aquacontrol32 V%s", SKETCH_VERSION );
   ESP_LOGI( TAG, "ESP32 SDK: %s", ESP.getSdkVersion() );

   SPI.begin( SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN );


Added some links to useful faqs.

Added some links to useful faqs.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -343,6 +343,8 @@
   }
 }

+//http://www.iotsharing.com/2017/06/how-to-apply-freertos-in-arduino-esp32.html
+//http://www.iotsharing.com/2017/05/how-to-apply-finite-state-machine-to-arduino-esp32-avoid-blocking.html
 void loop()
 {
 }


Missed file

Missed file

--- src/drivefw/drivefw.ino
+++ src/drivefw/drivefw.ino
@@ -135,8 +135,9 @@
             }
             curl_easy_cleanup(pCURL);
         }
+*/
         //http_request("POST /CommandServer/currentJsonCommand HTTP/1.1\nHost: 192.168.1.6:8080\nAccept: */*\nContent-Length: 15\nContent-Type: application/x-www-form-urlencoded\nConnection: close\n\nPLATFORM:EDISON\n");
-*/
+        delay(1000);
     }

     return NULL;


Bugfix for initial position

Bugfix for initial position

--- arduino/mearm.ino
+++ arduino/mearm.ino
@@ -8,7 +8,7 @@
 class ServoCurve: public Curve
 {
 public:
-  ServoCurve(void): Curve(DEFAULT_PULSE_WIDTH, 0.00015) {}
+  ServoCurve(void): Curve(0, 0.00015) {}
 };

 class Controller: public ControllerBase


Removed delay and serial debug messages.

--- AnimatedGIFs.ino
+++ AnimatedGIFs.ino
@@ -97,9 +97,6 @@

     Serial.begin(115200);

-    // Wait for serial to settle
-    delay(2000);
-
     // Initialize matrix
     matrix.begin();
     matrix.setBrightness(defaultBrightness);
@@ -115,9 +112,7 @@
     }

     // Determine how many animated GIF files exist
-    numberOfFiles = enumerateGIFFiles(GIF_DIRECTORY, true);
-    Serial.print(F("number of GIF files: "));
-    Serial.println(numberOfFiles);
+    numberOfFiles = enumerateGIFFiles(GIF_DIRECTORY, false);
 }


Update Ethernet.ino

Update Ethernet.ino

--- examples/Transports/Ethernet/Ethernet.ino
+++ examples/Transports/Ethernet/Ethernet.ino
@@ -13,6 +13,7 @@
  * This example code is in public domain.
  *
  **************************************************************
+ *
  * This example shows how to use Arduino Ethernet shield (W5100)
  * to connect your project to Blynk.
  * Feel free to apply it to any other example. It's simple!


C1 values steps and pF display implemented

--- hal100/hal100.ino
+++ hal100/hal100.ino
@@ -55,7 +55,9 @@
 char tuningFreq[6];
 char key;
 char DisplayValueC1[6];
+char DisplayValueC1pH[6];
 char DisplayValueC2[6];
+char DisplayValueC2pH[6];
 char DisplayValueL[6];
 char DisplayValueLUH[4];
 char DisplayValueSWR[6];
@@ -169,7 +171,7 @@
   // Displays C1
   TFTscreen.stroke(0, 255, 0);                      // set the font color
   TFTscreen.setTextSize(2);                         // set the font size 2
-  TFTscreen.text("C1", 5, 65);                     // write the text to coordinates
+  TFTscreen.text("C1", 5, 55);                     // write the text to coordinates
   // Displays C2
   TFTscreen.stroke(0, 255, 0);                      // set the font color
   TFTscreen.setTextSize(2);                         // set the font size 2
@@ -197,7 +199,7 @@
 //  eraseFreqTopScreen();                             // clear previously entered drequesncy at display top
 //  eraseEnteredFrequency();                          // clear entered frequency at display bottom
 //  displayFreqTopScreen();                           // display desired frequesncy at display top
-  //  SetFrequencyStage1();
+//  SetFrequencyStage1();
 //}

@@ -301,7 +303,7 @@
   dtostrf(stepsToMh(valueRotateL), 4, 2, DisplayValueLUH);
   if (isBusy) {
     TFTscreen.stroke(255, 255, 0);
-  } else {
+  } else {
     TFTscreen.stroke(0, 255, 0);
   }
   TFTscreen.setTextSize(2);
@@ -314,35 +316,75 @@
   TFTscreen.text(DisplayValueLUH, 40, 25);
 }

-void displayL() {                                             // display L steps and uH
-  displayLSteps();
-  displayValueLuH();
+void displayL() {                                             // display L steps and uH
+  displayLSteps();
+  displayValueLuH();
 }

 void EraseDisplayL() {                                        // erase L steps and uH
-  EraseDisplayLSteps();
-  ErasDisplayValueLuH();
-}
-
-
-void displayC1() {                                       // display C values
+  EraseDisplayLSteps();
+  ErasDisplayValueLuH();
+}
+
+ double stepsC1topH(double x) {
+   return  3.5215908593183684e+002 * pow(x,0)
+        + -1.6245967367326516e-001 * pow(x,1)
+        + -8.9757122524750620e-004 * pow(x,2)
+        +  5.3372752892602197e-006 * pow(x,3)
+        + -1.7696527557016530e-008 * pow(x,4)
+        +  3.3363571963309934e-011 * pow(x,5)
+        + -3.6438105893235793e-014 * pow(x,6)
+        +  2.2733846666230038e-017 * pow(x,7)
+        + -7.5016703085658784e-021 * pow(x,8)
+        +  1.0154127876671653e-024 * pow(x,9);
+}
+
+void displayC1steps() {                                       // display C1 steps values
   dtostrf(valueRotateC1, 5, 0, DisplayValueC1);
   if (isBusy) {
     TFTscreen.stroke(255, 255, 0);
   } else {
     TFTscreen.stroke(0, 255, 0);
   }
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC1, 40, 65);
-}
-
-void EraseDisplayC1() {                                   // erase display C values
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC1, 55, 70);
+}
+
+void EraseDisplayC1steps() {                                   // erase display C1 steps values
   TFTscreen.stroke(0, 20, 20);
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(DisplayValueC1, 40, 65);
-}
-
-void displayC2() {                                       // display C values
+  TFTscreen.setTextSize(1);
+  TFTscreen.text(DisplayValueC1, 55, 70);
+}
+
+void displayValueC1pH() {                                         // display C1 values in pH
+  dtostrf(stepsC1topH(valueRotateC1), 4, 1, DisplayValueC1pH);
+  if (isBusy) {
+    TFTscreen.stroke(255, 255, 0);
+  } else {
+    TFTscreen.stroke(0, 255, 0);
+  }
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC1pH, 40, 55);
+}
+
+void ErasDisplayValueC1pH() {                                   // erase display C1 values in pH
+  TFTscreen.stroke(0, 20, 30);
+  TFTscreen.setTextSize(2);
+  TFTscreen.text(DisplayValueC1pH, 40, 55);
+}
+
+void displayC1() {                                             // display C1 values
+  displayC1steps();
+  displayValueC1pH();
+}
+
+void EraseDisplayC1() {                                        // erase C1 values
+  EraseDisplayC1steps();
+  ErasDisplayValueC1pH();
+}
+
+
+void displayC2() {                                       // display C2 steps values
   dtostrf(valueRotateC2, 5, 0, DisplayValueC2);
   if (isBusy) {
     TFTscreen.stroke(255, 255, 0);
@@ -353,37 +395,37 @@
   TFTscreen.text(DisplayValueC2, 40, 85);
 }

-void EraseDisplayC2() {                                   // erase display C values
+void EraseDisplayC2() {                                   // erase display C2 steps values
   TFTscreen.stroke(0, 20, 20);
   TFTscreen.setTextSize(2);
   TFTscreen.text(DisplayValueC2, 40, 85);
 }

 double stepsToMh(float x) {
-    return  3.2408606623203362e-001 * pow(x, 0)
-            +  4.8175734249036963e-005 * pow(x, 1)
-            + -8.2394558534492893e-009 * pow(x, 2)
-            +  4.1381892772191581e-012 * pow(x, 3)
-            + -5.0628320718901775e-016 * pow(x, 4)
-            +  3.2564586259750260e-020 * pow(x, 5)
-            + -1.1101886921087241e-024 * pow(x, 6)
-            +  1.3237902692887521e-029 * pow(x, 7)
-            +  3.9488291689952899e-034 * pow(x, 8)
-            + -1.8793946779017113e-038 * pow(x, 9)
-            +  3.2823426065013548e-043 * pow(x, 10)
-            + -2.7820892583909193e-048 * pow(x, 11)
-            +  9.4929814793314678e-054 * pow(x, 12);
-  }
-
-
-
-void eraseFrequency() {                         // when * pressed - erases entered frequency bottom of the screen
-  EnteredFreqString = "";
-  TuningFreqString = "";
-  TFTscreen.stroke(0, 20, 30);
-  TFTscreen.setTextSize(2);
-  TFTscreen.text(enteredFreq, 50, 110);
-}
+  return  3.2408606623203362e-001 * pow(x, 0)
+          +  4.8175734249036963e-005 * pow(x, 1)
+          + -8.2394558534492893e-009 * pow(x, 2)
+          +  4.1381892772191581e-012 * pow(x, 3)
+          + -5.0628320718901775e-016 * pow(x, 4)
+          +  3.2564586259750260e-020 * pow(x, 5)
+          + -1.1101886921087241e-024 * pow(x, 6)
+          +  1.3237902692887521e-029 * pow(x, 7)
+          +  3.9488291689952899e-034 * pow(x, 8)
+          + -1.8793946779017113e-038 * pow(x, 9)
+          +  3.2823426065013548e-043 * pow(x, 10)
+          + -2.7820892583909193e-048 * pow(x, 11)
+          +  9.4929814793314678e-054 * pow(x, 12);
+}
+
+
+
+//void eraseFrequency() {                         // when * pressed - erases entered frequency bottom of the screen
+//  EnteredFreqString = "";
+//  TuningFreqString = "";
+//  TFTscreen.stroke(0, 20, 30);
+//  TFTscreen.setTextSize(2);
+//  TFTscreen.text(enteredFreq, 50, 110);
+//}

 //void tuningDisplay() {
 //  for (i = 0; i < 4; i++) {
@@ -469,9 +511,9 @@
     case PRESSED:
       //    lcd.print(eKey);
       switch (eKey) {
-//        case '#':                           // submit frequesncy
-//          SetFrequency();
-//         break;
+        //        case '#':                           // submit frequesncy
+        //          SetFrequency();
+        //         break;
         case 'c':                           // "C1 Cold" motor move 5 step CCW
           incC1(-1);
           break;
@@ -490,23 +532,15 @@
         case 'U':                           // "L" motor move 100 step CW
           incL(+10.0);
           break;
-        case '*':                           // erase entered frequency
-          eraseFrequency();
-          break;
+///        case '*':                           // erase entered frequency
+//          eraseFrequency();
+//          break;
         case 'S':                           // erase entered frequency
           mechAutoTune();
           break;
         case 'K':                           // erase entered frequency
           mechFineTune();
           break;
-
-          //        case 'U':                           // calibrate both motors
-          //          mechCalibrate(channelC1);
-          //          break;
-          //        case 'D':                           // calibrate both motors
-          //          mechCalibrate(channelL);
-          //          break;
-
       }
   }
 }


Add battery low event and format value of volts

--- battery-monitor.ino
+++ battery-monitor.ino
@@ -1,17 +1,19 @@
 #define VCC 3273
 #define BATTERY_PIN A0
-#define R1 21440 // Resistor R1 Ohms
-#define R2 3242 // Resistor R2 Ohms
+#define R1 221200 // Resistor R1 Ohms
+#define R2 21440 // Resistor R2 Ohms
 #define CONNECT_WAIT_MILLIS 5000
-//#define SLEEP_SECS 15
-#define SLEEP_SECS 300
-//#define SLEEP_SECS 3600
+#define LOW_THRESHOLD 12000 // milliVolts
+//#define SLEEP_SECS 15 // 15 seconds
+//#define SLEEP_SECS 900 // 15 minutes
+#define SLEEP_SECS 3600 // 1 hour

 // Set manual mode so that if no network is available at startup, photon can go back to sleep
 SYSTEM_MODE(MANUAL);

 const float DIV_RATIO = (R1 + R2) / (float) R2;
 const char VOLTAGE_EVENT[11] = "carVoltage";
+const char LOW_EVENT[14] = "carLowVoltage";

 // set to true when the photon can sleep
 volatile bool canSleep = false;
@@ -35,11 +37,15 @@
 }

 void publishVoltageEvent() {
-    char mV[8];
-    getBatteryMilliVolts();
+    char eventData[5];
+    uint16_t milliVolts = getBatteryMilliVolts();
     delay(10);
-    sprintf(mV, "%d", getBatteryMilliVolts());
-    Particle.publish(VOLTAGE_EVENT, mV, 60, PRIVATE);
+    milliVolts = getBatteryMilliVolts();
+    sprintf(eventData, "%.1f", milliVolts / 1000.0);
+    if (milliVolts < LOW_THRESHOLD) {
+        Particle.publish(LOW_EVENT, eventData, 60, PRIVATE);
+    }
+    Particle.publish(VOLTAGE_EVENT, eventData, 60, PRIVATE);
 }

 void waitForVoltageEvent() {


changed fan speed

changed fan speed

--- fujitsu_heatpump/fujitsu_ir/fujitsu_ir.ino
+++ fujitsu_heatpump/fujitsu_ir/fujitsu_ir.ino
@@ -37,13 +37,13 @@
       // MODE: MODE_AUTO, MODE_HEAT, MODE_COOL, MODE_DRY, MODE_FAN
       // FAN: FAN_AUTO, FAN_1, FAN_2, FAN_3, FAN_4
       digitalWrite(LED, HIGH);
-      heatpumpIR->send(irSender, POWER_ON, MODE_HEAT, FAN_AUTO, temp, VDIR_UP, HDIR_AUTO);
+      heatpumpIR->send(irSender, POWER_ON, MODE_HEAT, FAN_1, temp, VDIR_UP, HDIR_AUTO);
     }
     if (OnState == LOW && OffState == HIGH) {
       digitalWrite(LED, LOW);
-      heatpumpIR->send(irSender, POWER_OFF, MODE_HEAT, FAN_AUTO, temp, VDIR_UP, HDIR_AUTO);
+      heatpumpIR->send(irSender, POWER_OFF, MODE_HEAT, FAN_1, temp, VDIR_UP, HDIR_AUTO);
     }
     delay(10);
-  }
 }

+


whoops, accidentally made game run infinite

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -1,4 +1,4 @@
-/*
+w/*
  * arduboy-game, Modus Create 2016
 */

@@ -110,7 +110,7 @@

   // Loop to simulate a game that ends with score being
   // close to value of randomScore
-  while (true) {
+  while (score < randomScore)) {
     arduboy.clearDisplay();
     sprintf(textBuf, "SCORE %u", score);
     printText(textBuf, 0, 0, 1);