update

update

--- _05-two-ds18b20/_05-two-ds18b20.ino
+++ _05-two-ds18b20/_05-two-ds18b20.ino
@@ -59,8 +59,8 @@

 String clientName;

-  float tempCoutside ;
-  float tempCinside ;
+float tempCoutside ;
+float tempCinside ;

 int vdd;

@@ -73,7 +73,10 @@
   if (client.connect((char*) clientName.c_str())) {
     //
   } else {
-    goingToSleep();
+    if (DEBUG_PRINT) {
+      Serial.println("going to sleep / mqtt con fail");
+    }
+    //goingToSleep();
   }
   return client.connected();
 }
@@ -81,6 +84,7 @@
 void wifi_connect()
 {
   WiFiClient::setLocalPortStart(micros() + vdd);
+  //wifi_set_phy_mode(PHY_MODE_11B);
   wifi_set_phy_mode(PHY_MODE_11N);
   system_phy_set_rfoption(1);
   wifi_set_channel(channel);
@@ -96,11 +100,19 @@

     int Attempt = 0;
     while (WiFi.status() != WL_CONNECTED) {
+      if (DEBUG_PRINT) {
+        Serial.print(". ");
+        Serial.print(Attempt);
+      }
       delay(100);
       Attempt++;
       if (Attempt == 150)
       {
-        goingToSleep();
+        if (DEBUG_PRINT) {
+          Serial.println("going to sleep / wifi con fail");
+        }
+        //goingToSleep();
+        return;
       }
     }

@@ -115,6 +127,9 @@
   // start serial port
   if (DEBUG_PRINT) {
     Serial.begin(115200);
+    Serial.println("");
+    Serial.println("");
+    Serial.println("---");
   }
   delay(10);
   vdd = ESP.getVcc();
@@ -123,21 +138,7 @@
   delay(10);
   pinMode(dsout, OUTPUT);
   digitalWrite(dsout, HIGH);
-  delay(10);
-
-  sensors.begin();
-  if (!sensors.getAddress(insideThermometer, 0)) {
-    goingToSleep();
-  }
-  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
-  sensors.requestTemperatures();
-  tempCoutside = tempCinside = sensors.getTempC(insideThermometer);
-
-  digitalWrite(dsout, LOW);
-
-  if ( isnan(tempCinside) || isnan(tempCoutside) || isnan(vdd) ) {
-    goingToSleep();
-  }
+  delay(20);

   //
   wifi_connect();
@@ -152,6 +153,27 @@

   lastReconnectAttempt = 0;
   reconnect();
+
+  sensors.begin();
+  if (!sensors.getAddress(insideThermometer, 0)) {
+    if (DEBUG_PRINT) {
+      Serial.println("going to sleep / sensor fail");
+    }
+    goingToSleep();
+  }
+  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
+  sensors.requestTemperatures();
+  tempCoutside = tempCinside = sensors.getTempC(insideThermometer);
+
+  digitalWrite(dsout, LOW);
+
+  if ( isnan(tempCinside) || isnan(tempCoutside) || isnan(vdd) ) {
+    if (DEBUG_PRINT) {
+      Serial.println("going to sleep / sensor value nan");
+    }
+    goingToSleep();
+  }
+
 }

 void loop(void)
@@ -179,20 +201,20 @@
   payload += ",\"totalmillis\":";
   payload += (millis() - startMills) ;
   payload += ",\"wifiMills\":";
-  payload += wifiMills ;
+  payload += wifiMills ;
   payload += "}";

   if (sendmqttMsg(topic, payload)) {
-      if (DEBUG_PRINT) {
-        Serial.print("payload pub  ----> ");
-        Serial.println(millis() - startMills);
-      }
-      goingToSleep();
-  }
+    if (DEBUG_PRINT) {
+      Serial.print("payload pub  ----> ");
+      Serial.println(millis() - startMills);
+    }
+    goingToSleep();
+  }

   if ((millis() - startMills) > 15000) {
     if (DEBUG_PRINT) {
-      Serial.println("going to sleep with fail");
+      Serial.println("going to sleep with fail / long exe");
     }
     goingToSleep();
   }
@@ -202,13 +224,16 @@

 void goingToSleep()
 {
-  ESP.deepSleep(300000000);
+  if (DEBUG_PRINT) {
+    ESP.deepSleep(20000000);
+  } else {
+    ESP.deepSleep(300000000);
+  }
   delay(250);
 }

 boolean sendmqttMsg(char* topictosend, String payload)
 {
-
   if (client.connected()) {
     if (DEBUG_PRINT) {
       Serial.print("Sending payload: ");


writing to serial after connected

writing to serial after connected

--- Arduino/Bumblebee.ino
+++ Arduino/Bumblebee.ino
@@ -29,9 +29,10 @@
 	//  initialise things for the motor shield
 	//  do whatever else needs doing

-		Serial.println("Serial connected!");
 	}

+	Serial.println("Serial connected!");
+
 	AFMS.begin();
 }


arduino.ino: more whitespaces zealotism

arduino.ino: more whitespaces zealotism

--- arduino.ino
+++ arduino.ino
@@ -159,7 +159,7 @@
     else
       n = 0;
     if (n == 4 || i == DIM_BUFFER)
-      continua=0;
+      continua = 0;
     i++;
   }


Started adding the timer features.

Started adding the timer features.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -130,6 +130,7 @@
   float value;
   int is_timer_on;
   float timer_value;
+  unsigned long timer_start_time;
   int damping;
   int prev_damping;
   boolean connections[TOTAL_NUM_OF_PINS];
@@ -665,6 +666,7 @@

     g_aPins[i].is_timer_on = false;
     g_aPins[i].timer_value = 0.0;
+    g_aPins[i].timer_start_time = 0;
     g_aPins[i].damping = 0;
     g_aPins[i].prev_damping = 0;

@@ -734,10 +736,39 @@
   {
     if( !g_aPins[i].is_input ) // Process output pins
     {
-      if( g_aPins[i].is_analog ) // Process analog pins
-        analogWrite(i, getTotalPinValue(i)*ANALOG_OUT_MAX_VALUE );
+      if( g_aPins[i].is_analog ) // Process analog pins
+      {
+        if( g_aPins[i].is_timer_on ) // Process timer
+        {
+          Serial.print("Pin ");Serial.print(i);Serial.print(" timer ON");
+          Serial.print(" Start Time: ");Serial.println(g_aPins[i].timer_start_time);
+          if( (millis() - g_aPins[i].timer_start_time) >= g_aPins[i].timer_value*1000 ) // Timer expired
+          {
+            Serial.println("EXPIRED...!!!");
+            analogWrite(i, 0.0);
+          }
+          else
+          {
+            analogWrite(i, getTotalPinValue(i)*ANALOG_OUT_MAX_VALUE );
+          }
+        }
+        else // Timer is off
+        {
+          //Serial.print("Pin ");Serial.print(i);Serial.println(" timer OFF");
+          analogWrite(i, getTotalPinValue(i)*ANALOG_OUT_MAX_VALUE );
+        }
+      }
       else // Process digital pins
-        digitalWrite(i, getTotalPinValue(i) );
+      {
+        if( g_aPins[i].is_timer_on ) // Process timer
+        {
+          digitalWrite(i, getTotalPinValue(i) );
+        }
+        else
+        {
+          digitalWrite(i, getTotalPinValue(i) );
+        }
+      }
     }
   }
 }
@@ -1152,7 +1183,11 @@

       aJsonObject *poIsTimerOn = aJson.getObjectItem(poPinVals, "is_timer_on");
       if (poIsTimerOn)
-        g_aPins[i].is_timer_on = poIsTimerOn->valuebool;
+      {
+        g_aPins[i].is_timer_on = poIsTimerOn->valuebool;
+        if(g_aPins[i].is_timer_on)
+          g_aPins[i].timer_start_time = millis();
+      }

       aJsonObject *poTimerValue = aJson.getObjectItem(poPinVals, "timer_value");
       if (poTimerValue)


this code works

this code works

--- discont/Motor_Shield/MotorShield/MotorShield.ino
+++ discont/Motor_Shield/MotorShield/MotorShield.ino
@@ -2,12 +2,11 @@
 const int encoderRightData2 = 5;
 const int encoderLeftData1 = 2;
 const int encoderLeftData2 = 4;
-const int rightForwardSpeed = 7; //BLi
+const int rightForwardSpeed = 11; //BLi
 const int rightBackwardSpeed = 6; //HLi
 const int rightDisable = 8;
 const int leftForwardSpeed = 10;
 const int leftBackwardSpeed = 9;
-const int leftDisable = 11;

 volatile int tickDataRight = 0;
 volatile int tickDataLeft = 0;
@@ -79,7 +78,6 @@
   pinMode(rightDisable, OUTPUT);
   pinMode(leftForwardSpeed, OUTPUT);
   pinMode(leftBackwardSpeed, OUTPUT);
-  pinMode(leftDisable, OUTPUT);
   attachInterrupt(1, tickRight, CHANGE);
   attachInterrupt(0, tickLeft, CHANGE);

@@ -168,13 +166,13 @@
   if( abs(PWM_R) < 0 )
 	PWM_R = 0;

-  if(PWM_L < 0) {
+  /*if(PWM_L < 0) {
 	analogWrite(leftForwardSpeed, 0);
 	analogWrite(leftBackwardSpeed, -PWM_L);
   } else {
 	analogWrite(leftForwardSpeed, PWM_L);
 	analogWrite(leftBackwardSpeed, 0);
-  }
+  }*/

   /*if(PWM_R < 0) {
 	analogWrite(rightForwardSpeed, 0);
@@ -183,8 +181,11 @@
 	analogWrite(rightForwardSpeed, 255);
 	analogWrite(rightBackwardSpeed, 0);
   }*/
-  analogWrite(rightForwardSpeed, 100);
+
+  analogWrite(rightForwardSpeed, 255);
   analogWrite(rightBackwardSpeed, 0);
+  analogWrite(leftForwardSpeed, 255);
+  analogWrite(leftBackwardSpeed, 0);

   lastErrorL = ErrorL;
   lastErrorR = ErrorR;


Add external font test for GT30L32S4W (aka ER3304-1) chip.

--- examples/external-font-rom/external-font-rom.ino
+++ examples/external-font-rom/external-font-rom.ino
@@ -19,7 +19,7 @@

   delay(1000);

-  while (!Serial);
+  while (!Serial && (millis() < 5000));

   Serial.println("Initializing display...");

@@ -36,8 +36,8 @@

 void externalFontTestGT30L24T3Y()
 {
-  uint32_t starttime = millis();
-
+  tft.println("Test for GT30L24T3Y (aka ER3303-1)\n");
+
   tft.initExternalFontRom(0, rom);

   tft.selectExternalFont(RA8876_FONT_FAMILY_FIXED, RA8876_FONT_SIZE_16, RA8876_FONT_ENCODING_ASCII);
@@ -59,9 +59,65 @@
   tft.selectExternalFont(RA8876_FONT_FAMILY_ARIAL, RA8876_FONT_SIZE_24, RA8876_FONT_ENCODING_ASCII);
   tft.println("Arial 24.");
   showFont();
+}

-  uint32_t elapsedtime = millis() - starttime;
-  Serial.print("External font test took "); Serial.print(elapsedtime); Serial.println(" ms");
+void externalFontTestGT30L32S4W()
+{
+  tft.println("Test for GT30L32S4W (aka ER3304-1)\n");
+
+  int y = tft.getCursorY();
+
+  tft.initExternalFontRom(0, rom);
+
+  // --- Fixed
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_FIXED, RA8876_FONT_SIZE_16, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Fixed 8x16.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_FIXED, RA8876_FONT_SIZE_24, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Fixed 12x24.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_FIXED, RA8876_FONT_SIZE_32, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Fixed 16x32.");
+  showFont();
+
+  delay(2000);
+  tft.fillRect(0, y, tft.getWidth(), tft.getHeight(), 0);
+  tft.setCursor(0, y);
+
+  // --- Arial
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_ARIAL, RA8876_FONT_SIZE_16, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Arial 16.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_ARIAL, RA8876_FONT_SIZE_24, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Arial 24.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_ARIAL, RA8876_FONT_SIZE_32, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Arial 32.");
+  showFont();
+
+  delay(2000);
+  tft.fillRect(0, y, tft.getWidth(), tft.getHeight(), 0);
+  tft.setCursor(0, y);
+
+  // --- Times
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_TIMES, RA8876_FONT_SIZE_16, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Times 16.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_TIMES, RA8876_FONT_SIZE_24, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Times 24.");
+  showFont();
+
+  tft.selectExternalFont(RA8876_FONT_FAMILY_TIMES, RA8876_FONT_SIZE_32, RA8876_FONT_ENCODING_ASCII);
+  tft.println("Times 32.");
+  showFont();
 }

 void showFont()
@@ -81,13 +137,17 @@
   tft.selectInternalFont(RA8876_FONT_SIZE_32, RA8876_FONT_ENCODING_8859_1);
   tft.println("External font test\n");

-  if (rom == RA8876_FONT_ROM_GT30L24T3Y)
+  switch (rom)
   {
-    externalFontTestGT30L24T3Y();
-  }
-  else
-  {
-    tft.println("Sorry, no test yet for that font ROM chip.\n");
+    case RA8876_FONT_ROM_GT30L24T3Y:
+      externalFontTestGT30L24T3Y();
+      break;
+    case RA8876_FONT_ROM_GT30L32S4W:
+      externalFontTestGT30L32S4W();
+      break;
+    default:
+      tft.println("Sorry, no test yet for that font ROM chip.\n");
+      break;
   }

   delay(5000);


Default strip color changes when command 0x50 used.

--- arduino/StandardFirmataChipKITSSPPII/StandardFirmataChipKITSSPPII.ino
+++ arduino/StandardFirmataChipKITSSPPII/StandardFirmataChipKITSSPPII.ino
@@ -31,8 +31,11 @@

 #define NUMPIXELS 30 // Number of LEDs in strip
-#define DATAPIN    4
-#define CLOCKPIN   5
+#define DATAPIN    27
+#define CLOCKPIN   29
+#define RED  0xFF0000
+#define GREEN  0x00FF00
+#define BLUE  0x0000FF

 #define I2C_WRITE                   B00000000
 #define I2C_READ                    B00001000
@@ -51,6 +54,8 @@
  * GLOBAL VARIABLES
  *============================================================================*/
 /* apa102c rgb led strip */
+uint32_t frame[NUMPIXELS];
+uint32_t colors[3] = {RED, GREEN, BLUE };
 Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

@@ -230,6 +235,21 @@
   if (TOTAL_PORTS > 15 && reportPINs[15]) outputPort(15, readPort(15, portConfigInputs[15]), false);
 }

