Delete R_ANA3PT.ino

Delete R_ANA3PT.ino

--- BMS_Francais/Examples/R_ANA3PT-Arduino/R_ANA3PT.ino
+++ BMS_Francais/Examples/R_ANA3PT-Arduino/R_ANA3PT.ino
@@ -1,61 +0,0 @@
-/*-------------------------------------------------------------------------------------------------------------------------------------------*
- * SE2R : R_ANA3PT - Fonction de transformation d'un pourcentage en commande 3-Points                                             25/06/2015 *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- *        R_ANA3PT(float VPC[], float VTC[], int VNO, int VNF, int CFG)                                                           25/06/2015 *
- *                VPC : [00] : Signal de commande de régulation à convertir                                                                  *
- *                      [01] : Signal de commande retranscrit sur l'actionneur 3-points en fin du cycle courant                              *
- *                VTC : [00] : Durée du cycle de l'action 3-Points (s)                                                                       *
- *                      [01] : Durée totale de la pleine course de l'actionneur (s)                                                          *
- *                      [02] : Calcul du temps de cycle automate (s)                                                                         *
- *                      [03] : Compteur de durée depuis la dernière exécution de la fonction (s)                                             *
- *                      [04] : Mémoire des millis() de la dernière exécution de la fonction                                                  *
- *                      [05] : Durée de l'action sur les sorties pour le cycle d'exécution en cours                                          *
- *                VNO : Numéro de la voie de la sortie de commande d'ouverture  de l'actionneur 3-points                                     *
- *                VNF : Numéro de la voie de la sortie de commande de fermeture de l'actionneur 3-points                                     *
- *                CFG : Commande de forçage.                                                                                *
- *                      <0 : VPC[0] maintenu à 0                                                                                *
- *                      0  : VPC[0] figé dans sa dernière valeur connue                                                                      *
- *                      1  : VPC[0] est fixé par le calcul de régulation PID                                                                 *
- *                      2  : VPC[0] maintenue à VPC[3]                                                                                *
- *                      3  : VPC[0] maintenue à 100                                                                                *
- *                      >3 : VPC[0] maintenu à 0                                                                                *
- *       Interne  NUM : [00] : Mémoire dans l'exécution de l'écart du cycle précédent                                                        *
- *                      [01] : Mémoire dans l'exécution de la variation d'écart du cycle précédent                                           *
- *                      [02] : Mémoire dans l'exécution de la variation d'écart du cycle précédent                                           *
- *-------------------------------------------------------------------------------------------------------------------------------------------*
- * Copyright SE2R under the APACHE Licence                                                                                *
- *-------------------------------------------------------------------------------------------------------------------------------------------*
- * Plate-formes testées : Arduino Leonardo, Arduino Uno, Industruino                                                                         *
- * ------------------------------------------------------------------------------------------------------------------------------------------*
- * 25/06/2015 : DD, SE2R : Testée et validée sur banc                                                                                *
- * ------------------------------------------------------------------------------------------------------------------------------------------*/
-
-// Déclaration des bibliothèques nécessaires à l'exécution du programme ---------------------------------------------------------------------*
-#include <BMS.h>                         // Biblio   - SE2R - Fonctions BMS
-BMS BMS;
-
-// Déclaration des variables nécessaires à l'exécution du programme -------------------------------------------------------------------------*
-float VPC_XXXX[2];                       // R_ANA3PT - Table des commandes
-float VTC_XXXX[6];                       // R_ANA3PT - Table des coefficients de régulation
-int VNO_OUVR;                            // R_ANA3PT - Numéro de voie de la sortie de commande d'ouverture
-int VNF_FERM;                            // R_ANA3PT - Numéro de voie de la sortie de commande de fermeture
-int VCO_XXXX;                            // R_ANA3PT - Commande de forçage, ici en position auto
-void setup() {                           // Initialisation ----------------------------------------------------------------------------------*
-  VTC_XXXX[0] = 30;                      // R_ANA3PT - Durée du cycle de rafraîchissement de l'action sur la vanne
-  VTC_XXXX[1] = 180;                     // R_ANA3PT - Durée de la course complète de la vanne
-  VCO_XXXX = 1;                          // R_ANA3PT - Commande de forçage
-  pinMode(7, OUTPUT);                    // Système  - Affectation de la voie 07 en tant que sortie de commande d'ouverture
-  pinMode(8, OUTPUT);                    // Système  - Affectation de la voie 08 en tant que sortie de commande de fermeture
-  Serial.begin(9600);                    // Port COM - Paramétrage du port série
-}
-void loop() {                            // Exécution ---------------------------------------------------------------------------------------*
-  VPC_XXXX[0] = analogRead(0) / 10.23;                                              // Lecture 0-100% de l'entrée analogique 0
-  BMS.R_ANA3PT(VPC_XXXX, VTC_XXXX, 7, 8, VCO_XXXX);
-  Serial.print(VTC_XXXX[3]);
-  Serial.print("\t");
-  Serial.print(VTC_XXXX[5]);
-  Serial.print("\t");
-  Serial.print(VPC_XXXX[0]);
-  Serial.print("\t");
-  Serial.println(VPC_XXXX[1]);
-}


Tweak variables to improve robustness and response time

We now take the median of 5 samples, meaning that salt and pepper
noise has to occur 3 out of 5 times to have an effect.

Also, the highRatio is now set to 1/8th instead of 1/6th to make
the fan turn on quicker.

--- shofanduino2_dht11/shofanduino2_dht11.ino
+++ shofanduino2_dht11/shofanduino2_dht11.ino
@@ -29,9 +29,9 @@
 const float min_humidity_diff= 10.0; // RH %
 const float max_humidity = 100.0; // needed because we add min_humidity_diff

-RunningMedian samples = RunningMedian(3);
-
-const float thresholdHighRatio = 6.0f;
+RunningMedian samples = RunningMedian(5);
+
+const float thresholdHighRatio = 8.0f;
 const float thresholdLowRatio = 16.0f;
 float thresholdLow = 0.0;
 float thresholdHigh = 0.0;


Improved interrupt handling

Improved interrupt handling

Fix an issue with the Core will crash if interrupt on backlight happens too often. Now interrupt is detached when backlight is on, and re-attach when backlight is off.

--- weatherstation.ino
+++ weatherstation.ino
@@ -24,6 +24,8 @@
 int BackLightTrigger = D3;
 int trigger = 0;
 bool refresh = true;
+bool readOK = false;
+bool flip = false;

 // Pin out defs
 int led = D7;
@@ -402,18 +404,33 @@

 void publishReadings()
 {
+    int res = 1;
+    int tries = 5;
+
     if ((millis() - lastT) > (CHTUPDPERIOD * 1000)) {
+        display_string_5x7(6,1,"Publishing");
         lastT = millis();
-        readAM2321();
-        char szEventInfo[64];
-        sprintf(szEventInfo, "field1=%.1f&field2=%.2f", temp, humi);
-        sendToThingSpeak(WRITEKEY,String(szEventInfo));
+        if (readOK == false) {
+            res = readAM2321();
+            while (res && (tries-- > 0)) {
+              delay(1000);
+              res = readAM2321();
+            }
+        }
+        if (!res || readOK) {
+            readOK = true;
+            char szEventInfo[64];
+            sprintf(szEventInfo, "field1=%.1f&field2=%.2f", temp, humi);
+            sendToThingSpeak(WRITEKEY,String(szEventInfo));
+        }
         Spark.sleep(CHTUPDPERIOD - 30);
     }
 }

 void backLightOn()
 {
+    display_string_5x7(6,1,"BL ON ");
+    detachInterrupt(BackLightTrigger);
     RGB.control(false);
     trigger = millis() + BACKLDUR;
     transfer_command_lcd(0xaf);//--turn on oled panel
@@ -423,11 +440,13 @@

 void backLightOff()
 {
+    display_string_5x7(6,1,"BL Off");
     RGB.control(true);
     RGB.color(0,0,0);
     //display_string_5x7(6,1,"DISP OFF");
     transfer_command_lcd(0xae);//--turn off oled panel
     refresh=false;
+    attachInterrupt(BackLightTrigger, backLightOn, RISING);
 }

@@ -437,14 +456,15 @@
   DHT22.isrCallback();
 }

-void readAM2321() {
+int readAM2321() {
   int lt = millis();
   int result;

-  detachInterrupt(BackLightTrigger);
+  display_string_5x7(6,1,"Reading...");
     DHT22.acquire();
   while (DHT22.acquiring() && (millis() - lt < TIMEOUT))
     ;
+  //display_string_5x7(6,1,"Done Read ");
   //delay(500);
   //DHT22.acquire();
   //while (DHT22.acquiring())
@@ -484,11 +504,11 @@
       status = "Unknown            ";
       break;
   }
-
+  if (!result) {
     temp = DHT22.getCelsius();
     humi = DHT22.getHumidity();
-    attachInterrupt(BackLightTrigger, backLightOn, RISING);
-
+  }
+  return result;
 }

@@ -539,19 +559,26 @@

 void loop()
 {
+    readOK = false;
+    flip = !flip;
+
     if (refresh) {
       Time.timeStr().substring(4,19).toCharArray(dispCS, 16);
       display_string_5x7(1,1,"     ");
       display_string_5x7(1,20,dispCS);

-      readAM2321();
-      status.toCharArray(dispCS, 20);
-      display_string_5x7(6,1,dispCS);
-
-//      sprintf(dispCS, "T: %0.1f, H: %0.1f    ", temp, humi);
-//      display_string_5x7(3,1,dispCS);
-      sprintf(dispCS, "%0.1fC, %0.1f%%    ", temp, humi);
-      display_string_8x16(3,1,dispCS);
+      if (flip) {
+          if (!readAM2321()) {
+            readOK = true;
+            status.toCharArray(dispCS, 20);
+            display_string_5x7(6,1,dispCS);
+
+      //      sprintf(dispCS, "T: %0.1f, H: %0.1f    ", temp, humi);
+      //      display_string_5x7(3,1,dispCS);
+            sprintf(dispCS, "%0.1fC, %0.1f%%    ", temp, humi);
+            display_string_8x16(3,1,dispCS);
+          }
+      }
     }

     publishReadings();


Fix mcufriend ID reporting - Add message to see serial output

--- examples/arduino/diag_ard_touch_detect/diag_ard_touch_detect.ino
+++ examples/arduino/diag_ard_touch_detect/diag_ard_touch_detect.ino
@@ -57,6 +57,7 @@

 char m_acTxt[MAX_STR];
 gslc_tsRect m_rStatus = (gslc_tsRect) { 40, 60, 50, 10 };
+gslc_tsRect m_rReport = (gslc_tsRect) { 40, 80, 140, 10 };
 gslc_tsFont* m_pFont = NULL;

 #define MAX_FONT                1
@@ -74,6 +75,7 @@

   // Status
   gslc_DrvDrawTxt(&m_gui, m_rStatus.x, m_rStatus.y, m_pFont, "Detecing Pins", GSLC_TXT_DEFAULT, GSLC_COL_YELLOW, GSLC_COL_BLACK);
+  gslc_DrvDrawTxt(&m_gui, m_rReport.x, m_rReport.y, m_pFont, "See Serial Monitor output...", GSLC_TXT_DEFAULT, GSLC_COL_GREEN, GSLC_COL_BLACK);
 }

 bool DetectPins()
@@ -84,6 +86,12 @@
   int nPinYm = -1;

   int i, j, value, Apins[2], Dpins[2], Values[2], found = 0;
+  int nMcuFriendId = -1;
+
+  #if defined(DRV_DISP_ADAGFX_MCUFRIEND)
+    // For MCUFRIEND displays, detect the ID
+    nMcuFriendId = m_disp.readID();
+  #endif // DRV_DISP_ADAGFX_MCUFRIEND

   GSLC_DEBUG_PRINT("Making all control and bus pins INPUT_PULLUP\n", "");
   GSLC_DEBUG_PRINT("Typical 30k Analog pullup with corresponding pin\n", "");
@@ -140,7 +148,7 @@
     GSLC_DEBUG_PRINT("  // Pinout for DRV_TOUCH_SIMPLE 4-wire resistive touchscreen\n", "");
     #if defined(DRV_DISP_ADAGFX_MCUFRIEND)
       // For MCUFRIEND displays, report the ID
-      snprintf(m_acTxt, MAX_STR, "(MCUFRIEND ID=0x%04X)", m_disp.readID());
+      snprintf(m_acTxt, MAX_STR, "(MCUFRIEND ID=0x%04X)", nMcuFriendId);
       GSLC_DEBUG_PRINT("  // %s\n", m_acTxt);
     #endif
     GSLC_DEBUG_PRINT("  #define ADATOUCH_PIN_YP   A%d    // \"Y+\": Must be an analog pin\n", (nPinYp - A0));


Update Beta_1-2-3-um.ino

Update Beta_1-2-3-um.ino

--- Beta_1-2-3-um/Beta_1-2-3-um.ino
+++ Beta_1-2-3-um/Beta_1-2-3-um.ino
@@ -308,18 +308,18 @@

 // IR-SENSOR Lesung (Durchschnitt)
