ino cleanup, needs finish

ino cleanup, needs finish

--- piserverpanel/piserverpanel.ino
+++ piserverpanel/piserverpanel.ino
@@ -1,19 +1,65 @@
 #include <TimerOne.h>

-#define LED_R         6
-#define LED_G         9
-#define LED_B        10
-#define BUTTON        2
-#define PUSHLOCK_NO   7
-#define PUSHLOCK_NC   3
-
-#define LOCKED      LOW
-#define UNLOCKED   HIGH
-#define UNDEFINED     2
+#define LED_R                       6
+#define LED_G                       9
+#define LED_B                      10
+
+#define BUTTON                      2
+#define PUSHLOCK_NO                 7
+#define PUSHLOCK_NC                 3
+
+#define LOCKED                    LOW
+#define UNLOCKED                 HIGH
+#define UNDEFINED                   2
+
 #define HEARTBEAT_TIMEOUT       10000
 #define HEARTBEAT_SMALL_TIMEOUT  3333

-#define RUN           8
+#define RUN                         8
+
+#define BAUDRATE               115200
+
+//isr
+void isr_button_push();       //obsolete?
+void isr_pushlock_change();
+
+//physical routines
+void serial_flush();
+void touch_run_pin();
+
+//heartbeat detection
+long detect_heartbeat_any();
+long detect_heartbeat();
+long detect_heartbeat_ack();
+long detect_heartbeat_abort();
+long get_last_heartbeat();
+
+//heartbeat animations
+void led_heartbeat();
+void led_heartbeat_missing();
+void led_heartbeat_ack();
+void led_heartbeat_abort();
+
+//generic led routines
+void led_color(byte r, byte g, byte b);
+void led_off();
+void led_red();
+
+//States                          //state matching led animations
+void *server_bootable();          void animate_bootable();
+void *server_booting();           void animate_booting();
+void *server_running();           void animate_running();
+void *server_shutdown();          void animate_shutdown();
+void *server_shutdown_active();   void animate_shutdown_active();
+void *server_hungup();            void animate_hungup();
+void *server_reset();             void animate_reset();
+void *server_locked();            void animate_locked();
+
+//FSM
+typedef void *(*StateFunc)();
+StateFunc statefunc = server_bootable();
+
+//++++ cleanup due!

 byte button = 0;
 byte pushlock = UNDEFINED;
@@ -29,239 +75,308 @@
 int cmode = 0;

 int incomingByte = 0;
-unsigned long tracker, tracker2, beat;
-
-typedef void *(*StateFunc)();
-
-//States
-void *server_bootable();
-void *server_start();
-void *server_booting();
-void *server_running();
-void *server_shutdown();
-void *server_hungup();
-void *server_reset();
-void *server_locked();
-
-StateFunc statefunc;
+unsigned long heartbeat, track_last_heartbeat, track_missing_heartbeat, track_uart;
+int show_missing_beat = 1;

 void setup() {
-  pinMode(BUTTON, INPUT_PULLUP);
   pinMode(PUSHLOCK_NO, INPUT_PULLUP);
   pinMode(PUSHLOCK_NC, INPUT_PULLUP);
+  pinMode(BUTTON, INPUT_PULLUP);

   pinMode(LED_R, OUTPUT);
   pinMode(LED_G, OUTPUT);
   pinMode(LED_B, OUTPUT);
-
   pinMode(RUN, OUTPUT);
-
-  attachInterrupt(digitalPinToInterrupt(BUTTON), button_push, FALLING);
-  attachInterrupt(digitalPinToInterrupt(PUSHLOCK_NO), pushlock_change, CHANGE);
+
+  attachInterrupt(digitalPinToInterrupt(BUTTON), isr_button_push, FALLING);
+  attachInterrupt(digitalPinToInterrupt(PUSHLOCK_NO), isr_pushlock_change, CHANGE);
   //attachInterrupt(digitalPinToInterrupt(PUSHLOCK_NC), pushlock_open, CHANGE);

   pushlock = digitalRead(PUSHLOCK_NO);
-
-//  if (pushlock == LOCKED) {
-//    statefunc = server_locked;
-//  } else {
-    statefunc = server_booting;
-//  }
-  tracker = millis();
-  tracker2 = tracker;
-
-  Serial.begin(115200);
+
+  track_last_heartbeat = millis();
+  track_missing_heartbeat = track_last_heartbeat;
+
+  Serial.begin(BAUDRATE);
 }

 void loop() {
-  statefunc = (StateFunc)(*statefunc)();
-}
-
-void touch_run_pins() {
+  heartbeat = detect_heartbeat();
+  statefunc = (StateFunc)(*statefunc)();    //FSM
+}
+
+//isr
+void isr_button_push() {
+  button = 1;
+}
+
+void isr_pushlock_change() {
+  pushlock = digitalRead(PUSHLOCK_NO);
+}
+
+//physical routines
+void serial_flush() {
+  int buf;
+  while (Serial.available() > 0) {
+      buf = Serial.read();
+  }
+}
+
+void touch_run_pin() {
   digitalWrite(RUN, HIGH);
   delay(50);
   digitalWrite(RUN, LOW);
 }