+//----------------------------------
+/*
+ * contact DOTSTAR strip
+ */
+void dotstarHello() {
+ strip.clear();
+  for (int ii = 0; ii < NUMPIXELS; ii++) {
+    frame[ii] = BLUE; //initialize all to BLUE
+    strip.setPixelColor(ii, frame[ii]);
+  }
+  strip.show();
+
+}
+
+
 // -----------------------------------------------------------------------------
 /* Sets a pin that is in Servo mode to a particular output value
  * (i.e. pulse width). Different boards may have different ways of
@@ -310,7 +330,6 @@
           attachServo(pin, -1, -1);
         }
       }
-      break;
     case I2C:
       if (IS_PIN_I2C(pin)) {
         // mark the pin as i2c
@@ -422,6 +441,9 @@
   unsigned int delayTime;

   switch (command) {
+    case 0x50:
+        dotstarHello();
+    break;
     case I2C_REQUEST:
       mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
       if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
@@ -685,6 +707,8 @@

 void setup()
 {
+
+
   Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

   Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
@@ -703,6 +727,14 @@
   Firmata.begin(57600);
 #endif
   systemResetCallback();  // reset to default config
+
+
+ strip.clear();
+  for (int ii = 0; ii < NUMPIXELS; ii++) {
+    frame[ii] = GREEN; //initialize all to BLUE
+    strip.setPixelColor(ii, frame[ii]);
+  }
+  strip.show();
 }

 /*==============================================================================


Added variables appId, lightStatus, waterPumpStatus, waterLevelStatus

--- plantstation.ino
+++ plantstation.ino
@@ -1,11 +1,9 @@
+#include "ApiClient.h"
+#include "Bridge.h"
+#include "Console.h"
 #include "DHT.h"
+#include "KeenClient.h"
 #include "OneWire.h"
-#include "Console.h"
-
-#include "Bridge.h"
-#include "ApiClient.h"
-#include "KeenClient.h"
-
 #include "params.h"

 // hardware
@@ -36,6 +34,11 @@

 int lightResistor;

+String appId = "Plant01";
+boolean lightStatus = false;
+String waterLevelStatus = "OK";
+boolean waterPumpStatus = false;
+
 void setup() {
   Serial.begin(9600);
   Serial.println("PlantStation is warming up\n");
@@ -126,7 +129,9 @@

 void sendToKeen(struct my_airmeasurement, int lightResistor, struct my_soilmeasurement) {
   String my_output = "{";
-  my_output += "\"HumidityPercent\":";
+  my_output += "\"AppId\":\"";
+  my_output += appId;
+  my_output += "\",\"HumidityPercent\":";
   my_output += am.humidityAir;
   my_output += ",\"AirTemperatureCelcius\":";
   my_output += am.tempAirC;
@@ -140,6 +145,12 @@
   my_output += sm.tempSoilC;
   my_output += ",\"ProbeTemperatureFahrenheit\":";
   my_output += sm.tempSoilF;
+  my_output += ",\"WaterLevelStatus\":\"";
+  my_output += waterLevelStatus;
+  my_output += "\",\"LightStatus\":";
+  my_output += lightStatus;
+  my_output += ",\"WaterPumptStatus\":";
+  my_output += waterPumpStatus;
   my_output += "}";

   keen.setApiVersion(F("3.0"));
@@ -157,11 +168,14 @@
   }
   Console.println();

-//  Console.flush();
+  Console.flush();
 }

 void outputEvent(struct my_airmeasurement, int lightResistor, struct my_soilmeasurement) {
-  String my_output = "HumidityPercent:";
+  String my_output = "";
+  my_output += "AppId:";
+  my_output += appId;
+  my_output += ";HumidityPercent:";
   my_output += am.humidityAir;
   my_output += ";AirTemperatureCelcius:";
   my_output += am.tempAirC;
@@ -175,6 +189,12 @@
   my_output += sm.tempSoilC;
   my_output += ";ProbeTemperatureFahrenheit:";
   my_output += sm.tempSoilF;
+  my_output += ";WaterLevelStatus:";
+  my_output += waterLevelStatus;
+  my_output += ";LightStatus:";
+  my_output += lightStatus;
+  my_output += ";WaterPumptStatus:";
+  my_output += waterPumpStatus;

   Serial.println(my_output);
   Console.println(my_output);


Add measurement of print floating-point number.

--- examples/Benchmarks/CosaBenchmarkUART/CosaBenchmarkUART.ino
+++ examples/Benchmarks/CosaBenchmarkUART/CosaBenchmarkUART.ino
@@ -65,10 +65,12 @@
   MEASURE("two character string:", 1) trace << PSTR("10") << endl;
   MEASURE("integer:", 1) trace << 10 << endl;
   MEASURE("long integer:", 1) trace << 10L << endl;
+  MEASURE("floating point:", 1) trace << 10.0 << endl;
   MEASURE("three characters:", 1) trace << '1' << '0' << '0' << endl;
   MEASURE("three character string:", 1) trace << PSTR("100") << endl;
   MEASURE("integer:", 1) trace << 100 << endl;
   MEASURE("long integer:", 1) trace << 100L << endl;
+  MEASURE("floating point:", 1) trace << 100.0 << endl;

   // Measure time to print max integer << endl; 8, 16 and 32 bit.
   MEASURE("max int8_t:", 1) trace << (int8_t) 0x7f << endl;


Delete _1_2_3_um_T1.ino

Delete _1_2_3_um_T1.ino

--- Code_V1/_1_2_3_um_T1.ino
+++ Code_V1/_1_2_3_um_T1.ino
@@ -1,267 +0,0 @@
-#include "pitches.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-// ----- Variablen -----
-
-const int PLredPin = 9;     // PIN'S für playerLED: links
-const int PLgreenPin = 10;  //                      dritte von links
-const int PLbluePin = 11;   //                      rechts
-const int GAMEredPin = 5;   // PIN'S für GAMELED:   links
-const int GAMEgreenPin = 6; //                      dritte von links
-const int GAMEbluePin = 7;  //                      rechts
-const int speaker = 8;      // 8-ohm speaker
-const int irSense = A0;     // IR-Entfernungssensor analog pin A0
-
-// --------- Spielvariablen -----------
-
-bool Stop = true;           // Spiellampe = Rot
-bool playerOne = true;      // Spieler im Spiel
-int startbedingung = 0;     // Tickt 5 mal also 5 Messungen
-int testwert = 0;           // Wert zum ermitteln der Startposition
-int preval = 0;             // erster Messwert Sensor
-int val = 0;                // zweiter Messwert Sensor
-int calc = 0;               // Betrag der Differenz der beiden oberen Variablen
-
-enum zustand {Start, Play, Win, Lose};  // Zustand wo im Spiel man ist
-enum zustand gamecheck = Start;
-
-// ----- IR Sensor -----
-
-int distance = 0;           // Distanzvariable
-int averaging = 0;          // Durchschnittsdistanz
-
-
-
-
-
-
-// ----------------------------------------- SETUP ------------------------------------------------
-void setup() {
-    Serial.begin(9600); // Serial Monitor window
-    // ----- Pins für gameLED -------
-    pinMode(5, OUTPUT);
-    pinMode(6, OUTPUT);
-    pinMode(7, OUTPUT);
-    // ----- Pins für playerLED -----
-    pinMode(9, OUTPUT);
-    pinMode(10, OUTPUT);
-    pinMode(11, OUTPUT);
-    // ----- Systemstartmelodie -----
-    systemstartMelodie();
-    playerLedColor(0, 0, 255);
-}
-
-// ----------------------------------------- LOOP ------------------------------------------------
-void loop() {
-    // ----------------------------------------- Startbedingung prüfen ------------------------------------------------
-
-
-    if ( gamecheck == Win ){
-        gameLedColor(255, 200, 200);
-        siegMelodie();
-        delay(3000);                                            // ÜBERGANGSLÖSUNG
-        gamecheck = Start;                                      // ÜBERGANGSLÖSUNG --> 3s warten und neustart
-    }
-
-    while (gamecheck == Start) {
-       checkStart();                                            // Funktion Startbedingung prüfen
-    }
-
-    //  ---------------- Startbedingung erfüllt -> Spiel geht los! -----------------------------------------
-    while (gamecheck == Play){
-        checkGame();                                            // Funktion Verhalten im Spiel
-
-    }
-    // --- Spieler hat sich bei Rot bewegt ---
-    if (gamecheck == Lose) {
-        playerLedColor(255, 0, 0);                          // Spieler ROT
-        verlorenMelodie();
-        gamecheck = Start;
-    }
-}
-
-// ----------------------------------------------- Funktionen ---------------------------------------------------------
-
-void checkStart() {
-    gameLedColor(0, 0, 255);                                // gameLED auf Blau stellen
-    testwert = irRead() ;
-    if(testwert > 600 && testwert < 630) {                  // Bei 5 erfolgreichen Tests gamecheck = Play
-        Serial.print("Start Test -- Positiv: ");
-        Serial.println(testwert);
-        startbedingung++;
-    }
-    else {
-        Serial.print("Start Test -- Negativ: ");            // Bei negativem Test startbedingung == 0
-        Serial.println(testwert);
-        startbedingung = 0;
-    }
-
-    if ( startbedingung == 5){                              // Startbedingung erfüllt
-        delay(2000);                                        // 2 Sekunden warten
-        startMelodie();                                     // Startmelodie
-        playerLedColor(0, 255, 0);                          // Beide Lampen Grün
-        gameLedColor(0, 255, 0);
-        startbedingung = 0;
-        gamecheck = Play;
-        Stop = false;                                       // gameLED GRÜN
-    }
-}
-
-void checkGame() {
-    // --- Wenn große Lampe Grün ist ---
-    if ( Stop == false ) {
-        for (int j = 0; j<=randomTime()*2; j++) {
-            preval = irRead() ;
-            Serial.print("preval(GRÜN): ");
-            Serial.println(preval);
-            if ( preval > 865 ) {
-                gamecheck = Win;
-                break;
-            }
-        }
-        if (gamecheck == Play) changeLight();               // Rot werden
-    }
-
-    // --- Wenn große Lampe rot ist ---
-    if ( Stop == true ) {
-        preval = irRead();                                  // 1 Messung zum vergleich ob sich bewegt wurde in Rotphase
-        Serial.print("Preval: ");
-        Serial.println(preval);
-        for (int k=0; k<=randomTime()*4; k++ ) {            // 4x die Sekunde neue Messung
-            val = irRead() ;
-            Serial.print("Val: ");
-            Serial.println(val);
-            calc = abs((val-preval));                       // Wird mit erster Messung verglichen
-            Serial.print("Calc: ");
-            Serial.println(calc);
-            if ( calc > 10 ) {
-                gamecheck = Lose;                           // Spieler aus dem Spiel -> Zurück an Startbedingung
-                break;
-            }
-        }
-        if (gamecheck == Play) changeLight();               // Ist Spieler noch im Spiel -> Grün werden
-
-        }
-}
-
-
-
-
-
-
-/* Durchschnitt aus den letzten 5 Messwerten (um Messungenauigkeiten vorzubeugen)
- * Standardwerte: del = 50, counts = 5
- * !!!!EIN IRREAD DAUERT ALSO 250 MS!!!! */
-
-int irRead() {
-    averaging = 0;
-    for (int i=0; i<=5; i++) { // sampling of [counts] readings from sensor
-        distance = analogRead(irSense);
-        averaging = averaging + distance;
-        delay(50);     //  Wait 55 ms between each read
-                        //  According to datasheet time between each read
-                        //  is -38ms +/- 10ms. Waiting 55 ms assures each
-                        //  read is from a different sample
-    }
-    distance = averaging / 5;  // Average out readings
-    return(distance);               // Return value
-}
-
-// playerLED in bestimmter Farbe leuchten lassen (RGB)
-void playerLedColor(int a, int b, int c) {
-    analogWrite(PLredPin, a);
-    analogWrite(PLgreenPin, b);
-    analogWrite(PLbluePin, c);
-}
-
-//gameLED in bestimmter Farbe leuchten lassen (RGB)
-void gameLedColor(int a, int b, int c) {
-    analogWrite(GAMEredPin, a);
-    analogWrite(GAMEgreenPin, b);
-    analogWrite(GAMEbluePin, c);
-}
-
-/* gibt je nachdem ob Rot- oder Grünphase ist eine zufällige Zeit aus
- * ROT: zwischen 1-10s
- * GRÜN: zwischen 1-3s */
-const int randomTime(){
-    int randomtime = 0;
-    if (Stop == true) {
-        randomtime = rand() %10 + 1;
-    }
-    else {
-        randomtime = rand() %4 + 1;
-    }
-    return(randomtime);
-}
-
-// Wechselt die Farbe der gameLED und den bool Stop
-void changeLight() {
-    if(Stop == false){
-        Stop = true;
-        gameLedColor(255, 0, 0);
-    }
-    else {
-        Stop = false;
-        gameLedColor(0, 255, 0);
-    }
-}
-
-// ------------------------------------------- Melodien ---------------------------------------------------------------
-void systemstartMelodie() {
-    // ----- Noten für Melodie und Länge der Noten -----
-    int melody[] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
-    int noteDurations[] = {4, 8, 8, 4, 4, 4, 4, 4};
-
-    for (int thisNote = 0; thisNote <= 8; thisNote++){
-            int noteDuration = 1000 / noteDurations[thisNote];
-            tone(speaker, melody[thisNote], noteDuration);
-            int pauseBetweenNotes = noteDuration * 1.30;
-            delay(pauseBetweenNotes);
-            noTone(speaker);
-    }
-}
-
-void startMelodie() {
-// ----- Noten für Melodie und Länge der Noten -----
-    int melody[] = {NOTE_A3, NOTE_A3, NOTE_A3, NOTE_C4};
-    int noteDurations[] = {4, 4, 4, 4};
-
-    for (int thisNote = 0; thisNote <= 4; thisNote++){
-                int noteDuration = 1000 / noteDurations[thisNote];
-                tone(speaker, melody[thisNote], noteDuration);
-                int pauseBetweenNotes = noteDuration * 1.30;
-                delay(pauseBetweenNotes);
-                noTone(speaker);
-    }
-}
-
-void verlorenMelodie() {
-        // ----- Noten für Melodie und Länge der Noten -----
-        int melody[] = {NOTE_G3, NOTE_D4, 0, NOTE_D4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_G3, NOTE_E3, 0, NOTE_E3, NOTE_C3};
-        int noteDurations[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
-
-
-        for (int thisNote = 0; thisNote <= 12; thisNote++){
-                int noteDuration = 1000 / noteDurations[thisNote];
-                tone(speaker, melody[thisNote], noteDuration);
-                int pauseBetweenNotes = noteDuration * 1.30;
-                delay(pauseBetweenNotes);
-                noTone(speaker);
-        }
-}
-
-void siegMelodie() {
-// ----- Noten für Melodie und Länge der Noten -----
-    int melody[] = {NOTE_C4, NOTE_E4, NOTE_G4, 0, NOTE_C5, NOTE_G4, NOTE_C5};
-    int noteDurations[] = {4, 4, 4, 4, 2, 4, 2};
-
-    for (int thisNote = 0; thisNote <= 7; thisNote++){
-                int noteDuration = 1000 / noteDurations[thisNote];
-                tone(speaker, melody[thisNote], noteDuration);
-                int pauseBetweenNotes = noteDuration * 1.30;
-                delay(pauseBetweenNotes);
-                noTone(speaker);
-    }
-}


initialise_eeprom

--- _09_ir_tx_rx/_09_ir_tx_rx.ino
+++ _09_ir_tx_rx/_09_ir_tx_rx.ino
@@ -1,19 +1,3 @@
-/*
-A4, A5 - I2C
-
-A2 - SETUP / IN
-A0 - ENTER / IN
-D12 - DOWN / IN
-D11 - UP / IN
-D10 - IR / IN
-D9 - BUZZER /OUT
-D4 - TEMP(DS18B20) /IN
-D3 - IR / OUT
-D2 - PIR /IN
-*/
-
-
-

 #include <Wire.h>
 #include <OneWire.h>
@@ -21,18 +5,39 @@
 #include <LiquidCrystal_I2C.h>
 #include <IRremote.h>

+// eeprom
+#include <avr/eeprom.h>
+#define eeprom_read_to(dst_p, eeprom_field, dst_size) eeprom_read_block(dst_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(dst_size, sizeof((__eeprom_data*)0)->eeprom_field))
+#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)); }
+
+// Change this any time the EEPROM content changes
+const long magic_number = 0x0326;
+
+struct __eeprom_data {
+  long magic;
+  boolean pwrSrc;     // True : connected to TV, False : usb powered
+  boolean wrkMode;    // True : thermostat + TV, False : thermostat
+  boolean startMode;  // if wrkMode == True, True : run TV on/off or channel change, False : do nothing indicating a sign on the lcd
+  boolean beepMode;   // True : beep on
+  boolean offMode;    // True : TV on/off, False : channel change
+  int channelGap;     // 1 ~ 5
+  int tvOnTime;       // 30 ~ 120
+  int tvOffTime;      // 5 ~ 20
+};
+
 //
 int SETUP_IN_PIN = A2;
-//int ENTER_IN_PIN = A0;
-int ENTER_IN_PIN = 13;
+int WRK_MODE_IN_PIN = A0;
+/*
 int UP_IN_PIN    = 12;
 int DN_IN_PIN    = 11;
-
-//
+*/
+
 int IR_IN_PIN    = 10;
 int PIR_IN_PIN   = 2;
-
-int BZ_OU_PIN    =  9;
+int BZ_OU_PIN    = 9;

 // LCD
 LiquidCrystal_I2C lcd(0x27, 20, 4);
@@ -54,10 +59,13 @@
 DeviceAddress insideThermometer;

 //
-float tempCinside ;
+float tempCinside;
 long startMills;
-long tv_startMills;
-
+long tv_off_Mills;
+int setUpStatus;
+int wrkModeStatus;
+
+// lcd
 byte termometru[8] =
 {
   B00100,
@@ -73,36 +81,48 @@
 void setup()
 {

+  // start serial
+  Serial.begin (38400);
+  Serial.println("TV controller Starting");
+  delay(20);
+
+  // Timer start
+  startMills = millis();
+
   // lcd
   lcd.init();
   lcd.backlight();
   lcd.clear();
-  lcd.createChar(1, termometru);
-  lcd.setCursor(0, 0);
-  lcd.write(1);
-  // lcd
-
-  Serial.begin (38400);
-  Serial.println("TV controller Starting");
-  delay(20);
-
-  irrecv.enableIRIn(); // Start the receiver
-
-  startMills = millis();
+
+  // ir
+  irrecv.enableIRIn();

   // pin mode
-
   pinMode(SETUP_IN_PIN, INPUT_PULLUP);
-  pinMode(ENTER_IN_PIN, INPUT_PULLUP);
+  pinMode(WRK_MODE_IN_PIN, INPUT_PULLUP);
+  /*
   pinMode(DN_IN_PIN, INPUT_PULLUP);
   pinMode(UP_IN_PIN, INPUT_PULLUP);
+  */
   pinMode(PIR_IN_PIN, INPUT_PULLUP);

+  // buzzer
   pinMode(BZ_OU_PIN, OUTPUT);
   digitalWrite(BZ_OU_PIN, HIGH);

-
-  // temp
+  // read pin status
+  setUpStatus   = digitalRead(SETUP_IN_PIN);
+  wrkModeStatus = digitalRead(WRK_MODE_IN_PIN);
+
+  // initialize eeprom
+  long magic;
+  eeprom_read(magic, magic);
+  if ((magic != magic_number) || ( setUpStatus == 0 ) {
+     run_initialise_setup();
+  }
+
+
+  // temp sensor
   sensors.begin();
   if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
   sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
@@ -113,36 +133,47 @@
     Serial.println("Failed to read from sensor!");
     return;
   }
-  // temp
-
+
+  // lcd
+  lcd.createChar(1, termometru);
+  lcd.setCursor(0, 0);
+  lcd.write(1);
+
 }

 void loop()
 {
+
+
+
   /*
    *
     pinMode(SETUP_IN_PIN, INPUT_PULLUP);
-    pinMode(ENTER_IN_PIN, INPUT_PULLUP);
+    pinMode(WRK_MODE_IN_PIN, INPUT_PULLUP);
     pinMode(DN_IN_PIN, INPUT_PULLUP);
     pinMode(UP_IN_PIN, INPUT_PULLUP);
     pinMode(PIR_IN_PIN, INPUT_PULLUP);
    *
    */
   /*
-    int x = digitalRead(ENTER_IN_PIN);
+    int x = digitalRead(WRK_MODE_IN_PIN);
     Serial.println(x);
     //getdalastemp();
     //Serial.println(tempCinside);
     delay(1000);
   */

+/*
   decode_results results;

   if (irrecv.decode(&results)) {
     dumpInfo(&results);

   }
+*/
+
+

 }

@@ -185,3 +216,58 @@
 }

+void initialise_eeprom()
+{
+  /*
+  eeprom_write(0, first);
+  eeprom_write(0, second);
+  eeprom_write(magic_number, magic);
+  */
+}
+
+void run_initialise_setup() {
+
+  decode_results results;
+
+  lcd.clear();
+  lcd.setCursor(0, 0);
+  lcd.print('setup :');
+  lcd.setCursor(0, 1);
+  lcd.print('press any button');
+
+  while(irrecv.decode(&results) != 1 ) { }
+
+  lcd.setCursor(0, 0);
+  lcd.print('s');
+
+
+/*
+  lcd.setCursor(0, 0);
+
+  if ((magic != magic_number) || ( setUpStatus == 0 ) {
+
+
+  lcd.print('0');
+
+  boolean pwrSrc;     // True : connected to TV, False : usb powered
+  boolean wrkMode;    // True : thermostat + TV, False : thermostat
+  boolean startMode;  // if wrkMode == True, True : run TV on/off or channel change,
+                      // False : do nothing indicating a sign on the lcd
+  boolean beepMode;   // True : beep on
+  boolean offMode;    // True : TV on/off, False : channel change
+  int channelGap;     // 1 ~ 5
+  int tvOnTime;       // 30 ~ 120
+  int tvOffTime;      // 5 ~ 20
+
+
+  decode_results results;
+
+  if (irrecv.decode(&results)) {
+    dumpInfo(&results);
+
+  }
+
+ */
+  // initialise_eeprom();
+
+}


OSD finally quiet with logger active

OSD finally quiet with logger active

--- KISS_OSD/KISS_OSD.ino
+++ KISS_OSD/KISS_OSD.ino
@@ -218,16 +218,16 @@
 static uint16_t current = 0;
 static int8_t armed = 0;
 static int8_t idleTime = 0;
-static uint16_t LipoVoltage = 0;
-static uint16_t LipoMAH = 0;
+static int16_t LipoVoltage = 0;
+static int16_t LipoMAH = 0;
 static int16_t  previousMAH = 0;
 static int16_t totalMAH = 0;
-static uint16_t MaxAmps = 0;
-static uint16_t MaxC    = 0;
-static uint16_t MaxRPMs = 0;
-static uint16_t MaxWatt = 0;
-static uint16_t MaxTemp = 0;
-static uint16_t MinBat = 0;
+static int16_t MaxAmps = 0;
+static int16_t MaxC    = 0;
+static int16_t MaxRPMs = 0;
+static int16_t MaxWatt = 0;
+static int16_t MaxTemp = 0;
+static int16_t MinBat = 0;
 static int16_t motorKERPM[4] = {0,0,0,0};
 static int16_t maxKERPM[4] = {0,0,0,0};
 static int16_t motorCurrent[4] = {0,0,0,0};
@@ -465,7 +465,8 @@
               motorCurrent[i] < 0 || motorCurrent[i] > 10000 ||
               motorKERPM[i] < 0 || motorKERPM[i] > 500 ||
               ESCVoltage[i] < 0 || ESCVoltage[i] > 10000 ||
-              ESCmAh[i] < 0)
+              ESCmAh[i] < 0 ||
+              AuxChanVals[i] < 0)
            {
              return false;
            }