-/* Durchschnitt aus den letzten 5 Messwerten (um Messungenauigkeiten vorzubeugen)
+/* Durchschnitt aus den letzten 10 Messwerten (um Messungenauigkeiten vorzubeugen)
  * IRREAD() => 250 MS! */
 int irRead() {
     averaging = 0;
-    for (int i=0; i<=10; i++) { // IR-Sensor_Wert Einlesen (5x)
+    for (int i=0; i<=10; i++) { // IR-Sensor_Wert Einlesen (10x)
         distance = analogRead(irSense);
         averaging = averaging + distance;
-        delay(55);      /*  50 ms zwischen Lesewerten warten.
+        delay(55);      /*  55 ms zwischen Lesewerten warten.
                           According to datasheet time between each read
                           is -38ms +/- 10ms. */
     }
-    distance = averaging / 5;       // Durchschnitt der Lesewerte in distance
+    distance = averaging / 10;       // Durchschnitt der Lesewerte in distance
     return(distance);               // Rückgabewert
 }


I2CDevice

--- examples/All/All.ino
+++ examples/All/All.ino
@@ -22,6 +22,8 @@
 */

 #include <TextDevices.h>
+#include <Wire.h>
+#include <I2CDevice.h>
 #include <PulseinDevice.h>
 #include <ShiftersDevice.h>
 #include <ShortcutsDevice.h>
@@ -29,6 +31,7 @@
 #include <WatchersDevice.h>

 TextDevices::Devices            devices;
+TextDevices::I2CDevice          i2cDevice;
 TextDevices::PulseinDevice      pulseinDevice;
 TextDevices::ShiftersDevice     shiftersDevice;
 TextDevices::ShortcutsDevice    shortcutsDevice;
@@ -38,6 +41,7 @@
 void setup() {
     Serial.begin(9600);
     devices.setup(&Serial);
+    devices.registerDevice(&i2cDevice);
     devices.registerDevice(&pulseinDevice);
     devices.registerDevice(&shiftersDevice);
     devices.registerDevice(&shortcutsDevice);


Switch to external clock automatically when a clock signal is received on GT3.

--- examples/seq/seq.ino
+++ examples/seq/seq.ino
@@ -75,6 +75,7 @@

 DUINO_Filter * slew_filter;

+void clock_ext_isr();
 void clock_isr();
 void reset_isr();

@@ -86,8 +87,7 @@

   virtual void setup()
   {
-    // TODO: attach GT3 to hardware clock isr that sets clock to EXT
-    gt_attach_interrupt(GT3, clock_isr, CHANGE);
+    gt_attach_interrupt(GT3, clock_ext_isr, CHANGE);
     gt_attach_interrupt(GT4, reset_isr, RISING);
   }

@@ -205,6 +205,7 @@
     last_stage = 0;
     last_diradd_mode = false;
     last_reverse = false;
+    ext_clock_received = false;

     // draw top line
     display->draw_du_logo_sm(0, 0, DUINO_SSD1306::White);
@@ -550,6 +551,16 @@
       display_changed[2] = true;
     }

+    // update clock from input
+    if(ext_clock_received)
+    {
+      bool clock_selected = (main_selected == 1) && (top_selected == 4);
+      display->fill_rect(109, 12, 17, 7, clock_selected ? DUINO_SSD1306::White : DUINO_SSD1306::Black);
+      display_clock(109, 12, params.vals.clock_bpm, clock_selected ? DUINO_SSD1306::Black : DUINO_SSD1306::White);
+      display_changed[1] = true;
+      ext_clock_received = false;
+    }
+
     // update display
     if(display_changed[0])
     {
@@ -571,6 +582,14 @@
     {
       display->display(0, 127, display_changed[4] ? 6 : 7, 7);
     }
+  }
+
+  void set_clock_ext()
+  {
+    params.vals.clock_bpm = 0;
+    seq_values.clock_ext = true;
+    ext_clock_received = true;
+    update_clock();
   }

  private:
@@ -730,6 +749,8 @@
   bool last_diradd_mode;
   bool last_reverse;

+  bool ext_clock_received;
+
   bool display_changed[6];

   struct DU_SEQ_Parameter_Values {
@@ -757,6 +778,16 @@

 ENCODER_ISR(interface->encoder);

+void clock_ext_isr()
+{
+  if(!seq_values.clock_ext)
+  {
+    interface->set_clock_ext();
+  }
+
+  clock_isr();
+}
+
 void clock_isr()
 {
   clock_gate = seq_values.clock_ext ? function->gt_read_debounce(GT3) : !clock_gate;


testing

testing

--- module/module.ino
+++ module/module.ino
@@ -198,6 +198,8 @@
 		if (debug) {
 			Serial.print("PeriodX: "); Serial.print(periodX);
 			Serial.print(" PeriodY: "); Serial.print(periodY);
+			Serial.print(" "); Serial.print(signals[0]); Serial.print(signals[1]); Serial.print(signals[2]);
+			Serial.print(" "); Serial.print(checkHistory(signals));
 			Serial.print(" Start Time: "); Serial.print(startTime);
 			Serial.print(" Pulse Count: "); Serial.println(pulseCount);
 		}


Clean up

Clean up

--- module/module.ino
+++ module/module.ino
@@ -175,7 +175,7 @@
 				elapsedTime = calculateTime(startTime);

 				// Any valid accumulated time will be returned
-				if (pulseCount > minCount) {
+				if (startTime > 0) {
           			return elapsedTime;
 				}
 				else {
@@ -218,6 +218,7 @@
 				if (startTime == 0) {
 					startTime = millis();
 				}
+				pulseCount += 1;
 			}
 		}
 		// if periodX and periodY IS NOT a valid pair
@@ -248,8 +249,8 @@
 		}

 		// record the previous state
-		lastPeriodX = periodX;
-		lastPeriodY = periodY;
+		//lastPeriodX = periodX;
+		//lastPeriodY = periodY;
 		signals[i] = inRange(periodX, periodY);
 		i++;


Turn on fan

Turn on fan

--- ComputerBox/ComputerBox.ino
+++ ComputerBox/ComputerBox.ino
@@ -33,6 +33,10 @@

   dht.begin();
   Serial.println("DHT22found");
+
+  // Turn on the fan
+  digitalWrite(fan_pin, HIGH);
+  Serial.println("Fan turned on");

   int x, y, c = 0;
   Serial.println("Starting to look for sensors...");


Configuration of connected lamps.

Configuration of connected lamps.

--- esp8266/TestServer/TestServer.ino
+++ esp8266/TestServer/TestServer.ino
@@ -17,6 +17,9 @@
 // Maximum number of devices connected to IO pins.
 #define MAX_DEVICES 8

+// Length of name strings. (hostname, room names, lamp names, etc.)
+#define NAME_LEN 32
+

 enum Io_Type {
   test,
@@ -26,14 +29,14 @@
 };

 typedef struct Connected_device {
-  char unique_id[32];
-  char room[32];
+  char name[NAME_LEN];
+  char room[NAME_LEN];
   Io_Type io_type;
   int io_pins[4];
 } Connected_device;

 struct Config {
-  char hostname[32];
+  char hostname[NAME_LEN];
   Connected_device devices[MAX_DEVICES];
   char config_version[4];
   // TODO: add WFI ssid and password.
@@ -48,11 +51,24 @@

+// Configuration
+void SetHostname(const char* new_hostname) {
+  strncpy(config.hostname, new_hostname, NAME_LEN);
+}
+
+void SetDevice(const unsigned int index, struct Connected_device device) {
+  if (index < MAX_DEVICES) {
+    memcpy(&(config.devices[index]), &device, sizeof(device));
+  }
+}
+
+
 // mDNS
-//extern String brokers[MAX_BROKERS][4];  // Array containing information about brokers received over mDNS.
 Brokers brokers(QUESTION_SERVICE);

-void answerCallback(const mdns::Answer* answer){ brokers.ParseMDnsAnswer(answer); }
+void answerCallback(const mdns::Answer* answer) {
+  brokers.ParseMDnsAnswer(answer);
+}
 mdns::MDns my_mdns(NULL, NULL, answerCallback);

@@ -126,6 +142,21 @@
   message += config.config_version;
   message += "\n";

+  for(int i = 0; i < MAX_DEVICES; ++i){
+    message += i;
+    message += "  ";
+    message += config.devices[i].name;
+    message += "  ";
+    message += config.devices[i].room;
+    message += "  ";
+    message += config.devices[i].io_type + "  ";
+    message += config.devices[i].io_pins[0] + ",";
+    message += config.devices[i].io_pins[1] + ",";
+    message += config.devices[i].io_pins[2] + ",";
+    message += config.devices[i].io_pins[3];
+    message += "\n";
+  }
+
   message += brokers.Summary();

   http_server.send(200, "text/plain", message);
@@ -133,9 +164,46 @@
 }

 void handleConfig() {
+  const unsigned int now = millis() / 1000;
+
   String message = "";
+
   if (http_server.hasArg("test_arg")) {
     message += "test_arg: " + http_server.arg("test_arg") + "\n";
+  }
+  if (http_server.hasArg("hostname")) {
+    char tmp_buffer[NAME_LEN];
+    http_server.arg("hostname").toCharArray(tmp_buffer, NAME_LEN);
+    SetHostname(tmp_buffer);
+    message += "hostname: " + http_server.arg("hostname") + "\n";
+  }
+  if (http_server.hasArg("device") and http_server.hasArg("name") and http_server.hasArg("room") and http_server.hasArg("io_type") and http_server.hasArg("io_pins")) {
+    unsigned int index = http_server.arg("device").toInt();
+    Connected_device device;
+    http_server.arg("name").toCharArray(device.name, NAME_LEN);
+    http_server.arg("room").toCharArray(device.room, NAME_LEN);
+    if (http_server.arg("io_type") == "test") {
+      device.io_type = Io_Type::test;
+    } else if (http_server.arg("io_type") == "rgb") {
+      device.io_type = Io_Type::rgb;
+    } else if (http_server.arg("io_type") == "pwm") {
+      device.io_type = Io_Type::pwm;
+    } else if (http_server.arg("io_type") == "onoff") {
+      device.io_type = Io_Type::onoff;
+    }
+    char tmp_buffer[NAME_LEN];
+    http_server.arg("io_pins").toCharArray(tmp_buffer, NAME_LEN);
+    char* pch = strtok (tmp_buffer, ",");
+    int i = 0;
+    while (pch != NULL and i < 4)
+    {
+      device.io_pins[i] = atoi(pch);
+      pch = strtok(NULL, ",");
+    }
+
+    SetDevice(index, device);
+
+    message += "device: " + http_server.arg("device") + "\n";
   }

   http_server.send(200, "text/plain", message);
@@ -215,5 +283,5 @@
   if (!mqtt_client.connected()) {
     Serial.println("MQTT disconnected.");
     mqtt_connect();
-  }
-}
+  }
+}


Delete relais_serre_LCDi2c_V.3.ino

Delete relais_serre_LCDi2c_V.3.ino