+//generic led routines
+void led_color(byte r, byte g, byte b) {
+  analogWrite(LED_R, 255-r);
+  analogWrite(LED_G, 255-g);
+  analogWrite(LED_B, 255-b);
+}
+
+void led_off() {
+  led_color(0,0,0);
+}
+
+void led_red() {
+  led_color(255, 0, 0);
+}
+
+//heartbeat animations
+void led_heartbeat() {
+  show_color(0,255,0);
+  delay(10);
+  show_color(255,0,0);
+  delay(10);
+  show_color(0,0,0);
+  delay(15);
+}
+void led_heartbeat_missing() {
+  show_color(255,0,0);
+  delay(10);
+  show_color(255,0,0);
+  delay(10);
+  show_color(0,0,0);
+  delay(15);
+}
+
+void led_heartbeat_ack() {
+  show_color(255,0,255);
+  delay(10);
+  show_color(255,0,255);
+  delay(10);
+  show_color(0,0,0);
+  delay(15);
+}
+
+void led_heartbeat_abort() {
+  show_color(0,0,255);
+  delay(10);
+  show_color(255,255,255);
+  delay(10);
+  show_color(0,0,0);
+  delay(15);
+}
+
+
+//heartbeat detection
+long detect_heartbeat_any();
+
+long detect_heartbeat() {
+  int last_heartbeat = millis()-track_last_heartbeat;
+
+//  if (!Serial) {
+//    return -1;
+//  }
+
+  if (((millis()-track_missing_heartbeat) > 3000) && last_heartbeat > 3000) {
+    if (show_missing_beat == 1) {
+      show_missing_heartbeat();
+    }
+    track_missing_heartbeat = millis();
+  }
+
+  if (Serial.available() > 0) {
+    incomingByte = Serial.read();
+
+    serial_flush();
+
+    if (incomingByte == 0x42) {
+      track_last_heartbeat = millis();
+      track_missing_heartbeat = track_last_heartbeat;
+      show_heartbeat();
+      return last_heartbeat;
+    } else {
+      return -1;
+    }
+  } else {
+    return 0;
+  }
+}
+
+long detect_heartbeat_ack() {
+  if (Serial.available() > 0) {
+    incomingByte = Serial.read();
+
+    serial_flush();
+
+    if (incomingByte == 0x108) {
+      Serial.println("ok");
+      show_active_heartbeat();
+      return 1;
+    } else {
+      return 0;
+    }
+  } else {
+    return -1;
+  }
+}
+
+long detect_heartbeat_abort() {
+  if (Serial.available() > 0) {
+    incomingByte = Serial.read();
+
+    serial_flush();
+
+    if (incomingByte == 0x109) {
+      Serial.println("ok");
+      show_abort_heartbeat();
+      return 1;
+    } else {
+      return 0;
+    }
+  } else {
+    return -1;
+  }
+}
+
+long get_last_heartbeat() {
+  return millis()-track_last_heartbeat;
+}
+
+//state matching led animations
+
+void animate_bootable();
 void fade_bootable(byte del) {
   analogWrite(LED_R, 255);
   analogWrite(LED_G, 255-c_g);
   analogWrite(LED_B, 255);

-  c_g = c_g + fade_g;
-
+  c_g = c_g - fade_g;
+
+  if ( c_g > 88 ) {
+    c_g = 87;
+  }
+
   if ( c_g <= 0 || c_g >= 87 ) {
     fade_g = -fade_g;
   }

   if (fade_g > 0) {
-   delay(del/2);
-  } else {
-   delay(del);
-  }
-}
-
+   delay(del/2);
+  } else {
+   delay(del);
+  }
+}
+
+void animate_booting();
+void fade_boot(byte del) {
+  analogWrite(LED_R, 255-c_r);
+  analogWrite(LED_G, 255-c_g);
+  analogWrite(LED_B, 255-c_b);
+
+  //analogWrite(LED_G, 255);
+  //analogWrite(LED_B, 255);
+
+  c_r = c_r + fade_r;
+  c_g = c_g + fade_g;
+  c_b = c_b + fade_b;
+
+  if ( c_r <= 0 || c_r >= 200 ) {
+    fade_r = -fade_r;
+  }
+  if ( c_g <= 0 || c_g >= 255 ) {
+    fade_g = -fade_g;
+  }
+  if ( c_b <= 0 || c_b >= 155 ) {
+    fade_b = -fade_b;
+  }
+
+  fade_delay = fade_delay + fdel;
+  if (fade_delay <= 1 || fade_delay >=del) {
+    fdel = -fdel;
+  }
+  delay(fade_delay);
+}
+
+void animate_running();
+
+void animate_shutdown();
 void fade_shutdown(byte del) {
   analogWrite(LED_R, 255-c_r);
   analogWrite(LED_G, 255-c_r);
   analogWrite(LED_B, 255);

   c_r = c_r + fade_b;
-
+
+  if (c_r > 141) {
+    c_r = 140;
+  }
+
   if ( c_r <= 0 || c_r >= 140 ) {
     fade_b = -fade_b;
   }

   if (fade_b > 0) {
-   delay(del);
-  } else {
-   delay(del/3);
-  }
-}
-
+   delay(del);
+  } else {
+   delay(del/3);
+  }
+}
+
+void animate_shutdown_active();
+
+void animate_hungup();
 void fade_hungup(byte del) {
   analogWrite(LED_R, 255-c_r);
   analogWrite(LED_G, 255);
   analogWrite(LED_B, 255);

   c_r = c_r + fade_r;
-
-  if ( c_r <= 0 || c_r >= 240 ) {
+
+  if ( c_r <= 0 || c_r >= 255 ) {
     fade_r = -fade_r;
   }
-
+
   delay(del);
 }

-void show_red() {
-  analogWrite(LED_R, 0);
-  analogWrite(LED_G, 255);
-  analogWrite(LED_B, 255);
-}
-
-void show_color(byte r, byte g, byte b) {
-  analogWrite(LED_R, 255-r);
-  analogWrite(LED_G, 255-g);
-  analogWrite(LED_B, 255-b);
-}
-
-void show_none() {
-  show_color(0,0,0);
-}
-
-void show_heartbeat() {
-  show_color(0,255,0);
-  delay(10);
-  show_color(255,0,0);
-  delay(10);
-  show_color(0,0,0);
-  delay(15);
-}
-
-void show_missing_heartbeat() {
-  show_color(255,0,0);
-  delay(10);
-  show_color(255,0,0);
-  delay(10);
-  show_color(0,0,0);
-  delay(15);
-}
-
-void fade_boot(byte del) {
-  analogWrite(LED_R, 255-c_r);
-  analogWrite(LED_G, 255-c_g);
-  analogWrite(LED_B, 255-c_b);
-
-  //analogWrite(LED_G, 255);
-  //analogWrite(LED_B, 255);
-
-  c_r = c_r + fade_r;
-  c_g = c_g + fade_g;
-  c_b = c_b + fade_b;
-
-  if ( c_r <= 0 || c_r >= 200 ) {
-    fade_r = -fade_r;
-  }
-  if ( c_g <= 0 || c_g >= 255 ) {
-    fade_g = -fade_g;
-  }
-  if ( c_b <= 0 || c_b >= 155 ) {
-    fade_b = -fade_b;
-  }
-
-  fade_delay = fade_delay + fdel;
-  if (fade_delay <= 1 || fade_delay >=del) {
-    fdel = -fdel;
-  }
-  delay(fade_delay);
-}
-
-void button_push() {
-  button = 1;
-  //delay(50);
-}
-
-void pushlock_change() {
-  pushlock = digitalRead(PUSHLOCK_NO);
-}
-
-void serial_flush() {
-  int buf;
-  while (Serial.available() > 0) {
-      buf = Serial.read();
-  }
-}
-
-long heartbeat() {
-  int last_heartbeat = millis()-tracker;
-
-//  if (!Serial) {
-//    return -1;
-//  }
-
-  if (((millis()-tracker2) > 3000) && last_heartbeat > 3000) {
-    show_missing_heartbeat();
-    tracker2 = millis();
-  }
-
-  if (Serial.available() > 0) {
-    incomingByte = Serial.read();
-
-    serial_flush();
-
-    if (incomingByte == 0x42) {
-      tracker = millis();
-      tracker2 = tracker;
-      show_heartbeat();
-      return last_heartbeat;
-    } else {
-      return -1;
-    }
-  } else {
-    return 0;
-  }
-}
-
-long last_heartbeat() {
-  return millis()-tracker;
-}
+void animate_reset();
+void animate_locked();
+
+//states

 void *server_bootable() {
+  if (Serial) {
+    Serial.println("bootable");
+  }
+
   if (pushlock == LOCKED) {
     show_red();
     delay(80);
     return server_locked;
   } else {
     fade_bootable(45);
-
-    if ((last_heartbeat() < HEARTBEAT_TIMEOUT || heartbeat() > 0 )) { // && Serial
+
+    if ((last_heartbeat() < HEARTBEAT_TIMEOUT || detect_heartbeat() > 0 )) { // && Serial
       serial_flush();
       return server_booting;
     }
-
+
     if (digitalRead(BUTTON)) {
       delay(100);
-      tracker = millis();
+      track_last_heartbeat = millis();
       serial_flush();
       return server_start;
     } else {
@@ -271,145 +386,159 @@
   }
 }

-void *server_start() {
-//  if (Serial) {
-//    Serial.println("touching run pins on pi");
-//  }
-  touch_run_pins();
+void *server_booting() {
+  if (Serial) {
+    Serial.println("?");
+  }
+
+  if (last_heartbeat() > 10000) {
+
+    return server_bootable;
+  }
+
+  if (heartbeat() <= 0) {
+    fade_boot(40);
+
+    return server_booting;
+  } else {
+
+    return server_running;
+  }
+}
+
+void *server_running() {
+  led_off();
+
+  heartbeart = detect_heartbeat();
+
+  if (Serial) {
+    Serial.println("running");
+    Serial.println(last_heartbeat());
+  }
+
+  if (pushlock == LOCKED) {
+    if (last_heartbeat() > 30000 || detect_heartbeat() < 0 ) {
+
+      return server_locked;
+    } else {
+      track_uart = millis();
+      return server_shutdown;
+    }
+  } else {
+    if (last_heartbeat() > HEARTBEAT_TIMEOUT) {
+
+      return server_hungup;
+    } else {
+
+      return server_running;
+    }
+  }
+
+}
+
+void *server_shutdown() {
+
+  if ((millis()-track_uart) > 5000) {
+    if (Serial) {
+      Serial.println("shutdown");
+      delay(100);
+    }
+    track_uart = millis();
+  }
+
+  //fade_shutdown(35);
+  show_red();
+
+  if (detect_heartbeat_ack() == 1) {
+    return server_shutdown_active;
+  } else {
+    return server_shutdown;
+  }
+}
+
+void *server_shutdown_active() {
+  heartbeart = detect_heartbeat();
+  show_missing_heartbeat();
+  delay(100);
+  show_red();
+
+  if (digitalRead(BUTTON)) {
+    delay(100);
+    track_last_heartbeat = millis();
+    serial_flush();
+    if (detect_heartbeat_abort() == 1) {
+      if (Serial) {
+        Serial.println("abort shutdown");
+      }
+      return server_running;
+    }
+  }
+
+  if (last_heartbeat() < HEARTBEAT_TIMEOUT) {
+    serial_flush();
+    return server_shutdown_active;
+  } else {
+    serial_flush();
+    return server_locked;
+  }
+}
+
+void *server_hungup() {
+  if (Serial) {
+    Serial.println("hung up");
+    Serial.println(last_heartbeat());
+  }
+
+  heartbeart = detect_heartbeat();
+  heartbeart = last_heartbeat();
+
+  if (heartbeart < HEARTBEAT_TIMEOUT || detect_heartbeat() > 0) {
+
+    return server_running;
+  } else {
+
+    if (heartbeart > HEARTBEAT_TIMEOUT && heartbeart < 20000UL) {
+      fade_hungup(25);
+    } else if (heartbeart > 20000UL && heartbeart < 30000UL) {
+      fade_hungup(15);
+    } else if (heartbeart > 30000UL && heartbeart < 450000UL) {
+      fade_hungup(5);
+    }
+
+    if (heartbeart > 45000UL) {
+      show_red();
+    }
+
+    if (last_heartbeat() > 60000UL) {
+
+      return server_reset;
+    } else {
+
+      return server_hungup;
+    }
+
+  }
+}
+
+void *server_reset() {
+  if (Serial) {
+    Serial.println("touching run pins on pi");
+  }
+  touch_run_pin();
   serial_flush();
   return server_booting;
 }

-void *server_booting() {
-//  if (Serial) {
-//    Serial.println("Waiting for Heartbeat");
-//    Serial.println("?");
-//  }
-  if (last_heartbeat() > 10000) {
-
+void *server_locked() {
+  if (Serial) {
+    Serial.println("LOCKED");
+  }
+  if (pushlock == LOCKED) {
+    led_off();
+    serial_flush();
+    return server_locked;
+  } else {
+    serial_flush();
     return server_bootable;
   }
-
-  if (heartbeat() <= 0) {
-    fade_boot(40);
-
-    return server_booting;
-  } else {
-
-    return server_running;
-  }
-}
-
-void *server_running() {
-  show_none();
-
-  beat = heartbeat();
-//  if (Serial) {
-//    Serial.println("running");
-//    Serial.println(last_heartbeat());
-//  }
-
-  if (pushlock == LOCKED) {
-    if (last_heartbeat() > 30000 || heartbeat() < 0 ) {
-
-      return server_locked;
-    } else {
-
-      return server_shutdown;
-    }
-  } else {
-    if (last_heartbeat() > HEARTBEAT_TIMEOUT) {
-
-      return server_hungup;
-    } else {
-
-      return server_running;
-    }
-  }
-
-}
-
-void *server_shutdown() {
-  if (Serial) {
-    Serial.println("shutdown");
-  } else {
-    show_missing_heartbeat();
-    delay(40);
-    show_missing_heartbeat();
-    delay(40);
-    show_missing_heartbeat();
-    delay(40);
-    show_missing_heartbeat();
-    delay(40);
-    show_missing_heartbeat();
-    delay(40);
-  }
-
-  beat = heartbeat();
-  fade_shutdown(35);
-
-  if (last_heartbeat() < HEARTBEAT_TIMEOUT) {
-    serial_flush();
-    return server_shutdown;
-  } else {
-    serial_flush();
-    return server_locked;
-  }
-}
-
-void *server_hungup() {
-//  if (Serial) {
-//    Serial.println("hung up");
-//    Serial.println(last_heartbeat());
-//  }
-
-  beat = heartbeat();
-  beat = last_heartbeat();
-
-  if (beat < HEARTBEAT_TIMEOUT || heartbeat() > 0) {
-
-    return server_running;
-  } else {
-
-    if (beat > HEARTBEAT_TIMEOUT && beat < 20000UL) {
-      fade_hungup(25);
-    } else if (beat > 20000UL && beat < 30000UL) {
-      fade_hungup(15);
-    } else if (beat > 30000UL && beat < 450000UL) {
-      fade_hungup(5);
-    }
-
-    if (beat > 45000UL) {
-      show_red();
-    }
-
-    if (last_heartbeat() > 60000UL) {
-
-      return server_reset;
-    } else {
-
-      return server_hungup;
-    }
-
-  }
-}
-
-void *server_reset() {
-//  if (Serial) {
-//    Serial.println("touching run pins on pi");
-//  }
-  touch_run_pins();
-  serial_flush();
-  return server_booting;
-}
-
-void *server_locked() {
-  if (pushlock == LOCKED) {
-    show_none();
-    serial_flush();
-    return server_locked;
-  } else {
-    serial_flush();
-    return server_bootable;
-  }
-}
+}


Bring code in repo in sync with code flashed into the actual door unit as per 2018-03-07

--- test/PoE-test/spacedeur-asis-2017/spacedeur-asis-2017.ino
+++ test/PoE-test/spacedeur-asis-2017/spacedeur-asis-2017.ino
@@ -2,6 +2,7 @@
     to the existing setup late 2017.
 */

+#include "/Users/dirkx/.passwd.h"
 // Wired ethernet.
 //
 #define ETH_PHY_ADDR      1
@@ -341,7 +342,7 @@
     wipeCache();
   } else {
     caching = true;
-    listDir(SPIFFS, " / ", "");
+    listDir(SPIFFS, "/", "");
   };

   Serial.println("setup() done.\n\n");
@@ -394,7 +395,7 @@
     SPIFFS.mkdir(String(i));

   Serial.println("Directory structure created.");
-  listDir(SPIFFS, " / ", "");
+  listDir(SPIFFS, "/", "");
   caching = true;
 };

@@ -403,7 +404,7 @@
   for (int i = 0; i < uid.size; i++) {
     path += String(uid.uidByte[i], DEC);
     if (i == 0)
-      path += " / ";
+      path += "/";
     else
       path += ".";
   };


laatste versie

laatste versie

--- programmaNano/programmaNano.ino
+++ programmaNano/programmaNano.ino
@@ -1,16 +1,19 @@
 #include <Servo.h>
-int reader;
-// Generally, you should use "unsigned long" for variables that hold time
-// The value will quickly become too large for an int to store
+
 unsigned long previousMillis = 0;
 bool stippenlijn = false;
 bool boven= false;
 bool beneden = true;
-const long interval = 15;
+const long interval = 20;
+
+bool validDistance = false;
+long afstandwaarde = 0;
+int count = 0;
+int afstand = 0;

 #define echoPin 5          // Echo Pin
 #define trigPin 4          // Trigger Pin
-#define timeOutPin A5       //De pin om de sensor aan en uit te doen
+#define timeOutPin 12       //De pin om de sensor aan en uit te doen

 int coila1 = 6;
 int coila2 = 7;
@@ -23,7 +26,7 @@
 int draainaarboven =0;
 int positie = 0;

-int maximumRange = 60;                   // Maximum range needed
+int maximumRange = 200;                   // Maximum range needed
 int minimumRange = 0;                     // Minimum range needed

 int rechtseAfstand  = -1;
@@ -38,7 +41,7 @@
 void setup(){
   myservo.attach(3);  // attaches the servo on pin 11 to the servo object
   Serial.begin(9600);
-  reader = 0;
+

   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
@@ -54,32 +57,21 @@
 void loop(){

   unsigned long currentMillis = millis();
-  if (Serial.available() > 1) {
-      reader = Serial.parseInt();
-      delay(2);
+
+
+
+
+
+  if(beneden){
+    draainaarbeneden = 10 - middenpuntpositie;    // zorgt ervoor dat de pen naar beneden gaat
+    beneden=false;
   }
-
-  if (reader == 0) { myservo.write(80);  delay(500); reader = -1; }
-  else if (reader == 1) { myservo.write(60); delay(500); reader = -1;}
-  else if (reader == 2) { myservo.write(100); delay(500); reader = -1; }
-  else if (reader == 3) { myservo.write(0); delay(1000); reader = -1; }
-  else if (reader == 4) { myservo.write(180); delay(1000); reader = -1; }
-  else if (reader == 6) {  beneden = true; stippenlijn = false; reader = -1; }
-  else if (reader == 7) {stippenlijn = true ; beneden = false; reader = -1; }
-  else{
-
-  if(beneden){
-
-    draainaarbeneden = 10 - middenpuntpositie;
-    beneden=false;
-
- }
-
-  if(stippenlijn && !beneden){
+
+  if(stippenlijn && !beneden){                      // zorgt ervoor dat er een stippelijn patroon getekend wordt
     if(middenpuntpositie<=0){
        draainaarbeneden = 10 - middenpuntpositie;
     }
-    if(middenpuntpositie>=10){
+    if(middenpuntpositie>=10){
       draainaarboven = middenpuntpositie;
     }
   }
@@ -87,12 +79,13 @@

      if (currentMillis - previousMillis >= interval) {
-
-        Distance();
+
+         //automatischrijdenZigZag();           // functie om automatisch zig zag te rijden te rijden
+         automatischrijden();                   // functie om automatisch te rijden

-            if(draainaarboven>0){
-              digitalWrite(enable, HIGH);
+            if(draainaarboven>0){               // wordt gebruikt om de stappen motor naar boven te draaien
+              digitalWrite(enable, HIGH);        // zorgt dat de H brug aan staat

               switch(positie){
                 case 0:
@@ -131,8 +124,8 @@
                   break;
               }

-            }else if(draainaarbeneden>0){
-              digitalWrite(enable, HIGH);
+            }else if(draainaarbeneden>0){     // zorgt dat de stappen motor naar beneden gaat.
+              digitalWrite(enable, HIGH);     // zorgt dat de H brug aan staat

               switch(positie){
                 case 0:
@@ -173,54 +166,48 @@

             }
             else{
-              digitalWrite(enable, LOW);
+              digitalWrite(enable, LOW); // zet de H-brug terug uit
             }
-        previousMillis = currentMillis;
-
-    }
-  }
-
+        previousMillis = currentMillis;
+    }
+
+
+}
+
+
+void automatischrijdenZigZag(){     // de zig zag code
+  afstand = filterDistance();       // de afstand wordt gemeten
+  if (afstand == 1){                // als er een object dicht in de buurt is

-
-
-
-
-}
-
-
-void automatischrijdenZigZag(){
-  afstand = filterDistance();
-  if (afstand == 1){
-
-    Serial.println(11); //Verstuurd stop
-     if (rechtsDraaien == true) {
-      while(rechtseAfstand <1){
-        rechtseAfstand = RechtsKijken90();
+    Serial.println(11);             //Verstuurd stop
+     if (rechtsDraaien == true) {   // als de wagen naar rechts moet draaien
+      while(rechtseAfstand <1){     // als er rechts een object is, blijf dan naar rechts kijken
+        rechtseAfstand = RechtsKijken90();    //// zorgt dat de sensor naar rechts kijkt
       }
-      if(rechtseAfstand >1){
-         Serial.println(3); // Verstuurd om rechts te draaien
-
-          schuinKijken = false;
-          myservo.write(80);
+      if(rechtseAfstand >1){            // als er rechts geen object meer is
+         Serial.println(3);             // Verstuurd om rechts te draaien
+
+          schuinKijken = false;
+          myservo.write(80);            // zet servo terug in het midden
           afstand=0;
-         delay(4000);
+         delay(4000);                   // wacht dat de wagen gedraaid
          beneden = true;
-         stippenlijn = false;
+         stippenlijn = false;           // geen stippenlijn meer tekenen maar een lijn
          rechtsDraaien = false;
         }
       }
-      else if(rechtsDraaien == false){
-       while(linkseAfstand <1){
-        linkseAfstand = LinksKijken90();
+      else if(rechtsDraaien == false){    // als de wagen naar links moet draaien
+       while(linkseAfstand <1){           // als er links nog een object is blijven kijken naar links
+        linkseAfstand = LinksKijken90();   // kijkt naar links
        }
-        if(linkseAfstand >1){
-          Serial.println(4); // Verstuurd om links te draaien
-
-          schuinKijken = false;
-          myservo.write(80);
+        if(linkseAfstand >1){           // als er links geen object meer is
+          Serial.println(4);        // Verstuurd om links te draaien
+
+          schuinKijken = false;
+          myservo.write(80);      / zet servo terug in het midden
           afstand=0;
           delay(4000);
-          stippenlijn = true ;
+          stippenlijn = true ;      // zorgt dat er terug een stippellijn patroon wordt getekend
           beneden = false;
           rechtsDraaien = true;

@@ -232,6 +219,77 @@

     }
     else if(afstand ==2){
+
+        if (schuinKijken == false){ // als hij nog niet schuin kijkt
+          Serial.println(11); //Verstuurd stop
+          schuinKijken = true;
+
+          rechtseAfstand = RechtsKijken20();        // kijkt naar een object schuint rechts
+          linkseAfstand = LinksKijken20();           // kijkt naar een object schuint link
+
+          if( rechtseAfstand <=2 &&  rechtseAfstand > 0|| linkseAfstand <= 2 &&  linkseAfstand > 0){
+            if(rechtseAfstand < linkseAfstand){  // als het object rechts dicheter is dan links
+              myservo.write(60);            // laat de servo kijken naar schuin rechts
+
+            }
+
+          }
+          else{
+            myservo.write(80);            // als er links of rechts geen dichte objecten zijn zet servo terug in het midden
+          }
+          rechtseAfstand = -1;
+          linkseAfstand = -1;
+        }
+      Serial.println(2); //Verstuurd om traag te rijden
+    }
+    else if(afstand ==3) {
+
+      Serial.println(5);//Verstuurd om snel te rijden
+    }else{
+       Serial.println(11); //verstuurd stop
+    }
+
+}
+void automatischrijden(){
+  afstand = filterDistance();
+  if (afstand == 1){   // als er een object dicht in de buurt is
+
+    Serial.println(11); //Verstuurd stop
+
+      rechtseAfstand = RechtsKijken90(); // zorgt dat de sensor naar rechts kijkt
+      delay(100);
+
+      if(rechtseAfstand >1){  // als er rechts niets is draai naar rechts
+         Serial.println(3); // Verstuurd om rechts te draaien
+         myservo.write(80);
+         delay(4000);
+         schuinKijken = false;
+         afstand=0;
+        }else{
+          linkseAfstand = LinksKijken90(); // kijkt naar links
+          delay(100);
+          if(linkseAfstand >1){   // als er links niets is draai naar links
+            Serial.println(4); // Verstuurd om links te draaien
+            myservo.write(80); // zet servo terug in het midden
+            delay(4000);
+            schuinKijken = false;
+            afstand=0;
+
+           }else{             // als er zowel links als rechts een object is draai 180 graden
+               Serial.println(6); // Verstuurd om 180 graden te draaien
+               myservo.write(80); // zet servo terug in het midden
+               delay(5000);
+               schuinKijken = false;
+               afstand=0;
+
+           }
+        }
+
+        rechtseAfstand = -1;
+        linkseAfstand = -1;
+
+    }
+    else if(afstand ==2){ // code om schuin te kijken

         if (schuinKijken == false){
           Serial.println(11); //Verstuurd stop
@@ -243,9 +301,7 @@
           if( rechtseAfstand <=2 &&  rechtseAfstand > 0|| linkseAfstand <= 2 &&  linkseAfstand > 0){
             if(rechtseAfstand < linkseAfstand){
               myservo.write(60);
-
-            }
-
+            }
           }
           else{
             myservo.write(80);
@@ -260,33 +316,32 @@
       Serial.println(5);//Verstuurd om snel te rijden
     }else{
        Serial.println(11); //verstuurd stop
-    }
-
-}
-
-int RechtsKijken90() {
+    }
+}
+
+int RechtsKijken90() { // code om rechts te kijken

   myservo.write(0);
   delay(1000);
   return kijken();

 }
-int LinksKijken90() {
+int LinksKijken90() { // code om links te kijken
   myservo.write(180);
   delay(1000);
   return kijken();
 }
-int RechtsKijken20() {
+int RechtsKijken20() {  // code om schuin rechts te kijken
   myservo.write(60);
   delay(500);
   return kijken();
 }
-int LinksKijken20() {
+int LinksKijken20() {// code om schuin links te kijken
   myservo.write(100);
   delay(500);
   return kijken();
 }
-int kijken(){
+int kijken(){ // code om de afstand van de sensor te weten en de waardes te filteren
   int tempafstand = 0;
   while(tempafstand == 0){
     tempafstand = filterDistance();
@@ -297,7 +352,7 @@

-void Distance(){ // meet de afstand van de sensor
+long Distance(){ // meet de afstand van de sensor

   long duration, distance;                  // Duration used to calculate distance
   digitalWrite(timeOutPin, HIGH);
@@ -320,22 +375,17 @@
     digitalWrite(timeOutPin, LOW);
   }

-  else {
-    /* Send the distance to the computer using Serial protocol, and
-    turn LED OFF to indicate successful reading. */
-    //Serial.println(distance);
-  }
-  Serial.println(distance);
-}
-
-int filterDistance() {
+  return distance;
+}
+
+int filterDistance() { // functie die de afstand waardes filtert naar makkelijkere waardes.

   afstandwaarde = Distance();
   if(count <= 5 && afstandwaarde == 201 || afstandwaarde == 0) {
     count++;
-    afstandwaarde = Distance();
+    afstandwaarde = Distance(); //  haalt de afstand op
     return 0;
-  }else{
+  }else{     // als de waarde niet vals is of 5 keer zijn max range heeft
      count = 0;
     if(afstandwaarde < 15 && afstandwaarde > 0){
        return 1;
@@ -349,7 +399,7 @@
   }
 }

-
+ // codes om de H-brug van de stappen motor aan te sturen

 void a1Enb2(){
     digitalWrite(coila1, HIGH);
@@ -402,4 +452,3 @@
 }

-


Arduino.ino - fixed typo in comment.

Arduino.ino - fixed typo in comment.

--- Arduino/Arduino.ino
+++ Arduino/Arduino.ino
@@ -1,6 +1,6 @@
 /*
  * Emulate a Magic Remote Control to programmatically send a color code
- * to a Magic Lightning RGB LED light
+ * to a Magic Lighting RGB LED light
  * Date October 27, 2014
  * Copyright 2014 Robert Moro
  *


Fixed a bug in the setSSid function.

Fixed a bug in the setSSid function.

--- BackEnd/BackEnd.ino
+++ BackEnd/BackEnd.ino
@@ -1148,13 +1148,17 @@
 ///////////////////////////////
 void procSsidMsg( aJsonObject *_pJsonSsid )
 {
-  aJsonObject *poSsid = aJson.getObjectItem(_pJsonSsid, "ssid");
-  if ( poSsid && String(poSsid->valuestring).length() <= SSID_MAX_LENGTH )
-  {
-    if( strcmp(g_sSsid, poSsid->valuestring) )
-    {
-      sprintf(g_sSsid, "%s", poSsid->valuestring);
-      setSsidName(poSsid->valuestring);
+ // aJsonObject *poSsid = aJson.getObjectItem(_pJsonSsid, "ssid");
+ // Serial.println("HERE");
+ // Serial.print("here SSID size: ");Serial.println(String(_pJsonSsid->valuestring).length());
+  if ( String(_pJsonSsid->valuestring).length() <= SSID_MAX_LENGTH )
+  {
+   //  Serial.print("SSID size: ");Serial.println(String(_pJsonSsid->valuestring).length());
+    if( strcmp(g_sSsid, _pJsonSsid->valuestring) )
+    {
+     //     Serial.print("SSID: ");Serial.println(_pJsonSsid->valuestring);
+      sprintf(g_sSsid, "%s", _pJsonSsid->valuestring);
+      setSsidName(_pJsonSsid->valuestring);
     }
   }
  }
@@ -1396,7 +1400,7 @@
       int iSsidLen = strlen(Line)-strlen(Find);
       // Truncate Ssid if it too long
       int n = iSsidLen < SSID_MAX_LENGTH ? iSsidLen : SSID_MAX_LENGTH;
-      strncpy(_sSsidName, SubStr+strlen(Find), n);
+      strncpy(_sSsidName, SubStr+strlen(Find), n-1);
     }
   }

@@ -1473,7 +1477,7 @@
     // Test code
     ///////////////////////////////////////

-    getSerialCommand();
+ //   getSerialCommand();

 /*
     g_iCatNumber++;


Added delay to badge

Added delay to badge

--- TiLDA_MKe/examples/PersonalisedBadge/PersonalisedBadge.ino
+++ TiLDA_MKe/examples/PersonalisedBadge/PersonalisedBadge.ino
@@ -49,6 +49,9 @@
     tilda.glcd.drawStr(0, 110, "scientist.");
   }
   while(tilda.glcd.nextPage());
+
+  // Can easily afford to take it easy
+  delay(50);
 }

 /**


Manage backlight for access status

Manage backlight for access status

--- firmware/sentry.ino
+++ firmware/sentry.ino
@@ -14,6 +14,10 @@
 #define LCD_DB6 D3
 #define LCD_DB7 D4

+#define LCD_BL_R A0
+#define LCD_BL_G A2
+#define LCD_BL_B A1
+
 #define LED_PIN D7
 #define MAX_CARDS 1000

@@ -45,6 +49,13 @@
   Serial1.begin(9600);

   pinMode(LED_PIN, OUTPUT);
+  pinMode(LCD_BL_R, OUTPUT);
+  pinMode(LCD_BL_G, OUTPUT);
+  pinMode(LCD_BL_B, OUTPUT);
+
+  digitalWrite(LCD_BL_R, HIGH);
+  digitalWrite(LCD_BL_G, HIGH);
+  digitalWrite(LCD_BL_B, LOW);

   Particle.subscribe("sentry/wipe-members", wipeMembers);
   Particle.subscribe("sentry/append-members", appendMembers);
@@ -134,6 +145,10 @@
   lcd.print("SENTRY");
   lcd.setCursor(0, 1);
   lcd.print("  online");
+
+  digitalWrite(LCD_BL_R, HIGH);
+  digitalWrite(LCD_BL_G, HIGH);
+  digitalWrite(LCD_BL_B, LOW);
 }

 // Accept data in tab delineated CSV format, where each row is:
@@ -195,6 +210,11 @@
     card = cards[i];
     if (card.rfid == code) {
       lcd.print(card.greeting);
+
+      digitalWrite(LCD_BL_R, HIGH);
+      digitalWrite(LCD_BL_G, LOW);
+      digitalWrite(LCD_BL_B, HIGH);
+
       delay(3000);
       resetLCD();
       return;
@@ -202,7 +222,11 @@
   }

   lcd.print(" ACCESS  DENIED ");
+  digitalWrite(LCD_BL_R, LOW);
+  digitalWrite(LCD_BL_G, HIGH);
+  digitalWrite(LCD_BL_B, HIGH);
   delay(3000);
+
   resetLCD();
 }


updating pixel count

updating pixel count

--- firmware/http-neopixel-skull/skull.ino
+++ firmware/http-neopixel-skull/skull.ino
@@ -5,7 +5,7 @@
 //the pin your spark is using to control neopixels
 #define PIXEL_PIN D2
 //the number of pixels you are controlling
-#define PIXEL_COUNT 150
+#define PIXEL_COUNT 168

 //0-149 - strip
 //pixels 150-154 = small skull 1


fix led count

fix led count

--- testing/arduino/self-driving-v6.ino
+++ testing/arduino/self-driving-v6.ino
@@ -33,7 +33,7 @@
 // LED
 const uint8_t ledPin = 11;
 const bool ledBatterySaving = true;
-Adafruit_NeoPixel LEDStrip = Adafruit_NeoPixel(26, ledPin, NEO_GRB + NEO_KHZ800);
+Adafruit_NeoPixel LEDStrip = Adafruit_NeoPixel(24, ledPin, NEO_GRB + NEO_KHZ800);

 // Motor / Wheels
 const uint8_t motorPin1_1 = A3;


Update motor.ino

Update motor.ino

--- DroidMain/motor.ino
+++ DroidMain/motor.ino
@@ -10,12 +10,13 @@
     /* This function will run the motors across the range of possible speeds.
      * Note that maximum speed is determined by the motor itself and the operating voltage.
      * the PWM values sent by analogWrite() are fractions of the maximum speed possible by your hardware.
-     * As an input value the relative definition of the used power range 0-100% which is converted to the corresponding PWM range 75-255.
-     * In theory the PWM range is 0-255. However in practice with this setup the operating range will be around 75-255 PWM.
-     * Formula: "PWM value to Motor driver" = "Min PWM" + (("Max PWM" - "Min PWM")/100))* Power%
-     * Driving direction can be defined by +/- values. Value (+) -> forward and Value(-) -> backward
-     * Note that PWM operating range will be depending on several factors like capacity of batteries, overall system load, etc.
-     * And finally each of the droid setup is different. Each of the devices are unique and requires case-by-case fine tunings.
+     * As an input value the relative definition of the used power range 0-100% which is converted to the
+     * corresponding PWM range 75-255. In theory the PWM range is 0-255. However in practice with this setup
+     * the operating range will be around 75-255 PWM.
+     * Formula: "PWM value to Motor driver" = "Min PWM" + (("Max PWM" - "Min PWM")/100))* Power%)
+     * Driving direction can be defined by switching polarity value. Value (+) -> forward and Value(-) -> backward.
+     * Note that PWM operating range is depending on several factors, like capacity of batteries, overall system load
+     * and well... each of the droid setups are different. The droids are unique and requires fine tunings, case-by-case.
      */
     boolean in1ena = (rightpower < 0)?false:true;
     boolean in2ena = (rightpower < 0)?true:false;


aggiunta del buzzer

aggiunta del buzzer

--- nodeMCU/plant/functions.ino
+++ nodeMCU/plant/functions.ino
@@ -37,8 +37,11 @@
    client.println();

    Serial.println();
-
-   delay(2000);
+   digitalWrite(14, HIGH);
+   delay(500);
+   digitalWrite(14, LOW);
+
+   delay(1500);
    client.stop();

    }//end if


colocando pra funcionar bem com mais de um botão, ta tudo funcionando agora!! eeeee

--- codigo.ino
+++ codigo.ino
@@ -235,11 +235,6 @@
     Serial.println(buttons_list[pressed_button].codeLen);

 }
-//============================================================
-// int lastButtonState;
-// int lastBtnStateOfBtn2;
-// int lastBtnStateOfBtn3;
-//============================================================

 int check_button_released(int button_index){
     return buttons_list[button_index].last_button_state == HIGH && buttons_list[button_index].button_state == LOW;
@@ -249,12 +244,28 @@
     return buttons_list[button_index].button_state;
 }

-
+int what_button_index_was_pressed(){
+    for(int i=0; i < 2; i++){
+        if(check_button_pressed(i)){
+            return i;
+        }
+    }
+    return -1;
+}
+int what_button_index_was_released(){
+    for(int i=0; i < 2; i++){
+        if(check_button_released(i)){
+            return i;
+        }
+    }
+    return -1;
+}
 void re_enable_IRIn_if_button_released(){
-
-    if (check_button_released(0) | check_button_released(1))
-    {
-        Serial.println("Released a button");
+    int button_index = what_button_index_was_released();
+    if (button_index != -1)
+    {
+        Serial.print("Released button");
+        Serial.println(button_index);
         irrecv.enableIRIn(); // Re-enable receiver
     }
     return;
@@ -269,30 +280,43 @@
     buttons_list[1].last_button_state = buttons_list[1].button_state;
 }

+int check_button_pressed_and_sendCode(){
+    int button_index = what_button_index_was_pressed();
+    if (button_index != -1)
+    {
+        last_pressed_button = button_index; //marks the correct button_index as the last pressed
+        Serial.print("Pressed Button ");
+        Serial.print(last_pressed_button);
+        Serial.println(", sending");
+
+        digitalWrite(STATUS_PIN, HIGH);
+
+        int is_repeating = buttons_list[button_index].last_button_state == buttons_list[button_index].button_state;
+        sendCode(is_repeating, last_pressed_button);
+
+        digitalWrite(STATUS_PIN, LOW);
+
+        //return true
+        return 1;
+    }
+    //return false
+    return 0;
+}
+
 void loop()
 {
+    update_state_of_buttons();
+
+    re_enable_IRIn_if_button_released();
+
     // If button pressed, send the code.
-    update_state_of_buttons();
-    //========================================================
-
-    // int secondButtonState = digitalRead(SECOND_BUTTON_PIN);
-    // int thirdButtonState = digitalRead(THIRD_BUTTON_PIN);
-    //========================================================
-
-    re_enable_IRIn_if_button_released();
-
-    if (check_button_pressed(0))
-    {
-        last_pressed_button = 0; //marca o primeiro botao como sendo o pressionado
-        Serial.println("Pressed, sending");
-        digitalWrite(STATUS_PIN, HIGH);
-        sendCode(buttons_list[0].last_button_state == buttons_list[0].button_state, last_pressed_button);
-        digitalWrite(STATUS_PIN, LOW);
+    if (check_button_pressed_and_sendCode())
+    {
         delay(50); // Wait a bit between retransmissions
     }
     else if (irrecv.decode(&results))
     {
-        printDadosBotao(0);
+        printDadosBotao(last_pressed_button);
         digitalWrite(STATUS_PIN, HIGH);
         storeCode(&results, last_pressed_button);
         irrecv.resume(); // resume receiver


refactored slot configuration and update the slot after cv write.

--- src/Full_decoder/Full_decoder.ino
+++ src/Full_decoder/Full_decoder.ino
@@ -5,7 +5,7 @@
 without computer connected this line should be commented out.
 */
 #define DEBUG_OUTPUT
-//#undef DEBUG_OUTPUT
+#undef DEBUG_OUTPUT

 #ifdef DEBUG_OUTPUT
 #define USE_SERIAL
@@ -67,6 +67,35 @@
   LocoNet.reportSensor(address, state);
 }

+void configureSlot(uint8_t slot) {
+  uint8_t pin_config;
+  uint16_t pin, address, pos1, pos2, speed, fbslot1, fbslot2;
+
+    pin_config = eeprom_read_byte((uint8_t*)&(_CV.pin_conf[slot]));
+    pin   = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.arduinopin));
+    address = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.address));
+    switch (pin_config) {
+      case 2: //Servo
+        //ServoSwitch(i,0);
+        pos1  = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.pos1));
+        pos2  = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.pos2));
+        speed = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.speed));
+        fbslot1  = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.fbslot1));
+        fbslot2  = eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.fbslot2));
+        confpins[slot] = new ServoSwitch(slot, pin, address, pos1, pos2, speed, servoEnablePin, fbslot1, fbslot2);
+        confpins[slot]->restore_state(eeprom_read_word((uint16_t*)&(_CV.conf[slot].servo.state)));
+        break;
+      case 1: // Input
+        confpins[slot] = new InputPin(slot, pin, address);
+        break;
+      default:
+        confpins[slot] = new ConfiguredPin(slot, pin, address);
+        break;
+    }
+    DEBUG("Pin #");
+    DEBUGLN(i);
+    confpins[slot]->print();
+}
 void setup() {
   pinMode( servoEnablePin, OUTPUT);
   disableServos();
@@ -81,36 +110,11 @@
   LocoNet.init(LOCONET_TX_PIN);

   uint8_t i = 0;
-  uint8_t pin_config;
-  uint16_t pin, address, pos1, pos2, speed, fbslot1, fbslot2;
   DEBUG("Max # of pins:");
   DEBUGLN(MAX);

   for (i = 0; i < MAX; i++) {
-    pin_config = eeprom_read_byte((uint8_t*)&(_CV.pin_conf[i]));
-    pin   = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.arduinopin));
-    address = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.address));
-    switch (pin_config) {
-      case 2: //Servo
-        //ServoSwitch(i,0);
-        pos1  = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.pos1));
-        pos2  = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.pos2));
-        speed = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.speed));
-        fbslot1  = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.fbslot1));
-        fbslot2  = eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.fbslot2));
-        confpins[i] = new ServoSwitch(i, pin, address, pos1, pos2, speed, servoEnablePin, fbslot1, fbslot2);
-		    confpins[i]->restore_state(eeprom_read_word((uint16_t*)&(_CV.conf[i].servo.state)));
-        break;
-      case 1: // Input
-        confpins[i] = new InputPin(i, pin, address);
-        break;
-      default:
-        confpins[i] = new ConfiguredPin(i, pin, address);
-        break;
-    }
-    DEBUG("Pin #");
-    DEBUGLN(i);
-    confpins[i]->print();
+    configureSlot(i);
   }
   programmingMode = false;
 }
