Some actual functionality has been added. Still doesn't work though.

--- system_monitor/system_monitor.ino
+++ system_monitor/system_monitor.ino
@@ -17,17 +17,24 @@

 #define AREF_VOLT 4.096 //Using an external voltage reference (LM4040)
 #define TEST 1 //Used during testing to enable/disable certain functionality
+#define NAME_LENGTH 24 // Length of the filenames
+
+#define RED_LED_PIN 3
+#define GREEN_LED_PIN 4
+
+// Global variable containing the current filename
+char filename[25] = "Poop.csv";

 const char NUM_SOURCES = 4; //number of voltage/current sources
 // System Order: Batt, Solar, Hydro, Load
-const char[] VOLT_PIN = [0, 1, 2, 3];
-const char[] VOLT_MULTI = [4, 5, 6, 7]; //Voltage divider multiplier
-const char[] AMP_PIN = [8, 9, 10, 11];
-const char[] AMP_MULTI = [1, 4, 4, 3]; //Number of wire passes
+const char VOLT_PIN[] = {0, 1, 2, 3};
+const char VOLT_MULTI[] = {3.8764, 7.3357, 12.3537, 3.8764}; //Voltage divider multiplier
+const char AMP_PIN[] = {8, 9, 10, 11};
+const char AMP_MULTI[] = {1, 4, 4, 3}; //Number of wire passes

 //Address of temperature sensors
 const int NUM_TEMPS = 3;
-const int[] TEMP_ADDRESS[1234, 5678, 9101];
+const int TEMP_ADDRESS[] = {1234, 5678, 9101};

 // Intervals used between readings/SD writes
 float STANDBY_INTERVAL = 3;
@@ -44,34 +51,77 @@
 // the logging file
 File TGC_logfile;