--- relais_serre_LCDi2c_V.3.ino
+++ relais_serre_LCDi2c_V.3.ino
@@ -1,980 +0,0 @@
-#include <EEPROM.h>
-#include <avr/pgmspace.h>
-//---------------------LCD-------------------
-#include <Wire.h>
-#include <LCD.h>
-#include <LiquidCrystal_I2C.h>
-
-#define I2C_ADDR    0x22              // Define I2C Address where the PCF8574A is
-#define BACKLIGHT_PIN     3
-
-LiquidCrystal_I2C  lcd(I2C_ADDR,2,1,0,4,5,6,7);
-//---------------------RTC--------------------
-#include <DS3231.h>
-DS3231  rtc(SDA, SCL);                // Init the DS3231 using the hardware interface
-Time  t;
-
-#include <DHT.h>
-#define DHTPIN            A1          // Pin which is connected to the DHT sensor.
-#define DHTTYPE           DHT11       // Uncomment the type of sensor in use:
-DHT dht(DHTPIN, DHTTYPE);
-int yr; byte mt; byte dy; byte hr; byte mn; byte sc;
-
-//--------------------LCD Menu----------------
-//menuPin
-boolean menuPinState = 1;
-boolean lastMenuPinState = 1;
-//curseur
-byte currentMenuItem = 1;
-//buttonstate
-byte state = 0;
-byte laststate = 0;
-//menu
-int menu = 0;
-//#items/menu
-byte Nbitems = 6;
-char* menuitems[10];
-//--------------Relais--------------------
-//Sorties
-#define ROLLUP1_POWER  12//relais on/off - moteur1
-#define ROLLUP1_DIRECTION  11 //relais gauche/droite - moteur1
-#define ROLLUP2_POWER  10//relais on/off - moteur2
-#define ROLLUP2_DIRECTION  9 //relais gauche/droite - moteur2
-#define FAN  8 //relais ventilation forcée
-#define CHAUFFAGE1 7 //relais fournaise1
-#define CHAUFFAGE2 6 // relais fournaise2
-#define menuPin 3
-//vocabulaire
-const int CLOSE = HIGH;
-const int OPEN = LOW;
-const int ON = LOW;
-const int OFF = HIGH;
-
-//----------------------Program-----------------
-//**********PROGRAMMATION PAR DÉFAUT*************
-//Programmes de températures
-byte HP1 = 7;                   //Heure d'exécution du premier programme
-byte MP1 = 30;                  //Minutes d'exécution du premier programme
-byte TEMP_CIBLEP1 = 20;         //Température cible du program 1
-byte HP2 = 11;                  //Heure d'exécution du deuxième programme
-byte MP2 = 0;                   //Minutes d'exécution du deuxième programme
-byte TEMP_CIBLEP2 = 24;         //Température cible du program2
-byte HP3 = 19;                  //Heure d'exécution du deuxième programme
-byte MP3 = 30;                  //Minutes d'exécution du deuxième programme
-byte TEMP_CIBLEP3 = 22;         //Température cible du programme 3
-//Sorties:
-byte HYST_ROLLUP = 2;           //hysteresis rollup
-byte HYST_VENT = 2;             //hysteresis ventilation
-byte HYST_FOURNAISE1 = 2;       //hysteresis fournaise 1
-byte HYST_FOURNAISE2 = 2;       //hysteresis fournaise 2
-//Modificateurs
-byte rmodE = 11;                //Modificateur relais (Mod.réel = rmodE-11, donc 11 équivaut à un modificateur de 0C, 13 de 2C, 9 de -2C, etc.
-byte vmodE = 13;                //Modificateur ventilation
-byte f1modE = 9;                //Modificateur fournaise1
-byte f2modE = 9;                //Modificateur fournaise2
-//temps de rotation et pauses
-byte rotation = 4;
-byte pause = 2;
-//***********************************************
-
-//consignes initiales
-byte opened = 0;
-byte last_opened = 0;
-boolean heating1 = false;                     //fournaise 1 éteinte par défaut
-boolean last_heating1 = false;
-boolean heating2 = false;                     //fournaise 2 éteinte par défaut
-boolean last_heating2 = false;
-boolean fan = false;                          //VENTilation forcée éteinte par défaut
-boolean last_fan = false;
-float greenhouseTemperature = 20.0;               //température par défaut : 20C (ajusté après un cycle)
-float last_greenhouseTemperature = 20.0;
-float greenhouseHumidity;
-float last_greenhouseHumidity = 40.0;
-int rmod = (rmodE-11);                        //modificateur relais
-int vmod = (vmodE-11);                        //modificateur VENTilation
-int f1mod = (f1modE-11);                      //modificateur fournaise1
-int f2mod = (f2modE-11);                      //modificateur fournaise2
-int TEMP_CIBLE = 20;                          //température cible par défaut : 20C (ajustée après un cycle))
-int TEMP_ROLLUP = TEMP_CIBLE + rmod;
-int TEMP_VENTILATION = TEMP_CIBLE + vmod;
-int TEMP_FOURNAISE1 = TEMP_CIBLE + f1mod;
-int TEMP_FOURNAISE2 = TEMP_CIBLE + f2mod;
-byte PROGRAMME = 1;                           //Programme horaire par défaut
-long ROTATION_TIME = (rotation*1000);         //temps de rotation des moteurs(en mili-secondes)
-long PAUSE_TIME = (pause*1000);               //temps d'arrêt entre chaque ouverture/fermeture(en mili-secondes)
-
-//incréments d'ouverture(nombre d'incréments d'ouverture = PCT_OPEN/NB_OF_STEPS_IN_ANIMATION = 25/5 = 5 incréments d'ouverture)
-const int PCT_OPEN = 25;
-const int NB_OF_STEPS_IN_ANIMATION = 5; //doit être un divisible de PCT_OPEN
-//Autres variables
-const int SLEEPTIME = 1000; //temps de pause entre chaque exécution du programme(en mili-secondes)
-
-
-void setup(){
- Serial.begin(9600);
- rtc.begin();
- dht.begin();
- lcd.begin(20, 4);
- lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
- lcd.setBacklight(HIGH);
- //newDefaultSettings();
- loadPreviousSettings();
- clearPrintTitle();
-
- //Définition et initalisation des sorties
-  pinMode(menuPin, INPUT_PULLUP);
-  pinMode(ROLLUP1_POWER, OUTPUT);
-  digitalWrite(ROLLUP1_POWER, HIGH);
-  pinMode(ROLLUP2_POWER, OUTPUT);
-  digitalWrite(ROLLUP2_POWER, HIGH);
-  pinMode(ROLLUP1_DIRECTION, OUTPUT);
-  digitalWrite(ROLLUP1_DIRECTION, HIGH);
-  pinMode(ROLLUP2_DIRECTION, OUTPUT);
-  digitalWrite(ROLLUP2_DIRECTION, HIGH);
-  pinMode(CHAUFFAGE1, OUTPUT);
-  digitalWrite(CHAUFFAGE1, HIGH);
-  pinMode(CHAUFFAGE2, OUTPUT);
-  digitalWrite(CHAUFFAGE2, HIGH);
-  pinMode(FAN, OUTPUT);
-  digitalWrite(FAN, HIGH);
-
-//Remise à niveau des rollup
-  Serial.println(F("Resetting position"));
-  opened = 100;
-  for (int i=0; i<5; i++){
-    closeSides();
-    delay(PAUSE_TIME);}
-  Serial.println(F("Resetting done"));
-
-  displayTempHRStatus();
-  displayRollupStatus();
-  displayFanHeaterStatus();
- }
-
-void loop(){
-if (digitalRead(menuPin) == LOW){
-    menuPinState = 0;
-    if (menuPinState != lastMenuPinState){
-      displayMenu(menu);}
-    Menu(menu);
-    lastMenuPinState = menuPinState;
-    delay(50);}
-
-else if (digitalRead(menuPin) == HIGH){
-    menuPinState = 1;
-    if (menuPinState != lastMenuPinState){
-      displayTempHRStatus();
-      displayRollupStatus();
-      displayFanHeaterStatus();
-      }
-    Controle();
-    lastMenuPinState = menuPinState;
-    delay(SLEEPTIME);}
-}
-//*******************************************CONTROLE**********************************
-void Controle(){
-  //-----------------Horloge-----------------
-  t = rtc.getTime();
-  int heure = t.hour;
-  int minutes = t.min;
- if (((heure >= HP1)  && (heure < HP2))  && (minutes >= MP1)){
-    TEMP_CIBLE = TEMP_CIBLEP1;
-    PROGRAMME = 1;
-  }
-  else if(((heure >= HP2)  && (heure < HP3))  && (minutes >= MP2)){
-    TEMP_CIBLE = TEMP_CIBLEP2;
-    PROGRAMME = 2;
-  }
-  else if((heure >= HP3)  && (minutes >= MP3)){
-    TEMP_CIBLE = TEMP_CIBLEP3;
-    PROGRAMME = 3;
-  }
-  //--------------DHT11--------------------
-  greenhouseTemperature = dht.readTemperature();
-  greenhouseHumidity = dht.readHumidity();
-//--------------Relais--------------------
-//Programme d'ouverture/fermeture des rollups
-  if(greenhouseTemperature < TEMP_ROLLUP-(HYST_ROLLUP/2)){
-    closeSides();
-  }else if(greenhouseTemperature > TEMP_ROLLUP+(HYST_ROLLUP/2)){
-    openSides();
-  }
-//Programme fournaise1
-  if (greenhouseTemperature < (TEMP_FOURNAISE1-(HYST_FOURNAISE1/2))){
-    setHeater1(ON);
-    digitalWrite(CHAUFFAGE1, ON);
-  }else if(greenhouseTemperature > (TEMP_FOURNAISE1+(HYST_FOURNAISE1/2))){
-    setHeater1(OFF);
-    digitalWrite(CHAUFFAGE1, OFF);
-  }
-//Programme fournaise2
-  if (greenhouseTemperature < (TEMP_FOURNAISE2-(HYST_FOURNAISE2/2))){
-    setHeater2(ON);
-    digitalWrite(CHAUFFAGE2, ON);
-  }else if(greenhouseTemperature > (TEMP_FOURNAISE2+(HYST_FOURNAISE2/2))){
-    setHeater2(OFF);
-    digitalWrite(CHAUFFAGE2, OFF);
-  }
-//Programme ventilation forcée
-   if (greenhouseTemperature > (TEMP_VENTILATION - (HYST_VENT/2))){
-    setFan(ON);
-    digitalWrite(FAN, ON);
-  }else if(greenhouseTemperature < (TEMP_VENTILATION + (HYST_VENT/2))){
-    setFan(OFF);
-    digitalWrite(FAN, OFF);
-  }
-//--------------Affichage sériel--------------------
-    Serial.println(F(""));
-    Serial.println(F("-----------------------"));
-    Serial.print(rtc.getDOWStr());
-    Serial.print(F(",  "));
-    // Send date
-    Serial.print(rtc.getDateStr());
-    Serial.print(F(" - "));
-    // Send time
-    Serial.println(rtc.getTimeStr());
-    Serial.print(F("PROGRAMME : "));
-    Serial.println(PROGRAMME);
-
-    Serial.println(F("-----------------------"));
-    Serial.print(F("Temperature cible :"));
-    Serial.print(TEMP_CIBLE);
-    Serial.println(F(" C"));
-
-    Serial.print(F("Temperature actuelle: "));
-    Serial.print(greenhouseTemperature);
-    Serial.println(" C");
-    Serial.print(F("Humidite: "));
-    Serial.print(greenhouseHumidity);
-    Serial.println(F("%"));
-    Serial.println(F("-----------------------"));
-    if(fan == false){
-    Serial.println(F("FAN: OFF"));}
-    else if(fan == true){
-    Serial.println(F("FAN: ON"));}
-    if(heating1 == false){
-    Serial.println(F("HEATING1: OFF"));}
-    else if(heating1 == true){
-    Serial.println(F("HEATING1: ON"));}
-    if(heating2 == false){
-    Serial.println(F("HEATING2 : OFF"));}
-    else if(heating2 == true){
-    Serial.println(F("HEATING2 : ON"));}
-//--------------Affichage LCD--------------------
-  lcd.setCursor(0, 0);
-  if((greenhouseTemperature!= last_greenhouseTemperature)||(greenhouseHumidity != last_greenhouseHumidity)){
-  displayTempHRStatus();
-  }
-  if(opened != last_opened){
-  displayRollupStatus();
-  }
-  if((fan != last_fan)||(heating1 != last_heating1)){
-  displayFanHeaterStatus();
-  }
-
-last_greenhouseTemperature = greenhouseTemperature;
-last_greenhouseHumidity = greenhouseHumidity;
-last_opened = opened;
-last_fan = fan;
-last_heating1 = heating1;
-last_heating2 = heating2;
-}
-
-//Affichage du % d'ouverture des rollup
-void setOpenedStatus(int pctIncrease){
-  opened += pctIncrease;
-  if(opened < 0) {
-    opened = 0;
-  }else if (opened > 100){
-    opened = 100;
-  }
-  Serial.print(F("    "));
-  Serial.println(opened);
-  lcd.setCursor(16, 1);
-  lcd.print(opened);
-  lcd.print(F("% "));
-}
-
-//Exécution de la séquence d'ouverture/fermeture
-void animate(int movement){
-  for (int i=0; i < NB_OF_STEPS_IN_ANIMATION; i++){
-      delay(ROTATION_TIME / NB_OF_STEPS_IN_ANIMATION);
-      setOpenedStatus(movement * PCT_OPEN / NB_OF_STEPS_IN_ANIMATION);
-    };
-}
-
-//Programme d'ouverture des rollup
-void openSides(){
-  if(opened < 100){
-    Serial.println(F(""));
-    Serial.println(F("  Opening"));
-    lcd.setCursor(0, 1);
-    lcd.print(F("OUVERTURE... "));
-    digitalWrite(ROLLUP1_POWER,ON);
-    digitalWrite(ROLLUP1_DIRECTION, OPEN);
-    digitalWrite(ROLLUP2_POWER,ON);
-    digitalWrite(ROLLUP2_DIRECTION, OPEN);
-    animate(1);
-    digitalWrite(ROLLUP1_POWER,OFF);
-    digitalWrite(ROLLUP2_POWER,OFF);
-    Serial.println(F("  Done opening"));
-    lcd.setCursor(0, 1);
-    lcd.print(F("ROLLUPS:     "));
-    delay(PAUSE_TIME);
-  }
-}
-
-//Programme de fermeture des rollups
-void closeSides(){
-  if (opened > 0){
-    Serial.println(F(""));
-    Serial.println(F("  Closing"));
-    lcd.setCursor(0, 1);
-    lcd.print(F("FERMETURE... "));
-    digitalWrite(ROLLUP1_POWER,ON);
-    digitalWrite(ROLLUP1_DIRECTION, CLOSE);
-    digitalWrite(ROLLUP2_POWER,ON);
-    digitalWrite(ROLLUP2_DIRECTION, CLOSE);
-    animate(-1);
-    digitalWrite(ROLLUP1_POWER, OFF);
-    digitalWrite(ROLLUP2_POWER, OFF);
-    Serial.println(F("  Done closing"));
-    lcd.setCursor(0, 1);
-    lcd.print(F("ROLLUPS:     "));
-    delay(PAUSE_TIME);
-  }
-}
-
-
-//État de la première fournaise
-void setHeater1(int heaterCommand1){
-  if ((heaterCommand1 == ON) && (heating1 == false)){
-    Serial.println(F(""));
-    Serial.println(F("  Start heating1"));
-    heating1 = true;
-  }else if ((heaterCommand1 == OFF) && (heating1 == true)){
-    Serial.println(F(""));
-    Serial.println(F("  Stop heating1"));
-    heating1 = false;
-    }
-  }
-
-//État de la deuxième fournaise
-void setHeater2(int heaterCommand2){
-  if ((heaterCommand2 == ON) && (heating2 == false)){
-    Serial.println(F(""));
-    Serial.println(F("  Start heating2"));
-    heating2 = true;
-  }else if ((heaterCommand2 == OFF) && (heating2 == true)){
-    Serial.println(F(""));
-    Serial.println(F("  Stop heating2"));
-    heating2 = false;
-    }
-  }
-
-//État de la ventilation
-void setFan(int fanCommand){
-  if ((fanCommand == ON) && (fan == false)){
-    Serial.println(F(""));
-    Serial.println(F("  Start fan"));
-
-    fan = true;
-  }else if ((fanCommand == OFF) && (fan == true)){
-    Serial.println(F(""));
-    Serial.println(F("  Stop fan"));
-    fan = false;
-  }
-}
-void displayTempHRStatus(){
-  lcd.setCursor(0,0);
-  lcd.print(F("                    "));
-  lcd.setCursor(0,0);
-  lcd.print(F("T: "));
-  lcd.print(greenhouseTemperature);
-  lcd.print(F("C  "));
-  lcd.setCursor(10,0);
-  lcd.print(F("HR: "));
-  lcd.print(greenhouseHumidity);
-  lcd.print("%");
-}
-void displayRollupStatus(){
-  lcd.setCursor(0,1);
-  lcd.print(F("                    "));
-  lcd.setCursor(0, 1);
-  lcd.print(F("ROLLUPS:     "));
-  lcd.setCursor(16, 1);
-  lcd.print(opened);
-  lcd.print(F("% "));
-}
-void displayFanHeaterStatus(){
-  lcd.setCursor(0,2);
-  lcd.print(F("                    "));
-  lcd.setCursor(0,3);
-  lcd.print(F("                    "));
-  if(fan == false){
-      lcd.setCursor(0, 2);
-      lcd.print(F("FAN:"));
-      lcd.setCursor(16,2);
-      lcd.print(F("OFF"));}
-  else if(fan == true){
-      lcd.setCursor(0,2);
-      lcd.print(F("FAN:"));
-      lcd.setCursor(16,2);
-      lcd.print(F("ON "));}
-  if(heating1 == false){
-      lcd.setCursor(0, 3);
-      lcd.print(F("HEATING:"));
-      lcd.setCursor(16,3);
-      lcd.print(F("OFF"));}
-  else if(heating1 == true){
-      lcd.setCursor(0,3);
-      lcd.print(F("HEATING: "));
-      lcd.setCursor(16,3);
-      lcd.print(F("ON "));}
-}
-//*******************************************EEPROM***********************************************
-void newDefaultSettings(){
- EEPROM.write(0,HYST_ROLLUP);
- EEPROM.write(1,HYST_VENT);
- EEPROM.write(2,HYST_FOURNAISE1);
- EEPROM.write(3,HYST_FOURNAISE2);
- EEPROM.write(4,HP1);
- EEPROM.write(5,MP1);
- EEPROM.write(6,TEMP_CIBLEP1);
- EEPROM.write(7,HP2);
- EEPROM.write(8,MP2);
- EEPROM.write(9,TEMP_CIBLEP2);
- EEPROM.write(10,HP3);
- EEPROM.write(11,MP3);
- EEPROM.write(12,TEMP_CIBLEP3);
- EEPROM.write(13,rotation);
- EEPROM.write(14,pause);
- EEPROM.write(15,rmodE);
- EEPROM.write(16,vmodE);
- EEPROM.write(17, f1modE);
- EEPROM.write(18, f2modE);
-}
-
-void loadPreviousSettings(){
- HYST_ROLLUP = EEPROM.read(0);
- HYST_VENT = EEPROM.read(1);
- HYST_FOURNAISE1 = EEPROM.read(2);
- HYST_FOURNAISE2 = EEPROM.read(3);
- HP1 = EEPROM.read(4);
- MP1 = EEPROM.read(5);
- TEMP_CIBLEP1 = EEPROM.read(6);
- HP2 = EEPROM.read(7);
- MP2 = EEPROM.read(8);
- TEMP_CIBLEP2 = EEPROM.read(9);
- HP3 = EEPROM.read(10);
- MP3 = EEPROM.read(11);
- TEMP_CIBLEP3 = EEPROM.read(12);
- rotation = EEPROM.read(13);
- pause = EEPROM.read(14);
- rmodE = EEPROM.read(15);
- vmodE = EEPROM.read(16);
- f1modE = EEPROM.read(17);
- f2modE = EEPROM.read(18);
- }
-
-
-
-//**************************************MENU****************************************************
-void Menu(int x){
-  int a = analogRead(0);
-  buttonState(a);
-
-  if ((state == 1) && (state != laststate)){
-      currentMenuItem = currentMenuItem + 1;
-      real_currentMenuItem(Nbitems);
-      displayMenu(x);
-  } else if ((state == 2) && (state != laststate)){
-      currentMenuItem = currentMenuItem - 1;
-      real_currentMenuItem(Nbitems);
-      displayMenu(x);
-  } else if ((state == 3) && (state != laststate)){
-      real_currentMenuItem(Nbitems);
-      selectMenu(x, currentMenuItem);
-  }
-  laststate = state;
-}
-
-void buttonState(int x){
-  if(x < 800){state = 0;}
-  else if(x < 900){state = 1;}
-  else if (x < 950){state = 2;}
-  else if (x < 1000){state = 3;}
-}
-
-void real_currentMenuItem(int x){
-  if(currentMenuItem < 1){
-  currentMenuItem = 1;
-  }
-  else if(currentMenuItem > x){
-  currentMenuItem = x;
-  }
-}
-
-void Scrollingmenu (int x, const char a[20] PROGMEM, const char b[20] PROGMEM, const char c[20] PROGMEM, const char d[20] PROGMEM, const char e[20] PROGMEM, const char f[20] PROGMEM, const char g[20] PROGMEM, const char h[20] PROGMEM, const char i[20] PROGMEM, const char j[20] PROGMEM, int y){
-  const int numLcdRows = 3;
-  byte scrollPos = 0;
-  Nbitems = x;
-  const char* menuitems[] PROGMEM = {a,b,c,d,e,f,g,h,i,j};
-
-        if (y > numLcdRows){scrollPos = y - numLcdRows;
-      } else {scrollPos = 0;
-      }
-      clearPrintTitle();
-      for (int i=0; i < numLcdRows; ++i) {
-            lcd.setCursor(0, i+1);
-            lcd.print(menuitems[i + scrollPos]);
-            }
-      lcd.setCursor(19, (y - scrollPos));
-      lcd.blink();
-}
-
-void Scrollingnumbers(int x, int y, int z, int a){
-  const int numLcdRows = 3;
-  int scrollPos = 0;
-  Nbitems = x;
-
-      if (y > numLcdRows){scrollPos = y - numLcdRows;
-      } else {scrollPos = 0;
-      }
-      clearPrintTitle();
-      for (int i=0; i < numLcdRows; ++i) {
-            lcd.setCursor(0, i+1);
-            if(y < 4){
-            lcd.print((z-a)+(i*a)+(a));}
-            else if(y < x){
-            lcd.print((z-a)+(i*a)+((y-2)*a));}
-            else if (y == x){
-            lcd.print("back");}
-            else{}
-            }
-      lcd.setCursor(19, (y - scrollPos));
-      lcd.blink();
-}
-void clearPrintTitle(){
-  lcd.noBlink();
-  lcd.clear();
-  lcd.setCursor(0,0);
-  lcd.print("**ROBOT-SERRE**V.1**");
-}
-//***********************************DISPLAY****************************************************
-//Scrollingmenu(Nbitems, Item1, item2, item3, item4, item5, Item6, item7, item8, item9, item10, currentMenuItem); //leave variable "Itemx" blank if it doesnt exist
-//Scrollingnumbers(Nbitems, currentMenuItem, starting number, multiplicator);
-
-void displayMenu(int x){
-  switch (x){
-  case 0: Scrollingmenu(6, "Temperature/humidex","Date/time","Rollups","Ventilation","Chauffage","Programmes","","","","", currentMenuItem);break;
-  case 1: Scrollingmenu(6, "Date","Time", "SetDOW", "Set date","Set time","back","","","","", currentMenuItem);break;
-  case 11: Scrollingmenu(8, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "back","","", currentMenuItem);break;
-  case 12:Scrollingnumbers(11, currentMenuItem, 2016, 1);  break;
-  case 121: Scrollingnumbers(13, currentMenuItem, 1 ,1);  break;
-  case 1211: Scrollingnumbers(32, currentMenuItem, 1, 1); break;
-  case 13: Scrollingnumbers(25, currentMenuItem, 1, 1);break;
-  case 131: Scrollingnumbers(62, currentMenuItem, 0 , 1); break;
-  case 1311: Scrollingnumbers(62, currentMenuItem, 0, 1);break;
-  case 2: Scrollingmenu(6, "Etat", "Programme", "Set hysteresis", "Set rotation time(s)", "Set pause time(s)", "back","","","","", currentMenuItem);break;
-  case 21: Scrollingnumbers(6, currentMenuItem, 2, 2);break;
-  case 22: Scrollingnumbers(21, currentMenuItem, 1, 1);break;
-  case 23: Scrollingmenu(10, "5", "15", "20", "30", "45", "60", "75", "90", "120", "back", currentMenuItem);break;
-  case 3: Scrollingmenu(3, "Etat", "Set hysteresis", "back", "", "", "", "", "", "", "", currentMenuItem);break;
-  case 31: Scrollingnumbers(6, currentMenuItem, 2, 2);break;
-  case 4: Scrollingmenu(5, "(F1)Etat", "(F2)Etat","(F1)Set hysteresis", "(F2)Set hysteresis", "back", "", "", "", "", "", currentMenuItem);break;
-  case 41: Scrollingnumbers(6, currentMenuItem, 2, 2);break;
-  case 42: Scrollingnumbers(6, currentMenuItem, 2, 2);break;
-  case 5: Scrollingmenu(9, "Programme 1", "Programme 2", "Programme 3", "Modificateurs", "Set Programme 1", "Set Programme 2", "Set Programme 3", "Set Modificateurs", "back","",currentMenuItem);break;
-  case 51:Scrollingmenu(3, "Set Heure", "Set Temp. cible", "back","","","","","","","", currentMenuItem);break;
-  case 511: Scrollingnumbers(25, currentMenuItem, 1 , 1); break;
-  case 5111: Scrollingnumbers(62, currentMenuItem, 0, 1);break;
-  case 512: Scrollingnumbers(51, currentMenuItem, 0 , 1); break;
-  case 52: Scrollingmenu(3, "Set Heure", "Set Temp. cible", "back","","","","","","","", currentMenuItem);break;
-  case 521: Scrollingnumbers(25, currentMenuItem, 1, 1); break;
-  case 5211: Scrollingnumbers(62, currentMenuItem, 0, 1);break;
-  case 522: Scrollingnumbers(51, currentMenuItem, 0, 1); break;
-  case 53: Scrollingmenu(3, "Set Heure", "Set Temp. cible", "back","","","","","","","", currentMenuItem);break;
-  case 531: Scrollingnumbers(25, currentMenuItem, 1 , 1); break;
-  case 5311: Scrollingnumbers(62, currentMenuItem, 0, 1);break;
-  case 532: Scrollingnumbers(51, currentMenuItem, 0, 1); break;
-  case 54: Scrollingmenu(3, "Mod. rollups", "Mod. ventilation", "Mod. fournaise1", "Mod. fournaise2", "back","","","","","", currentMenuItem);break;
-  case 541: Scrollingnumbers(22, currentMenuItem, -10, 1);break;
-  case 542: Scrollingnumbers(22, currentMenuItem, -10, 1);break;
-  case 543: Scrollingnumbers(22, currentMenuItem, -10, 1);break;
-  case 544: Scrollingnumbers(22, currentMenuItem, -10, 1);break;
-  }
-}
-//*****************************************SELECT**********************************************
-
-void switchmenu(int x){
-  delay(1000);
-  menu = x;
-  currentMenuItem = 1;
-  Nbitems = 3;
-  displayMenu(menu);
-}
-
-void selectMenu(int x, int y){
-  switch (x){
-  //------------------------------SelectrootMenu-------------------------------------
-  //"Temperature/humidex","Date/time","Rollups","Ventilation","Chauffage"
-  case 0:
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("Temperature : "));lcd.print(dht.readTemperature());lcd.print(F("C"));
-         lcd.setCursor(0,2);lcd.print(F("HR : "));lcd.print(dht.readHumidity());lcd.print(F("%"));
-    break;
-    case 2:switchmenu(1);break;
-    case 3:switchmenu(2);break;
-    case 4:switchmenu(3);break;
-    case 5:switchmenu(4);break;
-    case 6:switchmenu(5);break;
-     }
-  break;
-  //-------------------------------SelectMenu1-----------------------------------------
-  //"Date","Time","Set DOW" "Set date", "Set time","back"
-  case 1 :
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(rtc.getDOWStr());
-         lcd.setCursor(0,2);lcd.print(F("Date : "));lcd.print(rtc.getDateStr());
-    break;
-    case 2:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("Time : "));lcd.print(rtc.getTimeStr());
-    break;
-    case 3:switchmenu(11);break;
-    case 4:switchmenu(12);break;
-    case 5:switchmenu(13);break;
-    case 6:switchmenu(0);break;
-    }
-  break;
-  //-------------------------------SelectMenu12-----------------------------------------
-  //SET DAY OF THE WEEK
-  case 11 :
-    switch(y){
-    case 1:rtc.setDOW(MONDAY);switchmenu(1);break;
-    case 2:rtc.setDOW(TUESDAY);switchmenu(1);break;
-    case 3:rtc.setDOW(WEDNESDAY);switchmenu(1);break;
-    case 4:rtc.setDOW(THURSDAY);switchmenu(1);break;
-    case 5:rtc.setDOW(FRIDAY);switchmenu(1);break;
-    case 6:rtc.setDOW(SATURDAY);switchmenu(1);break;
-    case 7:rtc.setDOW(SUNDAY);switchmenu(1);break;
-    case 8:switchmenu(1);break;
-    }
-  break;
-  //-------------------------------SelectMenu12-----------------------------------------
-  //SET YEAR
-  case 12 :
-    if(y<Nbitems){yr = (2015+y);switchmenu(121);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu131-----------------------------------------
-  //SET MONTH
-  case 121 :
-    if(y<Nbitems){mt = y;switchmenu(1211);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu1311-----------------------------------------
-  //SET DAY
-  case 1211 :
-    if(y<Nbitems){dy = y;rtc.setDate(dy,mt,yr);switchmenu(1);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu14-----------------------------------------
-  //SET HOUR
-  case 13 :
-    if(y<Nbitems){hr = y;switchmenu(131);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu141-----------------------------------------
-  //SET MINUTES
-  case 131 :
-    if(y<Nbitems){mn = y;switchmenu(1311);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu1411-----------------------------------------
-  //SET SECONDS
-  case 1311 :
-    if(y<Nbitems){sc = y;rtc.setTime(hr,mn,sc);switchmenu(1);}
-    else{switchmenu(1);}
-  break;
-  //-------------------------------SelectMenu2-----------------------------------------
-  //"Etat", "Programme", "Set hysteresis", "Set rotation time(s)", "Set pause time(m)", "back"
-  case 2 :
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("Ouverture : "));lcd.print(opened);lcd.print(F("%"));
-         lcd.setCursor(0,2);lcd.print(F("TP : "));lcd.print(pause);lcd.print(F("s | TR :"));lcd.print(rotation);lcd.print(F("s"));
-         lcd.setCursor(0,3);lcd.print(F("Hysteresis : "));lcd.print(HYST_ROLLUP);lcd.print(F("C"));
-    break;
-    case 2:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("Programme : "));lcd.print(PROGRAMME);
-         lcd.setCursor(0,2);lcd.print(F("Temp. cible : "));lcd.print(TEMP_CIBLE);lcd.print(F("C"));
-         lcd.setCursor(0,3);lcd.print(F("Temp. rollup : "));lcd.print(TEMP_ROLLUP);lcd.print(F("C"));
-    break;
-    case 3:switchmenu(21);break;
-    case 4:switchmenu(22);break;
-    case 5:switchmenu(23);break;
-    case 6:switchmenu(0);break;
-    }
-  break;
-  //-------------------------------SelectMenu21-----------------------------------------
-  //SET HYSTERESIS
-  case 21 :
-    if(y<Nbitems){HYST_ROLLUP = (y*2);switchmenu(2);EEPROM.write(0,HYST_ROLLUP);}
-    else{switchmenu(2);}
-  break;
-  //-------------------------------SelectMenu22-----------------------------------------
-  //SET ROTATION TIME
-  case 22 :
-    if(y<Nbitems){rotation = y;switchmenu(2);EEPROM.write(13, rotation);}
-    else{switchmenu(2);}
-  break;
-  //-------------------------------SelectMenu23-----------------------------------------
-  //"5", "15", "20", "30", "45", "60", "75", "90", "120", "back"
-  case 23 :
-  switch(y){
-    case 1:pause = 5;switchmenu(2);EEPROM.write(14, pause);break;
-    case 2:pause = 15;switchmenu(2);EEPROM.write(14, pause);break;
-    case 3:pause = 20;switchmenu(2);EEPROM.write(14, pause);break;
-    case 4:pause = 30;switchmenu(2);EEPROM.write(14, pause);break;
-    case 5:pause = 45;switchmenu(2);EEPROM.write(14, pause);break;
-    case 6:pause = 60;switchmenu(2);EEPROM.write(14, pause);break;
-    case 7:pause = 75;switchmenu(2);EEPROM.write(14, pause);break;
-    case 8:pause = 90;switchmenu(2);EEPROM.write(14, pause);break;
-    case 9:pause = 120;switchmenu(2);EEPROM.write(14, pause);break;
-    case 10:switchmenu(2);break;
-  }
-  break;
-
-  //-------------------------------SelectMenu3-----------------------------------------
-  case 3 :
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("FAN : "));
-             if(fan == false){ lcd.print(F("OFF"));}
-             else {lcd.print(F("ON"));}
-         lcd.setCursor(0,2);lcd.print(F("Temp. cible : "));lcd.print(TEMP_VENTILATION);lcd.print(F("C"));
-         lcd.setCursor(0,3);lcd.print(F("Hysteresis : "));lcd.print(HYST_VENT);lcd.print(F("C"));
-    break;
-    case 2:switchmenu(31);break;
-    case 3:switchmenu(0);break;
-    }
-  break;
-  //-------------------------------SelectMenu31-----------------------------------------
-  //SET HYSTERESIS
-  case 31 :
-    if(y<Nbitems){HYST_VENT = (y*2);switchmenu(3); EEPROM.write(1, HYST_VENT);}
-    else{switchmenu(3);}
-  break;
-  //-------------------------------SelectMenu4-----------------------------------------
-  case 4 :
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("FOURNAISE(1) : "));
-             if(heating1 == false){lcd.print(F("OFF"));}
-             else {lcd.print(F("ON"));}
-         lcd.setCursor(0,2);lcd.print(F("Temp. cible : "));lcd.print(TEMP_FOURNAISE1);lcd.print(F("C"));
-         lcd.setCursor(0,3);lcd.print(F("Hysteresis : "));lcd.print(HYST_FOURNAISE1);lcd.print(F("C"));
-    break;
-    case 2:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("FOURNAISE(2) : "));
-             if(heating1 == false){lcd.print(F("OFF"));}
-             else {lcd.print(F("ON"));}
-         lcd.setCursor(0,2);lcd.print(F("Temp. cible : "));lcd.print(TEMP_FOURNAISE2);lcd.print(F("C"));
-         lcd.setCursor(0,3);lcd.print(F("Hysteresis : "));lcd.print(HYST_FOURNAISE2);lcd.print(F("C"));
-    break;
-    case 3:switchmenu(41);break;
-    case 4:switchmenu(42);break;
-    case 5:switchmenu(0);break;
-    }
-  break;
-  //-------------------------------SelectMenu41-----------------------------------------
-  //SET HYSTERESIS
-  case 41 :
-    if(y<Nbitems){HYST_FOURNAISE1 = (y*2);switchmenu(4);EEPROM.write(2, HYST_FOURNAISE1);}
-    else{switchmenu(4);}
-  break;
-  //-------------------------------SelectMenu42-----------------------------------------
-  //SET HYSTERESIS
-  case 42 :
-    if(y<Nbitems){HYST_FOURNAISE2 = (y*2);switchmenu(4);EEPROM.write(3,HYST_FOURNAISE2);}
-    else{switchmenu(4);}
-  break;
-  //-------------------------------SelectMenu5-----------------------------------------
-  //"Programme 1", "Programme 2", "Programme 3", "Modificateurs" "Set Programme 1", "Set Programme 2", "Set Programme 3", "Set Modificateurs", "back"
-  case 5 :
-    switch (y){
-    case 1:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("HD: "));lcd.print(HP1);lcd.print(F(":"));lcd.print(MP1);lcd.print(F(" | HF: "));lcd.print(HP2);lcd.print(F(":"));lcd.print(MP2);
-         lcd.setCursor(0,2);lcd.print(F("TEMP.CIBLE : "));lcd.print(TEMP_CIBLEP1);lcd.print(F("C"));
-    break;
-    case 2:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("HD: "));lcd.print(HP2);lcd.print(F(":"));lcd.print(MP2);lcd.print(F(" | HF: "));lcd.print(HP3);lcd.print(F(":"));lcd.print(MP3);
-         lcd.setCursor(0,2);lcd.print(F("TEMP.CIBLE : "));lcd.print(TEMP_CIBLEP2);lcd.print(F("C"));
-    break;
-    case 3:
-         lcd.noBlink();
-         clearPrintTitle();
-         lcd.setCursor(0,1);lcd.print(F("HD: "));lcd.print(HP3);lcd.print(F(":"));lcd.print(MP3);lcd.print(F(" | HF: "));lcd.print(HP1);lcd.print(F(":"));lcd.print(MP1);
-         lcd.setCursor(0,2);lcd.print(F("TEMP.CIBLE : "));lcd.print(TEMP_CIBLEP3);lcd.print(F("C"));
-    break;
-    case 4:
-          lcd.noBlink();
-          clearPrintTitle();
-          lcd.setCursor(0,1);lcd.print(F("TEMP.CIBLE : "));lcd.print(TEMP_CIBLE);
-          lcd.setCursor(0,2);lcd.print(F("RMod:"));lcd.print(rmod);
-          lcd.setCursor(8,2);lcd.print(F("| f1mod:"));lcd.print(f1mod);
-          lcd.setCursor(0,3);lcd.print(F("VMod:"));lcd.print(vmod);
-          lcd.setCursor(8,3);lcd.print(F("| f2mod:"));lcd.print(f2mod);
-    break;
-    case 5:switchmenu(51);break;
-    case 6:switchmenu(52);break;
-    case 7:switchmenu(53);break;
-    case 8:switchmenu(54);break;
-    case 9:switchmenu(0);break;
-    }
-  break;
-  //-------------------------------SelectMenu51-----------------------------------------
-  case 51:
-  switch(y){
-    case 1:switchmenu(511);break;
-    case 2:switchmenu(512);break;
-    case 3:switchmenu(5);break;
-  }
-  break;
-  //-------------------------------SelectMenu511-----------------------------------------
-  //SET HOUR
-  case 511 :
-    if(y<Nbitems){HP1 = y;switchmenu(5111);EEPROM.write(4,HP1);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu5111-----------------------------------------
-  //SET MINUTES
-  case 5111 :
-    if(y<Nbitems){MP1 = (y-1);switchmenu(51);EEPROM.write(5,MP1);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu512-----------------------------------------
-  //SET TEMP_CIBLE
-  case 512 :
-    if(y<Nbitems){TEMP_CIBLEP1 = y;switchmenu(51);EEPROM.write(6,TEMP_CIBLEP1);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu52-----------------------------------------
-  case 52:
-  switch(y){
-    case 1: switchmenu(521);break;
-    case 2:switchmenu(522);break;
-    case 3:switchmenu(5);break;
-  }
-  break;
-  //-------------------------------SelectMenu521-----------------------------------------
-  //SET HOUR
-  case 521 :
-    if(y<Nbitems){HP2 = y;switchmenu(5211);EEPROM.write(7,HP2);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu5211-----------------------------------------
-  //SET MINUTES
-  case 5211 :
-    if(y<Nbitems){MP2 = (y-1);switchmenu(51);EEPROM.write(8,MP2);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu522-----------------------------------------
-  //SET TEMP_CIBLE
-  case 522 :
-    if(y<Nbitems){TEMP_CIBLEP2 = y;switchmenu(52);EEPROM.write(9,TEMP_CIBLEP2);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu53-----------------------------------------
-  //"Heure", "Tempcible", "back"
-  case 53:
-  switch(y){
-    case 1: switchmenu(531);break;
-    case 2:switchmenu(532);break;
-    case 3:switchmenu(5);break;
-  }
-  break;
-  //-------------------------------SelectMenu531-----------------------------------------
-  //SET HOUR
-  case 531 :
-    if(y<25){HP3 = y;switchmenu(5311);EEPROM.write(10,HP3);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu5311-----------------------------------------
-  //SET MINUTES
-  case 5311 :
-    if(y<61){MP3 = (y-1);switchmenu(51);EEPROM.write(11,MP3);}
-    else{switchmenu(51);}
-  break;
-  //-------------------------------SelectMenu532-----------------------------------------
-  //SET TEMP_CIBLE
-  case 532 :
-    if(y<51){TEMP_CIBLEP3 = y;switchmenu(53);EEPROM.write(12,TEMP_CIBLEP3);}
-    else{switchmenu(53);}
-  break;
-  //-------------------------------SelectMenu54-----------------------------------------
-  //"Heure", "Tempcible", "back"
-  case 54:
-  switch(y){
-    case 1:switchmenu(541);break;
-    case 2:switchmenu(542);break;
-    case 3:switchmenu(543);break;
-    case 4:switchmenu(544);break;
-    case 5:switchmenu(5);break;
-  }
-  break;
-  //-------------------------------SelectMenu541-----------------------------------------
-  //SET MOD
-  case 541 :
-    if(y<Nbitems){rmodE = y;switchmenu(54);EEPROM.write(15,rmodE);}
-    else{switchmenu(54);}
-  break;
-  //-------------------------------SelectMenu541-----------------------------------------
-  //SET MOD
-  case 542 :
-    if(y<Nbitems){vmodE = y;switchmenu(54);EEPROM.write(16,vmodE);}
-    else{switchmenu(54);}
-  break;
-  //-------------------------------SelectMenu541-----------------------------------------
-  //SET MOD
-  case 543 :
-    if(y<Nbitems){f1modE = y;switchmenu(54);EEPROM.write(17,f1modE);}
-    else{switchmenu(54);}
-  break;
-  //-------------------------------SelectMenu541-----------------------------------------
-  //SET MOD
-  case 544 :
-    if(y<Nbitems){f2modE = y;switchmenu(54);EEPROM.write(18,f2modE);}
-    else{switchmenu(54);}
-  break;
-  }
-}
-
-
-
-
-
-


add <x> key to toggle debug

add <x> key to toggle debug

--- Lifter/Lifter.ino
+++ Lifter/Lifter.ino
@@ -22,7 +22,7 @@
 #define isLow(P)((*(pinOfPin(P))& pinMask(P))==0)
 #define digitalState(P)((uint8_t)isHigh(P))

-const boolean DEBUG = true;                 // send stuff to serial monitor for testing
+boolean DEBUG = true;                 // send stuff to serial monitor for testing

 const byte ledPin = 13;                     // on board LED
 const byte holdPinArm = 12;                 // enable pins for stepper drivers
@@ -227,6 +227,10 @@
         destinationArmPos = firstArmPos;
         LOADED = false;
       }
+      else if (inputString == "120") {
+        DEBUG = !DEBUG;
+        Serial.println("DEBUG <x> is: " + String(DEBUG));
+      }
       inputString = "";
     }
 } //end void-loop
@@ -277,8 +281,8 @@
     myserv.write(restServoPos);
     if (DEBUG)
       Serial.println("go to resting spot: " + String(restServoPos));
-    Serial.println("READY")
-    Serial.println("at " + String(stepperArm.currentPosition());
+    Serial.println("READY");
+    Serial.println("at " + String(stepperArm.currentPosition()));
   }
 }


Added 'invert' to the pins.

Added 'invert' to the pins.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -472,33 +472,27 @@
   return n;
 }