@@ -295,6 +299,9 @@
       DEBUG((uint8_t)lncvValue);
       write_cv(&_CV, lncvAddress, lncvValue);
       DEBUG(read_cv(&_CV, lncvAddress));
+      uint8_t slot = cv2slot(lncvAddress);
+      delete(confpins[slot]);
+      configureSlot(slot);
       //lncv[lncvAddress] = lncvValue;
       return LNCV_LACK_OK;
     }


Updated header comments noting license agreements

--- Grovey_Slocks_Hackster_v01.ino
+++ Grovey_Slocks_Hackster_v01.ino
@@ -1,3 +1,23 @@
+/***************************************************
+  This is the Arduino 101 code for Grovey sLocks
+  This software is written by Gerrikoio.
+  MIT license applies, see copy of license text in github folder
+
+  This example uses the curieBLE device and the code used
+  is an extract from CurieEddystoneURL.ino, which is
+   * Copyright (c) 2016 Bradford Needham, North Plains, Oregon, USA
+   * @bneedhamia, https://www.needhamia.com
+   * and is Licensed under the Apache 2.0 License, a copy of which
+   * is included in the following github repo:
+   * https://github.com/bneedhamia/CurieEddystoneURL
+  Thanks goes to bndeedhamia for saving me a lot of time
+
+  The rgb_lcd.h library used for the RGB LCD is
+  2013 Copyright (c) Seeed Technology Inc.  All right reserved.
+  It is provided under the MIT License (MIT). Details can be found here:
+  https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight
+ ****************************************************/
+
 // **** INCLUDES *****
 #include "CurieTimerOne.h"
 #include <CurieBLE.h>