Facilitate how to define which robot is being configured, on .ino now.

--- firmware/robot_firmware/robot_firmware.ino
+++ firmware/robot_firmware/robot_firmware.ino
@@ -1,3 +1,4 @@
+#define robot_number 1 //Define qual robô esta sendo configurado
 #include <pins.h>
 #include <radio.h>
 #include <motor.h>


Aperfeiçoamento de código

Aperfeiçoamento de código

Modificação do blink dos dígitos para torná-los mais suaves e visuais

--- ArduWatchRaspSerial.ino
+++ ArduWatchRaspSerial.ino
@@ -1,22 +1,8 @@
 // Arquivo upado na placa Arduino

 int portas[8] = {5, 6, 7, 8, 9, 10, 11, 12};
-int digito0[8] = {1, 1, 1, 0, 1, 1, 1, 0};
-int digito1[8] = {1, 0, 0, 0, 0, 0, 1, 0};
-int digito2[8] = {1, 1, 0, 1, 1, 1, 0, 0};
-int digito3[8] = {1, 1, 0, 1, 0, 1, 1, 0};
-int digito4[8] = {1, 0, 1, 1, 0, 0, 1, 0};
-int digito5[8] = {0, 1, 1, 1, 0, 1, 1, 0};
-int digito6[8] = {0, 1, 1, 1, 1, 1, 1, 0};
-int digito7[8] = {1, 1, 0, 0, 0, 0, 1, 0};
-int digito8[8] = {1, 1, 1, 1, 1, 1, 1, 0};
-int digito9[8] = {1, 1, 1, 1, 0, 0, 1, 0};
-int ponto[8] = {0, 0, 0, 0, 0, 0, 0, 1};
-
 String mensagem = "";
 char caractere;