-static long unsigned int g_luiCounter = 0;
+
 int  sendStatusToWebsiteNew(struct libwebsocket *wsi)
 {

   int n = 0;

-//  if( g_luiCounter%100 == 0)
-  {
-
-    unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + WEB_SOCKET_BUFFER_SIZE + LWS_SEND_BUFFER_POST_PADDING];
-    unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
+  unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + WEB_SOCKET_BUFFER_SIZE + LWS_SEND_BUFFER_POST_PADDING];
+  unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
+
+  updateBoardState();
+
+  aJsonObject *msg = getJsonBoardState();
+
+  aJsonStringStream stringStream(NULL, (char *)p, WEB_SOCKET_BUFFER_SIZE);
+  aJson.print(msg, &stringStream);
+  String sTempString((char *)p);

-    updateBoardState();
-
-    aJsonObject *msg = getJsonBoardState();
-
-    aJsonStringStream stringStream(NULL, (char *)p, WEB_SOCKET_BUFFER_SIZE);
-    aJson.print(msg, &stringStream);
-    String sTempString((char *)p);
-
-    n = libwebsocket_write(wsi, p, sTempString.length(), LWS_WRITE_TEXT);
-
-    aJson.deleteItem(msg);
-
-  }
-
-  g_luiCounter++;
+  n = libwebsocket_write(wsi, p, sTempString.length(), LWS_WRITE_TEXT);
+
+  aJson.deleteItem(msg);
+

   return n;
 }