@@ -30,8 +50,8 @@
   URL_PREFIX_HTTPS_COLON_SLASH_SLASH =  0x03;           // 0x03 = https://

 const int8_t
-  MIN_EEPADDR =                         32,             // EEPROM address for calibrated min angular sensor value
-  MAX_EEPADDR =                         36,             // EEPROM address for calibrated max angular sensor value
+  MIN_EEPADDR =                         32,             // EEPROM address for calibrated min angular sensor value (arbitrary address used)
+  MAX_EEPADDR =                         36,             // EEPROM address for calibrated max angular sensor value (arbitrary address used - make sure no overlap though!)
   TX_POWER_DBM =                        (-70 + 41),
   colorR =                              255,
   colorG =                              255,
@@ -132,7 +152,7 @@
   else {
     canMONITORdoor = true;

-    //read angle sensor vals a couple of times to ensure good readings from analog pin
+    //read angle sensor vals a couple of times to ensure good readings from analog pin
     for (int i = 0; i < 3; i++) {
       AngleVal = analogRead(PIN_ANGLE);
       delay(2);


update

update

--- src/TowerFloodIR/TowerFloodIR.ino
+++ src/TowerFloodIR/TowerFloodIR.ino
@@ -1,6 +1,6 @@
 // Compile for Arduino Pro/Pro Mini 5V 16Mhz with ATMega 328.
 // During compilation, hold down RESET on the mini, and release when "Uploading..."
-// The pinout for the Minis with the rectangular RESET button are flipped, so the programmer will face away from you.
+// Or, pop the board out of the PCB and program that way.

 // need to strike RobotIRRemote directory in Arduino IDE libraries folder.  Name collision!
 #include <IRremote.h> // IR connected to pin 3
@@ -49,8 +49,10 @@
 void setup()
 {
   Serial.begin(115200);
-  Serial << "Startup." << endl;
-
+  Serial << F("Startup.") << endl;
+
+  Serial << F("Clock speed (MHz): ") << F_CPU << endl;
+
   SSerial.begin(9600);
   ET.begin(details(newColorInst), &SSerial);


Added simple benchmark on log.

Added simple benchmark on log.

--- examples/DemoArcRPM/DemoArcRPM.ino
+++ examples/DemoArcRPM/DemoArcRPM.ino
@@ -213,6 +213,11 @@
 		LastRPMLogUpdate += DEMO_RPM_LOG_UPDATE_INTERVAL;
 		Serial.print("RPM: ");
 		Serial.println(DemoRPM);
+		RPMStart = micros();
+		RPMDriver.UpdateRPM(DemoRPM, Now);
+		RPMEnd = micros();
+		//Serial.println(RPMDriver.Debug());
+		Serial.print("Update RPM took: ");
 	}

 	if (Now - LastRPMUpdate > DEMO_RPM_UPDATE_INTERVAL - 1)


Swiping only active in sketches list

Swiping only active in sketches list

Prevents navigation sometimes failing because it detects a swipe.

--- examples/SketchList/SketchList.ino
+++ examples/SketchList/SketchList.ino
@@ -359,7 +359,7 @@
   }

   /* Update last known swipe position and time */
-  swipe_last_pos = touch_y;
+  swipe_last_pos = (touch_x <= (SKETCHES_FULLW+SKETCHES_OFF_X)) ? touch_y : 0xFFFF;
   swipe_last_time = millis();

   /* Handle button presses here */
@@ -1070,4 +1070,4 @@

 uint8_t LCD_isTouched(uint16_t x, uint16_t y, uint8_t w, uint8_t h) {
   return touch_x >= x && touch_y >= y && touch_x < (x + w) && touch_y < (y + h);
-}+}


Gate out pin

Gate out pin

--- examples/cvseq_test/cvseq_test.ino
+++ examples/cvseq_test/cvseq_test.ino
@@ -4,6 +4,7 @@
 #define OUT_PIN_1 6
 #define OUT_PIN_2 5
 #define TEMPO_PIN 2
+#define GATE_PIN 4

 #define OCTAVES 3

@@ -70,6 +71,7 @@
     pinMode(LED_PIN, OUTPUT);
     pinMode(OUT_PIN_1, OUTPUT);
     pinMode(OUT_PIN_2, OUTPUT);
+    pinMode(GATE_PIN, OUTPUT);

     Serial.begin(9600);

@@ -124,7 +126,7 @@
     int val = scale[(idx % scale_size)] + (octave * (idx / scale_size));

     // Quant Secondary