-int blink_ponto = 250;
-int blink_digito = 100;

 void setup() {
   Serial.begin(9600);
@@ -30,14 +16,16 @@
     mensagem = Serial.readString();
     for (int i = 0; i < 4; i++) {
       if (i == 2) {
-        for (int i = 0; i < 8; i++) {
-          digitalWrite(portas[i], ponto[i]);
-        }
-        delay(blink_ponto);
+        digitalWrite(12, HIGH);
+        delay(75);
+        digitalWrite(12, LOW);
+        delay(75);
+        digitalWrite(12, HIGH);
+        delay(100);
         for (int i = 0; i < 8; i++) {
           digitalWrite(portas[i], LOW);
         }
-        delay(blink_ponto);
+        delay(125);
       }
       caractere = mensagem[i];
       Serial.println(caractere);
@@ -49,104 +37,156 @@
 void switch_blink() {
   switch (caractere) {
     case '0':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito0[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(5, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(125);
+      digitalWrite(10, HIGH);
+      delay(125);
+      digitalWrite(9, HIGH);
+      delay(125);
+      digitalWrite(7, HIGH);
+      delay(125);
+      digitalWrite(6, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '1':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito1[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(5, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '2':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito2[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(6, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      delay(125);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(9, HIGH);
+      delay(125);
+      digitalWrite(10, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '3':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito3[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      digitalWrite(11, HIGH);
+      delay(125);
+      digitalWrite(6, HIGH);
+      digitalWrite(10, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '4':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito4[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(7, HIGH);
+      delay(125);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      digitalWrite(11, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '5':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito5[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(6, HIGH);
+      delay(125);
+      digitalWrite(7, HIGH);
+      delay(125);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(125);
+      digitalWrite(10, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '6':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito6[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(6, HIGH);
+      delay(125);
+      digitalWrite(7, HIGH);
+      delay(125);
+      digitalWrite(9, HIGH);
+      delay(125);
+      digitalWrite(10, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(125);
+      digitalWrite(8, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '7':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito7[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(6, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '8':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito8[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      digitalWrite(9, HIGH);
+      delay(125);
+      digitalWrite(6, HIGH);
+      digitalWrite(10, HIGH);
+      delay(125);
+      digitalWrite(7, HIGH);
+      digitalWrite(11, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
     case '9':
-      for (int i = 0; i < 8; i++) {
-        digitalWrite(portas[i], digito9[i]);
-      }
-      delay(blink_digito);
+      digitalWrite(8, HIGH);
+      delay(125);
+      digitalWrite(7, HIGH);
+      delay(125);
+      digitalWrite(6, HIGH);
+      delay(125);
+      digitalWrite(5, HIGH);
+      delay(125);
+      digitalWrite(11, HIGH);
+      delay(125);
+      digitalWrite(10, HIGH);
+      delay(250);
       for (int i = 0; i < 8; i++) {
         digitalWrite(portas[i], LOW);
       }
-      delay(blink_digito);
+      delay(125);
       break;
   }
 }


Revert removal of Mic input pointer

Revert removal of Mic input pointer

--- NLMS_AEC/NLMS_AEC.ino
+++ NLMS_AEC/NLMS_AEC.ino
@@ -36,7 +36,7 @@
 void getBuffer1();
 void playData();
 void displayData();
-void NLMS_AEC(int16_t *x);
+void NLMS_AEC(int16_t *Mic, int16_t *x);

 // GUItool: begin automatically generated code
 AudioInputI2S            Mic;           //microphone
@@ -126,12 +126,12 @@
         //read one 128 block of samples and copy it into array
         memcpy((byte*)pablock+(256*(x-1)),Memory.readBuffer(),256);
         Memory.freeBuffer(); // free buffer memory
-//        NLMS_AEC(pablock);
+//        NLMS_AEC(pablock, pablock);
 //        playData(Perror,0); // play 128 block from buffered array
         l = 1; // set n to 1 to get out of while loop
       }//end if
     }//end while
-    NLMS_AEC(pablock);
+    NLMS_AEC(pablock, pablock);
     playData(Perror,0); // play 128 block from buffered array
     l = 0;
    Memory.clear(); // clear all audio memory
@@ -144,7 +144,7 @@
 // NMLS algorithm
 // inputs are Mic Signal, far end signal and index of n-1 block wher n is the current block itteration
 // previous block data is used to modify current block data samples
-void NLMS_AEC(int16_t *x)
+void NLMS_AEC(int16_t *Mic, int16_t *x)
 {
   int16_t yhat = 0;
   int64_t xtdl = 0;
@@ -175,7 +175,7 @@
     } while (ww < wend);
     yhat = yhat64 / 32768;

-    error[h] = x[gg+h]-yhat;
+    error[h] = Mic[gg+h]-yhat;
     xtdl = xtdl + psi;
     mu0 = (67108864*mu)/xtdl;


fix example

fix example

--- examples/Widgets/Twitter/Twitter.ino
+++ examples/Widgets/Twitter/Twitter.ino
@@ -44,7 +44,7 @@
   }

   // Tweet immediately on startup
-  Blynk.tweet("My Arduino project is tweeting using @blynk_app and this is awesome!\n #arduino #IoT #blynk");
+  Blynk.tweet("My Arduino project is tweeting using @blynk_app and it’s awesome!\n #arduino #IoT #blynk");

   // Setup a function to be called every 10 minutes
   timer.setInterval(10L * 60000L, tweetUptime);


PID_test v0.3

PID_test v0.3

--- PID_test/PID_test.ino
+++ PID_test/PID_test.ino
@@ -13,12 +13,12 @@
 double whedia= 0.7;   // wheel diameter in m
 int CPR = 40;     // Encoder Count per Revolutions (double of holes using up & down interrupt)
 int period=200;   // sample timer period in ms
-double lv=0., rv=0.;// motor speed innumber tics per period
+double lv=0., rv=0., lvt=0., rvt=0. ;// motor speed innumber tics per period with two methods
 int ti=0;         // tic timer counter
 double lOut,rOut,lSet,rSet;   // PID output and demands
 double lkp=10,lki=0,lkd=0;     // Left wheel PID constants
 double rkp=10,rki=0,rkd=0;     // Right wheel PID constants
-int kt=1000/period; // number of periods in 1sec
+int kt=period/1000; // number of periods in 1sec
 int rcurrenttime, rlasttime, lcurrenttime, llasttime;

 //PID(&Input, &Output, &Setpoint, Kp, Ki, Kd, Direction)
@@ -34,10 +34,13 @@
   lmc0=lmc;
   rv=(rmc-rmc0)*kt; //+1000./(millis() - rlasttime);    // rv right install velocity
   rmc0=rmc;
-
+  if(lv>0) lv = lvt;
+  if(rv>0) rv = rvt;
   ti+=1;                  // tic counter
   Serial.print("lv: ");
   Serial.print(lv);
+  Serial.print(" lvt: ");
+  Serial.print(lvt);
   lPID.Compute();
   Serial.print("rv: ");
   Serial.print(rv);
@@ -73,13 +76,13 @@
 void lencode() {          // GPIO ISR Interrupt service routines for encoder changes

   lcurrenttime = millis();
-  //lv = 1000./(lcurrenttime - llasttime);
+  lvt = 1000./(lcurrenttime - llasttime);
   llasttime = lcurrenttime;
   lmc=lmc+ldir;
 }
 void rencode(){
   rcurrenttime = millis();
-  //rv = 1000./(rcurrenttime - rlasttime);
+  rvt = 1000./(rcurrenttime - rlasttime);
   rlasttime = rcurrenttime;
   rmc=rmc+rdir;
 }


lcd: max out eta at 99:59

lcd: max out eta at 99:59

--- src/src.ino
+++ src/src.ino
@@ -154,6 +154,7 @@
   lcd.setCursor(8 * 18, 24);
   if (eta_time >= 0) {
     long secs = eta_time / 1000;
+    secs = min(99*60*60 + 59*60, secs);  // max at 99:59
     int hrs = secs / 60 / 60;
     int mins = secs / 60 % 60;
     snprintf(out, LINE_LEN, "%2d:%02d", hrs, mins);


ScanNetworks tries using WiFi.firmwareVersion() before .begin(), which hangs since the SimpleLink API isn't initialized.  Added WiFi.init() beforehand.

--- hardware/cc3200/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino
+++ hardware/cc3200/libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino
@@ -25,6 +25,7 @@
   //Initialize serial and wait for port to open:
   Serial.begin(115200);

+  WiFi.init();
   Serial.println(WiFi.firmwareVersion());

   // Print WiFi MAC address:


remove turnOff machine when finish

remove turnOff machine when finish

--- jarbas.ino
+++ jarbas.ino
@@ -25,12 +25,6 @@
   client.end();
 }

-void waitAndTurnOffCoffeeMachine() {
-  delay(10 * 60 * 1000); // Wait 10 minutes.
-  digitalWrite(RELAY, LOW); // Turn off.
-  turnOff = true;
-}
-
 void setup() {
   wifi.addAP(WIFI, PASSWORD);
   pinMode(RELAY, OUTPUT);
@@ -42,7 +36,7 @@

   if (!turnOff && coffeeIsReady && wifi.run() == WL_CONNECTED) {
     notifySlack();
-    waitAndTurnOffCoffeeMachine();
+    turnOff = true;
   }

   delay(1000);


Removed accidental #define ESP32

Removed accidental #define ESP32

--- HMTL_Module/HMTL_Module.ino
+++ HMTL_Module/HMTL_Module.ino
@@ -232,7 +232,6 @@
   }
 #endif

-#define ESP32
 #if defined(ESP32)
   if (true) { // TODO: Should any of this be put into the stored config?
     /* Startup a connection and add a wifi socket */


0.8.7 condition to upgrade

0.8.7 condition to upgrade

--- sonoff-firmware/sonoff-upgrade.ino
+++ sonoff-firmware/sonoff-upgrade.ino
@@ -104,7 +104,8 @@
       String(Configuration.version) == "0.4.0" ||
       String(Configuration.version) == "0.5.0" ||
       String(Configuration.version) == "0.6.1" ||
-      String(Configuration.version) == "0.7.0") {
+      String(Configuration.version) == "0.7.0" ||
+      String(Configuration.version) == "0.8.7") {
     Eeprom.saveSwitchType(sonoffDefault.switch_type);
   }
 }


edit test

edit test

--- Functionality/test/test.ino
+++ Functionality/test/test.ino
@@ -1,6 +1,7 @@
 // Arduino Interactive: button t
 // Copyright 2015 Jeroen Doggen, Christian Munk, Tom Peeters

+int test = 777;
 int delayTime = 10000;                            // 10 seconds
 int buttonState = 0;


Finished ISS tracker ion file

Finished ISS tracker ion file

--- ISS_tracker/ISS_tracker.ino
+++ ISS_tracker/ISS_tracker.ino
@@ -31,28 +31,18 @@
 while (Serial.available())  {
    altitude = Serial.parseFloat();
    asmuth = Serial.parseFloat();
+   Serial.flush();
+//   Serial.print(altitude);Serial.print(' ');Serial.println(asmuth);
 }

 //to ensure altitude is positive since servo is 0-180
 altitude = (int)altitude;
-if (altitude >= 0 && altitude <=180){
-  myServo.write(altitude);
-}
-if (altitude > 180 && altitude <360){
-  myServo.write(altitude - 180);
-}
+myServo.write(altitude+90);

 // defining variables
 double step_deg = 1.8; //degrees
 int step_count = 0; //number of steps taken

-//trial cases when rotating back around the 0-> 360 and 360->0
-if (abs(asmuth_old-asmuth) > 300 && asmuth_old > 300) {
-  asmuth_old = asmuth_old - 360;
-}
-if (abs(asmuth_old-asmuth) > 300 && asmuth > 300) {
-  asmuth_old = asmuth_old + 360;
-}

 //calculating need for change in stepper motor
 double asmuth_change = asmuth - asmuth_old;
@@ -63,13 +53,13 @@
 if (stepper_move > 1) {
   myMotor->step(stepper_move,FORWARD, SINGLE);
   if (stepper_move != 0){
-    Serial.println(stepper_move);
+//    Serial.println(stepper_move);
 }
 }
 if (stepper_move < -1) {
   myMotor->step(-1*stepper_move,BACKWARD, SINGLE);
   if (stepper_move != 0){
-    Serial.println(stepper_move);
+//    Serial.println(stepper_move);
   }
 }


Fixed the Arduino test project so it compiles.

--- ide/Arduino/ucmd_tests/ucmd_tests.ino
+++ ide/Arduino/ucmd_tests/ucmd_tests.ino
@@ -1,21 +1,21 @@
 #include "Arduino.h"
 #include "ucmd_tests.h"

-uc_tests *tests_instance;
+uc_test *test;

-void tests_print(const char *str) {
+void test_print(const char *str, void *state) {
   Serial.print(str);
 }

 void setup() {
   Serial.begin(9600);
   while (!Serial);
-  tests_instance = uc_tests_get_instance();
-  uc_tests_set_print(tests_instance, tests_print);
+  test = uc_tests_get_test();
+  uc_test_set_print_func(test, test_print);
 }

 void loop() {
-  uc_tests_main(tests_instance);
+  uc_test_run(test);
   delay(1000);
 }


Update Rapid_Shell.ino

Update Rapid_Shell.ino

--- Rapid_Shell/Rapid_Shell.ino
+++ Rapid_Shell/Rapid_Shell.ino
@@ -2,7 +2,7 @@
 // This script is designed for use on Windows machines with QWERTY as a keyboard layout
 // As DigiKeyboard Library does not support AZERTY text yet in print(), you have to use the "az_qw_convert.sh" script to convert AZERTY to QWERTY layout.
 // For more scripts checkout: https://git.io/vAGf4
-// Developer: NBN | 02/13/2018 @19:00
+// Developer: NBN | 02/13/2018 @19:00 UTC
 void setup() {
   // Initialize the digital pin as an output.
   pinMode(1, OUTPUT); //LED on Model A
@@ -16,7 +16,7 @@
 // BEGIN - Open CMD in Administrator Privileges
   DigiKeyboard.sendKeyStroke(0, MOD_GUI_LEFT);
   DigiKeyboard.delay(1500);
-  DigiKeyboard.print("c;d");
+  DigiKeyboard.print("cmd");
   DigiKeyboard.delay(1500);
   DigiKeyboard.sendKeyStroke(KEY_ENTER, MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
   DigiKeyboard.delay(1000);
@@ -28,9 +28,9 @@
   DigiKeyboard.delay(1500);
   DigiKeyboard.println("MODE CON: COLS=15 LINES=1");
   DigiKeyboard.delay(250);
-  DigiKeyboard.println("cd %TEMP%");
+  DigiKeyboard.println("cd %TEMP%"); // Change to temp directory
   DigiKeyboard.delay(250);
-  DigiKeyboard.println("copy con tmp.cmd");
+  DigiKeyboard.println("copy con tmp.cmd"); // Create the file tmp.cmd
   DigiKeyboard.delay(500);
   DigiKeyboard.println("start C:/Windows/System32/Ribbons.scr /s");
   DigiKeyboard.delay(250);


Updated arduino version

Updated arduino version

--- apps/Arduino/ss_basic/ss_basic.ino
+++ apps/Arduino/ss_basic/ss_basic.ino
@@ -15,7 +15,7 @@
  *
  */

-#define VERSION "SS_v0.1.4"
+#define VERSION "SS_v0.1.5"
 #define FALSE_START_TICKS 4
 #define MAX_RACERS 4


Add fairness counter for multiple sensor processing

--- examples/MultipleSensorsSerialPrinter/MultipleSensorsSerialPrinter.ino
+++ examples/MultipleSensorsSerialPrinter/MultipleSensorsSerialPrinter.ino
@@ -31,6 +31,8 @@
 RadiationWatch radiationWatch1(2, 3);
 // Second Pocket Geiger: signPin = 4, noisePin = 5
 RadiationWatch radiationWatch2(4, 5);
+// Fairness counter.
+unsigned int counter = 0;

 void onRadiation1()
 {
@@ -74,6 +76,15 @@

 void loop()
 {
-  radiationWatch1.loop();
-  radiationWatch2.loop();
+  // Just to be sure both processing loops get
+  // equal amount of processing. Should not be useful/has
+  // any effect, except maybe at high radiation count levels.
+  if (counter % 2 == 0) {
+    radiationWatch1.loop();
+    radiationWatch2.loop();
+  } else {
+    radiationWatch2.loop();
+    radiationWatch1.loop();
+  }
+  counter++;
 }


Update code for message scroll - non functional


Trimming received commands

Trimming received commands

--- Arduino/WhatsBot/WhatsBot.ino
+++ Arduino/WhatsBot/WhatsBot.ino
@@ -1,5 +1,5 @@
 const int Rate = 9600;
-const char CommandEnd = 0x26; // Ampersand
+const char CommandSeparator = 0x10; // New Line
 const char Separator = 0x20; // Space

 void setup()
@@ -13,20 +13,22 @@
 {
   char Buffer[128];

-  int Readed = Serial.readBytesUntil(0x26, Buffer, 128); // 0x10
+  int Readed = Serial.readBytesUntil(CommandSeparator, Buffer, 128);

   if(Readed > 0)
   {
     Blink();

     String Command = String(Buffer).substring(0, Readed);
+    Command.toLowerCase();
+    Command.trim();

     int Offset = Command.indexOf(Separator);
     String Object = Command.substring(0, Offset);
     String Params = Command.substring(Offset + 1);

     if(Object == "pin")
-      Serial.println(Pin(Params));
+      Serial.print(Pin(Params) + CommandSeparator);
   }
 }

@@ -87,7 +89,7 @@
     else if(Mode == "low")
       digitalWrite(Pin, LOW);
     //else if(Mode == "toggle")
-    //  ;
+    //  digitalWrite(Pin, !digitalRead(Pin));
     else
       return "pin_value_invalid";


Memset and friends don't work with volatile variables.

--- arduino/tachometer/tachometer.ino
+++ arduino/tachometer/tachometer.ino
@@ -3,14 +3,13 @@

 float conversion_factor = 1.0;

-volatile int pulse_count[2];
-volatile int ring_buffer[2][BUF_LEN];
+volatile int pulse_count[2] = {
+  0};
+volatile int ring_buffer[2][BUF_LEN] = {
+  0};

 void setup()
 {
-  memset(pulse_count, 0, sizeof(pulse_count));
-  memset(ring_buffer, 0, sizeof(ring_buffer));
-
   Serial.begin(115200);

   pinMode(IRQ_0_PIN, INPUT_PULLUP);
@@ -30,11 +29,13 @@
   int counts[2][BUF_LEN];

   cli();
-  memcpy(counts, ring_buffer, sizeof(ring_buffer));
+  for(int i = 0; i < 2; i++)
+    for(int j = 0; j < BUF_LEN; j++)
+      counts[i][j] = ring_buffer[i][j];
   sei();

-  qsort(ring_buffer[IRQ_0][0], BUF_LEN, sizeof(int), cmp<int>);
-  qsort(ring_buffer[IRQ_1][0], BUF_LEN, sizeof(int), cmp<int>);
+  //  qsort(counts[IRQ_0][0], BUF_LEN, sizeof(int), cmp<int>);
+  //  qsort(counts[IRQ_1][0], BUF_LEN, sizeof(int), cmp<int>);

   // report the median
   send(counts[IRQ_0][BUF_LEN / 2], counts[IRQ_1][BUF_LEN / 2]);
@@ -63,7 +64,8 @@
   ring_buffer[IRQ_0][idx] = pulse_count[IRQ_0];
   ring_buffer[IRQ_1][idx] = pulse_count[IRQ_1];

-  memset(pulse_count, 0, sizeof(pulse_count));
+  for(int i =0; i < 2; i++)
+    pulse_count[i] = 0;
 }

 void tach_0_isr()
@@ -75,3 +77,4 @@
 {
   pulse_count[IRQ_1]++;
 }
+


Fixed the duplicate pin definitions in StepTest.ino.

--- examples/StepTest/StepTest.ino
+++ examples/StepTest/StepTest.ino
@@ -14,9 +14,6 @@

 const uint8_t amisSlaveSelect = 9;
 const uint8_t amisStepPin = 10;
-
-const uint8_t amisStepPin = 9;
-const uint8_t amisSlaveSelect = 10;
 const uint8_t amisClrPin = 11;
 const uint8_t scopeTriggerPin = 12;


add test_compare to adc_test

add test_compare to adc_test

--- examples/adc_test/adc_test.ino
+++ examples/adc_test/adc_test.ino
@@ -49,6 +49,111 @@
 uint8_t adc_pins_diff[] = {A10, A11};
 #endif // defined

+
+int value = 0;
+
+// test the analog pins that also have a digital function
+bool test_pullup_down(bool pullup) {
+    uint8_t mode = pullup ? INPUT_PULLUP : INPUT_PULLDOWN;
+
+    const int max_val = adc->getMaxValue(ADC_NUM::ADC_0);
+
+    bool pass_test = true;
+
+    for (int i=0;i<DIG_PINS;i++) {
+        pinMode(adc_pins_dig[i], mode);
+        value = adc->analogRead(adc_pins_dig[i]);
+        bool fail_condition = pullup ? (value < 0.95*max_val) : (value > 0.05*max_val);
+        if (fail_condition) {
+            Serial.print("A"); Serial.print(i); Serial.print(": ");
+            Serial.print("FAILED "); Serial.print(pullup ? "INPUT_PULLUP" : "INPUT_PULLDOWN");
+            Serial.print("("); Serial.print(value); Serial.print(")");
+            Serial.println(". ");
+            pass_test = false;
+        }
+    }
+
+    return pass_test;
+}
+
+const uint8_t pin_cmp = A0;
+
+bool test_compare() {
+    bool pass_test = true;
+
+    // measurement will be ready if value < 1.0V
+    adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_NUM::ADC_0), 0, ADC_NUM::ADC_0);
+
+    pinMode(pin_cmp, INPUT_PULLUP); // set to max
+    // this should fail
+    value = adc->analogRead(pin_cmp, ADC_NUM::ADC_0);
+    if (adc->adc0->fail_flag != ADC_ERROR::COMPARISON) {
+        Serial.println("Comparison didn't fail.");
+        adc->adc0->printError();
+        pass_test = false;
+    }
+    adc->adc0->resetError();
+
+    pinMode(pin_cmp, INPUT_PULLDOWN); // set to min
+    // this should be ok
+    value = adc->analogRead(pin_cmp, ADC_NUM::ADC_0);
+    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
+        Serial.println("Some other error happened when comparison should have succeeded.");
+        adc->adc0->printError();
+        pass_test = false;
+    }
+    adc->adc0->resetError();
+
+    return pass_test;
+}
+
+bool test_compare_range() {
+    bool pass_test = true;
+
+    // ready if value lies out of [1.0,2.0] V
+    adc->enableCompareRange(1.0*adc->getMaxValue(ADC_NUM::ADC_0)/3.3, 2.0*adc->getMaxValue(ADC_NUM::ADC_0)/3.3, 0, 1, ADC_NUM::ADC_0);
+
+
+    pinMode(pin_cmp, INPUT_PULLUP); // set to max
+    // this should be ok
+    value = adc->analogRead(pin_cmp, ADC_NUM::ADC_0);
+    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
+        Serial.println("Some other error happened when comparison should have succeeded.");
+        adc->adc0->printError();
+        pass_test = false;
+    }
+
+    pinMode(pin_cmp, INPUT_PULLDOWN); // set to min
+    adc->adc0->resetError();
+    // this should be ok
+    value = adc->analogRead(pin_cmp, ADC_NUM::ADC_0);
+    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
+        Serial.println("Some other error happened when comparison should have succeeded.");
+        adc->adc0->printError();
+        pass_test = false;
+    }
+    adc->adc0->resetError();
+
+
+    return pass_test;
+}
+
+
+bool test_averages() {
+    elapsedMicros timeElapsed;
+    bool pass_test = true;
+
+    const uint8_t averages[] = {1, 2, 4, 8, 16, 32};
+    for(int i=0; i<6; i++) {
+        adc->setAveraging(averages[i]);
+        timeElapsed = 0;
+        adc->analogRead(A0, ADC_NUM::ADC_0);
+        Serial.println((uint32_t)timeElapsed);
+    }
+
+    return pass_test;
+}
+
 void setup() {

     pinMode(LED_BUILTIN, OUTPUT);
@@ -75,10 +180,6 @@
     // it can be any of the ADC_MED_SPEED enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED or VERY_HIGH_SPEED
     adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_LOW_SPEED); // change the sampling speed

-    // always call the compare functions after changing the resolution!
-    //adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_NUM::ADC_0), 0, ADC_NUM::ADC_0); // measurement will be ready if value < 1.0V
-    //adc->enableCompareRange(1.0*adc->getMaxValue(ADC_NUM::ADC_0)/3.3, 2.0*adc->getMaxValue(ADC_NUM::ADC_0)/3.3, 0, 1, ADC_NUM::ADC_0); // ready if value lies out of [1.0,2.0] V
-
     // If you enable interrupts, notice that the isr will read the result, so that isComplete() will return false (most of the time)
     //adc->enableInterrupts(ADC_NUM::ADC_0);

@@ -92,48 +193,38 @@

     //adc->setReference(ADC_REFERENCE::REF_1V2, ADC_NUM::ADC_1);

-    // always call the compare functions after changing the resolution!
-    //adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_NUM::ADC_1), 0, ADC_NUM::ADC_1); // measurement will be ready if value < 1.0V
-    //adc->enableCompareRange(1.0*adc->getMaxValue(ADC_NUM::ADC_1)/3.3, 2.0*adc->getMaxValue(ADC_NUM::ADC_1)/3.3, 0, 1, ADC_NUM::ADC_1); // ready if value lies out of [1.0,2.0] V
-

     // If you enable interrupts, note that the isr will read the result, so that isComplete() will return false (most of the time)
     //adc->enableInterrupts(ADC_NUM::ADC_1);

     #endif

-    delay(500);
-}
-
-int value = 0;
-int pin=0;
-
-void test_pull(bool pullup) {
-    uint8_t mode = pullup ? INPUT_PULLUP : INPUT_PULLDOWN;
-
-    for (int i=0;i<DIG_PINS;i++) {
-        pinMode(adc_pins[i], mode);
-        value = adc->analogRead(adc_pins_dig[i]);
-        if (value < 3.2) {
-            Serial.print("A"); Serial.print(i); Serial.print(": ");
-            Serial.print("FAILED "); Serial.print(pullup ? "INPUT_PULLUP" : "INPUT_PULLDOWN"); Serial.println(". ");
-        }
-    }
-}
+    delay(2000);
+
+    ////// START TESTS /////////////
+
+    bool pullup_test = test_pullup_down(true);
+    Serial.print("PULLUP TEST "); Serial.println(pullup_test ? "PASS" : "FAIL");
+    bool pulldown_test = test_pullup_down(false);
+    Serial.print("PULLDOWN TEST "); Serial.println(pulldown_test ? "PASS" : "FAIL");
+    bool compare_test = test_compare();
+    Serial.print("COMPARE TEST "); Serial.println(compare_test ? "PASS" : "FAIL");
+    bool compare_range_test = test_compare_range();
+    Serial.print("COMPARE RANGE TEST "); Serial.println(compare_range_test ? "PASS" : "FAIL");
+
+    test_averages();
+}
+
+

 void loop() {
-
-    test_pull(true);
-    test_pull(false);
-
-
     // Print errors, if any.
     adc->printError();
     adc->resetError();

-    //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
+    digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));

     delay(500);


Add long, detailed explanation of static in C++

--- Dremelfuge.ino
+++ Dremelfuge.ino
@@ -41,7 +41,7 @@
   const uint8_t LCD_COLUMNS = 20, LCD_ROWS = 4;

   wpb.begin();
-  wpb.turnLEDOn();
+  wpb.turnLEDOn();                //

   pinMode(MOTOR_PIN, OUTPUT);
   pinMode(POT_PIN, INPUT);
@@ -59,10 +59,24 @@

 void loop()
 {
-                                                      //*** static local variables--i.e. static variables inside of functions--are NOT STACK VARIABLES;
-                                                      //    their values persist even after function ends, as long as the program is still running
-                                                      //*** also, static local variables still only have local scope
-                                                      //*** perform operations with data of the same type, so as to boost performance by not needing to typecast
+  /* Explanation of static keyword in C++:
+   3 types of things can be static: (local) function variables, & class
+   member data (variables and functions--functions = pointer to address of
+   instructions). But `static` gets implemented the same way in each. There
+   exists special memory segments called DATA and BSS (which is just DATA but
+   for uninitialized data). At compile, global and `static` data are each *given
+   their own addresses within DATA or BSS, addresses where they will live (be
+   stored at) forever.* *When the program first runs, BEFORE main(), global and
+   `static` data are initialized to whatever value you set in source code*--you
+   can see this in the Assembly code. If you only declared global or `static`
+   data, then they will be initialized to 0 and placed in BSS. `static` data is
+   not deallocated when out of scope--*its address is permanent, and though the
+   values that live there may change, those values will never be erased (as long
+   as the program is running).* Of course, that `static` data can only be
+   accessed when it's within scope, making it much safer than similar global data.
+  */
+
+                                                      //*** perform operations with data of the same type, so as to boost performance by not needing to implicitly typecast
   static unsigned long setDuration;                   // the duration that the centrifuge should run
   static unsigned long spinningStartTime;             // point on the timeline where the countdown starts, i.e. when wpb is pressed the second time
   static uint8_t motorSpeed;
@@ -142,6 +156,7 @@
         lcd.setCursor(0, 1);
         lcd.print(F("Finished in: "));
         changedUIString = true;
+        Serial.println("reached only once");
       }

       unsigned long secondsLeft = (setDuration - (millis() - spinningStartTime))/1000;  //*** save RAM AND flash memory by only doing this calculation once per case in loop()


Made stars move right to left.

Made stars move right to left.

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -27,7 +27,6 @@
 Player spaceShip;

-
 void printText(char *message, int x, int y, int textSize) {
   arduboy.setCursor(x, y);
   arduboy.setTextSize(textSize);
@@ -138,7 +137,7 @@
 void highScoreScreen() {
   // TODO, this is placeholder
   arduboy.clear();
-  printText("HIGH SCORE", 5, 15, 1);
+  printText("HIGH SCORE ", 5, 15, 1);
   arduboy.print(highScore);
   arduboy.display();
   delay(3000);
@@ -299,7 +298,7 @@
   score = 0;
   spaceShip.reset();
   // Random test to set score
-  unsigned int randomScore = random(65000, 99999);
+  unsigned int randomScore = 5000;//random(65000, 99999);

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

     drawPlayerShip();
     drawEnemies();
@@ -329,7 +328,7 @@

 void drawStarLayer() {
   for (int i = 0; i < numStars; i++) {
-     arduboy.drawPixel(stars[i].x, stars[i].y, 1);
+     arduboy.drawPixel(stars[i].x, stars[i].y, 3);
   }
 }

@@ -448,11 +447,11 @@
 void updateStarFieldVals() {

   for (int i = 0; i < numStars; i++) {
-     if (stars[i].x > 200) {
-       stars[i].x = 0;
-       stars[i].y = random(100);
+     if (stars[i].x < -1) {
+       stars[i].x = 128 + random(20);
+       stars[i].y = random(100) + 10;
      } else {
-         stars[i].x ++;
+         stars[i].x--;
      }
   }


Add some debounce handling

Add some debounce handling

Suppresses repeated inputs

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -1,10 +1,10 @@
 /* Code for laser guzheng
- * Copyright (C) 2016 Jason Lu
- *
- * Licensed under the MIT License
- * This code has NO WARRANTY! You are
- * responsible for anything that happens
- */
+   Copyright (C) 2016 Jason Lu
+
+   Licensed under the MIT License
+   This code has NO WARRANTY! You are
+   responsible for anything that happens
+*/

 // Port I/O defines
 #define THRESHOLD 700
@@ -18,10 +18,13 @@
 // MIDI property defines
 #define VOLUME 0x7F

+// Debounce threshold (milliseconds)
+#define DEBOUNCE_THRESHOLD 100
+
 /* Comment out the below to enable a slight delay between reading
- * each note. This may be necessary because sometimes rapidly reading
- * analog values can cause strange values. Comment out the below if
- * you notice anything strange, because this is probably the culprit */
+   each note. This may be necessary because sometimes rapidly reading
+   analog values can cause strange values. Comment out the below if
+   you notice anything strange, because this is probably the culprit */
 #define NODELAY

 #ifndef NODELAY
@@ -74,18 +77,20 @@
 int instrumentArray[NUMINSTRUMENTS] = {0x01, 0x07, 0x2E, 0x4A, 0x29, 0x16};

 /* Flag values for each laser. These values will operate on the bit
- * levels, directly with binary. They work together with the
- * lastNote variable to keep track of blocked lasers.
- * Here, I use an AND operator to read if the value has been
- * set, and OR to set the value. */
+   levels, directly with binary. They work together with the
+   lastNote variable to keep track of blocked lasers.
+   Here, I use an AND operator to read if the value has been
+   set, and OR to set the value. */
 uint8_t laserArray[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

 /* Variable to keep track of the last played instrument. The real
- * data shows up when converted to binary, since we use binary
- * operator tricks. When the first laser is hit, it is 00000001. If
- * the second one is hit, then it is 00000010, and the third one is
- * 00000100, and so on. */
+   data shows up when converted to binary, since we use binary
+   operator tricks. When the first laser is hit, it is 00000001. If
+   the second one is hit, then it is 00000010, and the third one is
+   00000100, and so on. */
 uint8_t lastNote = 0;
+
+unsigned long debounce[8] = {0};

 // Function to write notes over serial
 void noteOn(int cmd, int pitch, int velocity) {
@@ -101,133 +106,133 @@
 void musicOn(int ID) {
   if (noteSet == 0) {
     switch (ID) {
-    case 0:
-      noteOn(NOTEON, note1, VOLUME);
-      break;
-    case 1:
-      noteOn(NOTEON, note2, VOLUME);
-      break;
-    case 2:
-      noteOn(NOTEON, note3, VOLUME);
-      break;
-    case 3:
-      noteOn(NOTEON, note4, VOLUME);
-      break;
-    case 4:
-      noteOn(NOTEON, note5, VOLUME);
-      break;
-    case 5:
-      noteOn(NOTEON, note6, VOLUME);
-      break;
-    case 6:
-      noteOn(NOTEON, note7, VOLUME);
-      break;
-    case 7:
-      noteOn(NOTEON, note8, VOLUME);
-      break;
-    default:
-      // WTF? It shouldn't reach here, because that's an invalid ID
-      noteOn(NOTEOFF, note1, 0x00);
-      break;
+      case 0:
+        noteOn(NOTEON, note1, VOLUME);
+        break;
+      case 1:
+        noteOn(NOTEON, note2, VOLUME);
+        break;
+      case 2:
+        noteOn(NOTEON, note3, VOLUME);
+        break;
+      case 3:
+        noteOn(NOTEON, note4, VOLUME);
+        break;
+      case 4:
+        noteOn(NOTEON, note5, VOLUME);
+        break;
+      case 5:
+        noteOn(NOTEON, note6, VOLUME);
+        break;
+      case 6:
+        noteOn(NOTEON, note7, VOLUME);
+        break;
+      case 7:
+        noteOn(NOTEON, note8, VOLUME);
+        break;
+      default:
+        // WTF? It shouldn't reach here, because that's an invalid ID
+        noteOn(NOTEOFF, note1, 0x00);
+        break;
     }
   } else if (noteSet == 1) {
     switch (ID) {
-    case 0:
-      noteOn(NOTEON, note9, VOLUME);
-      break;
-    case 1:
-      noteOn(NOTEON, note10, VOLUME);
-      break;
-    case 2:
-      noteOn(NOTEON, note11, VOLUME);
-      break;
-    case 3:
-      noteOn(NOTEON, note12, VOLUME);
-      break;
-    case 4:
-      noteOn(NOTEON, note13, VOLUME);
-      break;
-    case 5:
-      noteOn(NOTEON, note14, VOLUME);
-      break;
-    case 6:
-      noteOn(NOTEON, note15, VOLUME);
-      break;
-    case 7:
-      noteOn(NOTEON, note16, VOLUME);
-      break;
-    default:
-      // WTF? It shouldn't reach here, because that's an invalid ID
-      noteOn(NOTEOFF, note1, 0x00);
-      break;
+      case 0:
+        noteOn(NOTEON, note9, VOLUME);
+        break;
+      case 1:
+        noteOn(NOTEON, note10, VOLUME);
+        break;
+      case 2:
+        noteOn(NOTEON, note11, VOLUME);
+        break;
+      case 3:
+        noteOn(NOTEON, note12, VOLUME);
+        break;
+      case 4:
+        noteOn(NOTEON, note13, VOLUME);
+        break;
+      case 5:
+        noteOn(NOTEON, note14, VOLUME);
+        break;
+      case 6:
+        noteOn(NOTEON, note15, VOLUME);
+        break;
+      case 7:
+        noteOn(NOTEON, note16, VOLUME);
+        break;
+      default:
+        // WTF? It shouldn't reach here, because that's an invalid ID
+        noteOn(NOTEOFF, note1, 0x00);
+        break;
     }
   }
 }
-
-  // Function for turning off a specific note based on ID
-  // Just a slightly modified version of musicOn()
+
+// Function for turning off a specific note based on ID
+// Just a slightly modified version of musicOn()
 void musicOff(int ID) {
   if (noteSet == 0) {
     switch (ID) {
-    case 0:
-      noteOn(NOTEOFF, note1, 0x7F);
-      break;
-    case 1:
-      noteOn(NOTEOFF, note2, 0x7F);
-      break;
-    case 2:
-      noteOn(NOTEOFF, note3, 0x7F);
-      break;
-    case 3:
-      noteOn(NOTEOFF, note4, 0x7F);
-      break;
-    case 4:
-      noteOn(NOTEOFF, note5, 0x7F);
-      break;
-    case 5:
-      noteOn(NOTEOFF, note6, 0x7F);
-      break;
-    case 6:
-      noteOn(NOTEOFF, note7, 0x7F);
-      break;
-    case 7:
-      noteOn(NOTEOFF, note8, 0x7F);
-      break;
-    default:
-      // WTF? It shouldn't reach here, because that's an invalid ID
-      noteOn(NOTEOFF, note1, 0x00);
-      break;
+      case 0:
+        noteOn(NOTEOFF, note1, 0x7F);
+        break;
+      case 1:
+        noteOn(NOTEOFF, note2, 0x7F);
+        break;
+      case 2:
+        noteOn(NOTEOFF, note3, 0x7F);
+        break;
+      case 3:
+        noteOn(NOTEOFF, note4, 0x7F);
+        break;
+      case 4:
+        noteOn(NOTEOFF, note5, 0x7F);
+        break;
+      case 5:
+        noteOn(NOTEOFF, note6, 0x7F);
+        break;
+      case 6:
+        noteOn(NOTEOFF, note7, 0x7F);
+        break;
+      case 7:
+        noteOn(NOTEOFF, note8, 0x7F);
+        break;
+      default:
+        // WTF? It shouldn't reach here, because that's an invalid ID
+        noteOn(NOTEOFF, note1, 0x00);
+        break;
     }
   } else if (noteSet == 1) {
     switch (ID) {
-    case 0:
-      noteOn(NOTEOFF, note9, VOLUME);
-      break;
-    case 1:
-      noteOn(NOTEOFF, note10, VOLUME);
-      break;
-    case 2:
-      noteOn(NOTEOFF, note11, VOLUME);
-      break;
-    case 3:
-      noteOn(NOTEOFF, note12, VOLUME);
-      break;
-    case 4:
-      noteOn(NOTEOFF, note13, VOLUME);
-      break;
-    case 5:
-      noteOn(NOTEOFF, note14, VOLUME);
-      break;
-    case 6:
-      noteOn(NOTEOFF, note15, VOLUME);
-      break;
-    case 7:
-      noteOn(NOTEOFF, note16, VOLUME);
-      break;
-    default:
-      // WTF? It shouldn't reach here, because that's an invalid ID
-      noteOn(NOTEOFF, note1, 0x00);
-      break;
+      case 0:
+        noteOn(NOTEOFF, note9, VOLUME);
+        break;
+      case 1:
+        noteOn(NOTEOFF, note10, VOLUME);
+        break;
+      case 2:
+        noteOn(NOTEOFF, note11, VOLUME);
+        break;
+      case 3:
+        noteOn(NOTEOFF, note12, VOLUME);
+        break;
+      case 4:
+        noteOn(NOTEOFF, note13, VOLUME);
+        break;
+      case 5:
+        noteOn(NOTEOFF, note14, VOLUME);
+        break;
+      case 6:
+        noteOn(NOTEOFF, note15, VOLUME);
+        break;
+      case 7:
+        noteOn(NOTEOFF, note16, VOLUME);
+        break;
+      default:
+        // WTF? It shouldn't reach here, because that's an invalid ID
+        noteOn(NOTEOFF, note1, 0x00);
+        break;
     }
   }
 }
@@ -237,13 +242,13 @@
   // Initialize serial at 115200 baud
   Serial.begin(115200);
   // Set the 74HC4051 command ports
-  pinMode(2,OUTPUT);
-  pinMode(3,OUTPUT);
-  pinMode(4,OUTPUT);
+  pinMode(2, OUTPUT);
+  pinMode(3, OUTPUT);
+  pinMode(4, OUTPUT);
   // Wait for a button press to start the loop, because
   // delaying can either be too short or too long, and
   // Hairless-MIDI (Windows) can't properly handle malformed
-  // MIDI commands.
+  // MIDI commands.
   while (!start) {
     if (digitalRead(INSTRUMENTBUTTON) == HIGH) {
       start = true;
@@ -260,22 +265,22 @@
   // LASTPORT+1 ports, from 0 to LASTPORT
   for (int i = 0; i <= LASTPORT; i++) {
     /* The following three lines convert the port we want
-     * into the correct bit selections for the 74HC4051. I'm
-     * not really sure exactly how it works, but I'm pretty
-     * sure it's some bit shifting
-     */
-    r0 = bitRead(i,0);
-    r1 = bitRead(i,1);
-    r2 = bitRead(i,2);
+       into the correct bit selections for the 74HC4051. I'm
+       not really sure exactly how it works, but I'm pretty
+       sure it's some bit shifting
+    */
+    r0 = bitRead(i, 0);
+    r1 = bitRead(i, 1);
+    r2 = bitRead(i, 2);
     // Select the correct input using the values we calculated above
     digitalWrite(2, r0);
     digitalWrite(3, r1);
     digitalWrite(4, r2);
     // Detect if the instrument selection button is pressed
-    if(digitalRead(INSTRUMENTBUTTON) == HIGH) {
+    if (digitalRead(INSTRUMENTBUTTON) == HIGH) {
       /* Make sure that this is the first time that the button
-       * has been pressed
-       */
+         has been pressed
+      */
       if (instrumentButtonState == 0) {
         if (currentInstrument >= (NUMINSTRUMENTS - 1)) {
           // Max number of instruments, so wrap around to 0
@@ -297,7 +302,7 @@
       instrumentButtonState = 0;
     }
     // Detect if note button has been pressed
-    if(digitalRead(NOTEBUTTON) == HIGH) {
+    if (digitalRead(NOTEBUTTON) == HIGH) {
       // Make sure that this is the first time that the button
       // has been pressed
       if (noteButtonState == 0) {
@@ -310,39 +315,44 @@
       // Button is no longer pressed, so reset the button state.
       noteButtonState = 0;
     }
+    if ((millis() - debounce[i]) > DEBOUNCE_THRESHOLD) {
 #ifdef SENSOR_FIX
-    int threshold = (i == 3) ? 950 : THRESHOLD;
-    if(analogRead(0) > threshold) {
+      int threshold = (i == 3) ? 950 : THRESHOLD;
+      if (analogRead(0) > threshold) {
 #else
-    if(analogRead(0) > THRESHOLD) {
+      if (analogRead(0) > THRESHOLD) {
 #endif
-      /* Apply the AND operator to the lastNote indicator and the
-       * corresponding value from the laser array to check if the
-       * laser bit has been set or not
-       *
-       * If it returns a non zero value, then that means it is set.
-       * If it is a zero, then the bit has not been set yet */
-      if (!(lastNote & (laserArray[i]))) {
-        // Beam has been cut
-        musicOn(i);
-        /* Set the bit using the OR operator between lastNote and
-         * the corresponding value from the laser array */
-        lastNote |= (laserArray[i]);
+        /* Apply the AND operator to the lastNote indicator and the
+           corresponding value from the laser array to check if the
+           laser bit has been set or not
+
+           If it returns a non zero value, then that means it is set.
+           If it is a zero, then the bit has not been set yet */
+        if (!(lastNote & (laserArray[i]))) {
+          debounce[i] = millis();
+
+          // Beam has been cut
+          musicOn(i);
+          /* Set the bit using the OR operator between lastNote and
+             the corresponding value from the laser array */
+          lastNote |= (laserArray[i]);
+        }
+      } else {
+        /* Check if the last note bit has been set or not using the
+           AND operator. This won't always be true because this section
+           of the code runs even if the beam hasn't been cut yet */
+        if ((lastNote & (laserArray[i]))) {
+          debounce[i] = millis();
+          /* Unset the flag using the AND and invert operators */
+          lastNote &= ~(laserArray[i]);
+        }
+        // Hand is gone. Stop the sound
+        musicOff(i);
       }
-    } else {
-      /* Check if the last note bit has been set or not using the
-       * AND operator. This won't always be true because this section
-       * of the code runs even if the beam hasn't been cut yet */
-      if ((lastNote & (laserArray[i]))) {
-        /* Unset the flag using the AND and invert operators */
-        lastNote &= ~(laserArray[i]);
-      }
-      // Hand is gone. Stop the sound
-      musicOff(i);
-    }
-    #ifndef NODELAY
-    // Delay 10 to prevent weird analog readings
-    delay(DELAY);
-    #endif
+#ifndef NODELAY
+      // Delay 10 to prevent weird analog readings
+      delay(DELAY);
+#endif
+    }
   }
 }


started porting from Lua

started porting from Lua

--- ardesp/joinme/joinme.ino
+++ ardesp/joinme/joinme.ino
@@ -1,12 +1,11 @@
 /*
- *  This sketch demonstrates how to scan WiFi networks.
- *  The API is almost the same as with the WiFi Shield library,
- *  the most obvious difference being the different file you need to include:
+ * joinme.ino --
+ * a port of the Lua Joinme wifi config utility to Arduino ESP IDE
  */
 #include "ESP8266WiFi.h"

 void setup() {
-  Serial.begin(115200);
+  Serial.begin(9600);

   // Set WiFi to station mode and disconnect from an AP if it was previously connected
   WiFi.mode(WIFI_STA);


Renaming some of the sensors

Renaming some of the sensors

--- computer_box/computer_box.ino
+++ computer_box/computer_box.ino
@@ -116,12 +116,11 @@
   //   return;
   // }

-  Serial.print("\"temp\":{");
-  Serial.print("\"h\":"); Serial.print(h); Serial.print(',');
-  Serial.print("\"c\":"); Serial.print(c); Serial.print(',');
-
-  for (int x = 0; x < num_ds18; x++) {
-    Serial.print("\"temp_");
+  Serial.print("\"humidity\":"); Serial.print(h); Serial.print(',');
+  Serial.print("\"temp_01\":"); Serial.print(c); Serial.print(',');
+
+  for (int x = 1; x < num_ds18; x++) {
+    Serial.print("\"temp_0");
     Serial.print(x + 1);
     Serial.print("\":");
     Serial.print(get_temperature(sensors_address[x]));
@@ -131,7 +130,6 @@
     }
   }

-  Serial.print('}');
 }

 /*


clean up

clean up

--- src/sketch.ino
+++ src/sketch.ino
@@ -1,4 +1,4 @@
-#include <Wire.h>
+#include <Wire.h>                                     // Gyro SDA SCL library
 #include "I2Cdev.h"
 #include "RTIMUSettings.h"
 #include "RTIMU.h"
@@ -11,16 +11,13 @@
 RTIMUSettings settings;                               // the settings object

 //  SERIAL_PORT_SPEED defines the speed to use for the debug serial port
-
 #define  SERIAL_PORT_SPEED  115200

 unsigned long lastDisplay;
 unsigned long lastRate;
-int sampleCount;

-unsigned long timer;
-unsigned long buzzTime;
-unsigned long silentTime;
+unsigned long buzzTime = 0;
+unsigned long silentTime = 0;
 boolean buzz = true;

 void setup()
@@ -31,9 +28,8 @@
   Wire.begin();
   imu = RTIMU::createIMU(&settings);                        // create the imu object

-  //Serial.print("ArduinoIMU starting using device "); Serial.println(imu->IMUName());
   if ((errcode = imu->IMUInit()) < 0) {
-    //Serial.print("Failed to init IMU: "); Serial.println(errcode);
+    //  Display error somehow
   }

   //if (imu->getCalibrationValid())
@@ -42,44 +38,41 @@
     //Serial.println("No valid compass calibration data");

   lastDisplay = lastRate = millis();
-  sampleCount = 0;
-  timer = millis();
 }

 RTVector3 q;

+unsigned long now;
+
 void loop()
 {
-  unsigned long now = millis();
-  unsigned long delta;
-
+  now = millis();
+  tryReadIMU();
+  buzz();
+}
+
+void tryReadIMU()
+{
   if (imu->IMURead()) {                                // get the latest data if ready yet
     fusion.newIMUData(imu->getGyro(), imu->getAccel(), imu->getCompass(), imu->getTimestamp());
-    sampleCount++;
-    if ((delta = now - lastRate) >= 1000) {
-      //Serial.print("Sample rate: "); Serial.print(sampleCount);
+    if ((now - lastRate) >= 1000) {
       imu->IMUGyroBiasValid();
         //Serial.println(", gyro bias valid");
       //else
         //Serial.println(", calculating gyro bias - don't move IMU!!");

-      sampleCount = 0;
       lastRate = now;
     }
-    //if ((now - lastDisplay) >= DISPLAY_INTERVAL) {
-      //lastDisplay = now;
-//      RTMath::display("Gyro:", (RTVector3&)imu->getGyro());                // gyro data
-//      RTMath::display("Accel:", (RTVector3&)imu->getAccel());              // accel data
-//      RTMath::display("Mag:", (RTVector3&)imu->getCompass());              // compass data
-//      RTMath::displayDegrees("", (RTVector3&)fusion.getFusionPose()); // fused output
-//      Serial.println();
-      q = (RTVector3&)fusion.getFusionPose();
-
-      Serial.print(q.y() * 57.2957795);
-      Serial.println();
-    //}
-  }
-
+
+    q = (RTVector3&)fusion.getFusionPose();
+
+    Serial.print(q.y() * 57.2957795);
+    Serial.println();
+  }
+}
+
+void buzz()
+{
   if (buzz && (now - buzzTime) >= abs((q.y() * 57.2957795))* 5){
     buzz = false;
     silentTime = now;


Screen cleaner fix

Screen cleaner fix

--- tempscreen.ino
+++ tempscreen.ino
@@ -47,7 +47,7 @@
     tft.setTextSize(3);
     tft.println("Temperatura");
     tft.setCursor(110, 110);
-    tft.fillRect(120, 110, 95, 60, WHITE);
+    tft.fillRect(105, 105, 100, 70, WHITE);
     tft.println(celsius);
   }


Fix hideous bugs that caused new runSteppersToPos() code to not work.

--- OpenStage/openStage_moveToTarget.ino
+++ OpenStage/openStage_moveToTarget.ino
@@ -113,20 +113,26 @@

 void runSteppersToPos(){
+  bool verbose=1;
+  if (verbose){
+     Serial.println("Entering runSteppersToPos");
+  }
+

   int n=0; //counter to monitor if the controller is locked in this loop
-
-  long keepMoving=0;
+  long keepMoving=1;
   while (keepMoving>0){
-
+
+    keepMoving=0;
     for (int ii=0; ii<numAxes; ii++){
       if (!axisPresent[ii]){
         continue;
       }
-      keepMoving += (*mySteppers[ii]).distanceToGo();
-      (*mySteppers[ii]).run();
+      if ((*mySteppers[ii]).distanceToGo()>0){
+          keepMoving++;
+          (*mySteppers[ii]).run();
+      }
     }
-

       //Sometimes the controller locks up following analog stick motions
       //This is due to it getting stuck in this loop with the motors at zero
@@ -140,9 +146,11 @@
         }
         currentTotalSpeed+=(*mySteppers[ii]).speed();
       }
+
       if (currentTotalSpeed==0){
             n++;
       }
+
       if (n>50){ //If we're stuck here not moving for 50 cycles then something's wrong!
         for (int ii=0; ii<5; ii++){
             serialBeep();
@@ -153,3 +161,4 @@
    } //close while loop

 } //End runSteppersToPos
+


Joystick moves wheel; NowheelRev added

Joystick moves wheel; NowheelRev added

--- Elcano_C2_Go/Elcano_C2_Go.ino
+++ Elcano_C2_Go/Elcano_C2_Go.ino
@@ -16,7 +16,7 @@
 #define FALSE 0
 #endif
 #define MEG 1000000
-#define DEBUG 1
+//#define DEBUG 1

 volatile int SpeedCyclometer_degPs;  // 20 mph is about 2000 deg / sec
 // Values to send over DAC
@@ -39,6 +39,12 @@
 const int TopSpeed_degPs = 1800;
 const int FullBrakeFB = 760;  // need to get a real value
 const int MinimumBrakeFB = 303;  // need to get a real value
+
+// Joystick limits
+const int limitStickUp = 893;  // observed
+const int limitStickDown = 150;  // guess
+const int limitStickLeft = 900;  // guess
+const int limitStickRight = 150; // guess

 /* There is hysteresis on steering.
   E.g. Move to the left until PWM 223, getting FB of 760.
@@ -76,7 +82,7 @@
 const int Motor = 0;
 const int Brakes = 1;
 const int Steering = 2;
-const unsigned long MinTimeStep_usec = 1000;
+const unsigned long MinTimeStep_usec = 10000;
 unsigned long loopTime_usec;
 class _Instruments
 {
@@ -124,20 +130,21 @@
         Feedback = filteredFB();  // 0 to 1023
     else
         Feedback = SpeedCyclometer_degPs;
-
+/*
     if (Feedback == desired_feedback ||
         (Feedback <= MinPosition && desired_feedback <= MinPosition) ||
         (Feedback >= MaxPosition && desired_feedback >= MaxPosition))
     {   // we have arrived at desired_position
         return(Feedback);
     }
+    */
     TimeNow_usec = micros();
     if (TimeNow_usec - LastTime_usec < MinTimeStep_usec)
     {   // not enough time has passed since the last command.
         return(Feedback);
     }
     //  read current
-    CurrentDraw = abs( analogRead(CurrentPin) - QuiescentCurrent);
+/*    CurrentDraw = abs( analogRead(CurrentPin) - QuiescentCurrent);
     if (CurrentDraw >= CurrentLimit)
     {
      //    Too much current; Pause movement
@@ -176,10 +183,16 @@
        }
        else  // go for it
        {
+*/
+        //  motor is handled differently
+        if (FeedbackPin ==  SteerFB || FeedbackPin ==  BrakeFB)
             analogWrite(SignalPin, desired_position);
+        else
+            DAC_Write(0, desired_position);
+
             LastCommand = desired_position;
-       }
-    }
+//       }
+//    }

 #ifdef DEBUG
     //debug prints.
@@ -251,7 +264,10 @@
            delayMicroseconds(100);             // analogRead takes 100 usec
        }
        int feedback = median_filter(feedbacks);
+#ifdef DEBUG
+       Serial.print("Feedback: ");
        Serial.print(feedback); Serial.print(", ");
+#endif
        return feedback;
   }
 } Instrument[3];
@@ -264,7 +280,7 @@
   Instrument[Motor].FeedbackPin = 0; // Motor feedback is wheel speed
   Instrument[Motor].CurrentPin = Current36V;
   Instrument[Motor].StepSize = 20; // max from range of 1023.
-  Instrument[Motor].CloseEnough = 1000;  // no feedback
+  Instrument[Motor].CloseEnough = 100;
   Instrument[Motor].Stuck = 3;
   Instrument[Motor].MinPosition = MinimumThrottle;  // position is 0-255
   Instrument[Motor].MaxPosition = FullThrottle;
@@ -273,7 +289,7 @@
   Instrument[Steering].FeedbackPin = SteerFB;
   Instrument[Steering].CurrentPin = CurrentSteer;
   Instrument[Steering].StepSize = 20;
-  Instrument[Steering].CloseEnough = 1;
+  Instrument[Steering].CloseEnough = 20;
   Instrument[Steering].Stuck = 3;
   Instrument[Steering].MinPosition = HardRight;  // position is PWM: 127 to 255
   Instrument[Steering].MaxPosition = HardLeft;
@@ -283,7 +299,7 @@
   Instrument[Brakes].FeedbackPin = BrakeFB;
   Instrument[Brakes].CurrentPin = CurrentBrake;
   Instrument[Brakes].StepSize = 50;
-  Instrument[Brakes].CloseEnough = 1;
+  Instrument[Brakes].CloseEnough = 20;
   Instrument[Brakes].Stuck = 3;
   Instrument[Brakes].MinPosition = MinimumBrake;  // position is PWM: 127 to 255
   Instrument[Brakes].MaxPosition = FullBrake;
@@ -308,15 +324,19 @@
   Instrument[Motor].CurrentLimit = 230;  // about 20A
   Instrument[Brakes].CurrentLimit = 55;  // about 5A
   Instrument[Steering].CurrentLimit = 55;
+  long counter = 0;
+  /*
    do
    {
       Instrument[Motor].go(MinimumThrottle);
       Instrument[Brakes].go(FullBrake);
       Instrument[Steering].go(Straight);
-   } while (abs( Instrument[Steering].Feedback - StraightFB) > Instrument[Steering].CloseEnough
+      counter++;
+   } while ((abs( Instrument[Steering].Feedback - StraightFB) > Instrument[Steering].CloseEnough
          || abs( Instrument[Brakes].Feedback - FullBrakeFB) > Instrument[Brakes].CloseEnough
-         || abs( Instrument[Motor].Feedback - 0) > Instrument[Motor].CloseEnough);
-
+         || abs( Instrument[Motor].Feedback - 0) > Instrument[Motor].CloseEnough)
+         && counter < 10000);
+ */
   // Read quiesent state of current sensors.
   Instrument[Brakes].CurrentDraw =
     Instrument[Brakes].QuiescentCurrent = analogRead(CurrentBrake);
@@ -366,10 +386,11 @@
         pinMode(CurrentSteer, INPUT);
         pinMode(BrakeFB, INPUT);
         pinMode(SteerFB, INPUT);
-
+        Serial.println("Start initialization");
         initialize();

-        twitch();
+ //       twitch();
+     Serial.println("Initialized");
 }
 void twitch()
 {
@@ -380,22 +401,49 @@
 }
 /*---------------------------------------------------------------------------------------*/
 /*---------------------------------------------------------------------------------------*/
-// WheelRev is called by an interrupt.
-
+// WheelRev is called by an interrupt.
+static unsigned long OldTick = 0;
+
 void WheelRev()
 {
-    static unsigned long OldTick = 0;
     unsigned long TickTime;
     unsigned long WheelRevMicros;
     TickTime = micros();
     if (OldTick == TickTime)
         return;
     if (OldTick <= TickTime)
+    {
       	WheelRevMicros = TickTime - OldTick;
+        if (WheelRevMicros < 100)
+            return;  // switch bounce
+    }
+
     else // overflow
       	WheelRevMicros = TickTime + ~OldTick;
     SpeedCyclometer_degPs = (360 * MEG) / WheelRevMicros;
     OldTick = TickTime;
+}
+void NoWheelRev()  // let the speed slow down if there has been no motion
+{
+    unsigned long NoTickTime;
+    unsigned long WheelRevMicros;
+    unsigned long EntryOldTick = OldTick;
+    NoTickTime = micros();
+    if (OldTick == NoTickTime)
+        return;
+    if (OldTick > NoTickTime)
+    {
+        OldTick = 0;  // overflow
+        return;
+    }
+    unsigned long TimeToNextClick = OldTick + SpeedCyclometer_degPs * MEG / 360;
+    if (NoTickTime < TimeToNextClick)
+        return;
+    WheelRevMicros = NoTickTime - OldTick;
+    // To do: lock out interrupts at this point
+    if (EntryOldTick == OldTick)
+        SpeedCyclometer_degPs = (360 * MEG) / WheelRevMicros;
+
 }

 /*---------------------------------------------------------------------------------------*/
@@ -544,32 +592,41 @@
   if (Instrument[Motor].StickMoved)
   {
      desired_position = Instrument[Motor].Joystick;
+     Serial.print(" FB: "); Serial.print(Instrument[Motor].Feedback);
+     Serial.print(" Motor: "); Serial.print(desired_position);
   }
   Instrument[Motor].go(desired_position);
-  Serial.print(" Motor: "); Serial.print(desired_position);
+  NoWheelRev();  // let speed slow down

   // apply brakes
   desired_position =  MinimumBrake;
   if (Instrument[Brakes].StickMoved)
   {
      desired_position = Instrument[Brakes].Joystick;
-  }
-  Instrument[Brakes].go(desired_position);
-  Serial.print(" Brakes: "); Serial.print(desired_position);
+     Serial.print(" FB: "); Serial.print(Instrument[Brakes].Feedback);
+     Serial.print(" Brakes: "); Serial.print(desired_position);
+  }
+//  Instrument[Brakes].go(desired_position);
+

  // apply steering
   desired_position =  Straight;
   if (Instrument[Steering].StickMoved)
   {
      desired_position = Instrument[Steering].Joystick;
-  }
-  Instrument[Steering].go(desired_position);
-    Serial.print(" Steering: "); Serial.println(desired_position);
+     Serial.print(" FB: "); Serial.print(Instrument[Steering].Feedback);
+     Serial.print(" Steering: "); Serial.print(desired_position);
+  }
+//  Instrument[Steering].go(desired_position);
+  if (Instrument[Motor].StickMoved || Instrument[Brakes].StickMoved ||
+     Instrument[Steering].StickMoved)
+     Serial.println(" ");
 }
 /*---------------------------------------------------------------------------------------*/
 void JoystickMotion()
 // All inputs are 0-1023
 {
+    long int x;
     int upStick = analogRead(AccelerateJoystick);
     int center  = analogRead(JoystickCenter);
     int sideStick = analogRead(SteerJoystick);
@@ -589,9 +646,21 @@
   else
   {
     //stick outside of deadband
-    Instrument[Motor].Joystick = MinimumThrottle + (FullThrottle - MinimumThrottle)
-      * (upStick - tinyUp) / (1023 - tinyUp);
+    if (upStick > limitStickUp)
+        upStick = limitStickUp;
+    x = (upStick - tinyUp);
+    x *= (FullThrottle - MinimumThrottle);
+    x /= (limitStickUp - tinyUp);
+    x  += MinimumThrottle;
+    Instrument[Motor].Joystick = x;
     Instrument[Motor].StickMoved =  TRUE;
+#ifdef DEBUG
+    Serial.print(" upStick: "); Serial.print(upStick);
+    Serial.print(" tinyUp: "); Serial.print(tinyUp);
+    Serial.print(" Min: "); Serial.print(MinimumThrottle);
+    Serial.print(" Full: "); Serial.print(FullThrottle);
+    Serial.print(" x: "); Serial.print(x);
+#endif
   }

   //Check if Stick moved beyond "down" deadBand
@@ -603,8 +672,13 @@
   }
   else
   {
-    Instrument[Brakes].Joystick = MinimumBrake + (FullBrake - MinimumBrake)
-      * (-upStick + tinyDown) / tinyDown;
+    if (upStick < limitStickDown)
+        upStick = limitStickDown;
+    x = (tinyDown - upStick);
+    x *= (FullBrake - MinimumBrake);
+    x /= (tinyDown - limitStickDown);
+    x  += MinimumBrake;
+    Instrument[Brakes].Joystick = x;
     Instrument[Brakes].StickMoved =  TRUE;
   }

@@ -617,12 +691,29 @@
   else if (sideStick > tinyUp)
   {
     //Stick moved past "up" deadband limit
-    Instrument[Steering].Joystick = Straight + (HardRight - Straight) * (sideStick - tinyUp) / (1023 - tinyUp);
+    if (sideStick > limitStickLeft)
+        sideStick = limitStickLeft;
+    x = (sideStick - tinyUp);  // positive
+    x *= (HardLeft - Straight);  // positive
+    x /= (limitStickLeft - tinyUp);  // x is positive
+    Instrument[Steering].Joystick = Straight + x;
     Instrument[Steering].StickMoved =  TRUE;
   }
   else
   {
-    Instrument[Steering].Joystick = Straight + (Straight - HardLeft) * (-sideStick + tinyDown) / tinyDown;
+    if (sideStick < limitStickRight)
+        sideStick = limitStickRight;
+    x = (tinyDown - sideStick);  // positive
+    x *= (Straight - HardRight);  // positive
+    x /= (tinyDown - limitStickRight);  // x is positive
+    Instrument[Steering].Joystick = Straight - x;
+#ifdef DEBUG
+    Serial.print(" sideStick: "); Serial.print(sideStick);
+    Serial.print(" tinyDown: "); Serial.print(tinyDown);
+    Serial.print(" HardRight: "); Serial.print(HardRight);
+    Serial.print(" limitStickRight: "); Serial.print(limitStickRight);
+    Serial.print(" x: "); Serial.print(x);
+#endif
     Instrument[Steering].StickMoved = TRUE;
   }
 }


Further optimisations; more comments explaining structure

--- MatrixEffect/MatrixEffect.ino
+++ MatrixEffect/MatrixEffect.ino
@@ -5,15 +5,11 @@
 #define NUM_LEDS (ROWS*COLS)

 CRGB leds[NUM_LEDS];
+CRGB new_colors[NUM_LEDS];
+

 #define LOOP_TIME 20
 #define UPDATE_TIME 150
-
-#define _R 0
-#define _G 1
-#define _B 2
-
-CRGB new_colors[NUM_LEDS];

 // Return 0-based led index for 0-based x and y grid co-ordinate values
@@ -29,18 +25,23 @@
   }
 }

+// Send the colours out to the LEDs---right now also includes the low-pass filtering
 void sendColors(){
-  for(uint8_t y=0; y<ROWS; ++y)
-    for(uint8_t x=0; x<COLS; ++x){
-      for(uint8_t i=0; i<3; ++i)
-        leds[xy2i(x,y)][i] = (uint8_t) (((uint16_t) leds[xy2i(x,y)][i]*19 + new_colors[xy2i(x,y)][i])/20);
-    }
+  // We do not need to use the array structure here---just copy some values
+  for(uint8_t i_led=0; i_led<NUM_LEDS; ++i_led)
+    for(uint8_t i=0; i<3; ++i)
+      leds[i_led][i] = (uint8_t) (((uint16_t) leds[i_led][i]*19 + new_colors[i_led][i])/20);
+
   LEDS.show();
 }

+// Update the colours: in this case, propagate the "on" pixels downwards and seed
+// new pixels on the first row, to obtain a "Matrix effect"
 boolean onPixels[ROWS][COLS];
 void updateColors(){

+  // Loop through the rows, starting from the bottom, copying the "on" state from the
+  // row above and then clearing that pixel, to have the "on" state "walk down" the cols
   for(uint8_t y=ROWS-1; y>0; --y)
     for(uint8_t x=0; x<COLS; ++x){
       if(onPixels[y-1][x]){
@@ -48,28 +49,30 @@
         onPixels[y][x] = true;
         // and turn off that preceding one
         onPixels[y-1][x] = false;
-      } else {
-        onPixels[y][x] = false;
       }
     }

-  // Seed a new pixel
+  // Seed a new pixel in the first row, with a 30% chance
   if(random(0,10)>7){
     uint8_t randx = random(0,COLS);
     onPixels[0][randx] = true;
     new_colors[xy2i(randx,0)].setHSV(random(0,256), 255, 255);
   }

+  // Now percolate down the colours from top to bottom (again by looping from bottom to top)
   for(uint8_t y=ROWS-1; y>0; --y)
     for(uint8_t x=0; x<COLS; ++x){
       if(onPixels[y][x]){
-        for(uint8_t i=0; i<3; ++i)
-          new_colors[xy2i(x,y)][i] = new_colors[xy2i(x,y-1)][i];
+        // If on, copy the colour from the row above
+        new_colors[xy2i(x,y)] = new_colors[xy2i(x,y-1)];
       } else {
-        for(uint8_t i=0; i<3; ++i)
-          new_colors[xy2i(x,y)][i] = 0;
+        // If off, turn the pixel off (the actual pixel colour has a FO low-pass filter)
+        new_colors[xy2i(x,y)] = CRGB::Black;
       }
     }
+
+  // Finally, turn off all pixels in the first row that are not "on"
+  // This is a separate loop, because the on pixels should not get their colour from row -1
   for(uint8_t x=0; x<COLS; ++x){
     //first row -> turn off the off pixels after propagation of colour
     if(!onPixels[0][x]){