@@ -663,11 +657,17 @@
     {
       if( g_aPins[i].is_analog ) // Process analog pins
       {
-        g_aPins[i].value = analogRead(i)/float(ANALOG_IN_MAX_VALUE);
+        if( g_aPins[i].is_inverted )
+          g_aPins[i].value = 1.0 - analogRead(i)/float(ANALOG_IN_MAX_VALUE);
+        else
+          g_aPins[i].value = analogRead(i)/float(ANALOG_IN_MAX_VALUE);
       }
       else // Process digital pins
       {
-        g_aPins[i].value = digitalRead(i);
+        if( g_aPins[i].is_inverted )
+          g_aPins[i].value = 1.0 - digitalRead(i);
+        else
+          g_aPins[i].value = digitalRead(i);
       }
     }
   }
@@ -990,13 +990,13 @@

       aJsonObject *poInputMin = aJson.getObjectItem(poPinVals, "input_min");
       if (poInputMin)
-          g_aPins[i].input_min = getFloat(poInputMin);
+          g_aPins[i].input_min = getJsonFloat(poInputMin);
 //        g_aPins[i].input_min = poInputMin->valuefloat;

       aJsonObject *poInputMax = aJson.getObjectItem(poPinVals, "input_max");
 //      Serial.print("Recieved JSON Str. Pin: "); Serial.print(i); Serial.print(" input_max: "); Serial.println(poInputMax->valuefloat);
       if (poInputMax)