-    int val2= map(seq.getSecondary(), 0, 1023, 0, 24);
+    int val2 = map(seq.getSecondary(), 0, 1023, 0, 24);
     /*
     Serial.println(
         "Step: " + String(seq.getStep()) +
@@ -147,5 +149,26 @@
     // 600 bpm = 100ms
     // 60 to 2400 bpm (exponetial scale)
     int tempo = map(analogRead(TEMPO_PIN), 0, 1023, 33, 5);
-    delay(tempo * tempo);
+    tempo *= tempo;
+
+    if (seq.isDoubleOut()) {
+        // in 2x8 use bottom val for duration %
+        val2 = map(seq.getSecondary(), 0, 1023, 0, 100);
+        // Some tollerance around actual triggers
+        Serial.println("High cycle: " +String(val2)+ " ms: "+ String((val2 / 100.0) * tempo));
+        if (val2 > 5 ){
+            digitalWrite(GATE_PIN, HIGH);
+        }
+        delay((val2 / 100.0) * tempo);
+        if (val2 < 95) {
+            digitalWrite(GATE_PIN, LOW);
+        }
+        delay((1 - (val2 / 100.0)) * tempo);
+    } else {
+        // 50% Duty cycle on gate pin
+        digitalWrite(GATE_PIN, HIGH);
+        delay(.5 * tempo);
+        digitalWrite(GATE_PIN, LOW);
+        delay(.5 * tempo);
+    }
 }


fix: interrupt

fix: interrupt

--- Advanced-Line-follower.ino
+++ Advanced-Line-follower.ino
@@ -24,7 +24,6 @@
 float error=0;
 float previous_error=0, previous_I=0;
 char c;
-//float speedmlp = 0.0;

 void setup() {

@@ -54,7 +53,6 @@

     if(startDrive){
-      //Serial.println("startdrive true");
       sensors.updateError();
       calculate_pid();

@@ -100,9 +98,7 @@
 void calculate_pid()
 {

-    error = (sensors.error);
-    //Serial.print(error);
-
+    error = (sensors.error)
     P = error;
     I = I + error*0.001;
     D = (error - previous_error)/.001;


change serial device

change serial device

--- FastCRC/examples/FastCRC_example.ino
+++ FastCRC/examples/FastCRC_example.ino
@@ -7,7 +7,7 @@
 #include <util/crc16.h>
 #include <FastCRC.h>

-#define Ser Serial1
+#define Ser Serial
 #define BUFSIZE 16384


fixed minor bug in isSame()

fixed minor bug in isSame()

--- tictactoe/tictactoe.ino
+++ tictactoe/tictactoe.ino
@@ -382,16 +382,22 @@

 boolean isSame(int array1[], int array2[]){
   boolean same = true;
-  for (int i=0; i < 9; i++){
-    if (same==false){
-      break;
-    }
-    if (array1[i] == array2[i]){
-      same = true;
-    } else {
-      same = false;
-    }
-  }
+  int size1 = sizeof(array1);
+  int size2 = sizeof(array2);
+    if (size1 == 9 && size2 == 9){
+    for (int i=0; i < 9; i++){
+      if (same==false){
+        break;
+      }
+      if (array1[i] == array2[i]){
+        same = true;
+      } else {
+        same = false;
+      }
+    }
+  } else {
+    same = false;
+  }
   return same;
 }


Final version for turning in.

Final version for turning in.

Fixed a minor bug where magenta did not make a sound and removed the score code since it wasn't tested and integrated.

--- DDR_Neo_Pixel_Strip_Display/DDR_Neo_Pixel_Strip_Display.ino
+++ DDR_Neo_Pixel_Strip_Display/DDR_Neo_Pixel_Strip_Display.ino
@@ -83,8 +83,6 @@

 // game state variables
 int whichSong = 0;
-int score = 0;
-int maximumScore = 0; // increases whenever a new "DanceMove" is created
 bool gameOver;
 // -----------------------------------------------------------------------------
 // End Game Objects, State Variables, and Timers
@@ -250,8 +248,6 @@
 void setupDDR()
 {
   gameOver = false;
-  score = 0;
-  maximumScore = 0;
   initCapacitiveSensor();

   pinMode(PIEZO, OUTPUT);
@@ -277,12 +273,6 @@
   // initialize danceMoveArray
   for (int i = 0; i < MAX_DANCE_MOVES; i++)
      danceMoveArray[i] = NULL;
-}
-
-void displayScore()
-{
-   Serial.print("You beat "); Serial.print(songNames[whichSong]); Serial.println("!");
-   Serial.print("Final Score: "); Serial.print(score); Serial.print(" / "); Serial.println(maximumScore);
 }

 void initCapacitiveSensor()
@@ -318,13 +308,13 @@
 void createDanceMove()
 {
    createDanceMoveTimer = millis();
-
+
    for (int i = 0; i < MAX_DANCE_MOVES; i++)
    {
       if (danceMoveArray[i] == NULL)
       {
          danceMoveArray[i] = new DanceMove(NUM_LEDS, strip, color[(random() % 6)],
-           DANCE_ZONE_LOWER_BOUND, DANCE_ZONE_UPPER_BOUND, maximumScore);
+           DANCE_ZONE_LOWER_BOUND, DANCE_ZONE_UPPER_BOUND);
          break;
       }
    }


Fixes 0 time check. strcmp does not always return 1 when not equal.

--- ArduinoSmartShieldIrrigationController.ino
+++ ArduinoSmartShieldIrrigationController.ino
@@ -169,7 +169,7 @@
     inValue [i] = strtok(NULL, delimiters); //remove remaining substrings as incoming values
     i++;
   }
-  if (strcmp(inValue[0],"on")==0 && strcmp(inValue[2],"0")==1) {   // add new station to queue
+  if (strcmp(inValue[0],"on")==0 && strcmp(inValue[2],"0")!=0) {   // add new station to queue
     int addStation=atoi(inValue[1]);
     queue[addStation]=1;
     stationTime[addStation]=atol(inValue[2])*60L*1000L;
@@ -190,7 +190,7 @@
   if (strcmp(inValue[0],"allOn")==0) {
     int i=1;
     while (i<stations+1) {
-      if (i != trafficCop && (strcmp(inValue[i],"0")==1)) {
+      if (i != trafficCop && (strcmp(inValue[i],"0")!=0)) {
         queue[i]=1;
       }
       stationTime[i]=atoi(inValue[i])*60L*1000L;


fixed bug in display refresh logic.

fixed bug in display refresh logic.

--- Firmware/JBC-Soldering-Controller/_05_display.ino
+++ Firmware/JBC-Soldering-Controller/_05_display.ino
@@ -25,31 +25,33 @@

     display.clearDisplay();
     display.setTextColor(WHITE);
-
+
     display.setTextSize(1);
     display.setCursor(0, 0);
     display.print("Set");
     display.setCursor(64, 0);
     display.print("Deg C");
-
+
     display.setTextSize(2);
     display.setCursor(0, 12);
     display.print((int16_t)params.setpoint);
-
+
     display.setCursor(64, 12);
     display.print(tip_temperature_copy);
-     uint16_t pwm_bar = status.pid_output/7.5;  //scale max PWM value (961) down to 128 pixels. TODO: dont leave this hard coded.
-     display.fillRect(0, 29, pwm_bar, 3, WHITE);
+    uint16_t pwm_bar = status.pid_output / 7.5; //scale max PWM value (961) down to 128 pixels. TODO: dont leave this hard coded.
+    display.fillRect(0, 29, pwm_bar, 3, WHITE);
     //display.print(" ");
     //display.print(ADS1118_INT_TEMP_C(adc_ic_temp_counts_copy));
     //display.setCursor(0, 20);

     //display.print(status.encoder_pos);

-
+
     display.display();
-
-    next_millis += DISPLAY_UPDATE_PERIOD;  //set up our loop to run again in x ms
+    if (!update_now)
+    {
+      next_millis += DISPLAY_UPDATE_PERIOD;  //set up our loop to run again in x ms
+    }
   }
 }


updated LEDs indicator logic with dedicated loop and boolean logic

--- src/analog_sensors_board.ino
+++ src/analog_sensors_board.ino
@@ -46,10 +46,9 @@
 #include <Wire.h>

 #define DELAY_SETUP 250         // setup flashing delay
+#define DELAY_LEDS 500          // led blink rate
 #define DELAY_SLOW 5000         // slow acquisition loop
-//#define DELAY_FAST 250          // fast acquisition loop
-#define DELAY_LEDS 500          // led blink rate
-
+#define DELAY_FAST 250          // fast acquisition loop

 // Nessie LEDs and Water Sensors
 #define LED_GREEN 6
@@ -58,6 +57,7 @@
 #define SW_MOTOR 9
 #define WATER_FWD 10
 #define WATER_AFT 11
+#define BAT_LOW 26.5f

 // Reference voltages (fine tuned):
@@ -132,18 +132,20 @@

 // time & timestamps
-int DELAY_FAST = 250;
-unsigned long time_slow;
+int delay_acs = 250;
+unsigned long time_env;
+unsigned long time_acs;
 unsigned long time_leds;
 unsigned long delta;

 // default inputs
-int status_water_fwd = HIGH;
-int status_water_aft = HIGH;
-int status_sw_motor = LOW;
-int status_led_green = LOW;
-int status_led_yellow = LOW;
-int status_led_red = LOW;
+int status_water_fwd = 0;
+int status_water_aft = 0;
+int status_sw_motor = 0;
+
+boolean status_led_green = false;
+boolean status_led_yellow = false;
+boolean status_led_red = false;

 // the setup routine runs once when you press reset
@@ -154,6 +156,18 @@
     // not ready
     pinMode(LED_PIN, OUTPUT);
     digitalWrite(LED_PIN, LOW);
+
+    // LEDs and INPUTs init
+    pinMode(LED_GREEN, OUTPUT);
+    pinMode(LED_YELLOW, OUTPUT);
+    pinMode(LED_RED, OUTPUT);
+    pinMode(SW_MOTOR, INPUT);
+    pinMode(WATER_FWD, INPUT);
+    pinMode(WATER_AFT, INPUT);
+
+    digitalWrite(LED_GREEN, LOW);
+    digitalWrite(LED_YELLOW, LOW);
+    digitalWrite(LED_RED, LOW);

     // flash the on-board led while waiting for connection
     // while(!Serial) {
@@ -166,33 +180,23 @@
     // switch to precise reference (2.56V)
     analogReference(INTERNAL);

-    // LED and INPUTs init
-    pinMode(LED_GREEN, OUTPUT);
-    pinMode(LED_YELLOW, OUTPUT);
-    pinMode(LED_RED, OUTPUT);
-    pinMode(SW_MOTOR, INPUT);
-    pinMode(WATER_FWD, INPUT);
-    pinMode(WATER_AFT, INPUT);
-
-    for(int i=0; i<4; i++){
-        // LED flash on
-        digitalWrite(LED_GREEN, HIGH);
-        digitalWrite(LED_YELLOW, HIGH);
-        digitalWrite(LED_RED, HIGH);
-
-        delay(1000);
-
-        // LED flash off
-        digitalWrite(LED_GREEN, LOW);
-        digitalWrite(LED_YELLOW, LOW);
-        digitalWrite(LED_RED, LOW);
-    }
+    // initial LEDs flashing
+    digitalWrite(LED_GREEN, HIGH);
+    digitalWrite(LED_YELLOW, HIGH);
+    digitalWrite(LED_RED, HIGH);

     // (reset) protection delay
-    //delay(1000);
+    delay(1000);
+
+    // reset LEDs
+    digitalWrite(LED_GREEN, LOW);
+    digitalWrite(LED_YELLOW, LOW);
+    digitalWrite(LED_RED, LOW);
+

     // enable watchdog
     wdt_enable(WDTO_8S);
+

     // bmp085 init
     Wire.begin();
@@ -203,48 +207,9 @@
     digitalWrite(LED_PIN, HIGH);
 }

-// the loop routine runs over and over again forever:
+
+// the loop routine runs over and over again forever
 void loop() {
-
-    // detect inputs
-    status_water_fwd = digitalRead(WATER_FWD);
-    status_water_aft = digitalRead(WATER_AFT);
-    status_sw_motor = digitalRead(SW_MOTOR);
-
-    if(status_sw_motor == LOW) {
-        status_led_green = 0x01;
-    } else {
-        status_led_green = 0x00;
-    }
-
-    if(true) {
-       status_led_yellow = 0x01;
-    } else {
-       status_led_yellow = 0x00;
-    }
-
-    if(status_water_fwd == HIGH && status_water_aft == HIGH) {
-        status_led_red = 0x01;
-    } else {
-        status_led_red = 0x00;
-    }
-
-    // led slow-loop delta
-    delta = millis() - time_leds;
-
-    if(delta >= DELAY_LEDS) {
-        // led indications
-        digitalWrite(LED_GREEN, status_led_green);
-        digitalWrite(LED_YELLOW, status_led_yellow);
-        digitalWrite(LED_RED, status_led_red);
-
-        // update timestamp
-        time_leds = millis();
-
-        // send indicators report
-        report_indicators();
-    }
-

     // serial control
     if(Serial.available() > 0) {
@@ -252,13 +217,13 @@

         switch(ser) {
             case 'S':
-                DELAY_FAST = 1000;
+                delay_acs = 1000;
                 break;
             case 'N':
-                DELAY_FAST = 500;
+                delay_acs = 500;
                 break;
             case 'F':
-                DELAY_FAST = 250;
+                delay_acs = 250;
                 break;
             case 'R':
                 wdt_disable();
@@ -272,31 +237,75 @@
     }

-    // start acquisition (with double readings to avoid interferences [1])
-    digitalWrite(LED_PIN, HIGH);
-
-    // current sensor
-    raw_acs0 = analogRead(A11);     // J5 (pin 2)
-    raw_acs0 = analogRead(A11);     // J5 (pin 2)
-
-    // signal end of acquisition
-    digitalWrite(LED_PIN, LOW);
-
-    // calculate output is Amps
-    acs0 = (float) (raw_acs0 - ACS715_OFF)  * ACS715_CONV;
-    //acs0 = (float) (ACS_ZERO - raw_acs0) * ACS714_CONV;
-
-    // send current report
-    report_current();
-
-    // acquisition slow-loop delta
-    delta = millis() - time_slow;
+    // detect inputs
+    status_water_fwd = digitalRead(WATER_FWD);
+    status_water_aft = digitalRead(WATER_AFT);
+    status_sw_motor = digitalRead(SW_MOTOR);
+
+    // led indicator loop
+    delta = millis() - time_leds;
+
+    if(delta >= DELAY_LEDS) {
+
+        if(status_sw_motor == LOW) {
+            status_led_green = true;
+        } else {
+            status_led_green = !status_led_green;
+        }
+
+        if(status_water_fwd == HIGH && status_water_aft == HIGH) {
+            status_led_red = true;
+        } else {
+            status_led_red = !status_led_red;
+        }
+
+        if( bat0 > BAT_LOW ) {
+            status_led_yellow = true;
+        } else {
+            status_led_yellow = !status_led_yellow;
+        }
+
+        // led indications
+        digitalWrite(LED_GREEN, status_led_green);
+        digitalWrite(LED_YELLOW, status_led_yellow);
+        digitalWrite(LED_RED, status_led_red);
+
+        // update timestamp
+        time_leds = millis();
+    }
+
+
+    // current sensor loop
+    delta = millis() - time_acs;
+
+    if(delta >= delay_acs) {
+        // start acquisition (with double readings to avoid interferences [1])
+        digitalWrite(LED_PIN, HIGH);
+
+        // current sensor
+        raw_acs0 = analogRead(A11);     // J5 (pin 2)
+        raw_acs0 = analogRead(A11);     // J5 (pin 2)
+
+        // signal end of acquisition
+        digitalWrite(LED_PIN, LOW);
+
+        // calculate output is Amps
+        acs0 = (float) (raw_acs0 - ACS715_OFF)  * ACS715_CONV;
+        //acs0 = (float) (ACS_ZERO - raw_acs0) * ACS714_CONV;
+
+        // send current report
+        report_current();
+
+        // update timestamp
+        time_acs = millis();
+    }
+
+
+    // environmental sensors loop
+    delta = millis() - time_env;

     // limit data rate
-    if( delta < DELAY_SLOW ) {
-        // pause between data acquisition
-        delay(DELAY_FAST);
-    } else {
+    if(delta >= DELAY_SLOW) {
         // analog inputs (battery)
         raw_bat0 = analogRead(A0);      // J4 (pin 1)
         raw_bat0 = analogRead(A0);      // J4 (pin 1)
@@ -368,23 +377,32 @@
         report_humidity();

+        // send indicators report
+        report_indicators();
+
+
         // send timestamp
         Serial.print("$TIME,");
-        Serial.println(time_slow, DEC);
+        Serial.println(time_env, DEC);

         // update timestamp
-        time_slow = millis();
+        time_env = millis();
     }
+

     // reset watchdog
     wdt_reset();
 }

+
 void report_indicators() {
-    Serial.print("$WATER_FWD,");
-    Serial.println(status_water_fwd, DEC);
-    Serial.print("$WATER_AFT,");
+    Serial.print("$WATER,");
+    Serial.print(status_water_fwd, DEC);
+    Serial.print(",");
     Serial.println(status_water_aft, DEC);
+
+    Serial.print("$MOTOR,");
+    Serial.println(status_sw_motor, DEC);

     Serial.print("$LED,");
     Serial.print(status_led_green, DEC);


LED Status and Debug level support

LED Status and Debug level support

--- src/miscr.ino
+++ src/miscr.ino
@@ -37,6 +37,8 @@
 #define FAN_PIN            9

 #define BUZZ_PIN           31
+#define STATUS_RED         35
+#define STATUS_GRN         33
 #define MAX_TEMP           200 // Maximum temperature in celcius

 #define PS_ON_PIN          12
@@ -76,11 +78,26 @@
 // Constructor for the updateLCD() function
 int updateLCD();

+// Sets the global debug level
+int debugLevel = 0;
+
 class TimeControl {
  public:
   bool pause; // Whether the machine is paused or not
   unsigned long pausetime; // Stamp for when the machine has been paused
   unsigned int increment; // How long it should wait for
+  void status(int statcode) {
+    dw(STATUS_GRN, LOW);
+    dw(STATUS_RED, LOW);
+    if(statcode == 0)
+      dw(STATUS_GRN, HIGH);
+    else if(statcode == 1)
+      dw(STATUS_RED, HIGH);
+    else {
+      dw(STATUS_RED, HIGH);
+      dw(STATUS_GRN, HIGH);
+    }
+  }
   TimeControl() {
     pause = false;
     pausetime = -1;
@@ -113,7 +130,7 @@
  */
 class Command {
  public:
-  float times; // TODO double data type for half-steps
+  float times;
   Command() {
     times = 0;
   }
@@ -196,9 +213,11 @@
   void msg(int status, String info) {
     getStatus(status);
     //Serial.print(" L000");
-    Serial.print(" // ");
-    Serial.println(info);
-    //Serial.println("");
+    if(debugLevel > 0) {
+      Serial.print(" // ");
+      Serial.println(info);
+    } else
+      Serial.println("");
   }
   void pos(int status, String info) {
     getStatus(status);
@@ -210,8 +229,11 @@
     Serial.print(" Z: ");
     Serial.print(globalPos.z);
     Serial.print(" E: N/A");
-    Serial.print(" // ");
-    Serial.println(info);
+    if(debugLevel > 0) {
+      Serial.print(" // ");
+      Serial.println(info);
+    } else
+      Serial.println("");
     //Serial.println("");
   }
   void tmp(int status) {
@@ -306,7 +328,7 @@
 };

 // Initialise LCD
-LiquidCrystal lcd(16, 17, 23, 25, 27, 29);
+LiquidCrystal lcd(16, 17, 29, 27, 25, 23);

 // Initialise Steppers
@@ -491,7 +513,7 @@
         globalDelay.val = calc3DFeedrate(findex, xindex, yindex, zindex);
       } else if(xindex == INT_MIN && yindex == INT_MIN && zindex == INT_MIN) {
         // TODO Permanently replace globalDelay default value
-        // globalDelay.defaultVal = findex;
+        globalDelay.defaultVal = findex;
       } else {
         out.msg(1, "Invalid Syntax for Feedrate Parameter");
         return false;
@@ -509,6 +531,8 @@

     return true;
   } else if(gindex == 28) {
+    time.status(2);
+
     int xindex = in.indexOf("X");
     int yindex = in.indexOf("Y");
     int zindex = in.indexOf("Z");
@@ -676,6 +700,17 @@
     // Fan off
     temperature.operation = false;
     return true;
+  } else if(mindex == 111) {
+    in = trim(in);
+    int sindex = getIndex('S', in);
+    if(sindex != INT_MIN)
+      debugLevel = sindex;
+    else {
+      out.msg(1, "No debug level specified");
+      return false;
+    }
+
+    return true;
   }

   out.msg(1, "Incorrect/Unsupported G-Code entered");