-float readVoltage(char PIN){
+void readVoltage(float *voltages[]){
+    #if TEST
+    for(int i=0; i++; i<NUM_SOURCES){
+        *voltages[i] = 13.8+i;
+    }
+        return;
+    #endif
+
+    for(int i=0; i++; i<NUM_SOURCES){
+        *voltages[i] =  analogRead(VOLT_PIN[i]) * VOLT_MULTI[i];
+    }
+    return;
+}//readVoltage
+
+void readAmp(float *amps[]){
+    #if TEST
+    for(int i=0; i++; i<NUM_SOURCES){
+        *amps[i] = 5.4+i;
+    }
+        return;
+    #endif
+
+    for(int i=0; i++; i<NUM_SOURCES){
+        *amps[i] =  analogRead(AMP_PIN[i]) * AMP_MULTI[i];
+    }
+    return;
+}//readAmp
+
+void readTemp(float *temps[]){
+    #if TEST
+    for(int i=0; i++; i<NUM_SOURCES){
+        *temps[i] = 20.3+i;
+    }
+        return;
+    #endif
+
+    for(int i=0; i++; i<NUM_TEMPS){
+        //do something
+    }
+    return;
+}//readTemp
+
+char readTime(){
     // TO DO
-    return 13.8;
+    return "2017_09_30-12-43-33";
 }

-float readAmp(char PIN){
-    // TO DO
-    return 4.1;
-}
-
-float readTemp(int address){
-    // TO DO
-    return 22.1;
-}
-
-char[] readTime(int address){
-    // TO DO
-    return "2017-09-30:12:43:33";
-}
-
-int writeSD(float[] volt, float[] amp, float[] temp, char[] time, float power){
+int writeSD(float volt[], float amp[], float temp[], char time[], float power){
     // TO DO
     return 0;
 }

-char[] readSD(){
+void readSD(char *data[]){
     // TO DO
-    return "0.1, 13.8, 20.0, stuff";
+    *data = "0.1, 13.8, 20.0, stuff";
+    return;
+}
+
+void newFile(){
+
+    char newName[] = "SHIT";
+    strcat(newName, ".csv");
+
+    TGC_logfile.close();
+    TGC_logfile = SD.open(newName, FILE_WRITE);
+
+    if(TGC_logfile){
+        TGC_logfile.println("#TGC Power System");
+        TGC_logfile.print("Created: ");
+        TGC_logfile.println(newName);
+    }
 }

 void standby(){
@@ -80,19 +130,12 @@
     float ampReadings[4];
     float tempReadings[3];

-    for(int i=0, i++, i<NUM_SORCES){
-        voltReadings[i] = readVoltage(VOLT_PIN[i]);
-        ampReadings[i] = readAmp(AMP_PIN[i]);
-    }
+    readVoltage(voltReadings[]);

-    for(int i=0, i++, i<NUM_TEMPS){
-        tempReadings[i] = readTemp(TEMP_ADDRESS[i]);
-    }

 }//standby

 void setup() {
-    //To-do

     Serial.begin(9600);
     Serial.println();


First crack at the wand lights. Adds blinking top, orange black, red slowblo, and blue body when activated

--- Arduino/Neutrino_Wand/Neutrino_Wand.ino
+++ Arduino/Neutrino_Wand/Neutrino_Wand.ino
@@ -10,12 +10,16 @@
 #define HIGH 0x1
 #define LOW  0x0

-// neopixel pins
+#define NEO_POWER 2 // for cyclotron and powercell
+Adafruit_NeoPixel powerStick = Adafruit_NeoPixel(44, NEO_POWER, NEO_GRB + NEO_KHZ800);
+
+// neopixel pins / setup
 #define NEO_NOSE 3 // for nose of wand
 Adafruit_NeoPixel noseJewel = Adafruit_NeoPixel(7, NEO_NOSE, NEO_GRB + NEO_KHZ800);

-#define NEO_POWER 2 // for cyclotron and powercell
-Adafruit_NeoPixel powerStick = Adafruit_NeoPixel(44, NEO_POWER, NEO_GRB + NEO_KHZ800);
+// neopixel pins / setup
+#define NEO_WAND 4 // for nose of wand
+Adafruit_NeoPixel wandLights = Adafruit_NeoPixel(4, NEO_WAND, NEO_GRB + NEO_KHZ800);

 // LED indexes into the neopixel powerstick chain for the cyclotron
 int c1Start = 16;
@@ -27,43 +31,41 @@
 int c4Start = 37;
 int c4End = 44;

-bool powerBooted = false; // has the pack booted up
-bool poweredDown = true;
-
-// soundboard pins
-#define SFX_RST 10
-#define SFX_RX 11
-#define SFX_TX 12
-
-// setup the board with the pins
-SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
-Adafruit_Soundboard sfx = Adafruit_Soundboard( & ss, NULL, SFX_RST);
-const int ACT = 13;// this connects to the act on the board so we can know if the audio is playing
-
-// ##############################
-// available options
-// ##############################
-const bool useGameCyclotronEffect = true; // set this to true to get the fading previous cyclotron light in the idle sequence
-
-// Possible Pack states
-bool isFiring = false;      // keeps track of the firing state
-bool shouldWarn = false;    // track the warning state for alert audio
-bool shuttingDown = false;  // is the pack in the process of shutting down
-
 // inputs for switches and buttons
 const int THEME_SWITCH = 5;
 const int STARTUP_SWITCH = 6;
 const int SAFETY_SWITCH = 7;
 const int FIRE_BUTTON = 8;

-// switch states for tracking
+// soundboard pins and setup
+#define SFX_RST 10
+#define SFX_RX 11
+#define SFX_TX 12
+const int ACT = 13;// this allows us to know if the audio is playing
+
+SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
+Adafruit_Soundboard sfx = Adafruit_Soundboard( & ss, NULL, SFX_RST);
+
+// ##############################
+// available options
+// ##############################
+const bool useGameCyclotronEffect = true; // set this to true to get the fading previous cyclotron light in the idle sequence
+
+// Possible Pack states
+bool powerBooted = false; // has the pack booted up
+bool isFiring = false;      // keeps track of the firing state
+bool shouldWarn = false;    // track the warning state for alert audio
+bool shuttingDown = false;  // is the pack in the process of shutting down
+bool poweredDown = true;
+
+// current switch states
+bool startup = false;
 bool theme = false;
-bool startup = false;
 bool safety = false;
 bool fire = false;
 bool warning = false;

-// audio track locations on soundboard
+// audio track names on soundboard
 const String startupTrack =   "T00     WAV";
 const String blastTrack =     "T01     WAV";
 const String endTrack =       "T02     WAV";
@@ -85,7 +87,9 @@
 const String boxTrack =       "T18     WAV";
 const String themeTrack =     "T19     OGG";

-QueueArray <int> dialogQueue; // this queue holds a shuffled list of dialog tracks we can pull from
+// this queue holds a shuffled list of dialog tracks we can pull from so we don't
+// play the same ones twice
+QueueArray <int> dialogQueue;

 // dialog trigger times/states
 unsigned long startDialogMillis;
@@ -93,7 +97,10 @@
 const int dialogWaitTime = 5000; // how long to hold down fire for a dialog to play
 const int warnWaitTime = 10000;  // how long to hold down fire before warning sounds

+// Arduino setup function
 void setup() {
+  randomSeed(analogRead(A0)); // try to get a good random seed
+
   // softwareserial at 9600 baud for the audio board
   ss.begin(9600);

@@ -115,6 +122,10 @@
   powerStick.begin();
   powerStick.setBrightness(20);
   powerStick.show(); // Initialize all pixels to 'off'
+
+  wandLights.begin();
+  wandLights.setBrightness(40);
+  wandLights.show();

   // set the modes for the switches/buttons
   pinMode(THEME_SWITCH, INPUT);
@@ -145,22 +156,17 @@
   }
 }

-int getRandomTrack()
-{
-  if ( !dialogQueue.isEmpty() )
-  {
+int getRandomTrack(){
+  if ( !dialogQueue.isEmpty() ){
     // pull the next dialog
     return dialogQueue.dequeue();
-  }
-  else
-  {
+  }else{
     // queue is empty so reset it and pull the first
     // random dialog
     int numDialog = sizeof(dialogArray) / sizeof(int);
     shuffleTrackArray( dialogArray, numDialog );

-    for (int i = 0; i < numDialog; i++)
-    {
+    for (int i = 0; i < numDialog; i++){
       dialogQueue.enqueue(dialogArray[i]);
     }

@@ -168,25 +174,17 @@
   }
 }

-// function for sorting arrays found here. Added random seed
+// function for sorting arrays found here.
 // https://forum.arduino.cc/index.php?topic=345964.0
-void shuffleTrackArray(int * array, int size)
-{
-  randomSeed(analogRead(A0));
-
+void shuffleTrackArray(int * array, int size){
   int last = 0;
   int temp = array[last];
-  for (int i = 0; i < size; i++)
-  {
+  for (int i = 0; i < size; i++){
     int index = random(size);
     array[last] = array[index];
     last = index;
   }
   array[last] = temp;
-}
-
-void stopTrack() {
-  sfx.stop();
 }

 /* ************* Main Loop ************* */
@@ -195,6 +193,7 @@
 int cyc_interval = 1000;      // interval at which to cycle lights for the cyclotron.
 int cyc_fade_interval = 15;   // fade the inactive cyclotron to light to nothing
 int firing_interval = 40;     // interval at which to cycle firing lights on the bargraph. We update this in the loop to speed up the animation so must be declared here (milliseconds).
+int wandFlashInterval = 1000; // interval at which we flash the top led on the wand

 void loop() {
   // get the current time
@@ -203,10 +202,14 @@
   // find out of the audio board is playing audio
   int playing = digitalRead(ACT);

-  // find out the theme switch state
+  // get the current switch states
   int theme_switch = digitalRead(THEME_SWITCH);
-
-  // if the theme switch has recently changed we should play the full ghostbusters theme song
+  int startup_switch = digitalRead(STARTUP_SWITCH);
+  int safety_switch = digitalRead(SAFETY_SWITCH);
+  int fire_button = digitalRead(FIRE_BUTTON);
+
+  // if the theme switch has recently changed from off to on we
+  // should play the full ghostbusters theme song
   if (theme_switch == 1) {
     if (theme == false) {
       playTrack(themeTrack);
@@ -215,14 +218,9 @@
   } else {
     theme = false;
   }
-
-  // now get the other switch/button states so we can handle animations/sounds
-  int startup_switch = digitalRead(STARTUP_SWITCH);
-  int safety_switch = digitalRead(SAFETY_SWITCH);
-  int fire_button = digitalRead(FIRE_BUTTON);
-
+
   // while the startup switch is set on
-  if (startup_switch == 1) {
+  if (startup_switch == 1) {
     // in general we always try to play the idle sound if started
     if (playing == 1 && startup == true) {
       playTrack(idleTrack);
@@ -233,6 +231,9 @@
       poweredDown = false;
       shuttingDown = false;
       powerSequenceOne(currentMillis, pwr_interval, cyc_interval, cyc_fade_interval);
+      flashWandLED(0, currentMillis, wandFlashInterval);    // set top light white blinking
+      setWandLightState(1, 2);    // set back light orange
+      setWandLightState(3, 0);    //set sloblow red
     } else {
       powerSequenceBoot(currentMillis);
     }
@@ -248,6 +249,10 @@
       }
     }

+    if( startup == true && safety_switch == 1 ){
+      setWandLightState(2, 3);    //set body white
+    }
+
     // if the safety switch is set off then we can fire when the button is pressed
     if ( safety_switch == 1 && fire_button == 0) {
       // if the button is just pressed we clear all led's to start the firing animations
@@ -296,6 +301,7 @@
             firing_interval = 20; // speed up the bar graph animation
             cyc_interval = 50;    // really speed up cyclotron
             cyc_fade_interval = 5;
+            wandFlashInterval = 250;
             if (playing == 1 || shouldWarn == false ) {
               shouldWarn = true;
               playTrack(warnTrack); // play the firing track with the warning
@@ -304,6 +310,7 @@
             pwr_interval = 40;    // speed up the powercell animation
             firing_interval = 30; // speed up the bar graph animation
             cyc_interval = 300;   // speed up cyclotron
+            wandFlashInterval = 500;
             cyc_fade_interval = 10;
             if (playing == 1) {
               playTrack(blastTrack); // play the normal blast track
@@ -317,6 +324,7 @@
           firing_interval = 40;
           cyc_interval = 1000;
           cyc_fade_interval = 15;
+          wandFlashInterval = 1000;
           fire = false;

           // see if we've been firing long enough to get the dialog or vent sounds
@@ -368,6 +376,7 @@
     } else {
       // if the safety is switched off play the click track
       if (safety == true) {
+        setWandLightState(2, 4);    //set body off
         safety = false;
         playTrack(clickTrack);
       }
@@ -415,6 +424,44 @@
 // animation level trackers for the boot and shutdown
 int currentBootLevel = -1;          // current powercell boot level sequence led
 int currentLightLevel = 15;         // current powercell boot light sequence led
+
+void setWandLightState(int lednum, int state){
+  switch ( state ) {
+    case 0: // set led red
+        wandLights.setPixelColor(lednum, wandLights.Color(255, 0, 0));
+      break;
+    case 1: // set led white
+      wandLights.setPixelColor(lednum, wandLights.Color(255, 255, 255));
+      break;
+    case 2: // set led orange
+      wandLights.setPixelColor(lednum, wandLights.Color(255, 255, 0));
+      break;
+    case 3: // set led orange
+      wandLights.setPixelColor(lednum, wandLights.Color(0, 0, 255));
+      break;
+    case 4: // set led off
+      wandLights.setPixelColor(lednum, 0);
+      break;
+  }
+
+  wandLights.show();
+}
+
+unsigned long prevFlashMillis = 0;        // last time we changed a powercell light in the idle sequence
+bool flashState = false;
+void flashWandLED(int lednum, int currentMillis, int flashInterval){
+  if (currentMillis - prevFlashMillis > flashInterval) {
+    prevFlashMillis = currentMillis;
+    if( flashState == false ){
+      wandLights.setPixelColor(lednum, wandLights.Color(255, 255, 255));
+      flashState = true;
+    }else{
+      wandLights.setPixelColor(lednum, 0);
+      flashState = false;
+    }
+  }
+  wandLights.show();
+}

 // helper function to set light states for the cyclotron
 int cyclotronRunningFadeOut = 255;  // we reset this variable every time we change the cyclotron index so the fade effect works
@@ -463,6 +510,11 @@
     powerStick.setPixelColor(i, 0);
   }
   powerStick.show();
+
+  for ( int j=0; j<=3; j++ ){
+    wandLights.setPixelColor(j, 0);
+  }
+  wandLights.show();
 }

 // boot animation on the powercell/cyclotron


Update ArduinoMainSketch.ino

Update ArduinoMainSketch.ino


Improve the stability

Improve the stability

--- DigitalSynthVRA8P/DigitalSynthVRA8P.ino
+++ DigitalSynthVRA8P/DigitalSynthVRA8P.ino
@@ -5,6 +5,7 @@
 #include "audio-out.h"

 void setup() {
+  noInterrupts();
   Synth<0>::initialize();
   SerialIn<0>::open();
   AudioOut<0>::open();


add third analog channel for solar panel volts


Delete Pattern_Recognition_Distance_Sensor.ino

--- Pattern_Recognition_Distance_Sensor.ino
+++ Pattern_Recognition_Distance_Sensor.ino
@@ -1,83 +0,0 @@
-//Distance Sensor
-//Feature is height
-//Pre-known object of different heights
-//Pattern is see what the object is closest to.
-
-#include <NewPing.h>
-
-#define TRIGGER_PIN 12
-#define ECHO_PIN 11
-#define MAX_DISTANCE 50
-
-NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
-
-struct Features {
-  int height;
-};
-
-Features Feature_Extraction() {
-  Features features;
-  //Get height
-
-  int dist = sonar.ping_cm();
-  features.height = MAX_DISTANCE - dist;
-
-  return features;
-}
-
-String Pattern_Recognition(Features features) {
-  //Banana is 3-7cm (3 <= x < 7)
-  //Apple-Orange height is 7-11cm (7 <= x < 11)
-  //Small box is 11-25cm (11 <= x < 25)
-  //Medium box is 25-35cm (25 <= x < 35)
-  //Big box is 35-45cm (35 <= x < 45)
-  //Pre-known object of different heights
-  //Pattern is see what the object is closest to.
-
-  String closest_object;
-
-  if(features.height >= 3 && features.height < 7) {
-    closest_object = "Banana";
-  }
-  else if(features.height >= 7 && features.height < 11) {
-    closest_object = "Apple or Orange";
-  }
-  else if(features.height >= 11 && features.height < 25) {
-    closest_object = "Small box";
-  }
-  else if(features.height >= 25 && features.height < 35) {
-    closest_object = "Medium box";
-  }
-  else if(features.height >= 35 && features.height < 45) {
-    closest_object = "Large box";
-  }
-  else {
-    closest_object = "Unknown";
-  }
-  return closest_object;
-}
-
-void Actuation(String object) {
-  Serial.print(object);
-}
-
-void setup() {
-
-  Serial.begin(9600);
-}
-
-void loop() {
-  //Turns both LEDs off before each reading
-
-  //Should put feature extraction and pattern recognition in one multi-second for loop to
-    //give the box time to go through the sensors.
-  Features feature_states;
-  feature_states = Feature_Extraction();
-
-  String closest_object;
-  closest_object = Pattern_Recognition(feature_states);
-
-  Actuation(closest_object);
-
-  delay(1000);
-}


New version

New version

--- Weight.ino
+++ Weight.ino
@@ -85,7 +85,7 @@

 //MENU
 char* EMPTY = "                ";
-char* beerSizes[] = {"0.33", "0.5"};
+MenuItem beerSizes[] = {{"0.33"}, {"0.5"}};
 MenuItem menu[] = {{"Calibrate"} , {"Tare"} , {"Beersize"} , {"Keg Weight"}};
 unsigned int lastItem = 3;
 unsigned int menuMarker = 0;
@@ -96,7 +96,6 @@

 void setup() {
   Serial.begin(BAUD_RATE);
-
   lcd.begin(16, 2);
   lcd.print("Starting...");
   for (int i = 0; i < WEIGHT_SENSORS; i++) {


UNTESTED beginning support for position recovery after crash

--- arduino/motor_driver/motor_driver.ino
+++ arduino/motor_driver/motor_driver.ino
@@ -34,6 +34,9 @@
 // EEPROM library
 #include <EEPROM.h>

+// PERSISTENT STORAGE locations
+const int EEPROM_MOTOR_ID = 0;
+const int EEPROM_REMEMBER_POSITION = 1;

 // IMPORTANT SETTINGS ----------------------------

@@ -58,7 +61,9 @@
 const int encoder0PinB = 3;  // black   PORTD BIT 3
 const byte encoder0PinBMask = 0x08;
 const int encoder0PinZ = 4;  // orange
-volatile long encoder0Pos = 0;
+volatile long encoder0Pos __attribute__ ((section (".noinit")));
+volatile long encoder0Checksum __attribute__ ((section (".noinit")));
+const long encoder0ChecksumKey = 314159265L;
 volatile long encoder0Zero = 0;
 volatile long encoder0ZeroState = 0;

@@ -103,7 +108,7 @@
 // NETWORK SETUP  -------

 // get motor id (0 for NW motor, 1 for NE, 2 for SE, 3 for SW) from EEPROM address 0
-int MOTOR_ID = EEPROM.read(0);
+int MOTOR_ID = EEPROM.read(EEPROM_MOTOR_ID);

 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, MOTOR_ID };
 IPAddress listeningIP(192,168,LOCALNET,42+MOTOR_ID); // you need to set this
@@ -149,8 +154,9 @@

 void setup() {
   setupEthernet();
-  setupEncoder();
-  setupMotorDriver();
+  homed = setupEncoder();
+  if (homed) state = OK;
+  setupMotorDriver(homed);
   setupEndstops();
   setupPID();

@@ -313,20 +319,32 @@
   myPID.SetOutputLimits(-ms, ms);
 }

-void setupEncoder() {
+// setupEncoder will check if encoder position is retained in RAM after a crash
+// and return true if so
+bool setupEncoder() {
   pinMode(encoder0PinA, INPUT);
   pinMode(encoder0PinB, INPUT);
   pinMode(encoder0PinZ, INPUT);
   // encoder pin on interrupt 0 (pin 2)
   attachInterrupt(0, doEncoderA, RISING);
-}
-
-void setupMotorDriver() {
+
+  if (EEPROM.read(EEPROM_REMEMBER_POSITION) == 1) {
+    // check if encoder value can be recovered after crash
+    if (encoder0Pos ^ encoder0ChecksumKey == encoder0Checksum) {
+      // yes! let's claim we're homed
+      return true;
+    }
+  }
+
+  return false;
+}
+
+void setupMotorDriver(bool poweron) {
   //pinMode(PULSEPIN, OUTPUT); pwm() will do this
   pinMode(DIRPIN, OUTPUT);
   pinMode(ENAPIN, OUTPUT);

-  digitalWrite(ENAPIN, 0); // disable motor driver
+  digitalWrite(ENAPIN, poweron); // disable motor driver

   // set up interrupts for motor speed control
   Timer1.initialize(1000);
@@ -416,6 +434,8 @@
   else {
     encoder0Pos ++;
   }
+
+  encoder0Checksum = encoder0Pos ^ encoder0ChecksumKey;
 }

@@ -615,6 +635,27 @@
 }

+// force calibration (one motor at a time only!)
+void oscSetPosition(OscMessage &m) {
+  if (m.getInt(0) == MOTOR_ID) {
+    encoder0Pos = (long)m.getFloat(1);
+  }
+}
+
+
+// preferences: try to remember encoder value through a crash
+void oscRememberPosition(OscMessage &m) {
+  if (m.size()==1 || (m.size()==2 && m.getInt(0)==MOTOR_ID)) {
+    int p = m.getInt(m.size()-1);
+    if (p) {
+      EEPROM.write(EEPROM_REMEMBER_POSITION, 1);
+    }
+    else {
+      EEPROM.write(EEPROM_REMEMBER_POSITION, 0);
+    }
+  }
+}
+

 // WATCHDOG TEST
 void oscCrash(OscMessage &m) {


Updated (still IP) arduino code

Updated (still IP) arduino code

--- ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
+++ ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
@@ -9,6 +9,7 @@
 float input_step;
 int input_mode;
 float input_torque;
+float input_delay;

 AMIS30543 stepper;

@@ -40,26 +41,43 @@

 void loop()
 {
-  if(Serial.available()){
+  //Serial.println("moo");
+  if(Serial.available() && false){
       String data = Serial.readString();

       // convert speed from RPM to milliseconds per step
       // 1 RPM = 200/60 steps/sec
-      input_speed = data.substring(1,5).toInt();
-      input_step = data.substring(6,14).toInt();
-      input_mode = data.substring(15,18).toInt();
-      input_delay = data.substring(19,25).toInt();
-      if(data.substring(26) == "Up")
+      int indices[4];
+      int j = 0;
+      for (int i= 1; i < data.length(); ++i)
+      {
+        if (data.substring(i,i+1) == "x")
+        {
+           indices[j] = i;
+           ++j;
+        }
+      }
+      input_speed = data.substring(1, indices[0]).toInt();
+      input_step = data.substring(indices[0]+1, indices[1]).toInt();
+      input_mode = data.substring(indices[1]+1, indices[2]).toInt();
+      input_delay = data.substring(indices[2]+1, indices[3]).toInt();
+      if(data.substring(indices[3]+1, data.length()) == "Up")
         setDirection(0);
-      if(data.substring(26) == "Down")
+      if(data.substring(indices[3]+1, data.length()) == "Down")
         setDirection(1);
-
+
+      //Serial.println(input_speed);
+      //Serial.println(input_step);
+      //Serial.println(input_mode);
+      //Serial.println(input_delay);
+      //Serial.println(data.substring(indices[3]+1, data.length()));
+
       // valid step modes: 1, 2, 4, 8, 16, 32, 64, 128
       stepper.setStepMode(input_mode);

       for (int x = 0; x < input_step; x++)
       {
-        step(input_speed);
+        step(input_delay);
         Serial.println(x);
       }
   }
@@ -67,7 +85,7 @@

 // Sends a pulse on the NXT/STEP pin to tell the driver to take
 // one step, and also delays to control the speed of the motor.
-void step(float user_speed)
+void step(float input_delay)
 {
   // The NXT/STEP minimum high pulse width is 2 microseconds.
   digitalWrite(amisStepPin, HIGH);


Add watchdog

Add watchdog

--- arduino-light-dimmer-ble/arduino-light-dimmer-ble.ino
+++ arduino-light-dimmer-ble/arduino-light-dimmer-ble.ino
@@ -125,11 +125,14 @@
 volatile uint8_t zerocross_isr_flag;
 uint16_t num_cycles;
 uint8_t led2_state;
+uint8_t mins_since_last_remote_command;
+
 DimmerChannel<SSR1_PIN> ch1;
 DimmerChannel<SSR2_PIN> ch2;
 DimmerChannel<SSR3_PIN> ch3;
 DimmerChannel<SSR4_PIN> ch4;

+
 void setup()
 {
   pinMode(LED1, OUTPUT);
@@ -145,6 +148,7 @@
   ch3.initialize();
   ch4.initialize();

+  mins_since_last_remote_command = 0;
   Serial.begin(9600);
   initialize_hm10_beacon();

@@ -166,6 +170,17 @@
     ++num_cycles;
     digitalWrite(LED1, (num_cycles & 0x10) ? HIGH : LOW);
     if (num_cycles == 600)  {  // Every ~1 minute
+      ++mins_since_last_remote_command;
+      if (mins_since_last_remote_command >= 240) {  // Every ~4 hours.
+        ch1.set_duty_cycle_smoothing_rate(1);
+        ch1.set_brightness(0);
+        ch2.set_duty_cycle_smoothing_rate(1);
+        ch2.set_brightness(0);
+        ch3.set_duty_cycle_smoothing_rate(1);
+        ch3.set_brightness(0);
+        ch4.set_duty_cycle_smoothing_rate(1);
+        ch4.set_brightness(0);
+      }
       ch1.store_brightness_in_eeprom();
       ch2.store_brightness_in_eeprom();
       ch3.store_brightness_in_eeprom();
@@ -250,6 +265,7 @@
   cmd.raw = Serial.read();
   if (cmd.raw != Serial.peek())
     return;
+
   Serial.read();  // Consume the copy msg;
   if (cmd.op == SET_PERIOD)  {
     switch (cmd.channel) {
@@ -268,6 +284,7 @@
   }
   led2_state = led2_state ? LOW : HIGH;
   digitalWrite(LED2, led2_state);
+  mins_since_last_remote_command = 0;
 }

 void hm10_beacon_send_current_brightness() {


Added configureToWrite

Added configureToWrite

--- software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
+++ software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
@@ -6,10 +6,13 @@

 I2cDiscreteIoExpander device(1);

+#define LEFT 0
+#define RIGHT 1
+
 void setup() {
   // put your setup code here, to run once:

-  Wire.begin();
+  Wire.begin();  //A4(SDA), A5(SCL)

   PCComm.begin(9600);
   PCComm.print("\n\r[Board Init]\n\r");
@@ -21,7 +24,7 @@

 const uint8_t dispRight = (1<<7);
 const uint16_t dispLeft = (dispRight<<8);
-const uint8_t charsL [16] = {0b1000000,0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000,0b0001000,0b0000011,0b1000110,0b0100001,0b0000110,0b0001110};
+const uint8_t charsL [16] = {0b1000000,0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000,0b0001000,0b0000011,0b1000110,0b0100001,0b0000110,0b0001110};  //Contains the constants for the 7seg values
 const uint8_t nothingL = 0b1111111;

 enum MasterStates {
@@ -41,23 +44,16 @@

   switch(CurrentState) {
     case DISPLEFT:
-      to_write += dispLeft;
-      to_write += charsL[1];
-      to_write += (charsL[2] << 8);
-
+	  configureToWrite(to_write, LEFT, '1' , '2');
+
       CurrentState = DISPRIGHT;
       break;
     case DISPRIGHT:
-      to_write += dispRight;
-      to_write += charsL[3];
-      to_write += (charsL[4] << 8);
-
+      configureToWrite(to_write, RIGHT, '3', '4');
+
       CurrentState = DISPLEFT;
       break;
   }
-
-
-  //to_write = 0 + charsL[4] + (charsL[2] << 8) + dispLeft;

   status = device.digitalWrite(to_write);

@@ -75,11 +71,38 @@
   ++iter;
 }

+void configureToWrite(uint16_t & to_write, bool l_r, char left_digit, char right_digit){
+	to_write = 0;
+
+	if(l_r == LEFT){
+		to_write += dispLeft;
+	}
+	else if (l_r == RIGHT){
+		to_write += dispRight;
+	}
+
+	if(isdigit(left_digit)){
+		to_write += charsL[(int)left_digit - 48];
+	}
+
+	if(isdigit(right_digit)){
+		to_write += (charsL[(int)right_digit - 48] << 8);
+	}
+
+}

 /* "Recycle Bin"

              //  mgfedcbamgfedcba
   //to_write = 0b0100000101000000;//(1<<1) + (1<<2) + (1<<3) + (1<<4) + (1<<5) + (1<<6) + (1<<7);

-
+
+    //  to_write += dispLeft;
+    //  to_write += charsL[1];
+    //  to_write += (charsL[2] << 8);
+
+    //  to_write += dispRight;
+    //  to_write += charsL[3];
+    //  to_write += (charsL[4] << 8);
+
 */


Added writeToDisplay member function

Added writeToDisplay member function

--- software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
+++ software/_proto_DriverFirmware/MainControlFirmware/MainControlFirmware.ino
@@ -39,6 +39,7 @@
 		~Display();
 		void dispRight();
 		void dispLeft();
+		int writeToDisplay();
 		I2cDiscreteIoExpander * device;
 		uint16_t current;
 		uint16_t left;
@@ -85,7 +86,7 @@

   uint16_t to_write = 0;

-  if(!timing){
+  if(!timing){  //Time to do the asynch task
 	//PCComm.println("[Processing configureToWrite]");

 	i = ++i%10;
@@ -109,9 +110,8 @@
       break;
   }

-
-  status = disp.device->digitalWrite(disp.current);
-  status2 = disp2.device->digitalWrite(disp.current);
+  disp.writeToDisplay();
+  disp2.writeToDisplay();

   /*
@@ -200,6 +200,10 @@
 	current = left;
 }

+int Display::writeToDisplay(){
+	device->digitalWrite(current);
+}
+
 //Display struct classes

 /* "Recycle Bin"


New sw Arduino serial

New sw Arduino serial

--- SoftwareArduino/SoftwareSerialArduinitoRasp/SoftwareSerialArduinitoRasp.ino
+++ SoftwareArduino/SoftwareSerialArduinitoRasp/SoftwareSerialArduinitoRasp.ino
@@ -24,13 +24,6 @@

 #include <SoftwareSerial.h>

-#include <PWM.h>
-
-int brightness = 0;         // how bright the LED is
-int fadeAmount = 5;         // how many points to fade the LED by
-int32_t frequency = 100;    //frequency (in Hz)
-uint8_t pwm_value = 25;     // pwm_value  = Motor Stopped   :  Pulse Widh = 1ns
-long duration, distance;
 int a, i, j = 0;
 int v[500];  // maximun message size

@@ -41,26 +34,13 @@
 {
   pinMode(13, OUTPUT);

-  pinMode(trigPin, OUTPUT);
-  pinMode(echoPin, INPUT);
-
-  pinMode(motorleft, OUTPUT);

   // Open hardware serial communications and wait for port to open:
   Serial.begin(9600);

   // set the data rate for the SoftwareSerial port
   mySerial.begin(9600);
-
-  //initialize all timers except for 0, to save time keeping functions
-  InitTimersSafe();
-  //sets the frequency for the specified pin
-  bool success = SetPinFrequencySafe(motorleft, frequency);
-  //if the pin frequency was set successfully, pin 13 turn on
-  if(success)     digitalWrite(13, HIGH);
-  else            digitalWrite(13, LOW);
-
-  pwmWrite(motorleft, pwm_value);  // Maximum Speed  // pwmWrite(led, DUTY * 256 / 100);  //
+  digitalWrite(13, HIGH);
   delay(1000);    // Time to turn motors on with low throtle
   digitalWrite(13, LOW);


Reimplement performRangeTest in terms of drawRectangle

--- dee-oh-tee.ino
+++ dee-oh-tee.ino
@@ -116,13 +116,9 @@
 }

 void performRangeTest() {
-  moveToPoint(0, 0, 50);
-  moveToPoint(-90, 90, 50);
-  moveToPoint(-90, -90, 50);
-  moveToPoint(90, -90, 50);
-  moveToPoint(90, 90, 50);
-  moveToPoint(-90, 90, 50);
-  moveToPoint(0, 0, 50);
+  moveToPoint(0, 0, 15);
+  drawRectangle(-USABLE_DEGREES / 2, -USABLE_DEGREES / 2, USABLE_DEGREES, USABLE_DEGREES, 15);
+  moveToPoint(0, 0, 15);
 }

 // Laser control


adding moisture sensor and average

adding moisture sensor and average

--- _04-lcd-dust/_04-mqtt-lcd-dust-sensor-nano/_04-mqtt-lcd-dust-sensor-nano.ino
+++ _04-lcd-dust/_04-mqtt-lcd-dust-sensor-nano/_04-mqtt-lcd-dust-sensor-nano.ino
@@ -1,5 +1,9 @@
 #include <IRremote.h>
 #include <Wire.h>
+#include <Average.h>
+
+Average<float> ave1(4);
+Average<float> ave2(4);

 /*
  Sharp Optical Dust Sensor GP2Y1010AU0F
@@ -8,6 +12,8 @@
 // ------------------------------------------
 int measurePin = A6; //Connect dust sensor to Arduino A6 pin
 int ledPower = 2;   //Connect 3 led driver pins of dust sensor to Arduino D2
+
+int moisturePin = A2;

 int IR_receive_recv_PIN = 6;
 int IR_receive_GND_PIN  = 7;
@@ -46,6 +52,8 @@
 int sleepTime = 9680;

 int voMeasured = 0;
+int moMeasured = 0;
+
 float calcVoltage = 0;
 float dustDensity = 0;

@@ -101,7 +109,7 @@

   delay(100);
   irsend.sendLGAC(code, 28);
-
+
   delay(100);
   irrecv.enableIRIn(); // Start the receiver
 }
@@ -290,7 +298,7 @@
     dumpInfo(&results);
   }

-  if ((millis() - startMills) > 3000 ) {
+  if ((millis() - startMills) > 200 ) {

     digitalWrite(ledPower, LOW); // power on the LED
     delayMicroseconds(samplingTime);
@@ -301,9 +309,18 @@
     digitalWrite(ledPower, HIGH); // turn the LED off
     delayMicroseconds(sleepTime);

+    moMeasured = analogRead(moisturePin);
+
+    ave1.push(voMeasured);
+    ave2.push(moMeasured);
+
     startMills = millis();

-    //Serial.println(voMeasured);
+    /*
+    Serial.println(ave1.mean());
+    Serial.println(ave2.mean());
+    */
+
   }

   if ((sleepmode == HIGH) && ( ( millis() - ac_startMills) >= 1800000 )) {
@@ -316,14 +333,16 @@

 void requestEvent()
 {
-  byte myArray[2];
+  byte myArray[4];
   int sleepmodetosend ;

   if ( sleepmode == o_sleepmode ) {
-    myArray[0] = (voMeasured >> 8 ) & 0xFF;
-    myArray[1] = voMeasured & 0xFF;
-
-    Wire.write(myArray, 2);
+    myArray[0] = (int(ave1.mean()) >> 8 ) & 0xFF;
+    myArray[1] = int(ave1.mean()) & 0xFF;
+    myArray[2] = (int(ave2.mean()) >> 8 ) & 0xFF;
+    myArray[3] = int(ave2.mean()) & 0xFF;
+
+    Wire.write(myArray, 4);
   }

   if ( sleepmode != o_sleepmode )  {
@@ -334,8 +353,10 @@
     }
     myArray[0] = (sleepmodetosend >> 8 ) & 0xFF;
     myArray[1] = sleepmodetosend & 0xFF;
-
-    Wire.write(myArray, 2);
+    myArray[2] = (int(ave2.mean()) >> 8 ) & 0xFF;
+    myArray[3] = int(ave2.mean()) & 0xFF;
+
+    Wire.write(myArray, 4);

     o_sleepmode = sleepmode;
   }


ble_set_in_test_mode_ACI done

ble_set_in_test_mode_ACI done

--- libraries/BLE/examples/ble_set_in_test_mode_ACI/ble_set_in_test_mode_ACI.ino
+++ libraries/BLE/examples/ble_set_in_test_mode_ACI/ble_set_in_test_mode_ACI.ino
@@ -36,7 +36,6 @@
 @todo: Test this to make sure it works with both the pyhon script and nRFgo studio: You can send the DTM commands from the nRFgo studio or from a Nordic Semiconductor supplied python script on a Windows PC.
  */
 #include <SPI.h>
-#include <avr/pgmspace.h>
 #include <hal_aci_tl.h>
 #include <lib_aci.h>

@@ -97,13 +96,17 @@
   aci_state.aci_pins.interface_is_interrupt	  = false;
   aci_state.aci_pins.interrupt_number	          = 1;

-  lib_aci_init(&aci_state);
+  //We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
+  //and initialize the data structures required to setup the nRF8001
+  //The second parameter is for turning debug printing on for the ACI Commands and Events so they be printed on the Serial
+  lib_aci_init(&aci_state, true);

   Serial.println(F("nRF8001 Reset done"));
 }

 void aci_loop(void)
 {
+
   // We enter the if statement only when there is a ACI event available to be processed
   if (lib_aci_event_get(&aci_state, &aci_data))
   {


Added a couple more asserts for setAuthenticationHeader.

--- tests/ApiClientTest.ino
+++ tests/ApiClientTest.ino
@@ -23,6 +23,22 @@
   const char *auth_header_char = "00000000000000000000000000000000";
   client.setAuthorizationHeader(auth_header_char);
   assertEqual(client.auth_header.type, POINTER_UNION_TYPE_CHAR);
+  assertEqual(client.auth_header.u.char_ptr, auth_header_char);
+
+  StringPointer auth_header;
+  auth_header.type = POINTER_UNION_TYPE_FLASHSTRING;
+  auth_header.u.flashstring_ptr = auth_header_flashstring;
+  client.setAuthorizationHeader(auth_header);
+  assertEqual(client.auth_header.u.flashstring_ptr, auth_header_flashstring);
+
+  auth_header.type = POINTER_UNION_TYPE_STRING;
+  auth_header.u.string_ptr = &auth_header_string;
+  client.setAuthorizationHeader(auth_header);
+  assertEqual(*client.auth_header.u.string_ptr, auth_header_string);
+
+  auth_header.type = POINTER_UNION_TYPE_CHAR;
+  auth_header.u.char_ptr = auth_header_char;
+  client.setAuthorizationHeader(auth_header);
   assertEqual(client.auth_header.u.char_ptr, auth_header_char);

 }
@@ -89,6 +105,7 @@
   retval = client.post(url_char, data_char);
   assertEqual(client.request_buffer, request);
   assertEqual(retval, 0);
+
 }

 test(get)


added some game status control

added some game status control

--- tictactoe/tictactoe.ino
+++ tictactoe/tictactoe.ino
@@ -39,8 +39,29 @@

 // the loop routine runs over and over again forever:
 void loop() {
-  checkColors();
-  setLeds();
+  int gameStatus = 0; //0 = ongoing game, 1 = you win, 2 = opponent wins
+  if (gameStatus == 0){
+    checkColors();
+    setLeds();
+    gameStatus = checkVictoryConditions();
+  } else if (gameStatus == 1){
+    blinkLeds(0,1);
+  } else if (gameStatus == 2){
+    blinkLeds(1,0);
+  }
+}
+
+void blinkLeds(int redValue, int greenValue){
+  sd.clear();
+  while(true){ //TODO change this
+    for (int i = 0; i < 9; i++){
+      sd.setPin(redPins[i],redValue);
+      sd.setPin(greenPins[i],greenValue);
+      delay(50);
+      sd.setPin(redPins[i],0);
+      sd.setPin(greenPins[i],0);
+    }
+  }
 }

 void setLeds(){
@@ -86,4 +107,9 @@
   return color;
 }

+//0 = ongoing game, 1 = you win, 2 = opponent wins
+int checkVictoryConditions(){

+}
+
+


add parameter to setWriteable

add parameter to setWriteable

--- examples/Blynk/Blynk.ino
+++ examples/Blynk/Blynk.ino
@@ -32,7 +32,7 @@
 void globalCallbackHandler(const IDatapoint& dp, DPValue value) {
   char value_str[15] = {0};
   value.getString(value_str, sizeof(value_str));
-  terminal.printf("Received: %s - %s: %s\n", dp.getGroup, dp.getName, value_str);
+  terminal.printf("Received: %s - %s: %s\n", dp.getGroup(), dp.getName(), value_str);
 }

 // send receive outside temperature to virtual pin V1
@@ -60,7 +60,7 @@
   VitoWifi.setLogger(&terminal);  // might be too verbose/fast for Blynk to handle
   VitoWifi.enableLogger();  // might be too verbose/fast for Blynk to handle
   VitoWifi.addDatapoint("outsidetemp", "boiler", 0x5525, TEMPL).setCallback(sendOutsidetemp);
-  VitoWifi.addDatapoint("roomtempset", "heating", 0x2306, TEMPS).setWriteable().setCallback(sendRoomtempSet);
+  VitoWifi.addDatapoint("roomtempset", "heating", 0x2306, TEMPS).setWriteable(true).setCallback(sendRoomtempSet);
   VitoWifi.setGlobalCallback(globalCallbackHandler);
   VitoWifi.setup(&Serial);


adding EOL charcters

adding EOL charcters

--- arduino/medox/medox.ino
+++ arduino/medox/medox.ino
@@ -109,9 +109,11 @@
   tempFloat = analogRead(temperature);
   tempFloat = tempFloat * (5 / 1024); //converting binary number to voltage (0-1024)->(0-5)
   Serial.print(tempFloat);
+  Serial.print("\r\n");
   tempFloat = analogRead(lightLevel);
   tempFloat = tempFloat * (5 / 1024); //converting binary number to voltage (0-1024)->(0-5)
   Serial.print(tempFloat);
+  Serial.print("\r\n");
 }

 //converting array of characters to int
@@ -162,8 +164,10 @@
   //check number of dispensed bills
   if(billCount == total)
     Serial.print("t");
+	Serial.print("\r\n");
   else if(billCount != total)
     Serial.print("f");
+	Serial.print("\r\n");
   billCount = 0; //resets billCount
 }


Firmware ~ Triangle cross mode - better color change mode

--- arduino/tLamp/TLamp.ino
+++ arduino/tLamp/TLamp.ino
@@ -10,12 +10,21 @@
 #define EMPTY_COMMAND_FAIL ""

 enum LightMode {
-  NONE, STATIC, CRUDE, CANDLE
+  NONE, STATIC, CRUDE, TRIANGLE, CANDLE
 };

 const int crude_T = 5000;
 const int crude_I = 255/2;
 const float crude_Ts = 1.0/6 * crude_T;
+
+int currentR;
+int currentG;
+int currentB;
+
+byte triangleMode = 0;
+byte triangleStep = 5;
+unsigned int triangleDelay = 50;
+unsigned long triangleStepTime;

 unsigned long lightModeStart = 0;
 LightMode lightMode = NONE;
@@ -59,6 +68,9 @@
     case LightMode::CRUDE:
       processCrudeLightMode();
       break;
+    case LightMode::TRIANGLE:
+      processTriangleLightMode();
+      break;
   }
 }

@@ -71,6 +83,48 @@
   setColor(r, g, b);
 }

+void processTriangleLightMode() {
+  unsigned long ms = millis();
+  if (ms < triangleStepTime) {
+    return;
+  }
+
+  int r = 0;
+  int g = 0;
+  int b = 0;
+
+  switch (triangleMode) {
+    case 0: // From RED to GREEN
+      r = currentR - triangleStep;
+      g = currentG + triangleStep;
+
+      if (r <= 0) r = 0;
+      if (g >= 255) g = 255;
+      if (g == 255) triangleMode = 1;
+      break;
+    case 1:
+      g = currentG - triangleStep;
+      b = currentB + triangleStep;
+
+      if (g <= 0) g = 0;
+      if (b >= 255) b = 255;
+      if (b == 255) triangleMode = 2;
+      break;
+    case 2:
+      r = currentR + triangleStep;
+      b = currentB - triangleStep;
+
+      if (b <= 0) b = 0;
+      if (r >= 255) r = 255;
+      if (r == 255) triangleMode = 0;
+      break;
+  }
+
+  setColor(r, g, b);
+
+  triangleStepTime = ms + triangleDelay;
+}
+
 String processCommand(String command) {
   if (command.startsWith("SET #")) {
     String colorStr = command.substring(5, 5+6);
@@ -93,6 +147,11 @@
     lightModeStart = millis();
     setLightMode(CRUDE);
     return EMPTY_COMMAND_SUCCESS;
+  } else if (command.equals("TRIANGLE_CROSS")) {
+    lightModeStart = millis();
+    setLightMode(TRIANGLE);
+    triangleMode = 0;
+    return EMPTY_COMMAND_SUCCESS;
   } else if (command.startsWith("VERSION")) {
     return FIRMWARE_VERSION;
   }
@@ -105,6 +164,10 @@
 }

 void setColor(int r, int g, int b) {
+  currentR = r;
+  currentG = g;
+  currentB = b;
+
   analogWrite(PIN_RED, r);
   analogWrite(PIN_GREEN, g / 2);// * 5 / 3);
   analogWrite(PIN_BLUE, b / 2);


some lights to flash serial example to better understand progress

--- rfidble/arduino_sketches/flash_serial_example/flash_serial_example.ino
+++ rfidble/arduino_sketches/flash_serial_example/flash_serial_example.ino
@@ -5,20 +5,23 @@
 #include <SPI.h>

 #define FSIZE 256
+#define ledPin 13

 const char *filename = "myfile2.txt";
-const char *contents = "1234567890ABCDEFGHIJ";
+const char *contents = "1234567890ABCDEFGHIJKL";

 void setup() {
   Serial.begin(9600);
+  pinMode(ledPin, OUTPUT);

+  parpadear (3,1000);
   // wait for Arduino Serial Monitor
-  while (!Serial) ;
-  delay(100);
-
+  delay(1000);
+  parpadear (5,200);
   // Init. SPI Flash chip
   if (!SerialFlash.begin(ONBOARD_FLASH_SPI_PORT, ONBOARD_FLASH_CS_PIN)) {
     Serial.println("Unable to access SPI Flash chip");
+    digitalWrite(ledPin, HIGH);
   }

   SerialFlashFile file;
@@ -26,16 +29,18 @@
   // Create the file if it doesn't exist
   if (!create_if_not_exists(filename)) {
     Serial.println("Not enough space to create file " + String(filename));
+    digitalWrite(ledPin, HIGH);
     return;
   }

   // Open the file and write test data
   file = SerialFlash.open(filename);
-
+  parpadear (3,100);
   file.write(contents, strlen(contents) + 1);
   Serial.println("String \"" + String(contents) + "\" written to file " + String(filename));
   file.close();
-
+
+  parpadear (3,100);
   // Open the file
   SerialFlashFile ff = SerialFlash.open(filename);
   Serial.print("Opening file: ");
@@ -45,6 +50,7 @@
   uint32_t sz = 21;//ff.size();
   Serial.print("Size: ");
   Serial.println(sz);
+  parpadear (3,100);

   uint32_t pos = ff.position();

@@ -61,7 +67,7 @@
   Serial.print("|||");
   Serial.print(String(mybuff));
   Serial.println("|||");
-
+  parpadear (10,50);
 }

 bool create_if_not_exists (const char *filename) {
@@ -76,3 +82,13 @@

 void loop() {
 }
+
+void parpadear(int times, int milliseconds){
+  for(int i=0; i<times; i++){
+    digitalWrite(ledPin, HIGH);
+    delay(milliseconds);
+    digitalWrite(ledPin, LOW);
+    delay(milliseconds);
+  }
+}
+


tentando colocar para salvar as infos dentro de um struct, para poder trocar depois de qual struct ira ler os dados, mas sem sucesso...

--- codigo.ino
+++ codigo.ino
@@ -30,10 +30,25 @@

 decode_results results;

+//Struct que guarda infos do botao, no caso sobre o codigo IR que ele deve reproduzir quando apertado
+typedef struct Button_Info{
+    int codeType;// -1 should be the default
+    int toggle;  //0 should be the default; The RC5/6 toggle state
+    unsigned long codeValue; // The code value if not raw
+    unsigned int rawCodes[RAWBUF]; // The durations if raw
+    int codeLen; // The length of the code
+} Button_Info;
+
 //=====================
 //VARIAVEIS GLOBAIS
 //=====================
-int ultimo_botao_press = FIRST_BUTTON_PIN; //por default o ultimo botao pressionado vai ser o primeiro
+int last_pressed_button = 0; //por default o ultimo botao pressionado vai ser o primeiro
+
+Button_Info button_one = { -1, 0 };// inicializando codeType =-1 e toggle=0;
+
+//lista dos botoes
+Button_Info buttons_list[1] = { button_one };
+
 //=====================
 //VARIAVEIS GLOBAIS - FIM
 //=====================
@@ -50,55 +65,57 @@
 }

 // Storage for the recorded code
-int codeType = -1; // The type of code
-unsigned long codeValue; // The code value if not raw
-unsigned int rawCodes[RAWBUF]; // The durations if raw
-int codeLen; // The length of the code
-int toggle = 0; // The RC5/6 toggle state
+// int codeType = -1; // The type of code
+// unsigned long codeValue; // The code value if not raw
+// unsigned int rawCodes[RAWBUF]; // The durations if raw
+// int codeLen; // The length of the code
+// int toggle = 0; // The RC5/6 toggle state
+

 // Stores the code for later playback
 // Most of this code is just logging
-void storeCode(decode_results *results)
-{
-    codeType = results->decode_type;
+void storeCode(decode_results *results, int pressed_button)
+{
+    buttons_list[pressed_button].codeType = results->decode_type;
     int count = results->rawlen;
-    if (codeType == UNKNOWN)
+    if (buttons_list[pressed_button].codeType == UNKNOWN)
     {
         Serial.println("Received unknown code, saving as raw");
-        codeLen = results->rawlen - 1;
+        buttons_list[pressed_button].codeLen = results->rawlen - 1;
         // To store raw codes:
         // Drop first value (gap)
         // Convert from ticks to microseconds
         // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
-        for (int i = 1; i <= codeLen; i++)
+        for (int i = 1; i <= buttons_list[pressed_button].codeLen; i++)
         {
             if (i % 2)
             {
                 // Mark
-                rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK - MARK_EXCESS;
+                buttons_list[pressed_button].rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK - MARK_EXCESS;
                 Serial.print(" m");
             }
             else
             {
                 // Space
-                rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK + MARK_EXCESS;
+                buttons_list[pressed_button].rawCodes[i - 1] = results->rawbuf[i] * USECPERTICK + MARK_EXCESS;
                 Serial.print(" s");
             }
-            Serial.print(rawCodes[i - 1], DEC);
+            Serial.print(buttons_list[pressed_button].rawCodes[i - 1], DEC);
         }
         Serial.println("");
     }
     else
     {
-        VerifyTypeOfSignal(results, codeType);
+        VerifyTypeOfSignal(results, pressed_button);
         Serial.println(results->value, HEX);
-        codeValue = results->value;
-        codeLen = results->bits;
-    }
-}
-void VerifyTypeOfSignal(decode_results *results, int codeType)
-{
-    if (codeType == NEC)
+        buttons_list[pressed_button].codeValue = results->value;
+        buttons_list[pressed_button].codeLen = results->bits;
+    }
+}
+
+void VerifyTypeOfSignal(decode_results *results, int pressed_button)
+{
+    if (buttons_list[pressed_button].codeType == NEC)
     {
         Serial.print("Received NEC: ");
         if (results->value == REPEAT)
@@ -108,95 +125,95 @@
             return;
         }
     }
-    else if (codeType == SONY)
+    else if (buttons_list[pressed_button].codeType == SONY)
     {
         Serial.print("Received SONY: ");
     }
-    else if (codeType == RC5)
+    else if (buttons_list[pressed_button].codeType == RC5)
     {
         Serial.print("Received RC5: ");
     }
-    else if (codeType == RC6)
+    else if (buttons_list[pressed_button].codeType == RC6)
     {
         Serial.print("Received RC6: ");
     }
     else
     {
         Serial.print("Unexpected codeType ");
-        Serial.print(codeType, DEC);
+        Serial.print(buttons_list[pressed_button].codeType, DEC);
         Serial.println("");
     }
 }

-void sendCode(int repeat)
-{
-    if (codeType == NEC)
-    {
-        sendCodeNec(repeat);
-    }
-    else if (codeType == SONY)
-    {
-        sendCodeSony();
-    }
-    else if (codeType == RC5 || codeType == RC6)
-    {
-        sendCodeRC5orRC6(repeat);
-    }
-    else if (codeType == UNKNOWN /* i.e. raw */)
+void sendCode(int repeat, int pressed_button)
+{
+    if (buttons_list[pressed_button].codeType == NEC)
+    {
+        sendCodeNec(repeat, pressed_button);
+    }
+    else if (buttons_list[pressed_button].codeType == SONY)
+    {
+        sendCodeSony(pressed_button);
+    }
+    else if (buttons_list[pressed_button].codeType == RC5 || buttons_list[pressed_button].codeType == RC6)
+    {
+        sendCodeRC5orRC6(repeat, pressed_button);
+    }
+    else if (buttons_list[pressed_button].codeType == UNKNOWN /* i.e. raw */)
     {
         // Assume 38 KHz
-        sendCodeUnknow();
-    }
-}
-void sendCodeNec(int repeat)
+        sendCodeUnknow(pressed_button);
+    }
+}
+void sendCodeNec(int repeat, int pressed_button)
 {

     if (repeat)
     {
-        irsend.sendNEC(REPEAT, codeLen);
+        irsend.sendNEC(REPEAT, buttons_list[pressed_button].codeLen);
         Serial.println("Sent NEC repeat");
     }
     else
     {
-        irsend.sendNEC(codeValue, codeLen);
+        irsend.sendNEC(buttons_list[pressed_button].codeType, buttons_list[pressed_button].codeLen);
         Serial.print("Sent NEC ");
-        Serial.println(codeValue, HEX);
-    }
-
-}
-void sendCodeSony()
-{
-    irsend.sendSony(codeValue, codeLen);
+        Serial.println(buttons_list[pressed_button].codeType, HEX);
+    }
+
+}
+void sendCodeSony(int pressed_button)
+{
+    irsend.sendSony(buttons_list[pressed_button].codeType, buttons_list[pressed_button].codeLen);
     Serial.print("Sent Sony ");
-    Serial.println(codeValue, HEX);
-}
-void sendCodeRC5orRC6(int repeat)
+    Serial.println(buttons_list[pressed_button].codeType, HEX);
+}
+void sendCodeRC5orRC6(int repeat, int pressed_button)
 {
     if (!repeat)
     {
         // Flip the toggle bit for a new button press
-        toggle = 1 - toggle;
+        buttons_list[pressed_button].toggle = 1 - buttons_list[pressed_button].toggle;
     }
     // Put the toggle bit into the code to send
-    codeValue = codeValue & ~(1 << (codeLen - 1));
-    codeValue = codeValue | (toggle << (codeLen - 1));
-    if (codeType == RC5)
+    buttons_list[pressed_button].codeValue = buttons_list[pressed_button].codeValue & ~(1 << (buttons_list[pressed_button].codeLen - 1));
+    buttons_list[pressed_button].codeValue = buttons_list[pressed_button].codeValue | (buttons_list[pressed_button].toggle << (buttons_list[pressed_button].codeLen - 1));
+    if (buttons_list[pressed_button].codeType == RC5)
     {
         Serial.print("Sent RC5 ");
-        Serial.println(codeValue, HEX);
-        irsend.sendRC5(codeValue, codeLen);
+        Serial.println(buttons_list[pressed_button].codeValue, HEX);
+        irsend.sendRC5(buttons_list[pressed_button].codeValue, buttons_list[pressed_button].codeLen);
     }
     else
     {
-        irsend.sendRC6(codeValue, codeLen);
+        irsend.sendRC6(buttons_list[pressed_button].codeValue, buttons_list[pressed_button].codeLen);
         Serial.print("Sent RC6 ");
-        Serial.println(codeValue, HEX);
-    }
-}
-
-void sendCodeUnknow()
-{
-    irsend.sendRaw(rawCodes, codeLen, 38);
+        Serial.println(buttons_list[pressed_button].codeValue, HEX);
+    }
+}
+
+void sendCodeUnknow(int pressed_button)
+{
+    irsend.sendRaw(buttons_list[pressed_button].rawCodes, buttons_list[pressed_button].codeLen, 38);
     Serial.println("Sent raw");
 }

@@ -228,16 +245,17 @@

     if (firstButtonState)
     {
+        last_pressed_button = 0; //marca o primeiro botao como sendo o pressionado
         Serial.println("Pressed, sending");
         digitalWrite(STATUS_PIN, HIGH);
-        sendCode(lastButtonState == firstButtonState);
+        sendCode(lastButtonState == firstButtonState, last_pressed_button);
         digitalWrite(STATUS_PIN, LOW);
         delay(50); // Wait a bit between retransmissions
     }
     else if (irrecv.decode(&results))
     {
         digitalWrite(STATUS_PIN, HIGH);
-        storeCode(&results);
+        storeCode(&results, last_pressed_button);
         irrecv.resume(); // resume receiver
         digitalWrite(STATUS_PIN, LOW);
     }


fine lynch flicks adjustment

fine lynch flicks adjustment

--- first_one/first_one.ino
+++ first_one/first_one.ino
@@ -61,7 +61,7 @@
 unsigned int actualStep     = 1;  // 1 - 5
 bool endCycle               = false;
 bool lynchON                = false;
-unsigned int lynchFlicks[]  = { 33,66,99,101,106,109,123,132,161 };
+unsigned int lynchFlicks[]  = { 18,24,25,29,33,49,61,73,87 };

 String message              = encode( "PWNED " );


[Bug] IRMQTTServer: Remove duplicate MQTT_CLIMATE from HA discovery (#869)

Accidently added the value of MQTT_CLIMATE twice.
Removed duplication.

Fixes #868

--- examples/IRMQTTServer/IRMQTTServer.ino
+++ examples/IRMQTTServer/IRMQTTServer.ino
@@ -2340,29 +2340,22 @@
       "{"
       "\"~\":\"" + MqttClimate + "\","
       "\"name\":\"" + MqttHAName + "\","
-      "\"pow_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_POWER "\","
-      "\"mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_MODE "\","
-      "\"mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" KEY_MODE
-          "\","
+      "\"pow_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_POWER "\","
+      "\"mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_MODE "\","
+      "\"mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_MODE "\","
       "\"modes\":[\"off\",\"auto\",\"cool\",\"heat\",\"dry\",\"fan_only\"],"
-      "\"temp_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_TEMP "\","
-      "\"temp_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" KEY_TEMP
-          "\","
+      "\"temp_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_TEMP "\","
+      "\"temp_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_TEMP "\","
       "\"min_temp\":\"16\","
       "\"max_temp\":\"30\","
       "\"temp_step\":\"1\","
-      "\"fan_mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/"
-          KEY_FANSPEED "\","
-      "\"fan_mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/"
-          KEY_FANSPEED "\","
+      "\"fan_mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_FANSPEED "\","
+      "\"fan_mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_FANSPEED "\","
       "\"fan_modes\":[\"auto\",\"min\",\"low\",\"medium\",\"high\",\"max\"],"
-      "\"swing_mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/"
-          KEY_SWINGV "\","
-      "\"swing_mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/"
-          KEY_SWINGV "\","
+      "\"swing_mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_SWINGV "\","
+      "\"swing_mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_SWINGV "\","
       "\"swing_modes\":["
-        "\"off\",\"auto\",\"highest\",\"high\",\"middle\",\"low\",\"lowest\""
-      "]"
+        "\"off\",\"auto\",\"highest\",\"high\",\"middle\",\"low\",\"lowest\"]"
       "}").c_str())) {
     mqttLog("MQTT climate discovery successful sent.");
     hasDiscoveryBeenSent = true;


Asservissement sur place

Asservissement sur place

--- src/Main/Main.ino
+++ src/Main/Main.ino
@@ -1,57 +1,120 @@
 #include <Encoder.h>

-Encoder myEnc(7, 8);
+Encoder leftEncoder(5, 6);
+Encoder rightEncoder(7, 8);

-int vitesse = 50;
+IntervalTimer timer;
+
 void setup() {
-   pinMode(9, OUTPUT);
-   pinMode(10, OUTPUT);
-   pinMode(11, OUTPUT);
-   pinMode(12, OUTPUT);
+    pinMode(9, OUTPUT);
+    pinMode(10, OUTPUT);
+    pinMode(11, OUTPUT);
+    pinMode(12, OUTPUT);

-   analogWriteFrequency(9, 16000);
-   analogWriteFrequency(10, 16000);
+    analogWriteFrequency(9, 16000);
+    analogWriteFrequency(10, 16000);

-   Serial.begin(9600);
-   Serial.println("Basic Encoder Test:");
-   // left
-   analogWrite(9, vitesse);
-   digitalWrite(11, HIGH);
+    Serial.begin(115200);

-   // right
-   analogWrite(10, vitesse);
-   digitalWrite(12, HIGH);
+    analogWrite(9, 0);
+    digitalWrite(11, LOW);
+    analogWrite(10, 0);
+    digitalWrite(12, LOW);
+
+    timer.begin(refresh, 1000);
 }

-long oldPosition  = -999;
+int32_t dist_right, dist_left, cmd_right, cmd_left, target_dist, target_angle;

 void loop() {
-   /*  long newPosition = myEnc.read();
-   if (newPosition != oldPosition) {
-     oldPosition = newPosition;
-     Serial.println(newPosition);
+    while (Serial.available() == 0) {
+        ;
+    }

-     double speed = (5000 - newPosition);
-     Serial.print("p= ");
-     Serial.print(newPosition);
-     Serial.print(", speed= ");
-     Serial.println(speed);
+    long int i;
+    unsigned char premierCaractere = Serial.read();
+    switch (premierCaractere) {
+        case 'a':
+            litEntierLong(&i);
+            target_dist = i;
+            Serial.println(target_dist);
+            break;
+        case 'b':
+            litEntierLong(&i);
+            target_angle = i;
+            Serial.println(target_angle);
+            break;
+        default:
+            break;
+    }
+}

-     if (speed > 0) {
-       analogWrite(10, speed > 60 ? 60 : speed);
-       digitalWrite(11, LOW);
-     } else {
-       analogWrite(10, -speed > 60 ? 60 : - speed);
-       digitalWrite(11, HIGH);
-     }*/
+void refresh() {
+    int32_t dist, cmd_dist, angle, cmd_angle, err_dist, err_angle;

-	if (Serial.available() > 0) {
-		int incomingByte = Serial.parseInt();
-		Serial.print("USB received: ");
-		Serial.println(incomingByte);
-               analogWrite(9, incomingByte);
-	}
+    dist_right = leftEncoder.read();
+    dist_left = rightEncoder.read();

-     // left
+    dist = (dist_left + dist_right) / 2;
+    angle = dist_right - dist_left;

+    err_dist = target_dist - dist;
+    err_angle = target_angle - angle;
+
+    cmd_dist = maximize(err_dist, 50);
+    cmd_angle = maximize(err_angle, 50);
+
+    cmd_right = cmd_dist + cmd_angle;
+    cmd_left = cmd_dist - cmd_angle;
+
+    if (cmd_right > 0) {
+        analogWrite(9, cmd_right);
+        digitalWrite(11, LOW);
+    } else {
+        analogWrite(9, -cmd_right);
+        digitalWrite(11, HIGH);
+    }
+
+    if (cmd_left > 0) {
+        analogWrite(10, cmd_left);
+        digitalWrite(12, HIGH);
+    } else {
+        analogWrite(10, -cmd_left);
+        digitalWrite(12, LOW);
+    }
 }
+
+int32_t maximize(int32_t value, int32_t max)
+{
+    if(max == -1) return value;
+
+    if (abs(value) > max) {
+        if(value > 0) {
+            return max;
+        } else {
+            return -max;
+        }
+    }
+    return value;
+}
+
+void litEntierLong(long int *i)
+{
+    long int aux = 0;
+    unsigned char j;
+    long int k = 10000000;
+    unsigned char c = 0; // les unsigned feront l'affaire ! -- Yann Sionneau
+    for (j = 0; j < 8; j++) {
+        while (Serial.available()==0) {
+            asm("nop");
+        }
+        c = Serial.read();
+        if (c < 48 || c > 57) {
+            aux = -1;
+            break;
+        }
+        aux += (c - 48) * k;
+        k /= 10;
+    }
+    *i = aux;
+}


testing some optimizations

testing some optimizations

--- frontdesk/frontdesk.ino
+++ frontdesk/frontdesk.ino
@@ -42,45 +42,40 @@
 		digitalWrite(ledPin, LOW);
 		rainbowCycle();

-		// If a tag is detected, go to the next state
+		// If a tag is detected, read data and alert web app
 		if (isValidResponse) {
-			state = 1;
-		}
-	}
-	// Read data -- this should probably not be state
+			sendCommand(CMD_READ, blockID, userData);
+			delay(waitforReadResponse);
+			isValidResponse = getResponse(readData);
+
+			// If data is successfully read, alert web app
+			if (isValidResponse) {
+				scannedID = (int)getTime(readData, numUserBytes, userOffset);
+
+				// LEDs on
+				green();
+				digitalWrite(ledPin, HIGH);
+				playCoinSound();
+				WIFI.listen();
+
+				// Constrain ID range for now... need to figure out why
+				// large IDs are being sent randomly
+				if ( isRange(scannedID, 0, 100) ) {
+					scanTest(scannedID);
+				}
+
+				RFID.listen();
+				state = 1;
+			}
+			else {
+      			red();
+				playDeath();
+				state = 0;
+			}
+		}
+	}
+	// Other tag operations
 	else if (state == 1) {
-		sendCommand(CMD_READ, blockID, userData);
-		delay(waitforReadResponse);
-		isValidResponse = getResponse(readData);
-
-		// If data is successfully read, alert web app
-		if (isValidResponse) {
-			scannedID = (int)getTime(readData, numUserBytes, userOffset);
-
-			// LEDs on
-      		green();
-			digitalWrite(ledPin, HIGH);
-			playCoinSound();
-
-			// Constrain ID range for now... need to figure out why
-			// large IDs are being sent randomly
-			WIFI.listen();
-			if ( isRange(scannedID, 0, 100) ) {
-				scanTest(scannedID);
-			}
-
-			RFID.listen();
-			state = 2;
-		}
-		// If data read fails, go back to scan state
-		else {
-      		red();
-			playDeath();
-			state = 0;
-		}
-	}
-	// Other tag operations
-	else if (state == 2) {
 		sendCommand(CMD_GET_SNR, blockID, machineID);
 		delay(waitforSerialResponse);
 		isValidResponse = getResponse(readData);
@@ -94,6 +89,7 @@
       		}
 		}
 	}
+	// Go back to scan state otherwise
 	else {
 		state = 0;
 	}
@@ -106,91 +102,94 @@

 	while (Serial.available()) {
 		// if no tag present, consume all data and send error
-		if (state == 0 || state == 1) {
+		if (state == 0) {
 			while (Serial.available()) {
 				Serial.read();
 			}
 			Serial.write(ERROR_CHAR);
 			Serial.write(END_CHAR);
 		}
+		// otherwise, receive data and process
 		else {
 			characterRead[i] = Serial.read();
 			i++;
 		}
 	}

-	// Read the time on card
-	if (characterRead[0] == COMMAND_GET_TIME) {
-		characterRead[0] = 0;
-
-		sendCommand(CMD_READ, blockID, machineID);
-		delay(waitforReadResponse);
-		isValidResponse = getResponse(readData);
-		existingTime = getTime(readData, numTimeBytes, timeOffset);
-
-		// Send it to ACM
-		while (!existingTime) {
-			Serial.write(existingTime);
-			existingTime >>= eightBits;
-		}
-
-		Serial.write(END_CHAR);
-	}
-
-	// Reset the time on card
-	if (characterRead[0] == COMMAND_RESET_TIME) {
-		characterRead[0] = 0;
-
-		preparePayload(COMMAND_RESET_TIME, 0, 0, 0);
-		sendCommand(CMD_WRITE, blockID, machineID);
-		delay(waitforWriteResponse);
-
-		Serial.write(done);
-		Serial.write(END_CHAR);
-	}
-
-	if (characterRead[0] == COMMAND_REGISTER) {
-		characterRead[0] = 0;
-
-		int numDigits = (int)(characterRead[1] - ASCII_OFFSET);
-		convertASCII(numDigits);
-
-		preparePayload(COMMAND_REGISTER, id, numDigits, 0);
-		sendCommand(CMD_WRITE, blockID, userData);
-		delay(waitforWriteResponse);
-
-		// Make sure time on card is zero when registered
-		if (!id) {
+	if (!characterRead[0]) {
+		// Read the time on card
+		if (characterRead[0] == COMMAND_GET_TIME) {
+			characterRead[0] = 0;
+
+			sendCommand(CMD_READ, blockID, machineID);
+			delay(waitforReadResponse);
+			isValidResponse = getResponse(readData);
+			existingTime = getTime(readData, numTimeBytes, timeOffset);
+
+			// Send it to ACM
+			while (!existingTime) {
+				Serial.write(existingTime);
+				existingTime >>= eightBits;
+			}
+
+			Serial.write(END_CHAR);
+		}
+
+		// Reset the time on card
+		if (characterRead[0] == COMMAND_RESET_TIME) {
+			characterRead[0] = 0;
+
 			preparePayload(COMMAND_RESET_TIME, 0, 0, 0);
 			sendCommand(CMD_WRITE, blockID, machineID);
+			delay(waitforWriteResponse);
+
+			Serial.write(done);
+			Serial.write(END_CHAR);
+		}
+
+		if (characterRead[0] == COMMAND_REGISTER) {
+			characterRead[0] = 0;
+
+			int numDigits = (int)(characterRead[1] - ASCII_OFFSET);
+			convertASCII(numDigits);
+
+			preparePayload(COMMAND_REGISTER, id, numDigits, 0);
+			sendCommand(CMD_WRITE, blockID, userData);
+			delay(waitforWriteResponse);
+
+			// Make sure time on card is zero when registered
+			if (!id) {
+				preparePayload(COMMAND_RESET_TIME, 0, 0, 0);
+				sendCommand(CMD_WRITE, blockID, machineID);
+				while (!id) {
+					Serial.write(id);
+					id >>= eightBits;
+				}
+			}
+
+			Serial.write(END_CHAR);
+			playUnderground();
+		}
+
+		// Update card permissions
+		if (characterRead[0] == COMMAND_REFRESH) {
+			characterRead[0] = 0;
+
+			int numDigits = (int)(characterRead[1] - ASCII_OFFSET);
+			convertASCII(numDigits);
+
+			preparePayload(COMMAND_REGISTER, id, numDigits, 0);
+			sendCommand(CMD_WRITE, blockID, userData);
+			delay(waitforWriteResponse);
+
 			while (!id) {
 				Serial.write(id);
 				id >>= eightBits;
 			}
-		}
-
-		Serial.write(END_CHAR);
-		playUnderground();
-	}
-
-	// Update card permissions
-	if (characterRead[0] == COMMAND_REFRESH) {
-		characterRead[0] = 0;
-
-		int numDigits = (int)(characterRead[1] - ASCII_OFFSET);
-		convertASCII(numDigits);
-
-		preparePayload(COMMAND_REGISTER, id, numDigits, 0);
-		sendCommand(CMD_WRITE, blockID, userData);
-		delay(waitforWriteResponse);
-
-		while (!id) {
-			Serial.write(id);
-			id >>= eightBits;
-		}
-
-		Serial.write(END_CHAR);
-		playUnderground();
+
+			Serial.write(END_CHAR);
+			playUnderground();
+		}
 	}
 }


added more logging msgs. Fixed bug when identifiying the commands.

--- tictactoe/tictactoe.ino
+++ tictactoe/tictactoe.ino
@@ -117,14 +117,15 @@
 boolean greenVictory = false;

 // hardware initialization
-void setup() {
-  Serial.begin(9600);
+void setup() {
+  // 0 - Initialize serial comms
+  Serial.begin(9600); // USB comm for debugging purposes
+  Serial1.begin(9600); // Comm with the base board
+
   Serial.println("*****************");
   Serial.println("***** Setup *****");
   Serial.println("*****************");
-  // 0 - Initialize board comm
-  Serial.println("Initializing board comm...");
-  Serial1.begin(9600);
+
   // 1 - Initialize the tictactoe board
   Serial.println("Initializing tictactoe squares...");
   for (int i = 0; i < 9; i++){
@@ -155,6 +156,8 @@
   Serial.println("*********************");
   Serial.println("***** Game Loop *****");
   Serial.println("*********************");
+  Serial.println("-Turn: " + String(turn));
+  Serial.println("-Start turn: " + start_turn);
   Serial.println("");
   delay(200);
   boolean waitForMove = true;
@@ -255,11 +258,11 @@

 void initializeHardwarePeripherals(){
   Serial.println("Initializing hardware:");
+  initializeBoard();
   initializeScreen();
   display.printText("Initializing...", 6, 1, GREEN);
   initializeRFID();
-  initializeSoundPlayer();
-  initializeBoard();
+  initializeSoundPlayer();
 }

 void initializeBoard(){
@@ -400,26 +403,31 @@
   Serial.println("Finding other player...");
   boolean notFound = true;
   while(notFound){
+    Serial.println("-Searching for other players...");
     String res = sendAndWait(MSG_FIND_GAME + SEP_CHAR_COMMANDS  + player_id + END_CHAR);
+    Serial.println("-reply: '" + res + "'");
     String command = getCommand(res);

     // if waiting_for_player -> delay 100
     // if not_registered -> register
     // if rival -> set start_turn, set rival_id, notFound = false
-    if (command == CMD_WAIT_FOR_RIVAL){
+    if (command.startsWith(CMD_WAITING_PLAYERS)){
       Serial.println("-Waiting for rivals...");
       delay(1000);
     }
-    else if (command == CMD_NOT_REGISTERED){ // This shouldn't happen
+    else if (command.startsWith(CMD_NOT_REGISTERED)){ // This shouldn't happen
       Serial.println("-Not registered");
       registerPlayer();
     }
-    else if (command == CMD_RIVAL){
+    else if (command.startsWith(CMD_RIVAL)){
       Serial.println("-Rival found");
       String parameters = getParameters(res);
       rival_id = getParameter(parameters, 1);
       start_turn = getParameter(parameters, 2);
       notFound = false;
+    } else{
+      Serial.println("Unknown command: '" + command + "'");
+
     }
   }
 }
@@ -435,11 +443,11 @@

     //if wait_for_move -> delay 1000
     //if rival_move -> notFound = false, rival_move = res 2
-    if (command == CMD_WAIT_FOR_MOVE){
+    if (command.startsWith(CMD_WAIT_FOR_MOVE)){
       Serial.println("Waiting for rival's move...");
       delay(1000);
     }
-    else if (command == CMD_RIVAL_MOVE){
+    else if (command.startsWith(CMD_RIVAL_MOVE)){
       String parameters = getParameters(res);
       String strMove = getParameter(parameters, 2);
       rivalMove = strMove.toInt();
@@ -460,11 +468,11 @@
   }
   String res = sendAndWait(MSG_DO_MOVE + SEP_CHAR_COMMANDS + player_id + SEP_CHAR_PARAMETERS  + player_move +  END_CHAR);
   String command = getCommand(res);
-  if (command = CMD_ACK){
+  if (command.startsWith(CMD_ACK)){
     Serial.println("Sent");
     notReceived = false;
   }
-  else if (command == CMD_WAIT_FOR_RIVAL){
+  else if (command.startsWith(CMD_WAIT_FOR_RIVAL)){
     Serial.println("Waiting for the rival to retrieve previous move...");
     delay(1000);
   }


fixed merge error

fixed merge error

--- stabilize/stabilize.ino
+++ stabilize/stabilize.ino
@@ -104,7 +104,7 @@
 void setup() {
   pinMode(kLedPin, OUTPUT);
   dataLoggingSetup();
-//  imuSetup();
+  imuSetup();
   motControlSetup();
   motSetup(1, 10,0.01,0.01); //pitch
   motSetup(2, 100,0.01,0.05); //roll


removed rallyx_timer firmware from this repo

--- firmware/rallyx_timer/rallyx_timer.ino
+++ firmware/rallyx_timer/rallyx_timer.ino
@@ -1,405 +0,0 @@
-#include <TimerOne.h>
-#include <Wire.h>
-#include <EEPROM.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-
-#define PIN_LED 13 // internal debug led
-#define PIN_SQW 22
-#define PIN_SCL 19
-#define PIN_SDA 18
-#define PIN_TS  0
-#define PIN_TF  1
-#define PIN_MTS 2
-#define PIN_MTF 3
-
-// all time is in milliseconds
-#define DEFAULT_DEBOUNCE 10
-#define DEFAULT_DEADTIME 10000
-
-// increment this any time the rom format is changed or needs to be cleared
-#define EEPROM_VERSION 0
-
-#define EVENT_MAX 2048
-
-typedef enum {
-  ROM_OFFSET_VERSION=0,
-  ROM_OFFSET_DEBOUNCE,
-  ROM_OFFSET_DEADTIME,
-  ROM_OFFSET_START
-} rom_offset_t;
-
-typedef enum {
-  SOURCE_START = 0,
-  SOURCE_FINISH,
-  SOURCE_MANUAL_START,
-  SOURCE_MANUAL_FINISH,
-} source_t;
-
-typedef struct
-{
-  uint32_t  pin;
-  bool      active;
-  uint32_t  debounce_count;
-  uint32_t  deadtime_count;
-  uint64_t  time;
-  source_t  source;
-} trigger_state_t;
-
-typedef struct
-{
-  uint64_t time;
-  source_t source;
-} event_t;
-
-volatile uint32_t debounce = DEFAULT_DEBOUNCE; // max number of debounce cycles
-volatile uint32_t deadtime = DEFAULT_DEADTIME; // deadtime before next trigger
-
-volatile uint64_t ms_time = 0; // master millisecond time
-
-volatile uint32_t event_count = 0;
-volatile event_t events[EVENT_MAX];
-
-#define INIT_TRIGGER(pin, source) {pin, false, 0, 0, 0, source}
-
-volatile trigger_state_t start_trigger = INIT_TRIGGER(PIN_TS, SOURCE_START);
-volatile trigger_state_t finish_trigger = INIT_TRIGGER(PIN_TF, SOURCE_FINISH);
-volatile trigger_state_t manual_start_trigger = INIT_TRIGGER(PIN_MTS, SOURCE_MANUAL_START);
-volatile trigger_state_t manual_finish_trigger = INIT_TRIGGER(PIN_MTF, SOURCE_MANUAL_FINISH);
-
-bool update_trigger( volatile trigger_state_t * trigger )
-{
-  // triggers are active low
-  // debounce_count follows pin state
-  if( digitalRead(trigger->pin) )
-  {
-    trigger->debounce_count = trigger->debounce_count < debounce ? trigger->debounce_count + 1 : debounce;
-  }
-  else
-  {
-    trigger->debounce_count = trigger->debounce_count > 0 ? trigger->debounce_count - 1 : 0;
-  }
-
-  trigger->deadtime_count = trigger->deadtime_count > 0 ? trigger->deadtime_count - 1 : 0;
-
-  if( trigger->active == false && trigger->debounce_count == 0 )
-  {
-    // falling debounced edge detected
-    trigger->active = true;
-
-    if( trigger->deadtime_count == 0 )
-    {
-      trigger->time = ms_time;
-      trigger->deadtime_count = deadtime;
-      events[event_count % EVENT_MAX].time = ms_time;
-      events[event_count % EVENT_MAX].source = trigger->source;
-      event_count++;
-    }
-    return true;
-  }
-  else if( trigger->active == true && trigger->debounce_count >= debounce )
-  {
-    // rising debounced edge detected
-    trigger->active = false;
-    return false;
-  }
-  else
-  {
-    // no change
-    return false;
-  }
-}
-
-void timer_tick(void)
-{
-  ms_time++;
-
-  update_trigger(&start_trigger);
-  update_trigger(&finish_trigger);
-  update_trigger(&manual_start_trigger);
-  update_trigger(&manual_finish_trigger);
-}
-
-uint32_t eeprom_read(uint32_t offset)
-{
-  uint32_t value;
-  uint32_t addr = offset * 4;
-
-  value = EEPROM.read(addr+0);
-  value |= EEPROM.read(addr+1) << 8;
-  value |= EEPROM.read(addr+2) << 16;
-  value |= EEPROM.read(addr+3) << 24;
-
-  return value;
-}
-
-void eeprom_write(uint32_t offset, uint32_t value)
-{
-  uint32_t addr = offset * 4;
-
-  EEPROM.write(addr+0, value & 0xff);
-  EEPROM.write(addr+1, (value >> 8) & 0xff);
-  EEPROM.write(addr+2, (value >> 16) & 0xff);
-  EEPROM.write(addr+3, (value >> 24) & 0xff);
-}
-
-void format_eeprom(void)
-{
-  eeprom_write(ROM_OFFSET_VERSION, EEPROM_VERSION);
-  eeprom_write(ROM_OFFSET_DEBOUNCE, debounce);
-  eeprom_write(ROM_OFFSET_DEADTIME, deadtime);
-  eeprom_write(ROM_OFFSET_START, 0xff);
-}
-
-void print_uint64(uint64_t value)
-{
-  char buf[32];
-  int i = 0;
-
-  if( value == 0 )
-  {
-    Serial.print('0');
-  }
-
-  while( value > 0 )
-  {
-    buf[i++] = '0' + (value % 10);
-    value /= 10;
-  }
-  while( i > 0 )
-  {
-    Serial.print(buf[i-1]);
-    i--;
-  }
-}
-
-void print_event(uint32_t index)
-{
-  switch(events[index].source)
-  {
-    case SOURCE_START:
-      Serial.print("1 ");
-      break;
-    case SOURCE_FINISH:
-      Serial.print("2 ");
-      break;
-    case SOURCE_MANUAL_START:
-      Serial.print("M1 ");
-      break;
-    case SOURCE_MANUAL_FINISH:
-      Serial.print("M2 ");
-      break;
-  }
-
-  print_uint64(events[index].time);
-}
-
-void setup(void)
-{
-  for( uint32_t pin = 0; pin < 34; pin++ )
-  {
-    switch(pin)
-    {
-      case PIN_LED:
-        pinMode(pin, OUTPUT);
-        break;
-      default:
-        pinMode(pin, INPUT_PULLUP);
-        break;
-    }
-  }
-
-  Serial.begin(0);
-
-  if( eeprom_read(ROM_OFFSET_VERSION) != EEPROM_VERSION )
-  {
-    format_eeprom();
-  }
-  else // load eeprom settings
-  {
-    debounce = eeprom_read(ROM_OFFSET_DEBOUNCE);
-    deadtime = eeprom_read(ROM_OFFSET_DEADTIME);
-  }
-
-  Timer1.initialize(1000);
-  Timer1.attachInterrupt(timer_tick);
-  Timer1.start();
-}
-
-void command_process(char * cmd, uint64_t value, bool val_ok )
-{
-  if( strcasecmp(cmd, "time") == 0 )
-  {
-    if( val_ok )
-    {
-      ms_time = value;
-    }
-    Serial.print("N ");
-    print_uint64(ms_time);
-    Serial.println();
-  }
-  else if( strcasecmp(cmd, "ping") == 0 )
-  {
-    Serial.print("P ");
-    print_uint64(val_ok ? value : 0);
-    Serial.println();
-  }
-  else if( strcasecmp(cmd, "id") == 0 )
-  {
-    Serial.println("I RALLYX_TIMER");
-  }
-  else if( strcasecmp(cmd, "recall") == 0 )
-  {
-    if( val_ok && value < event_count && (event_count < EVENT_MAX || value >= event_count - EVENT_MAX) )
-    {
-      Serial.print("R ");
-      print_event(value % EVENT_MAX);
-      Serial.write(' ');
-      Serial.println((uint32_t)value);
-      //Serial.println("R M1 123345 123");
-    }
-    else
-    {
-      Serial.println("E bad value");
-    }
-  }
-  else if( strcasecmp(cmd, "clear") == 0 )
-  {
-    event_count = 0;
-    Serial.println("C 0");
-  }
-  else if( strcasecmp(cmd, "count") == 0 )
-  {
-    Serial.print("C ");
-    Serial.println(event_count);
-  }
-  else if( strcasecmp(cmd, "max") == 0 )
-  {
-    Serial.print("M ");
-    Serial.println(EVENT_MAX);
-  }
-  else if( strcasecmp(cmd, "debounce") == 0 )
-  {
-    if( val_ok )
-    {
-      debounce = (uint32_t)value;
-      eeprom_write(ROM_OFFSET_DEBOUNCE, debounce);
-    }
-    Serial.print("B ");
-    Serial.println(debounce);
-  }
-  else if( strcasecmp(cmd, "deadtime") == 0 )
-  {
-    if( val_ok )
-    {
-      deadtime = (uint32_t)value;
-      eeprom_write(ROM_OFFSET_DEADTIME, deadtime);
-    }
-    Serial.print("D ");
-    Serial.println(deadtime);
-  }
-  else
-  {
-    Serial.println("E bad command");
-    Serial.print("E ");
-    Serial.println(cmd);
-  }
-}
-
-void command_update(void)
-{
-  static char buffer[256];
-  static uint32_t count = 0;
-  char c;
-  char *cmd;
-  char *param;
-  char *endptr;
-  uint64_t value;
-
-  while( Serial.available() )
-  {
-    c = Serial.read();
-    switch( c )
-    {
-      case '\r':
-      case '\n':
-        if( count > 0 )
-        {
-          // parse command
-          // format: <cmd> <value>
-          cmd = strtok(buffer, " ");
-          param = strtok(NULL, " ");
-          value = param != NULL ? strtoull(param, &endptr, 0) : 0;
-
-          command_process(cmd, value, (param != NULL) && (*endptr == 0));
-
-          // reset buffer
-          count = 0;
-          buffer[count] = 0;
-        }
-        break;
-      case 8:  // delete/backspace
-        if( count > 0 )
-        {
-          count--;
-          buffer[count] = 0;
-        }
-        break;
-      case '\t':
-        // convert tabs to single space
-        c = ' ';
-        // fall through to ' '
-      case ' ':
-        // filter out leading and multiple whitespace
-        if( count == 0 || buffer[count-1] == ' ')
-        {
-          break;
-        }
-        // fall through to default
-      default:
-        if( c >= 32 && count < (sizeof(buffer) - 1) )
-        {
-          buffer[count] = c;
-          count++;
-          buffer[count] = 0;
-        }
-        break;
-    }
-  }
-}
-
-void loop_wait(void)
-{
-  static uint64_t prev_time = 0;
-  while( prev_time == ms_time );
-  prev_time = ms_time;
-}
-
-void loop(void)
-{
-  static uint32_t count = 0;
-
-  digitalWrite(PIN_LED, HIGH);
-
-  if( count > event_count )
-  {
-    count = 0;
-  }
-
-  if( count < event_count )
-  {
-    Serial.print("T ");
-    print_event(count % EVENT_MAX);
-    Serial.write(' ');
-    Serial.println(count);
-    count++;
-  }
-
-  command_update();
-
-  digitalWrite(PIN_LED, LOW);
-
-  loop_wait();
-}
-


Infrared remote control to log scale

Infrared remote control to log scale

--- FablightFirmware/FablightFirmware.ino
+++ FablightFirmware/FablightFirmware.ino
@@ -130,8 +130,9 @@
 void handle_ir(void)
 {
     uint8_t button = fablight_ir_get_button();
-    const float ir_fact = 1.2;
+    const float ir_fact = 1.05;
     if (button==0) return;
+    Serial.print("Via infrared: button "); Serial.print(button); Serial.print("\n");
     switch (button) {
         case 11:  setPWMs( 0, 0, 0, 0 ); break;
         case 12:  setPWMs( 1, 1, 1, 1 ); break;


Added debugging LED code back

Added debugging LED code back

--- receiver/receiver.ino
+++ receiver/receiver.ino
@@ -23,9 +23,6 @@
 uint8_t myChannel = 0xFF; //The address of the current light, set by DIP switch

 void setup() {
-    //Initialize the built-in LED to output (for debugging)
-    pinMode(LED_BUILTIN, OUTPUT);
-
     Serial.begin(19200);
     Serial.println("Ready");
 }
@@ -96,4 +93,10 @@
     analogWrite(RED_PIN, red);
     analogWrite(GREEN_PIN, green);
     analogWrite(BLUE_PIN, blue);
+
+    //Debug
+    pinMode(LED_BUILTIN, OUTPUT);
+    digitalWrite(LED_BUILTIN, HIGH);
+    delay(1000);
+    digitalWrite(LED_BUILTIN, LOW);
 }


fix ArduBreakout example to compile until we fix tone


Updated the CosaBlinkRGB with additional states.

--- examples/CosaBlinkRGB/CosaBlinkRGB.ino
+++ examples/CosaBlinkRGB/CosaBlinkRGB.ino
@@ -33,12 +33,19 @@
 // The state machine
 FSM fsm;

+// The state functions
 void redState(FSM* fsm, uint8_t type, uint16_t value);
+void yellowState(FSM* fsm, uint8_t type, uint16_t value);
 void greenState(FSM* fsm, uint8_t type, uint16_t value);
+void cyanState(FSM* fsm, uint8_t type, uint16_t value);
 void blueState(FSM* fsm, uint8_t type, uint16_t value);
+void magentaState(FSM* fsm, uint8_t type, uint16_t value);
+
+// Timeout
+static const uint16_t TIMEOUT = 128;

 // Use an RGB LED connected to pins(5,6,7)
-OutputPin redLedPin(5);
+OutputPin redLedPin(5, 1);
 OutputPin greenLedPin(6);
 OutputPin blueLedPin(7, 1);

@@ -46,25 +53,43 @@
 void redState(FSM* fsm, uint8_t type, uint16_t value)
 {
   blueLedPin.toggle();
-  redLedPin.toggle();
-  fsm->set_timer(128);
+  fsm->set_timer(TIMEOUT);
+  fsm->set_state(yellowState);
+}
+
+void yellowState(FSM* fsm, uint8_t type, uint16_t value)
+{
+  greenLedPin.toggle();
+  fsm->set_timer(TIMEOUT);
   fsm->set_state(greenState);
 }

 void greenState(FSM* fsm, uint8_t type, uint16_t value)
 {
   redLedPin.toggle();
-  greenLedPin.toggle();
-  fsm->set_timer(256);
+  fsm->set_timer(TIMEOUT);
+  fsm->set_state(cyanState);
+}
+
+void cyanState(FSM* fsm, uint8_t type, uint16_t value)
+{
+  blueLedPin.toggle();
+  fsm->set_timer(TIMEOUT);
   fsm->set_state(blueState);
 }

 void blueState(FSM* fsm, uint8_t type, uint16_t value)
 {
   greenLedPin.toggle();
-  blueLedPin.toggle();
-  fsm->set_timer(512);
-  fsm->set_state(greenState);
+  fsm->set_timer(TIMEOUT);
+  fsm->set_state(magentaState);
+}
+
+void magentaState(FSM* fsm, uint8_t type, uint16_t value)
+{
+  redLedPin.toggle();
+  fsm->set_timer(TIMEOUT);
+  fsm->set_state(redState);
 }

 void setup()


improved comment

improved comment

--- examples/Tlc59711Test/Tlc59711Test.ino
+++ examples/Tlc59711Test/Tlc59711Test.ino
@@ -13,7 +13,7 @@
 #include <Tlc59711.h>

 const int NUM_TLC = 2;
-const int NUM_MODES = 6;   // data transfer modes to test
+const int NUM_MODES = 6;   // should match setXferMode()

 Tlc59711 tlc(NUM_TLC);


Correct buffer overflow and remove magic constants from esp8266 example

The msg[] array is defined as 50 bytes long, but then the snprintf is
protected at 75 bytes long, which is incorrectly 25 bytes longer than
the underlying array.

To correct this, define a new macro MSG_BUFFER_SIZE and use it in both
places:
 * defining msg[]
 * writing to msg[] with snprintf()

--- examples/mqtt_esp8266/mqtt_esp8266.ino
+++ examples/mqtt_esp8266/mqtt_esp8266.ino
@@ -35,7 +35,8 @@
 WiFiClient espClient;
 PubSubClient client(espClient);
 unsigned long lastMsg = 0;
-char msg[50];
+#define MSG_BUFFER_SIZE	(50)
+char msg[MSG_BUFFER_SIZE];
 int value = 0;

 void setup_wifi() {
@@ -124,7 +125,7 @@
   if (now - lastMsg > 2000) {
     lastMsg = now;
     ++value;
-    snprintf (msg, 75, "hello world #%ld", value);
+    snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
     Serial.print("Publish message: ");
     Serial.println(msg);
     client.publish("outTopic", msg);


V2.8

V2.8

Added User-Agent to logging and serial output of home page and 404 not found.
Fixed Bonjour service (mDNS still does not work with chrome mDNS on windows out of the box, you need Apple Bonjour V3)
Changed time buffer (ran in javascript on the browser) for Auto-Disco button in home page(1m30s) and /party page(2m30s)

--- esp32LightServerRGB.ino
+++ esp32LightServerRGB.ino
@@ -1,13 +1,18 @@
 #include <WiFi.h>
+#include <ESPmDNS.h>
 #include <DNSServer.h>
 #include <WebServer.h>
 #include <WiFiManager.h>
 #include <WiFiMulti.h>
 #include <HTTPClient.h>
 #include <Preferences.h>
-#include <ESPmDNS.h>
-
 Preferences preferences;
+
+// led pins
+const uint8_t pinRouge = 12;
+const uint8_t pinVerte = 14;
+const uint8_t pinBleu = 13;
+//end of led pins

 // sensors stuff
 #include <Wire.h>
@@ -18,13 +23,8 @@
 #define ONE_WIRE_BUS 15 //dallas sensor pin
 OneWire oneWire(ONE_WIRE_BUS);
 DallasTemperature sensors(&oneWire);
+DeviceAddress insideThermometer;
 // end of sensors
-
-// led pins
-uint8_t pinRouge = 12;
-uint8_t pinVerte = 14;
-uint8_t pinBleu = 13;
-//end of led pins

 // internally used vars
 // Some used vars, some of these are set and loaded in setup() using esp32 Preferences
@@ -382,7 +382,7 @@
              "var myVar = \" \";\n"
              "function startDisco(){\n"
              " disco();"
-             " myVar = setInterval(function(){ disco() }, 13500);\n"
+             " myVar = setInterval(function(){ disco() }, 150000);\n"
              "}\n"
              "</script>\n"
              "
\n";
@@ -449,6 +449,13 @@
 // index page
 void handleRoot() {
   String addy = server.client().remoteIP().toString();
+  String header;
+  String userAgent;
+  if (server.hasHeader("User-Agent")) {
+    userAgent = server.header("User-Agent");
+  } else {
+    userAgent = "Pas de userAgent ?";
+  }
   String contenu = "<!DOCTYPE html>\n\n\n";
   contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere soit</title>\n"
              "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
@@ -494,17 +501,20 @@
              "var myVar = \" \";\n"
              "function startDisco(){\n"
              " disco();"
-             " myVar = setInterval(function(){ disco() }, 18500);\n"
+             " myVar = setInterval(function(){ disco() }, 90000);\n"
              "}\n"
              "</script>\n"
              "
\n";
   server.send(200, "text/html", contenu);
   Serial.println("");
   Serial.println(addy);
+  Serial.println(userAgent);
   Serial.println("Page acceuil");
   logtourne();
   logs[1] = addy;
   logs[1] += " : Acceuil";
+  logs[1] += " : userAgent :";
+  logs[1] += userAgent;
 }

 //reset page
@@ -570,6 +580,7 @@
     preferences.clear();
     WiFiManager wifiManager;
     wifiManager.resetSettings();
+    Serial.println("Bip Bip... Mémoire effacée !");
     ESP.restart();
   }
 }
@@ -739,9 +750,17 @@

 // 404 not found page
 void handleNotFound() {
+  String header;
   String addy = server.client().remoteIP().toString();
   Serial.println("");
+  String userAgent;
   Serial.println(addy);
+  if (server.hasHeader("User-Agent")) {
+    userAgent = server.header("User-Agent");
+  } else {
+    userAgent = "Pas de userAgent ?";
+  }
+  Serial.println(userAgent);
   String htmlmessage = "<!DOCTYPE html>\n\n\n";
   htmlmessage += "<meta charset=\"UTF-8\" />\n<title>404 Not found</title>\n"
                  "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
@@ -783,6 +802,8 @@
   logs[1] = addy;
   logs[1] += " : 404 : URI=";
   logs[1] += uriL;
+  logs[1] += " : UserAgent=";
+  logs[1] += userAgent;
   logs[1] += " : Methode=";
   logs[1] += methodeL;
   logs[1] += " ";
@@ -816,14 +837,32 @@
           webadd += tempC;
           enweille = 1;
           dernd = tempC;
+        } else {
+          Serial.println("Erreure du senseur dallas 85 !");
+          if (dernd != "0") {
+            tempC = dernd;
+            webadd += "&field1=";
+            webadd += tempC;
+            enweille = 1;
+            Serial.print(tempC);
+            if (usesenseurdht == 1) {
+              Serial.print(" - ");
+            }
+          } else {
+            enweille = 0;
+          }
         }
       } else {
-        Serial.println("Dallas error !");
+        Serial.println("Erreure du senseur dallas -127 !");
         if (dernd != "0") {
           tempC = dernd;
           webadd += "&field1=";
           webadd += tempC;
           enweille = 1;
+          Serial.print(tempC);
+          if (usesenseurdht == 1) {
+            Serial.print(" - ");
+          }
         } else {
           enweille = 0;
         }
@@ -836,7 +875,7 @@
       int err = SimpleDHTErrSuccess;
       if ((err = dht22.read2(pinDHT22, &t, &h, NULL)) != SimpleDHTErrSuccess) {
         Serial.println("");
-        Serial.print("Read DHT22 failed, err=");
+        Serial.print("Erreure de lecture DHT, err=");
         Serial.println(err);
         if (dernh != 0) {
           h = dernh;
@@ -868,7 +907,7 @@
     if (enweille == 1) {
       Serial.println("");
       http.begin(webadd);
-      int httpCode = http.GET();//Send the request
+      int httpCode = http.GET();
       if (httpCode > 0) {
         Serial.println("Envoit réussit !");
         tstrouteur = 0;
@@ -893,6 +932,9 @@
 // web page for showing sensors data
 void handleTemp() {
   String addy = server.client().remoteIP().toString();
+  Serial.println("");
+  Serial.println(addy);
+  Serial.println("Page température");
   float latemp;
   float t;
   float h;
@@ -906,13 +948,13 @@
       if (tempC != "85.00") {
         dernd = tempC;
       } else {
-        Serial.println("Dallas error !");
+        Serial.println("Erreure du senseur dallas 85 !");
         if (dernd != "0") {
           tempC = dernd;
         }
       }
     } else {
-      Serial.println("Dallas error !");
+      Serial.println("Erreure du senseur dallas -127 !");
       if (dernd != "0") {
         tempC = dernd;
       }
@@ -924,7 +966,7 @@
     h = 0;
     int err = SimpleDHTErrSuccess;
     if ((err = dht22.read2(pinDHT22, &t, &h, NULL)) != SimpleDHTErrSuccess) {
-      Serial.print("Read DHT22 failed, err=");
+      Serial.print("Erreure de lecture DHT, err=");
       Serial.println(err);
       t = dernt;
       h = dernh;
@@ -980,8 +1022,6 @@
   contenu += liens;
   contenu += "\n

\n";
   server.send(200, "text/html", contenu);
-  Serial.println("");
-  Serial.println(addy);
   if (usesenseurdallas == 1) {
     Serial.print("Température : ");
     Serial.println(latemp);
@@ -1077,7 +1117,7 @@
   server.on("/party", handleClignote);
   server.on("/version", []() {
     String addy = server.client().remoteIP().toString();
-    server.send(200, "text/html", "V2.7, Steve Olmstead sansillusion@gmail.com\n\n

"
+    server.send(200, "text/html", "V2.8, Steve Olmstead sansillusion@gmail.com\n\n

"
                 "Added fader function\nRemoved connection watchdog (better have good signal)\n
"
                 "Removed mDns (did not work anyway)\n\n

"
                 "Added smoother fading\n\n

"
@@ -1107,7 +1147,9 @@
                 "Added option in /setup tu use or not temperature sensors\n
"
                 "Changed from Adafruit DHT library to simpleDHT for better reliability\n\n

"
                 "Changed /setup (removed use sensors and added use dht and use dallas checkboxes)\n
"
-                "Revamped /temp and lesliens() to accomodate new changes in setup\n\n

" + liens);
+                "Revamped /temp and lesliens() to accomodate new changes in setup\n\n

"
+                "Added User-Agernt information in logging and serial output of / and 404 not found page\n
"
+                "Fixed Bonjour service support you can now use ( http://lumiere.local ) if you have Bonjour V3 installed\n
"+ liens);
     Serial.println("");
     Serial.println(addy);
     Serial.println("Page de Version");
@@ -1116,11 +1158,16 @@
     logs[1] += " : Page de version";
   });
   server.onNotFound(handleNotFound);
+  const char * headerkeys[] = {"User-Agent"} ;//peut ajouter autres si besoin eg {"User-Agent", "Cookie"}
+  size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
+  server.collectHeaders(headerkeys, headerkeyssize );
   server.begin();
   Serial.println("Serveur web démaré");
-  delay(100);
-  MDNS.addService("http", "tcp", 80);
+  delay(500);
+  MDNS.addService("_http", "_tcp", 80);
+  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Impossible de trouver l'adresse du senseur 0");
   sensors.begin();
+  sensors.setResolution(insideThermometer, 12);// 9 ou 12 9 plus rapide mais moin préçis
 }

 void loop() {


use equalsIgnoreCase() instead of equals() in Serial_replyCommand()

--- esp8266_160220_BYOP.ino
+++ esp8266_160220_BYOP.ino
@@ -6,6 +6,8 @@

 /*
+ * v0.3 2016 Feb 20
+ *  - use equalsIgnoreCase() instead of equals() in Serial_replyToCommand()
  * v0.2 2016 Feb 20
  *  - fix Serial_readCommand() to handle CR code
  *  - add Serial_replyToCommand()
@@ -55,7 +57,7 @@

 void Serial_replyToCommand(String cmdline)
 {
-  if (cmdline.equals("hello")) {
+  if (cmdline.equalsIgnoreCase("hello")) {
     Serial.println("hello, 7of9");
   } else {
     Serial.println(cmdline);


General dev

General dev

--- UrabeVocalSynthA/UrabeVocalSynthA.ino
+++ UrabeVocalSynthA/UrabeVocalSynthA.ino
@@ -132,14 +132,14 @@
 void setup()
 {
   pinMode(22, OUTPUT);
-//  MIDI.begin(MIDI_CHANNEL_OMNI);
-//  MIDI.setHandleNoteOn(midi_note_handle);
+  MIDI.begin(MIDI_CHANNEL_OMNI);
+  MIDI.setHandleNoteOn(midi_note_handle);
   GS.begin(rcvPin, sndPin, ovfPin);
   jp_synth_man.init(GS);
-  for(int i=0; i<60; i++)
+  for(int i=0; i<100; i++)
     jp_synth_man.kana_buffer_add(p[i]);
   gui_man.draw();
-  Serial.begin(115200);
+//  Serial.begin(115200);
 }

 void midi_note_handle(byte channel, byte pitch, byte velocity)
@@ -178,11 +178,11 @@

 void loop()
 {
-  Keypad::PhysicalButton b = key_man.get_button(50, 0, Keypad::PHYSICAL_BUTTON_COUNT);
-  if(b != Keypad::_NONE)
-    Serial.println(b);
-
-  return;
+//  Keypad::PhysicalButton b = key_man.get_button(50, 0, Keypad::PHYSICAL_BUTTON_COUNT);
+//  if(b != Keypad::_NONE)
+//    Serial.println(b);
+
+//  return;

   heartbeat();
   ButtonValue key_result;