-          g_aPins[i].input_max = getFloat(poInputMax);
+          g_aPins[i].input_max = getJsonFloat(poInputMax);
 //        g_aPins[i].input_max = poInputMax->valuefloat;

       aJsonObject *poIsInverted = aJson.getObjectItem(poPinVals, "is_inverted");
@@ -1009,7 +1009,7 @@

       aJsonObject *poValue = aJson.getObjectItem(poPinVals, "value");
       if (poValue)
-          g_aPins[i].value = getFloat(poValue);
+          g_aPins[i].value = getJsonFloat(poValue);
 //        g_aPins[i].value = poValue->valuefloat;

       aJsonObject *poIsTimerOn = aJson.getObjectItem(poPinVals, "is_timer_on");
@@ -1018,7 +1018,7 @@

       aJsonObject *poTimerValue = aJson.getObjectItem(poPinVals, "timer_value");
       if (poTimerValue)
-          g_aPins[i].timer_value = getFloat(poTimerValue);
+          g_aPins[i].timer_value = getJsonFloat(poTimerValue);
 //        g_aPins[i].timer_value = poTimerValue->valuefloat;

       aJsonObject *poDamping = aJson.getObjectItem(poPinVals, "damping");
@@ -1029,7 +1029,7 @@
   }
 }

-float getFloat(aJsonObject * _poJsonObj)
+float getJsonFloat(aJsonObject * _poJsonObj)
 {
  float fRet = 0.0;
  switch(_poJsonObj->type)
@@ -1121,14 +1121,14 @@
         break;
       }
     }
-
+    /*
     Serial.print("Source: ");
     Serial.println(String(uiSourcePin));
     Serial.print("Target: ");
     Serial.println(String(uiTargetPin));
     Serial.print("Connect: ");
     Serial.println(String(uiTargetPin));
-
+    */
   }
 }


Added initial code to process connections.

--- ServerSketch/ServerSketch.ino
+++ ServerSketch/ServerSketch.ino
@@ -992,17 +992,15 @@
       // Process if status is OK
       Serial.println("STATUS: OK");

-      ///////
+      // Check if the message has pin data
       aJsonObject *pJsonPins = aJson.getObjectItem(poMsg, "pins");
       if( pJsonPins )  // Check if there is pin info
         procPinsMsg( pJsonPins );

-      //    Serial.println("HERE");
-      //    aJsonObject *pJsonConnections = aJson.getObjectItem(pJsonMsg, "connections");
-      //    Serial.println("HERE");
-
-
-
+      aJsonObject *pJsonConnections = aJson.getObjectItem(poMsg, "connections");
+      if( pJsonConnections )  // Check if there is pin info
+        procConnMsg( pJsonConnections );
+
       //      else if( pJsonConnections )  // Check if there is connection info
       //     {
       //      procConnMsg( pJsonConnections );
@@ -1099,18 +1097,26 @@
   //    snprintf(sPinState, sizeof(sPinState), "%s,%i,%i,%f", g_aPins[i].label, g_aPins[i].is_analog, g_aPins[i].is_input, g_aPins[i].value);
   //    Serial.println(sPinState);

-
     }
-
-
-
-
-  }
-}
-
+  }
+}
+
+// {"status":<OK,ERROR>,  "connections":[ {"source":"14","target":"3”} ]  }
 void procConnMsg( aJsonObject *_pJsonConnections )
 {
   Serial.println("Processing Connections");
+
+/*
+  // Iterate all pins and check if we have data available
+  for(int i=0; i<TOTAL_NUM_OF_PINS; i++)
+  {
+    char pinstr[3];
+    snprintf(pinstr, sizeof(pinstr), "%d", i);
+    aJsonObject *poPinVals = aJson.getObjectItem(_pJsonPins, pinstr);
+
+  }
+  */
+
 }

 /*
@@ -1131,6 +1137,8 @@
 int g_ToggleFlag = 0;
 char g_acPin3_On[] = "{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"2\":{\"label\":\"Pin 2\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"4\":{\"label\":\"Pin 4\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"7\":{\"label\":\"Pin 7\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"8\":{\"label\":\"Pin 8\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"12\":{\"label\":\"Pin 12\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"1\"}, \"3\":{\"label\":\"Pin 3\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"5\":{\"label\":\"Pin 5\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"6\":{\"label\":\"Pin 6\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"9\":{\"label\":\"Pin 9\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"10\":{\"label\":\"Pin 10\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}, \"11\":{\"label\":\"Pin 11\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.9\"}   }}";
 char g_acPin3_Off[] = "{\"status\":\"OK\",\"pins\":{ \"13\":{\"label\":\"Pin 13\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"2\":{\"label\":\"Pin 2\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"4\":{\"label\":\"Pin 4\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"7\":{\"label\":\"Pin 7\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"8\":{\"label\":\"Pin 8\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"12\":{\"label\":\"Pin 12\",\"is_analog\":\"false\",\"is_input\":\"false\",\"value\":\"0\"}, \"3\":{\"label\":\"Pin 3\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}, \"5\":{\"label\":\"Pin 5\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}, \"6\":{\"label\":\"Pin 6\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}, \"9\":{\"label\":\"Pin 9\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}, \"10\":{\"label\":\"Pin 10\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}, \"11\":{\"label\":\"Pin 11\",\"is_analog\":\"true\",\"is_input\":\"false\",\"value\":\"0.1\"}   }}";
+//char g_acConnA0_TO_3[] = "{\"status\":\"OK\",\"connections\":[{\"source\":\"14\",\"target\":\"3\”}]}";
+char g_acConnA0_TO_3[] = "{\"status\":\"OK\",\"connections\":[{\"source\":\"14\",\"target\":\"3\"}]}";

 void loop()
 {
@@ -1145,12 +1153,17 @@

     ///////////////////////////////////////
     // Test receiving message
+    /*
     if(g_ToggleFlag)
       snprintf(g_acMessage,sizeof(g_acMessage),g_acPin3_On);
     else
       snprintf(g_acMessage,sizeof(g_acMessage),g_acPin3_Off);
-
+
     g_ToggleFlag = ~g_ToggleFlag;
+      */
+
+    // Connect/Disconnect
+    snprintf(g_acMessage,sizeof(g_acMessage),g_acConnA0_TO_3);

     processMessage(g_acMessage);
     updateBoardState();


fps and display code

fps and display code

--- arduinoCode/LCDDisplayandArduino.ino
+++ arduinoCode/LCDDisplayandArduino.ino
@@ -1,82 +1,353 @@
-//  _ ___ _______     ___ ___ ___  ___ _   _ ___ _____ ___
-// / |_  )__ /   \   / __|_ _| _ \/ __| | | |_ _|_   _/ __|
-// | |/ / |_ \ |) | | (__ | ||   / (__| |_| || |  | | \__ \
-// |_/___|___/___/   \___|___|_|_\\___|\___/|___| |_| |___/
-//
-// LCD Display and Arduino
-//
-// Made by Hino Hau
-// License: Public Domain
-// Downloaded from: https://123d.circuits.io/circuits/1355136-lcd-display-and-arduino
-
-#include <LiquidCrystal.h>
-
-// initialize the library with the numbers of the interface pins
-LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
-
-int button = 2 ;
-int led = 5 ;
-int value ;
+
+
+// You can use any (4 or) 5 pins
+#define sclk 2
+#define mosi 3
+#define dc   4
+#define cs   5
+#define rst  6
+
+// Color definitions
+#define BLACK           0x0000
+#define RED             0xF800
+#define YELLOW          0xFFE0
+#define WHITE           0xFFFF
+#define GRAY            0xBDF7
+
+#include <FileIO.h>
+#include <avr/wdt.h>
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1351.h>
+#include <SPI.h>
+
+/*
+#include <Wire.h>
+#include <PN532_I2C.h>
+#include <PN532.h>
+#include <NfcAdapter.h>
+*/
+
+#include "FPS_GT511C3.h"
+#include "SoftwareSerial.h"
+
+Adafruit_SSD1351 tft = Adafruit_SSD1351(cs, dc, mosi, sclk, rst);
+
+FPS_GT511C3 fps(8, 9);
+
+/*
+PN532_I2C pn532i2c(Wire);
+PN532 nfc(pn532i2c);
+*/
+
+
+String bstr = "Waiting for a card";
+boolean enrolled = false;

 void setup() {
-  pinMode (button , INPUT );
-  pinMode (led , OUTPUT );
+  tft.begin();
+
+  //uint16_t time = millis();
+  tft.fillRect(0, 0, 128, 128, BLACK);
+  //time = millis() - time;
+
+  fps.Open();
+  delay(100);
+  fps.SetLED(true);
+
+  startupscreen();
+
+  profileDetails();
+
+
+  /*while (enrolled == false) {
+    FPSenroll();
+    delay(1000);
+  }*/

-  // set up the LCD's number of columns and rows:
-  lcd.begin(16, 2);
-  // Print a message to the LCD.
-  lcd.print("Welcome to MON");
-  delay(5000);
+  /*
+  nfc.begin();
+
+  uint32_t versiondata = nfc.getFirmwareVersion();
+  if (! versiondata) {
+    printLine("Didn't find NFC board");
+    while (1); // halt
+  }
+  nfc.setPassiveActivationRetries(0xFF);
+
+  nfc.SAMConfig();
+  printLine("Waiting for a card");
+
+  readNFC();
+  */
+
 }

 void loop() {
+
+}
+
+void startupscreen() {
+  tft.fillScreen(BLACK);
+  tft.setCursor(40, 70);
+  tft.setTextSize(3);
+  tft.setTextColor(GRAY);
+  tft.println("MON");
+  delay(3000);
+}
+
+void profileDetails() {
+  Bridge.begin();
+  FileSystem.begin();
+  String dataString;
+  String displayString[12];
+  dataString = "";
+  int i = 0;
+  File dataFile = FileSystem.open("/mnt/sd/profile.txt", FILE_READ);
+  char readchar = (char)dataFile.read();
+  while (readchar != EOF){
+    while (readchar != '\n') {
+      dataString += readchar;
+      readchar = (char)dataFile.read();
+    }
+    displayString[i] = dataString;
+    dataString = "";
+    readchar = (char)dataFile.read();
+    i++;
+  }
+  dataFile.close();

-  value = digitalRead (button);
-  int buttonPressed = 0
+  if (displayString[10] != "")
+  {
+    enrolled = true;
+  }
+
+  if (enrolled == false){
+    tft.fillScreen(BLACK);
+    tft.setCursor(0, 40);
+    tft.setTextColor(YELLOW);
+    tft.setTextSize(1);
+    tft.println("Your profile haven't");
+    tft.setCursor(0, 55);
+    tft.println("enrolled a fingerprint.");
+    tft.setCursor(0, 70);
+    tft.println("Please enroll now!");
+
+    while (enrolled == false) {
+      FPSenroll();
+
+    }
+  }

-  lcd.clear();
-  char s1[ ] = "Name:";
-  char s2[ ] = "Kwok Hin Hau";
-  char s3[ ] = "Status:";
-  char s4[ ] = "Available";
-  char s5[ ] = "ID:";
-  char s6[ ] = "463473584";
-  char s7[ ] = "Age:";
-  char s8[ ] = "20";
+  if (enrolled == true){
+    bool verified = false;
+    tft.fillScreen(BLACK);
+    tft.setCursor(0, 40);
+    tft.setTextColor(YELLOW);
+    tft.setTextSize(1);
+    tft.println("Your profile is");
+    tft.setCursor(0, 55);
+    tft.println("protected");
+    tft.setCursor(0, 70);
+    tft.println("Press your finger to");
+    tft.setCursor(0, 85);
+    tft.println("unlock it.");
+    while(verified == false)
+    {
+      if (fps.IsPressFinger())
+      {
+        fps.CaptureFinger(false);
+        int id = fps.Identify1_N();
+        if (id == displayString[11].toInt())
+        {
+          printLine("Finger found");
+          verified = true;
+        }
+        else
+        {
+          printLine("Finger not found");
+        }
+      }
+      else
+      {
+        printLine("Please press finger");
+      }
+      delay(1000);
+
+    }
+  }

-  lcd.setCursor(0, 0);
-  lcd.print(s1);
-  lcd.setCursor(0, 1);
-  lcd.print(s2);
-  delay(5000);
-  if (value == HIGH)
-    if (buttonPressed == 0)
-    buttonPressed = 1;
+  tft.fillScreen(BLACK);
+  tft.setCursor(0, 40);
+  tft.setTextColor(YELLOW);
+  tft.setTextSize(1);
+  tft.println("Welcome back");
+  tft.setCursor(0, 55);
+  tft.println(displayString[1]);
+  tft.setCursor(0, 70);
+  tft.println("Here is your profile details:");
+  delay(2000);
+
+  tft.fillScreen(BLACK);
+  tft.setTextSize(1);
+  int pos = 40;
+  int counter = 2;
+  for(counter = 2; counter<10; counter++)
+  {
+    tft.setCursor(0, pos);
+    if ( counter % 2 == 0)
+    {
+      tft.setTextColor(YELLOW);
+    }
     else
-    buttonPressed = 0;
-
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print(s3);
-  lcd.setCursor(0, 1);
-  lcd.print(s4);
-  delay(5000);
-
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print(s5);
-  lcd.setCursor(0, 1);
-  lcd.print(s6);
-  delay(5000);
-
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print(s7);
-  lcd.setCursor(0, 1);
-  lcd.print(s8);
-  delay(5000);
-
-
-
-
-  }
+    {
+      tft.setTextColor(WHITE);
+    }
+    tft.println(displayString[counter]);
+    pos = pos + 10;
+  }
+  /*
+  tft.setCursor(0,40);
+  tft.setTextColor(YELLOW);
+  tft.println(displayString[2]);
+  tft.setCursor(0, 50);
+  tft.setTextColor(WHITE);
+  tft.println(displayString[3]);
+  tft.setCursor(0, 60);
+  tft.setTextColor(YELLOW);
+  tft.println(displayString[4]);
+  tft.setCursor(0, 70);
+  tft.setTextColor(WHITE);
+  tft.println(displayString[5]);
+  tft.setCursor(0, 80);
+  tft.setTextColor(YELLOW);
+  tft.println(displayString[6]);
+  tft.setCursor(0, 90);
+  tft.setTextColor(WHITE);
+  tft.println(displayString[7]);
+  tft.setCursor(0, 100);
+  tft.setTextColor(YELLOW);
+  tft.println(displayString[8]);
+  tft.setCursor(0, 110);
+  tft.setTextColor(WHITE);
+  tft.println(displayString[9]);
+  */
+  delay(3000);
+}
+
+void FPSenroll() {
+  int enrollid = 0;
+  bool usedid = true;
+  while (usedid == true)
+  {
+    usedid = fps.CheckEnrolled(enrollid);
+    if (usedid == true) enrollid++;
+  }
+  fps.EnrollStart(enrollid);
+
+  // enroll
+  String str1 = "Press fingerE #";
+  str1 += enrollid;
+  printLine(str1);
+  while (fps.IsPressFinger() == false)
+  {
+    delay(100);
+  }
+  bool bret = fps.CaptureFinger(true);
+  int iret = 0;
+  if (bret != false)
+  {
+    printLine("Remove finger");
+    fps.Enroll1();
+    while (fps.IsPressFinger() == true) delay(100);
+    printLine("Press same finger 2");
+    while (fps.IsPressFinger() == false) delay(100);
+    bret = fps.CaptureFinger(true);
+    if (bret != false)
+    {
+      printLine("Remove finger");
+      fps.Enroll2();
+      while (fps.IsPressFinger() == true) delay(100);
+      printLine("Press same finger 3");
+      while (fps.IsPressFinger() == false) delay(100);
+      bret = fps.CaptureFinger(true);
+      if (bret != false)
+      {
+        printLine("Remove finger");
+        iret = fps.Enroll3();
+        if (iret == 0)
+        {
+          printLine("Enrolling Successfull");
+          enrolled = true;
+
+          FileSystem.begin();
+          File dataFile = FileSystem.open("/mnt/sd/profile.txt", FILE_APPEND);
+          if (dataFile) {
+            dataFile.println("ID:");
+            dataFile.println(enrollid);
+            dataFile.println("End");
+            dataFile.close();
+           }
+          delay(1000);
+          wdt_enable(WDTO_1S);
+          wdt_reset();
+        }
+        else
+        {
+          String str2 = "Enroll error#";
+          str2 += iret;
+          printLine(str2);
+        }
+      }
+      else
+      {
+        printLine("Failed 3rd finger");
+
+      }
+    }
+    else
+    {
+      printLine("Failed 2nd finger");
+
+    }
+  }
+  else
+  {
+    printLine("Failed 1st finger");
+
+  }
+}
+
+/*void readNFC() {
+  boolean success;
+  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
+  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
+
+  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
+  // 'uid' will be populated with the UID, and uidLength will indicate
+  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
+  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
+  if (success) {
+    printLine("Found a card!");
+    // Wait 1 second before continuing
+
+  }
+  else
+  {
+    // PN532 probably timed out waiting for a card
+    printLine("Timed out waiting for a card");
+  }
+  delay(1000);
+  readNFC();
+}*/
+
+void printLine(String str) {
+  tft.setCursor(0, 110);
+  tft.setTextColor(BLACK);
+  tft.println(bstr);
+  tft.setCursor(0, 110);
+  tft.setTextColor(RED);
+  tft.println(str);
+  bstr = str;
+}
+
+