@@ -698,10 +733,12 @@
  */
 int getSerialInput() {
   if(Serial.available() > 0) {
+    time.status(0);
     serialStr = Serial.readString();
     serialStr.trim();
     if(Serial.read() == -1) {
-      Serial.println(serialStr); // debug
+      if(debugLevel > 1)
+        Serial.println(serialStr); // debug
       if(serialStr == "?") {
         printSupportedCommands();
         return 0;
@@ -710,6 +747,8 @@
       if(parseGCode(serialStr))
         out.msg(0);
     }
+  } else {
+    time.status(1);
   }
   return 0;
 }
@@ -799,6 +838,10 @@

   // Initialise fan
   pm(FAN_PIN, OUTPUT);
+
+  // Initialise LED status
+  pm(STATUS_GRN, OUTPUT);
+  pm(STATUS_RED, OUTPUT);

   // Initialise motors
   sX.begin();


arduino: add presence sensor + buzzer on presence.

--- arduino/home_sensors/home_sensors.ino
+++ arduino/home_sensors/home_sensors.ino
@@ -3,10 +3,17 @@

 // We'll put the mcp on the PIN 0 if the arduino.
 int MCP9701_ARDUINO_PIN = 0;
+// Light sensor
 int LIGHT_PIN = 1;
+// Presence sensor
+int PIR_PIN = 2;
+
+// Set to false to not bip on presence
+bool bip = true;

 // Debug through the serial at 9600baud
 void setup() {
+    pinMode(9, OUTPUT);
     Serial.begin(9600);
     Serial.println("Initiating sensors loop.");
 }
@@ -23,9 +30,25 @@
         delay(200);
     }

+    bool pir = readPir();
+
     // Print the output on the serial.
     Serial.print("Temp: "); Serial.print(resTemp/5.0f); Serial.println(" C");
     Serial.print("Light: "); Serial.print(resLight/5.0f); Serial.println(" %");
+    Serial.print("PIR: "); Serial.print(pir ? "Yes" : "No"); Serial.println();
+
+    if (bip && pir) {
+        analogWrite(9, 20);
+        delay(50);
+        analogWrite(9, 0);
+    }
+}
+
+bool readPir() {
+    if (analogRead(PIR_PIN) > 500) {
+        return true;
+    }
+    return false;
 }

 float readLight() {


Update AWSCPumpTiming.ino

Update AWSCPumpTiming.ino

--- AWSCPumpTiming/AWSCPumpTiming.ino
+++ AWSCPumpTiming/AWSCPumpTiming.ino
@@ -10,8 +10,8 @@
 //Edit these times below to change factors
 unsigned long PumpInterval= 60000 *240;//How often in min
 unsigned long AirInterval= 60000 *15;//How often in min
-unsigned long PumpRunTime = 60000 *.3;//How Long in min
-unsigned long AirRunTime = 60000 *1;//How Long in min
+unsigned long PumpRunTime = 60000 *.4;//How Long in min
+unsigned long AirRunTime = 60000 *3;//How Long in min

 void setup() {
 pinMode(Pump, OUTPUT);


back to blue... red failed

back to blue... red failed

--- Scripts/fourelevenseventeen.ino
+++ Scripts/fourelevenseventeen.ino
@@ -50,38 +50,38 @@
  void loop() {

     if (timeOut+15700 < millis()) {        // idle state - 'breathe' the top and bottom LED to show program is looping
-       uint32_t red = (breathe, 0, 0);
+       uint32_t blue = (0, 0, breathe);
        breathe = breathe + change;
-       strip.setPixelColor(0, red);
-       strip.setPixelColor(27, red);
-       strip.setPixelColor(28, red);
-       strip.setPixelColor(57, red);
-       strip.setPixelColor(58, red);
-       strip.setPixelColor(87, red);
-       strip.setPixelColor(88, red);
-       strip.setPixelColor(117, red);
-       strip.setPixelColor(118, red);
-       strip.setPixelColor(147, red);
-       strip.setPixelColor(148, red);
-       strip.setPixelColor(177, red);
-       strip.setPixelColor(178, red);
-       strip.setPixelColor(207, red);
-       strip.setPixelColor(208, red);
-       strip.setPixelColor(237, red);
-       strip.setPixelColor(238, red);
-       strip.setPixelColor(267, red);
-       strip.setPixelColor(268, red);
-       strip.setPixelColor(297, red);
-       strip.setPixelColor(298, red);
-       strip.setPixelColor(327, red);
-       strip.setPixelColor(328, red);
-       strip.setPixelColor(357, red);
-       strip.setPixelColor(358, red);
-       strip.setPixelColor(387, red);
-       strip.setPixelColor(388, red);
-       strip.setPixelColor(417, red);
-       strip.setPixelColor(418, red);
-       strip.setPixelColor(446, red);
+       strip.setPixelColor(0, blue);
+       strip.setPixelColor(27, blue);
+       strip.setPixelColor(28, blue);
+       strip.setPixelColor(57, blue);
+       strip.setPixelColor(58, blue);
+       strip.setPixelColor(87, blue);
+       strip.setPixelColor(88, blue);
+       strip.setPixelColor(117, blue);
+       strip.setPixelColor(118, blue);
+       strip.setPixelColor(147, blue);
+       strip.setPixelColor(148, blue);
+       strip.setPixelColor(177, blue);
+       strip.setPixelColor(178, blue);
+       strip.setPixelColor(207, blue);
+       strip.setPixelColor(208, blue);
+       strip.setPixelColor(237, blue);
+       strip.setPixelColor(238, blue);
+       strip.setPixelColor(267, blue);
+       strip.setPixelColor(268, blue);
+       strip.setPixelColor(297, blue);
+       strip.setPixelColor(298, blue);
+       strip.setPixelColor(327, blue);
+       strip.setPixelColor(328, blue);
+       strip.setPixelColor(357, blue);
+       strip.setPixelColor(358, blue);
+       strip.setPixelColor(387, blue);
+       strip.setPixelColor(388, blue);
+       strip.setPixelColor(417, blue);
+       strip.setPixelColor(418, blue);
+       strip.setPixelColor(446, blue);
        strip.show();
        if (breathe == 100 || breathe == 0) change = -change;      // breathe the LED from 0 = off to 100 = fairly bright
        if (breathe == 100 || breathe == 0); delay (100);           // Pause at beginning and end of each breath


CarpetLedLogic.ino fixes

CarpetLedLogic.ino fixes

Moved array definitions into statics so they don't take up memory when
they aren't used.

--- CarpetLedLogic/CarpetLedLogic.ino
+++ CarpetLedLogic/CarpetLedLogic.ino
@@ -19,20 +19,21 @@
 #define RGB_DATA_PIN 7 // 6
 #define RGBW_DATA_PIN 6 // 7

-// TODO: wrap all of these in a class that represents the whole carpet
-CRGB dmxleds[NUM_DMX_LEDS];
-CRGB rgbleds[NUM_RGB_LEDS];
-
-struct CRGBW rgbwleds[NUM_RGBW_LEDS];
-CRGB convertedrgbwleds[NUM_THEORETICAL_RGBW_LEDS];
+// rope demo arrays
+CRGBW * rgbwleds;
+CRGB * convertedrgbwleds;

 void robeDemoSetup() {
-  // this needs to be passed the raw led array, we'll handle to conversion elsewhere
-  FastLED.addLeds<NEOPIXEL, RGBW_DATA_PIN>( convertedrgbwleds, NUM_THEORETICAL_RGBW_LEDS);
-  for ( int i = 0; i < NUM_RGBW_LEDS; ++i ) {
-    rgbwleds[i] = CRGB::Red;
-  }
-  FastLED.show();
+   static CRGBW rgbw[NUM_RGBW_LEDS];
+   static CRGB convrgbw[NUM_THEORETICAL_RGBW_LEDS];
+   rgbwleds = rgbw;
+   convertedrgbwleds = convrgbw;
+   // this needs to be passed the raw led array, we'll handle to conversion elsewhere
+   FastLED.addLeds<NEOPIXEL, RGBW_DATA_PIN>( convertedrgbwleds, NUM_THEORETICAL_RGBW_LEDS);
+   for ( int i = 0; i < NUM_RGBW_LEDS; ++i ) {
+     rgbwleds[i] = CRGB::Red;
+   }
+   FastLED.show();
 }

 void robeDemo() {
@@ -71,10 +72,6 @@
 }

 void setup() {
-   // FastLED.addLeds<DMXSIMPLE, DMX_DATA_PIN, RGB>(dmxleds, NUM_DMX_LEDS);
-   // FastLED.addLeds<NEOPIXEL, RGB_DATA_PIN>(rgbleds, NUM_RGB_LEDS);
-   // covertCRGBWArrayToCRGBArray( rgbwleds, convertedrgbwleds, NUM_RGBW_LEDS, NUM_THEORETICAL_RGBW_LEDS );
-
    // dmxSetup();
    robeDemoSetup();
 }


Fixed incorrect type in test.ino

Fixed incorrect type in test.ino

--- test/test.ino
+++ test/test.ino
@@ -149,7 +149,7 @@
 static void testParseHex()
 {
   Serial.println("parseHexByte");
-  uint8_t token[2];
+  char token[2];
   memset(token, '0', sizeof(2));
   uint8_t result = 0;


Add LED functionality to breadboard

Add LED functionality to breadboard

LED pin numbers have changed, as well as their mode.

--- Arduino_Code/Arduino_Code.ino
+++ Arduino_Code/Arduino_Code.ino
@@ -5,7 +5,7 @@
   const int btn3 = 8;
   const int led0 = 5;
   const int led1 = 3;
-  const int led2 = 9;
+  const int led2 = 4;
   const int led3 = 10;

  int btn[] = {btn0, btn1, btn2, btn3};
@@ -17,10 +17,10 @@
  pinMode(btn1, INPUT);
  pinMode(btn2, INPUT);
  pinMode(btn3, INPUT);
- pinMode(led0, INPUT);
- pinMode(led1, INPUT);
- pinMode(led2, INPUT);
- pinMode(led3, INPUT);
+ pinMode(led0, OUTPUT);
+ pinMode(led1, OUTPUT);
+ pinMode(led2, OUTPUT);
+ pinMode(led3, OUTPUT);

  Serial.println("Starting Program");

@@ -29,14 +29,21 @@
 void loop() {
   // put your main code here, to run repeatedly:
   for (int i = 0; i < 4; i ++) {
-    //if (digitalRead(btn[i] == HIGH)) {
-    //  digitalWrite(led[i], HIGH);
-    //}
-    //else {
+    if (digitalRead(btn[i]) == 1) {
+      digitalWrite(led[i], HIGH);
+      Serial.print("LED ");
+      Serial.print(i);
+      Serial.print(" on    ");
+    }
+    else {
       digitalWrite(led[i], LOW);
-    //}
+      Serial.print("LED ");
+      Serial.print(i);
+      Serial.print(" off    ");
+    }

   }
+  Serial.println(" ");
   Serial.print("Button0: ");
   Serial.print(digitalRead(btn0));
   Serial.print("   Button1: ");


Delete adxl345multi.ino

Delete adxl345multi.ino

--- src/adxl345multi.ino
+++ src/adxl345multi.ino
@@ -1,180 +0,0 @@
-#include "math.h";        // include math library for square root function
-#define Addr 0x53         // ADXL345 I2C address is 0x53(83)
-#define GScaling 0.003901 // 3.9mG per bit A2D Scaling
-#define A2DRES 8192       // 2^13 = 8192
-#define HALFSCALE 4095    // (2^13)/2 - 1
-
-int x0data[32], x1data[32], y0data[32], y1data[32], z0data[32], z1data[32];
-int xdata[32], ydata[32], zdata[32];
-int xos, yos, zos;
-int xavg, yavg, zavg;
-double Adata[8];
-
-int configAcc(String command);  // function declaration for calibration
-
-void setup()
-{
-  // Declare particle variables and function
-  Particle.variable("i2cdevice","ADXL345");
-  Particle.variable("xAvg",xavg);
-  Particle.variable("yAvg",yavg);
-  Particle.variable("ZAvg",zavg);
-  Particle.function("AccSetup", configAcc);
-
-  Wire.begin();                 // Initialise I2C communication as MASTER
-  Serial.begin(38400);          // set baud rate
-
-  Wire.beginTransmission(Addr);
-  Wire.write(0x2D);             // Select power control register
-  Wire.write(0x08);             // disable auto sleep
-  Wire.endTransmission();
-
-  Wire.beginTransmission(Addr);
-  Wire.write(0x31);             // Select data format register
-  Wire.write(0b00001011);       // Select full resolution, +/-16g
-  Wire.endTransmission();
-
-  delay(100);
-}
-
-void loop()
-{
-  for(int f = 0; f < 8; f++)      // step through 8 frequencies starting with ODR = 25Hz
-  {
-    Wire.beginTransmission(Addr); // Start I2C Transmission
-    Wire.write(0x2C);             // Select bandwidth rate register
-    Wire.write(8 + f);            // 25, 50, 100, 200, 400, 800, 1.6k, 3.2k
-    Wire.write(0x38);             // Set FIFO Control register
-    Wire.write(0b01011111);       // FIFO mode
-    Wire.endTransmission();
-    delay(100);
-
-    for(int i = 0; i < 32; i++)       // Read all 32 values from FIFO
-    {
-      Wire.beginTransmission(Addr);
-      Wire.write(0x32);               // Point to the DATAX0 register
-      Wire.requestFrom(Addr,6);       // request 6 bytes of data (X0 - Z1)
-      while(Wire.available())
-      {
-        x0data[i] = Wire.read();      // put x,y,z data into arrays
-        x1data[i] = Wire.read();
-        y0data[i] = Wire.read();
-        y1data[i] = Wire.read();
-        z0data[i] = Wire.read();
-        z1data[i] = Wire.read();
-      }
-      Wire.endTransmission();
-    }
-
-    for (int i=1; i<32; i++)    // read all 32 values from arrays to calculate amplitude
-    {
-      xdata[i] = ((x1data[i]) & 0x1F)<<8 | (x0data[i] & 0xFF);    // combine 5 MSB and 8 LSB into one variable
-      ydata[i] = ((y1data[i]) & 0x1F)<<8 | (y0data[i] & 0xFF);
-      zdata[i] = ((z1data[i]) & 0x1F)<<8 | (z0data[i] & 0xFF);
-
-      if (xdata[i]>HALFSCALE) xdata[i] -= A2DRES;  // convert to signed value
-      if (ydata[i]>HALFSCALE) ydata[i] -= A2DRES;  // convert to signed value
-      if (zdata[i]>HALFSCALE) zdata[i] -= A2DRES;  // convert to signed value
-
-      xdata[i] -= xos;                             // subtract offset
-      ydata[i] -= yos;
-      zdata[i] -= zos;
-
-// calculate amplitude by summing the squares, divide vectors by 100 to keep number manageable
-      Adata[f] += (xdata[i]*xdata[i])/100 + (ydata[i]*ydata[i])/100 + (zdata[i]*zdata[i])/100;
-      xavg += xdata[i];     // add samples for average, this is only useful for calibrating system at rest
-      yavg += ydata[i];
-      zavg += zdata[i];
-    }
-    Adata[f] = sqrt(Adata[f]);  // take the squareroot of the sume of the squares
-    xavg = xavg>>5;             // divide by 32 to get averages for offset
-    yavg = yavg>>5;
-    zavg = zavg>>5;
-  }
-  String devID = System.deviceID();
-
-// publish 8 A(f) values in json format
-  Particle.publish("Adata", "{ \"f1\": \"" + String(Adata[0]) + "\"," +
-   "\"f2\": \"" + String(Adata[1]) + "\"," +
-   "\"f3\": \"" + String(Adata[2]) + "\"," +
-   "\"f4\": \"" + String(Adata[3]) + "\"," +
-   "\"f5\": \"" + String(Adata[4]) + "\"," +
-   "\"f6\": \"" + String(Adata[5]) + "\"," +
-   "\"f7\": \"" + String(Adata[6]) + "\"," +
-   "\"f8\": \"" + String(Adata[7]) + "\" }", PRIVATE);
-
-   String xvalues = String(String(xdata[1]) +
-    ", " + String(xdata[2]) + ", " + String(xdata[3]) +
-    ", " + String(xdata[4]) + ", " + String(xdata[5]) +
-    ", " + String(xdata[6]) + ", " + String(xdata[7]) +
-    ", " + String(xdata[8]) + ", " + String(xdata[9]) +
-    ", " + String(xdata[10]) + ", " + String(xdata[11]) +
-    ", " + String(xdata[12]) + ", " + String(xdata[13]) +
-    ", " + String(xdata[14]) + ", " + String(xdata[15]) +
-    ", " + String(xdata[16]) + ", " + String(xdata[17]) +
-    ", " + String(xdata[18]) + ", " + String(xdata[19]) +
-    ", " + String(xdata[20]) + ", " + String(xdata[21]) +
-    ", " + String(xdata[22]) + ", " + String(xdata[23]) +
-    ", " + String(xdata[24]) + ", " + String(xdata[25]) +
-    ", " + String(xdata[26]) + ", " + String(xdata[27]) +
-    ", " + String(xdata[28]) + ", " + String(xdata[29]) +
-    ", " + String(xdata[30]) + ", " + String(xdata[31]));
-   Particle.publish("xvalues:", xvalues);
-
-   String yvalues = String(String(ydata[1]) +
-    ", " + String(ydata[2]) + ", " + String(ydata[3]) +
-    ", " + String(ydata[4]) + ", " + String(ydata[5]) +
-    ", " + String(ydata[6]) + ", " + String(ydata[7]) +
-    ", " + String(ydata[8]) + ", " + String(ydata[9]) +
-    ", " + String(ydata[10]) + ", " + String(ydata[11]) +
-    ", " + String(ydata[12]) + ", " + String(ydata[13]) +
-    ", " + String(ydata[14]) + ", " + String(ydata[15]) +
-    ", " + String(ydata[16]) + ", " + String(ydata[17]) +
-    ", " + String(ydata[18]) + ", " + String(ydata[19]) +
-    ", " + String(ydata[20]) + ", " + String(ydata[21]) +
-    ", " + String(ydata[22]) + ", " + String(ydata[23]) +
-    ", " + String(ydata[24]) + ", " + String(ydata[25]) +
-    ", " + String(ydata[26]) + ", " + String(ydata[27]) +
-    ", " + String(ydata[28]) + ", " + String(ydata[29]) +
-    ", " + String(ydata[30]) + ", " + String(ydata[31]));
-   Particle.publish("yvalues:", yvalues);
-
-   String zvalues = String(String(zdata[1]) +
-    ", " + String(zdata[2]) + ", " + String(zdata[3]) +
-    ", " + String(zdata[4]) + ", " + String(zdata[5]) +
-    ", " + String(zdata[6]) + ", " + String(zdata[7]) +
-    ", " + String(zdata[8]) + ", " + String(zdata[9]) +
-    ", " + String(zdata[10]) + ", " + String(zdata[11]) +
-    ", " + String(zdata[12]) + ", " + String(zdata[13]) +
-    ", " + String(zdata[14]) + ", " + String(zdata[15]) +
-    ", " + String(zdata[16]) + ", " + String(zdata[17]) +
-    ", " + String(zdata[18]) + ", " + String(zdata[19]) +
-    ", " + String(zdata[20]) + ", " + String(zdata[21]) +
-    ", " + String(zdata[22]) + ", " + String(zdata[23]) +
-    ", " + String(zdata[24]) + ", " + String(zdata[25]) +
-    ", " + String(zdata[26]) + ", " + String(zdata[27]) +
-    ", " + String(zdata[28]) + ", " + String(zdata[29]) +
-    ", " + String(zdata[30]) + ", " + String(zdata[31]));
-   Particle.publish("zvalues:", zvalues);
-
-  delay(60000);                     // wait 1 minute
-}
-
-int configAcc(String command)       // Particle function for accelerometer calibration
-{
-    if (command == "calibrate")     // if function call = calibrate, then offsets = averages
-    {
-      xos = xavg;
-      yos = yavg;
-      zos = zavg;
-      return 1;
-    }
-    else if (command == "reset")    // if function call = reset, then offsets = 0
-    {
-      xos = 0;
-      yos = 0;
-      zos = 0;
-      return 0;
-    }
-    else return -1;
-}


changed comments, removed comments...

changed comments, removed comments...

Signed-off-by: lolportal <1888343070d06eb06df67f855bc7a1b14a557af6@gmail.com>

--- Connection_controller/i2c.ino
+++ Connection_controller/i2c.ino
@@ -16,7 +16,7 @@
   IMU.PrintErrors=false;
 }

-void i2c_init(byte address) //присоединяемся к шине I2C с адресом address
+void i2c_init(const byte address) //присоединяемся к шине I2C с адресом address
 {
   Serial.println("\nConnection Controller!");
   Wire.begin(address);
@@ -55,17 +55,9 @@
 // ============= ОБРАБОТЧИК ГЛАВНОГО ПРЕРЫВАНИЯ ===============
 void main_interrupt()
 {
-  //long int start = millis();
-
-
-
-  //digitalWrite(DEBUG_PIN,HIGH);
   interrupts(); //разрешаем обработку других прерываний (Serial,i2c) внутри главного прерывания

   packet_request_and_reading(fromDepthSensorPacket,DEPTH_ADDRESS,FROM_DEPTH_SENSOR_DATA_SIZE,depthOutDebug);
-
-  //noInterrupts();
-

   parse_depth(); //Считываем значения глубины и скорости погружения в переменные feedbackDepth и feeedbackDepthSpeed, для комплексирования

@@ -74,12 +66,13 @@
   to_hor_vma_packet_making();
   to_ver_vma_packet_making();
   to_servocont_packet_making();
+  // Здесь был загадочный баг, когда 3 последних элемента массива toServocontPacket надо было заполнять вручную, а не внутри функции
+  // иначе не работало
   toServocontPacket[TO_SERV_ROT_TOOL_LEFT] = control[con_ROTATION_TOOL_L];
   toServocontPacket[TO_SERV_ROT_TOOL_RIGHT] = control[con_ROTATION_TOOL_R];
   toServocontPacket[TO_SERVOCONT_DATA_SIZE] = checksum_calc(toServocontPacket,TO_SERVOCONT_DATA_SIZE);
   to_depth_packet_making();

-//interrupts();
   packet_sending(HORVMA_ADDRESS,toHorVmaPacket,TO_HORVMA_DATA_SIZE);
   packet_sending(VERVMA_ADDRESS,toVerVmaPacket,TO_VERVMA_DATA_SIZE);
   packet_sending(SERVOCONT_ADDRESS,toServocontPacket,TO_SERVOCONT_DATA_SIZE);
@@ -89,7 +82,7 @@
   switch (slavePollCount)
   {
   case 3:
-    slavePollCount=0; //здесь не нужен Break !!!
+    slavePollCount=0; //здесь не нужен break, т.е. при переполнении slavePollCount - начинаем заново

   case 0:
     packet_request_and_reading(fromHorVmaPacket,HORVMA_ADDRESS,FROM_HORVMA_DATA_SIZE,horDebug);
@@ -108,23 +101,17 @@
     break;
   }

-//to_hor_vma_packet_making();
-//  to_ver_vma_packet_making();
-//  to_servocont_packet_making();
-//  to_depth_packet_making();
-//
+
   leakage = map(constrain(LEAK_THRESHOLD - analogRead(LEAK_PIN),0,LEAK_THRESHOLD),0,LEAK_THRESHOLD,0,255);

   report_making();

-
-  read_register(8);  //Yaw, Pitch, Roll
+// опрашиваем датчик положения
+  read_register(8);  // Yaw, Pitch, Roll
   read_register(19);  // Angular rates
   read_register(18);  // Accelerations

-
-
-
+// выводим сообщения отладочные сообщения, если требуется
   if (outDebug)
   {
     if (verDebug)
@@ -151,12 +138,8 @@
       packet_printing(toDepthSensorPacket,TO_DEPTH_SENSOR_DATA_SIZE);
     }
   }
-
-
-
-
-
-  if (IMU.NewYPR)
+  // если пришли данные с датчика положения, то выводим их, если требуется
+  if (IMU.NewYPR)	// данные об углах
   {
     if (yprDebug)
     {
@@ -175,7 +158,7 @@
     }
   }

-  if (IMU.NewAng)
+  if (IMU.NewAng)	// данные об угловых скоростях
   {
     if (gyroDebug)
     {
@@ -194,7 +177,7 @@
     }
   }

-  if (IMU.NewAccel)
+  if (IMU.NewAccel)	// данные об ускорениях
   {
     if (accelDebug)
     {
@@ -217,7 +200,7 @@

-  if (      depthInputDebug )
+  if ( depthInputDebug )
   {

     Serial.print("\nDepth: ");
@@ -228,9 +211,8 @@

   slavePollCount++;

-  //Serial.println(leakage,DEC);
   digitalWrite(DEBUG_PIN,LOW);
-  //Serial.println(millis()-start);
+
 }


added current sensor

added current sensor

--- ardesp/waterelf/waterelf.ino
+++ ardesp/waterelf/waterelf.ino
@@ -1030,21 +1030,23 @@
   return;
 }
 void getAnalog(float* a) {
-  dbg(analogDBG, "getAnalog: ");
+  dbg(analogDBG, "getAnalog\n");

   if(! GOT_ANALOG_SENSOR) {
     (*a) = 0.0;
   } else if(analogSensor == "analog_mains") {
-    (*a) = (float) emon1.calcIrms(1480);
+    (*a) = (float) ( emon1.calcIrms(1480) / 10 /*fudge!*/ );
+    dbg(analogDBG, "mains reading is ");
+    dbg(analogDBG, (*a)); dbg(analogDBG, "\n");
   } else if(analogSensor == "analog_pressure") {
     int analogValue = analogRead(A0);

     // conversion/"calibration" because sensor 4.5v=1.2MPa
     (*a) = (analogValue - 25) * .19;

-    dbg(analogDBG, "Value: ");
+    dbg(analogDBG, "value: ");
     dbg(analogDBG, analogValue);
-    dbg(analogDBG, "    Pressure: ");
+    dbg(analogDBG, "    pressure: ");
     dbg(analogDBG, (*a));
     dbg(analogDBG, " PSI\n");
   }


Updated description

Updated description

 It reads the state of a potentiometer (an analog input) and turns on an LED
 only if the LED goes above a certain threshold level. It prints the analog value
 regardless of the level.

updated to

 It reads the state of a potentiometer (an analog input) and turns on an LED
 only if the potentiometer goes above a certain threshold level. It prints the analog value
 regardless of the level.

--- build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino
+++ build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino
@@ -3,7 +3,7 @@

  This example demonstrates the use of if() statements.
  It reads the state of a potentiometer (an analog input) and turns on an LED
- only if the LED goes above a certain threshold level. It prints the analog value
+ only if the potentiometer goes above a certain threshold level. It prints the analog value
  regardless of the level.

  The circuit:


Code cosmetics

Code cosmetics

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -12,14 +12,14 @@
 #define WIFI_SSID "ssid"
 #define WIFI_KEY "wpakey"

-//#define USE_XS1_SERVER
+#define USE_XS1_SERVER
 #define XS1_IP (10, 11, 10, 18)
 #define XS1_URL "/control?callback=cname&cmd=set_state_sensor&number=9&value="
 #define XS1_TIMEFRAME 2

 // Uncomment these lines if you wish to use the the free strombewusstsein Web Service!
 #define USE_STROMBEWUSST_SERVER
-#define STROMBEWUSST_SERVER (188, 40, 78, 147)
+#define STROMBEWUSST_IP (188, 40, 78, 147)
 #define STROMBEWUSST_PORT 8888
 #define STROMBEWUSST_KEY {49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54};

@@ -35,22 +35,27 @@
 #define SERVER_PORT 80
 // *************************************

+#ifdef LOCAL
+  #define XS1_IP (192, 168, 178, 21)
+  #define STROMBEWUSST_IP (192, 168, 178, 21)
+#endif
+
 // Dynamic inclusion taking place

 #if defined(ARDUINO) && ARDUINO > 18
   #include <SPI.h>
 #endif

-#if defined(USE_ETHERNET_SHIELD)
+#ifdef USE_ETHERNET_SHIELD
   #include <Ethernet.h>
-  #if defined(USE_STROMBEWUSST_SERVER)
+  #ifdef USE_STROMBEWUSST_SERVER
     #include <EthernetUdp.h>
   #endif
 #endif

-#if defined(USE_WIFI_SHIELD)
+#ifdef USE_WIFI_SHIELD
   #include <WiFi.h>
-  #if defined(USE_STROMBEWUSST_SERVER)
+  #ifdef USE_STROMBEWUSST_SERVER
     #include <WiFiUdp.h>
   #endif
 #endif
@@ -64,7 +69,7 @@
   EthernetClient client;
   EthernetClient connection;
   EthernetServer server = EthernetServer(SERVER_PORT);
-  #if defined(USE_STROMBEWUSST_SERVER)
+  #ifdef USE_STROMBEWUSST_SERVER
     EthernetUDP udp;
   #endif
   byte ethernetMac[] = ETHERNET_MAC;
@@ -76,7 +81,7 @@
   WiFiClient connection;
   WiFiServer server = WiFiServer(SERVER_PORT);
   int connectionStatus = WL_IDLE_STATUS;
-  #if defined(USE_STROMBEWUSST_SERVER)
+  #ifdef USE_STROMBEWUSST_SERVER
     WiFiUDP udp;
   #endif
 #endif
@@ -89,7 +94,7 @@
 #ifdef USE_STROMBEWUSST_SERVER
   // UDP Format: <16xkey><1xtimeframe><1xticks>
   byte udpBuffer[18] = STROMBEWUSST_KEY;
-  IPAddress strombewusstIP STROMBEWUSST_SERVER;
+  IPAddress strombewusstIP STROMBEWUSST_IP;
 #endif

 // stores the # of bytes needed to store the information
@@ -213,8 +218,8 @@
         connection.println("Connection: close");
         connection.println();

-        connection.println("Angelegte Last: ");
-        connection.print(calculateWatt(1));
+        connection.print("Angelegte Last: ");
+        connection.println(calculateWatt(1));

       } else if (header.startsWith("GET /json"))
       {


Added some new features

Added some new features

--- examples/LCDKeyPadShieldAndRadioTEA5767Demo/LCDKeyPadShieldAndRadioTEA5767Demo.ino
+++ examples/LCDKeyPadShieldAndRadioTEA5767Demo/LCDKeyPadShieldAndRadioTEA5767Demo.ino
@@ -51,11 +51,12 @@

 char menu[MENU_DEPTH][MENU_LINES][MENU_TEXT] = {
                        {{" Mute"}, {" Search"}, {" Fine search"}, {" Register statn"}, {" Configuration"}, {" Stand by"}, {" Load deflt stn"}, {" Exit"}},
-                       {{" Search level"}, {" Backlit inten."}, {"Exit"}},
+                       {{" Search level"}, {" Backlit inten."}, {" Exit"}},
                        {{" Low"}, {" Medium"}, {" High"}, {"Exit"}}
                       };

 byte searchLevel;
+byte backlightIntensity;

 void loadDefaultStations() {
   for (int i=0 ; i < 16 ; i++) {
@@ -75,6 +76,15 @@
   return btnNONE;
 }

+byte findSelectedStationIndex(float station) {
+  for (int i = 0 ; i < 16 ; i++) {
+    if (stations[i] == station) {
+      return i;
+    }
+  }
+  return 0;
+}
+
 void loadStation() {
   byte intStation, floatStation;
   float station;
@@ -82,12 +92,16 @@
   intStation = EEPROM.read(0);
   floatStation = EEPROM.read(1);

+  radio.mute();
   if (intStation != 0xFF) {
     station = (intStation * 1.0) +  (floatStation * .1);
     radio.selectFrequency(station);
+    printSelectedFrequency(radio.readFrequencyInMHz());
+    stationIndex = findSelectedStationIndex(station);
   } else {
     radio.selectFrequency(stations[stationIndex]);
   }
+  radio.turnTheSoundBackOn();
 }

 void loadSearchLevel() {
@@ -111,10 +125,16 @@
   }
 }

+void loadBacklightIntensity() {
+  backlightIntensity = EEPROM.read(3);
+  analogWrite(backLightPin, backlightIntensity);
+}
+
 void loadConfiguration() {
-  //loadStation();
   loadDefaultStations();
+  loadStation();
   loadSearchLevel();
+  loadBacklightIntensity();
 }

 void saveStation(float station) {
@@ -157,11 +177,6 @@

   // Loads configuration
   loadConfiguration();
-  radio.selectFrequency(stations[0]);
-  //delay(2000);
-  printSelectedFrequency(radio.readFrequencyInMHz());
-  //radio.setSearchMidStopLevel();
-  //radio.selectFrequency(102.1);

   //From application_note_tea5767-8.pdf, limit the amount of noise energy.
   radio.setSoftMuteOn();
@@ -242,7 +257,7 @@
     //Necessary to elliminate noise while turning the radio back on
     delay(150);
     radio.turnTheSoundBackOn();
-    analogWrite(backLightPin, 255);
+    analogWrite(backLightPin, backlightIntensity);

     lcd.clear();
     lcd.setCursor(0,0);
@@ -291,12 +306,24 @@
             }
             break;
           }
+          // Increment fine search station
           case 6: {
             if (selectedStation < 108.0) {
               selectedStation += .1;
               radio.selectFrequency(selectedStation);
               printSelectedFrequency(selectedStation, 2, 0);
-            }
+              saveStation(selectedStation);
+            }
+            break;
+          }
+          // Increment backlight intensity
+          case 7: {
+            if ((backlightIntensity + 10) <= 255) {
+              backlightIntensity += 10;
+              analogWrite(backLightPin, backlightIntensity);
+              EEPROM.write(3, backlightIntensity);
+            }
+            break;
           }
         }
       }
@@ -337,12 +364,24 @@
             }
             break;
           }
+          // Decrement fine search station
           case 6: {
             if (selectedStation > 88.0) {
               selectedStation -= .1;
               radio.selectFrequency(selectedStation);
               printSelectedFrequency(selectedStation, 2, 0);
-            }
+              saveStation(selectedStation);
+            }
+            break;
+          }
+          // Decrement backlight intensity
+          case 7: {
+            if ((backlightIntensity - 10) >= 20) {
+              backlightIntensity -= 10;
+              analogWrite(backLightPin, backlightIntensity);
+              EEPROM.write(3, backlightIntensity);
+            }
+            break;
           }
         }
       }