changed directory for header file

changed directory for header file

--- firmware/examples/HDC1000test.ino
+++ firmware/examples/HDC1000test.ino
@@ -10,7 +10,7 @@
   Modified for Photon
  ****************************************************/

-#include "Adafruit_HDC1000.h"
+#include "Adafruit_HDC1000/Adafruit_HDC1000.h"

 // Connect Vin to 3-5VDC
 // Connect GND to ground


Now use DHCP for ethernet

Now use DHCP for ethernet

--- MainStation/MainStation.ino
+++ MainStation/MainStation.ino
@@ -50,7 +50,7 @@
 #define MAIN_SENSOR_UPDATE 240000

 // Timeout for HTTP Request
-#define HTTP_TIMEOUT 1000
+#define HTTP_TIMEOUT 2000

 // Touched
 CapacitiveSensor _touch = CapacitiveSensor(touchCommonPin,touchSensPin);
@@ -59,35 +59,16 @@
 Adafruit_BMP085 _mainSensor = Adafruit_BMP085();

 // MAC Address
-static byte _mymac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
+static const byte _mymac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };

 // remote website ip address and port
-static byte _webserver[] = { 192, 168, 0, 1 };
-
-// Arduino IP
-static byte _arduinoIP[] = { 192, 168, 0, 42 };
-
-// gateway ip address
-static byte _gwip[] = { 192, 168, 0, 254 };
+static const char _website[] PROGMEM = "http://www.example.com/";
+
+// Remote URL
+static const char _baseURL[] PROGMEM = "/riot-server/points/add/";

 // Main Ethernet Buffer
-byte Ethernet::buffer[300];
-
-// Page to display to user
-char _indexHTML[] PROGMEM =
-  "HTTP/1.0 200 OK\r\n"
-  "Content-Type: text/html\r\n"
-  "\r\n"
-  ""
-    "<title>"
-      "--- TTK Weather Station ---"
-    "</title>"
-    ""
-      "
I am the Weather Station
"
-      "
Uptime is $D$D:$D$D:$D$D
"
-    ""
-  ""
-;
+byte Ethernet::buffer[600];

 // Sensor Defintion
 typedef struct SensorStruct {
@@ -197,18 +178,14 @@
   Serial.begin(57600);
   Serial.println(F("--- TTK Weather Station ---"));

-  // Set Up RX
-  man.setupReceive(rxPin);
-
   // Set Up LCD
   _app.render.lcd.begin (16,2); // 16x2 LCD
   _app.render.lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
   _app.render.lcd.setBacklight(HIGH);
   _app.render.lcd.clear();
   _app.render.lcd.print(F("--- Welcome ---"));
-
-  // Start Receiving
-  man.beginReceiveArray(6, _app.rx.raw);
+  _app.render.lcd.setCursor(0,1);
+  _app.render.lcd.print(F("waiting IP..."));

   // Initialise
   if(!_mainSensor.begin())
@@ -223,27 +200,42 @@
   {
     Serial.println(F("Failed to access Ethernet controller"));
   }
-
-  Serial.println(F("Setting up static IP"));
-
-  // Static IP
-  ether.staticSetup(_arduinoIP,_gwip);
-
-  ether.printIp(F("My IP: "), ether.myip);
-  //ether.printIp(F("Netmask: "), ether.mymask);
-  ether.printIp(F("GW IP: "), ether.gwip);
-  //ether.printIp(F("DNS IP: "), ether.dnsip);
-
-  // Set Up destination IP
-  ether.copyIp(ether.hisip, _webserver);
-  ether.printIp(F("Destination Server: "), ether.hisip);
-
-  // Register Ping Callback
-  ether.registerPingCallback(pingCallback);
+
+  //
+  // Stop WatchDog during DHCP
+  wdt_disable();
+
+  Serial.println(F("Setting up Dynamic IP"));
+
+  if (!ether.dhcpSetup())
+  {
+    Serial.println(F("DHCP failed"));
+  }
+
+  ether.printIp(F("IP:  "), ether.myip);
+  ether.printIp(F("GW:  "), ether.gwip);
+  ether.printIp(F("DNS: "), ether.dnsip);
+
+  if (!ether.dnsLookup(_website))
+  {
+    Serial.println(F("DNS failed"));
+  }
+
+  ether.printIp(F("SRV: "), ether.hisip);

   // No Request Yet
   _app.eth.isHttpRequest = false;

+  //
+  // Re-Activate Watchdog
+  wdt_enable(WDTO_8S); // 8 sec
+
+  // Set Up RX
+  man.setupReceive(rxPin);
+
+  // Start Receiving
+  man.beginReceiveArray(6, _app.rx.raw);
+
   // Display Free RAM
   displayFreeRam();
 }
@@ -267,7 +259,6 @@

   // Paint
   render();
-
 }

@@ -334,9 +325,8 @@
    _app.render.paint = false;
   }

-
   // Increment
-  _app.render.tick++;
+  _app.render.tick++; // useless
 }

@@ -406,6 +396,15 @@

     digitalWrite(rxLed, LOW);
    }
+   else
+   {
+    // If no message found
+
+    // After some time
+    // reset then restart reveiving
+
+    //Serial.print(F("RF State = "));Serial.println(rx_mode);
+   }
 }

@@ -456,19 +455,17 @@

     _app.lastMainSensorUpdated = currentTime;

-    float buffer;
-
     // Read Temp sensor
-    _mainSensor.getTemperature(&buffer);
+    float temp = _mainSensor.readTemperature();

     // Notify new Value
-    fireNewSensorValue(1,buffer);
+    fireNewSensorValue(1, temp);

     // Read Pressure sensor (in Pa)
-    _mainSensor.getPressure(&buffer);
+    float pressure = (float) _mainSensor.readPressure();

     // Notify new Value (in hPa)
-    fireNewSensorValue(2,buffer/100);
+    fireNewSensorValue(2, pressure/100.0);
   }
 }

@@ -481,34 +478,11 @@
   // check if anything has come in via ethernet
   word len = ether.packetReceive();
   word pos = ether.packetLoop(len);