@@ -376,7 +415,23 @@
               }
             }
             markSelectedMenuItem(">", " ");
-            break;
+            break;
+          }
+          // Selecting on of the two menu items: "Search level", "Backlit inten." or "Exit"
+          case 3: {
+            if (selectedMenuItem > 0) {
+              selectedMenuItem--;
+
+              if (selectedMenuItem != 3) {
+                lcd.clear();
+                lcd.setCursor(0,0);
+                lcd.print(menu[1][selectedMenuItem]);
+                lcd.setCursor(0,1);
+                lcd.print(menu[1][selectedMenuItem+1]);
+              }
+            }
+            markSelectedMenuItem(">", " ");
+            break;
           }
           case 4: {
             if (selectedMenuItem > 0) {
@@ -425,8 +480,22 @@
               }
             }
             markSelectedMenuItem(" ", ">");
-            break;
-          }
+            break;
+          }
+          case 3:
+            if (selectedMenuItem < 2) {
+              selectedMenuItem++;
+
+              if (selectedMenuItem != 1) {
+                lcd.clear();
+                lcd.setCursor(0,0);
+                lcd.print(menu[1][selectedMenuItem-1]);
+                lcd.setCursor(0,1);
+                lcd.print(menu[1][selectedMenuItem]);
+              }
+            }
+            markSelectedMenuItem(" ", ">");
+            break;
           case 4: {
             if (selectedMenuItem < 2) {
               selectedMenuItem++;
@@ -600,28 +669,58 @@
             }
             break;
           }
+          // One of the 3 itens selected: "Search level", "Backlit intensity" or "Exit"
           case 3: {
-            state = 4;
-            lcd.clear();
-            if (searchLevel < 3) {
-              lcd.setCursor(0,0);
-              lcd.print(menu[2][0]);
-              lcd.setCursor(0,1);
-              lcd.print(menu[2][1]);
-            } else {
-              lcd.setCursor(0,0);
-              lcd.print(menu[2][1]);
-              lcd.setCursor(0,1);
-              lcd.print(menu[2][2]);
-            }
-            if (searchLevel == 1) {
-              markSelectedMenuItem(">", " ");
-            } else {
-              markSelectedMenuItem(" ", ">");
-            }
-            selectedMenuItem = searchLevel - 1;
+            switch(selectedMenuItem) {
+              // Level item selected
+              case 0: {
+                state = 4;
+                lcd.clear();
+                if (searchLevel < 3) {
+                  lcd.setCursor(0,0);
+                  lcd.print(menu[2][0]);
+                  lcd.setCursor(0,1);
+                  lcd.print(menu[2][1]);
+                } else {
+                  lcd.setCursor(0,0);
+                  lcd.print(menu[2][1]);
+                  lcd.setCursor(0,1);
+                  lcd.print(menu[2][2]);
+                }
+                if (searchLevel == 1) {
+                  markSelectedMenuItem(">", " ");
+                } else {
+                  markSelectedMenuItem(" ", ">");
+                }
+                selectedMenuItem = searchLevel - 1;
+                break;
+              }
+              // Backlight intensity selected
+              case 1: {
+                state = 7;
+
+                lcd.clear();
+                lcd.setCursor(0,0);
+                lcd.print("Backlight int.");
+                break;
+              }
+              // Exit
+              case 2: {
+                state = 0;
+
+                lcd.setCursor(0,0);
+                lcd.print("      MHz        ");
+                lcd.setCursor(0,1);
+                lcd.print("                 ");
+
+                // Starts station
+                printSelectedFrequency(radio.readFrequencyInMHz());
+                break;
+              }
+            }
             break;
           }
+          // One of the levels selected
           case 4: {
             state = 0;
             switch(selectedMenuItem+1) {
@@ -651,10 +750,16 @@
             printSelectedFrequency(radio.readFrequencyInMHz());
             break;
           }
-          case 5:
-          case 6: {
+          case 5: {
+
+            break;
+          }
+          // Exit
+          case 6:
+          case 7: {
             state = 0;

+            lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("      MHz        ");
             lcd.setCursor(0,1);