-
-  // check if valid tcp data is received
-  if (pos) {
-
-    // Init Buffer
-    _app.eth.buffer = ether.tcpOffset();
-
-    char* data = (char *) Ethernet::buffer + pos;
-    Serial.println(F("Ethernet data received :"));
-    Serial.println(data);
-
-    // UpTime
-    long t = millis() / 1000;
-    word h = t / 3600;
-    byte m = (t / 60) % 60;
-    byte s = t % 60;
-
-    // Populate Page to Buffer
-    _app.eth.buffer.emit_p(_indexHTML, h/10, h%10, m/10, m%10, s/10, s%10);
-
-    // send web page data
-    ether.httpServerReply(_app.eth.buffer.position());
-  }
-}
-
-
-//
-// Send Data to WebServer
+}
+
+
+//
+// Send Data to WebServer : sensorID/newValue
 //
 void sendDataToWebServer(byte sensorID, float newValue)
 {
@@ -519,15 +493,17 @@
   char newValueString[10];
   dtostrf(newValue, 2, 2, newValueString);

+  // Concat
   strcat(_app.eth.url,newValueString);

-  Serial.print(F("Begin HTTP Request = "));Serial.println(_app.eth.url);
+  Serial.print(F(">>> HTTP Request : "));Serial.println(_app.eth.url);

   // Init Request
   _app.eth.isHttpRequest = true;
-  unsigned long dateHTTPrequest = millis();
-
-  ether.browseUrl(PSTR("/riot-server/points/add/"), _app.eth.url, PSTR("localhost"), requestUrlCallback);
+  const unsigned long dateHTTPrequest = millis();
+
+  // Send Request
+  ether.browseUrl(_baseURL, _app.eth.url, _website, requestUrlCallback);

   //
   // Wait end of HTTP Request
@@ -535,41 +511,33 @@
   {
     ether.packetLoop(ether.packetReceive());
   }
-
+
   // Verify
   if(_app.eth.isHttpRequest)
   {
-    Serial.println(F("Fail Of HTTP Request"));
-
+    Serial.println(F("Fail Of HTTP Request !"));
+
     // Reset Flag
     _app.eth.isHttpRequest = false;
   }
-  else
-  {
-    Serial.println(F("End Of HTTP Request"));
-  }

   // Workaround to clean Ethernet ...
   for(int i=0;i<100;i++)
   {
     ether.packetLoop(ether.packetReceive());
   }
-
-}
-
-
-//
-// Ping Callback
-//
-static void pingCallback (byte* ptr) {
-  ether.printIp(">>> ping from: ", ptr);
 }

 //
 // End HTTP GET request Callback
 //
 static void requestUrlCallback (byte status, word off, word len) {
-  Serial.println("<<< reply ");
+  Serial.println(F("<<< RESPONSE :"));
+
+  // Set end of String (for correct display in println)
+  Ethernet::buffer[min(599, off + len)] = 0;
+
+  // Display response
   Serial.println((const char*) Ethernet::buffer + off);

   // Turn off HTTP request flag


LoaderTest: PS/2 keyboard with ATtiny85 first signs of life

https://youtu.be/kt3fdtl73NM

Special keys, for the time being:
Arrow keys : Game controller arrow buttons
TAB        : Game controller [A] button
ESC        : Send Terminal.gt1 (only makes sense in Loader)
PAGE DOWN  : Game controller [Select] button (changes video mode)
PAGE UP    : Reset Gigatron

--- Utils/LoaderTest/LoaderTest.ino
+++ Utils/LoaderTest/LoaderTest.ino
@@ -16,15 +16,14 @@
 // Not every microcontroller supports all functions.

 // Select 1 of the platforms:
-#define ArduinoUno   1
+#define ArduinoUno   1 // Default
 #define ArduinoMicro 0
 #define ATtiny85     0

 // Select a built-in GT1 image:
 const byte gt1File[] PROGMEM = {
   //#include "Blinky.h" // Blink pixel in middle of screen
-  //#include "Lines.h"  // Draw randomized lines (at67)
-  #include "Terminal.h" // TV Typewriter
+  #include "Lines.h"  // Draw randomized lines (at67)
 };

 // The object file is embedded (in PROGMEM) in GT1 format. It would be
@@ -159,17 +158,10 @@
  // Workaround as follows:
  void ps2interrupt(void); // As provided by PS2Keyboard
  ISR(PCINT0_vect) {
-   if (~PINB & (1<<keyboardClockPin)) { // FALLING edge of PS/2 clock
-     PORTB &= ~(1<<SER_DATA); // XXX Brief pulses (for debugging)
-     PORTB |=   1<<SER_DATA;
-     PORTB &= ~(1<<SER_DATA);
-     PORTB |=   1<<SER_DATA;
+   if (~PINB & (1<<keyboardClockPin)) // FALLING edge of PS/2 clock
      ps2interrupt();
-     PORTB &= ~(1<<SER_DATA);
-     PORTB |=   1<<SER_DATA;
-   }
+
  }
-
 #endif

 /*----------------------------------------------------------------------+
@@ -190,6 +182,10 @@
 #include <PS2Keyboard.h> // Install from the Arduino IDE's Library Manager

 PS2Keyboard keyboard;
+
+const byte terminalGt1[] PROGMEM = {
+  #include "Terminal.h" // TV Typewriter
+};

 /*
  *  Game controller button mapping
@@ -261,18 +257,18 @@
     char c = keyboard.read();
     switch (c) {
       // XXX These mappings are for testing purposes only
-      case PS2_PAGEDOWN:   sendController(~buttonSelect,2); break;
+      case PS2_PAGEDOWN:   sendController(~buttonSelect,1); break;
       case PS2_PAGEUP:     sendController(~buttonStart, 128+32); break; // XXX Change to Ctrl-Alt-Del
-      case PS2_TAB:        sendController(~buttonA,     2); break;
+      case PS2_TAB:        sendController(~buttonA,     1); break;
       #if !ATtiny85
-        case PS2_ESC:      sendController(~buttonB,     2); break;
+        case PS2_ESC:      sendController(~buttonB,     1); break;
       #else
-        case PS2_ESC:      doTransfer(gt1File);             break; // XXX HACK Find some proper short-cut. Ctrl-T?
+        case PS2_ESC:      doTransfer(terminalGt1);         break; // XXX HACK Find some proper short-cut. Ctrl-T?
       #endif
-      case PS2_LEFTARROW:  sendController(~buttonLeft,  2); break;
-      case PS2_RIGHTARROW: sendController(~buttonRight, 2); break;
-      case PS2_UPARROW:    sendController(~buttonUp,    2); break;
-      case PS2_DOWNARROW:  sendController(~buttonDown,  2); break;
+      case PS2_LEFTARROW:  sendController(~buttonLeft,  1); break;
+      case PS2_RIGHTARROW: sendController(~buttonRight, 1); break;
+      case PS2_UPARROW:    sendController(~buttonUp,    1); break;
+      case PS2_DOWNARROW:  sendController(~buttonDown,  1); break;
       case PS2_ENTER:      sendController('\n', 1);         break;
       case PS2_DELETE:     sendController(127, 1);          break;
       default:             sendController(c, 1);            break;
@@ -536,7 +532,7 @@
   // Send controller code for n frames
   // E.g. 4 frames = 3/60s = ~50 ms
   for (int i=0; i<n; i++) {
-    sendFirst(value, 8);
+    sendFirstByte(value);
     PORTB |= 1<<SER_DATA; // Send 1 when idle
   }

@@ -564,7 +560,7 @@
   // All together, we drop 2 bits from the 2nd byte in a frame. This achieves
   // byte alignment for the Gigatron at visible scanline 3, 11, 19, ... etc.

-  sendFirst(firstByte, 8);     // Protocol byte
+  sendFirstByte(firstByte);    // Protocol byte
   checksum += firstByte << 6;  // Keep Loader.gcl dumb
   sendBits(len, 6);            // Length 0, 1..60
   sendBits(address&255, 8);    // Low address bits
@@ -577,14 +573,30 @@
   PORTB |= 1<<SER_DATA;        // Send 1 when idle
 }

-void sendFirst(byte value, byte n)
+void sendFirstByte(byte value)
 {
   // Wait vertical sync NEGATIVE edge to sync with loader
   while (~PINB & (1<<SER_LATCH)) // Ensure vSync is HIGH first
     ;
   while (PINB & (1<<SER_LATCH)) // Then wait for vSync to drop
     ;
-  sendBits(value, n);
+
+  // Send first bit
+  if (value & 128)
+    PORTB |= 1<<SER_DATA;
+  else
+    PORTB &= ~(1<<SER_DATA);
+
+  // Wait for bit transfer at horizontal sync POSITIVE edge.
+  // This timing is tight for the first bit of the first byte and
+  // the reason that interrupts must be disabled on the microcontroller.
+  while (PINB & (1<<SER_PULSE))  // Ensure hSync is LOW first
+    ;
+  while (~PINB & (1<<SER_PULSE)) // Then wait for hSync to rise
+    ;
+
+  // Send remaining bits
+  sendBits(value, 7);
 }

 // Send n bits, highest first
@@ -598,8 +610,6 @@
       PORTB &= ~(1<<SER_DATA);

     // Wait for bit transfer at horizontal sync POSITIVE edge.
-    // This timing is tight for the first bit of the first byte and
-    // the reason that interrupts must be disabled on the Arduino.
     while (PINB & (1<<SER_PULSE))  // Ensure hSync is LOW first
       ;
     while (~PINB & (1<<SER_PULSE)) // Then wait for hSync to rise


let's not wait too much :) telnet running here

--- libraries/ESP8266mDNS/examples/DNS_SD_Arduino_OTA/DNS_SD_Arduino_OTA.ino
+++ libraries/ESP8266mDNS/examples/DNS_SD_Arduino_OTA/DNS_SD_Arduino_OTA.ino
@@ -92,5 +92,5 @@
     }
     free(sbuf);
   }
-  delay(100);
+  delay(1);
 }


Made some fixes to the output, now spits out the proper frequency and is more legible.

--- Arduino/_nano_firmware/nanoFirmware2/nanoFirmware2.ino
+++ Arduino/_nano_firmware/nanoFirmware2/nanoFirmware2.ino
@@ -2,7 +2,11 @@
 Code developed by Sensorica
 Modified from openmusiclabs.com 8.18.12 example sketch

-The code takes in
+We sample microphone and vibration sensor data and alternates between the two
+We pass the data through an FFT
+We searche for peaks in the FFT
+We calculate the 3dB peak-power at the peaks
+We output the data to the serial port
 */

 // do #defines BEFORE #includes
@@ -52,13 +56,13 @@

 //peak finding variables
 const int number_of_peaks = 5;
-const int noise_floor = 50;
+const int noise_floor = 100;
 int biggest_peaks[number_of_peaks];
-int dB3[FFT_N/2];
+int peak_power[FFT_N/2];

 //State Data
 boolean is_microphone = true;
-int down_sampling_rate = 5;
+int down_sampling_rate = 1;

 void setup() {
     // declare the ledPin as an OUTPUT:
@@ -118,17 +122,17 @@
     //SEND DATA TO ARDUINO-ARDUINO INTERFACE
     //NEED INPUT FROM JIM HERE

+//      is_microphone = true; //set to microphone mode
+//      down_sampling_rate =1;// microphone mode
+
+    //TIME DUPLEX BETWEEN MICROPHONE AND VIBRATION SENSOR
+    if (is_microphone == true){
+      is_microphone = false; //set to vibration mode
+      down_sampling_rate =20;//vibration mode uses downsampling factor 20
+    }else{
       is_microphone = true; //set to microphone mode
-      down_sampling_rate =20;// microphone mode
-
-//    //TIME DUPLEX BETWEEN MICROPHONE AND VIBRATION SENSOR
-//    if (is_microphone == true){
-//      is_microphone = false; //set to vibration mode
-//      down_sampling_rate =20;//vibration mode uses downsampling factor 20
-//    }else{
-//      is_microphone = true; //set to microphone mode
-//      down_sampling_rate =5;// microphone mode
-//    }
+      down_sampling_rate =1;// microphone mode
+    }

@@ -155,7 +159,7 @@
 void print_peaks(){
     Serial.println("3dB Bandwidth:");
     for(int i = 0 ; i < FFT_N/2; i++){
-      Serial.print(dB3[i]);
+      Serial.print(peak_power[i]);
       Serial.print(",");
     }
     Serial.println("");
@@ -165,16 +169,20 @@
  int scaling_factor = 1; //pos * BW_per_pos
   if(is_microphone==true){
     Serial.println("Microphone Peaks At:");
-    scaling_factor = 247;
+    scaling_factor = 133;
   }else{
     Serial.println("Vibration Sensor Peaks At:");
     scaling_factor = 7;
   }

     for(int i = 0 ; i < number_of_peaks; i++){
-      Serial.print(biggest_peaks[i]*scaling_factor);
-      Serial.print(",");
-      Serial.print(dB3[biggest_peaks[i]]);
+      if(biggest_peaks[i]!=0){
+      Serial.print((biggest_peaks[i]+1)*scaling_factor); //Print out the frequency
+      }else{
+          Serial.print(0);
+      }
+      Serial.print(",");
+      Serial.print(peak_power[biggest_peaks[i]]); //Print out the power at that peak
       Serial.print(",");
     }
     Serial.println("");
@@ -184,7 +192,7 @@

   //Initialize peak arrays
     for (int i = 0; i<FFT_N/2;i++){
-    dB3[i] = 0;
+    peak_power[i] = 0;
   }

   for (int i = 1; i < FFT_N/2-1; i++){
@@ -193,15 +201,19 @@
     if (fft_log_out[i] > noise_floor &&
         fft_log_out[i] >= fft_log_out[i-1] &&
         fft_log_out[i] >= fft_log_out[i+1]){
-          int j=i;
+          int j=i;
+
+          //Determine the BW of the peak
           while(fft_log_out[j] > fft_log_out[i]/2){
             if(j>=FFT_N/2-1){
               break;
             }
             j++;
           }
-//         dB3[i] = 2*(j-i-1)+1; //Algorithm to find the 3dB point
-        dB3[i] = fft_log_out[i]*(2*(j-i-1)+1); //This actually find the power
+
+
+//         dB3[i] = 2*(j-i-1)+1; //Algorithm to find the right hand 3dB point
+        peak_power[i] = fft_log_out[i]*(2*(j-i-1)+1); //Calculate the power of this peak
     }
   }

@@ -213,14 +225,14 @@
   //extract the biggest peaks
   int smallest_max_peak = 0;
   for (int i = 0; i<FFT_N/2;i++){
-    if (dB3[i] > smallest_max_peak){
+    if (peak_power[i] > smallest_max_peak){

       //Determine the index of the current smallest peak
       int smallest_peak_index=0;
       int smallest_peak=20000;
       for (int j = 0; j<number_of_peaks;j++){
-           if(dB3[biggest_peaks[j]]<smallest_peak){
-            smallest_peak = dB3[biggest_peaks[j]];
+           if(peak_power[biggest_peaks[j]]<smallest_peak){
+            smallest_peak = peak_power[biggest_peaks[j]];
             smallest_peak_index = j;
            }
       }
@@ -232,16 +244,16 @@
       smallest_peak=20000;
       smallest_peak_index=0;
       for (int j = 0; j<number_of_peaks;j++){
-           if(dB3[biggest_peaks[j]]<smallest_peak){
-            smallest_peak = dB3[biggest_peaks[j]];
+           if(peak_power[biggest_peaks[j]]<smallest_peak){
+            smallest_peak = peak_power[biggest_peaks[j]];
             smallest_peak_index = j;
            }
       }
-      smallest_max_peak = dB3[biggest_peaks[smallest_peak_index]];
-    }
-  }
-}
-
-
-
-
+      smallest_max_peak = peak_power[biggest_peaks[smallest_peak_index]];
+    }
+  }
+}
+
+
+
+


Update ArduCAM_Shield_V2_Camera_Playback.ino

--- ArduCAM/examples/Shield_V2/ArduCAM_Shield_V2_Camera_Playback/ArduCAM_Shield_V2_Camera_Playback.ino
+++ ArduCAM/examples/Shield_V2/ArduCAM_Shield_V2_Camera_Playback/ArduCAM_Shield_V2_Camera_Playback.ino
@@ -90,8 +90,16 @@
 Serial.println(F("ArduCAM Start!"));
 // set the SPI_CS as an output:
 pinMode(SPI_CS, OUTPUT);
+digitalWrite(SPI_CS, HIGH);
 //initialize SPI:
 SPI.begin();
+
+//Reset the CPLD
+myCAM.write_reg(0x07, 0x80);
+delay(100);
+myCAM.write_reg(0x07, 0x00);
+delay(100);
+
 while(1){
   //Check if the ArduCAM SPI bus is OK
   myCAM.write_reg(ARDUCHIP_TEST1, 0x55);


It works!

It works!

--- hjemat-arduino/hjemat-arduino.ino
+++ hjemat-arduino/hjemat-arduino.ino
@@ -1,3 +1,6 @@
+//#include <SoftwareSerial.h>
+//SoftwareSerial mySerial(2, 3);
+
 byte data[4];
 byte id = 0x2;

@@ -16,10 +19,11 @@
 byte comReturn    = 0x5;

 void setup() {
-  Serial.begin(9600, SERIAL_8O1);
-  pinMode(ledPin, OUTPUT);
+  Serial.begin(115200);
+  //Serial.begin(115200);

   DDRB = DDRB | B00110000;
+  PORTB = PORTB & B11011111;
 }

 void loop() {
@@ -27,6 +31,9 @@
     return;

   Serial.readBytes(data, 4);
+  /*Serial.print(data[0], BIN);
+  Serial.print(" | ");
+  Serial.println(data[0] >> 3);*/

   if (data[0] != 0){
     if (id == 0x0) {
@@ -39,10 +46,12 @@
     }
     else {
       if (data[0] >> 3 == id){
+        //Serial.println("I've been summoned!");
         byte kom = data[0] & B00000111;

         if (kom == comSet)
         {
+          //Serial.println("I've been told to do something");
           byte dataType =  data[1];
           int value = data[2];
           value = value << 8;
@@ -54,16 +63,22 @@
         }
         else if (kom == comGet)
         {
+          //Serial.println("I've to tell something");
           byte dataID =  data[1];

           returnValue(dataID);
         }
         else if (kom == comPing)
         {
+          //Serial.println("I've have to tell that I'm awake!");
           byte header = createHeader(comBack);
           byte pingback[4] = { header, productID[0], productID[1], productID[2] };
-
+          delay(150);
           tWrite(pingback, 4);
+        }
+        else
+        {
+          //Serial.println("I've do not know that they want :(");
         }
       }
     }
@@ -109,11 +124,12 @@

 void tWrite(byte bytes[], int numBytes)
 {
+  //Serial.println("Writing fine data");
   PORTB = PORTB | B00100000;
-  delay(50);
+  delay(5);
   Serial.write(bytes, numBytes);

-  delay(50);
+  delay(5);
   PORTB = PORTB & B11011111;
 }