#define and #ifdef makros to turn features on/off at compile time

--- Arduino_codeline/fairytale22/fairytale22.ino
+++ Arduino_codeline/fairytale22/fairytale22.ino
@@ -79,6 +79,15 @@
    - light on / off      - turn the operations light fader on or off

+   The box is capable of being controlled by a remote control with the following functions
+   - Volume Up
+   - Volume Down
+   - Previos Track
+   - Next Track
+   - Pause/Resume
+   - Light effect on / off
+
+
    Used Pins:
      NAME             PIN  USAGE
    - CLK / PN532_SCK   13  SPI Clock shared with VS1053, SD card and NFC breakout board
@@ -93,9 +102,9 @@

    - PN532_SS          10  NFC breakout board chip select pin

-   - infoLedPin             5  the pin to which the operation led is connected to
-   - warnLedPin            8  the pin to which the warning led is connected to
-   - errorLedPin           9  the pin to which the error led is connected to (e.g. used for LBO of powerboost 1000c)
+   - infoLedPin         5  the pin to which the operation led is connected to
+   - warnLedPin         8  the pin to which the warning led is connected to
+   - errorLedPin        9  the pin to which the error led is connected to (e.g. used for LBO of powerboost 1000c)

    - volPotPin         A0  the analog input pin that we use for the potentiometer
@@ -108,7 +117,13 @@
 */

 // make sure to change this to comment this out before uploading in production as it turns on lots and lots of serial messages
-#define DEBUG 1
+//#define DEBUG 1
+
+
+
+//
+// turn ON / OFF certain hardware features
+//

 // to enable the IR Remote Control option uncomment the following line
 //#define IRREMOTE 1
@@ -122,13 +137,22 @@
 // to enable the low battery warning with light and voice uncomment the follwing line
 //#define LOWBAT 1

-// to use NDEF to get the album directory (as opposed to the trackDb) uncomment the following line
-// ONLY ONE of the below and this line can be chosen
+// to enable the operations light on the front of the box, uncomment the following line
+#define OPRLIGHT 1
+// to enable time based operations light - turns off the light after 30 Minutes - uncomment the following line
+//#define OPRLIGHTTIME 1
+
+// Define the NFC <-> Album implementation
+// ONLY ONE of the these two options can be chosen
+// to use NDEF to get the album directory uncomment the following line
 #define NFCNDEF 1
-
 // to use the Adafruit NFC library to get the Tag UID and retrieve the directory from the trackDb
-// uncomment the following line. ONLY ONE of the above and this line can be chosen
+// uncomment the following line.
 //#define NFCTRACKDB 1
+
+// uncomment the next line to enable resuming the last played album on switch on
+// this is achieved via a special file on the SD card and works without a tag but uses the pause/resume button instead
+//#define RESUMELAST 1

 //
 // include SPI and SD libraries
@@ -165,20 +189,20 @@
 // SETUP NFC ADAPTER
 //
 #ifdef NFCNDEF
-// these includes are sued for the NDEF implementation
-#include <PN532_SPI.h>
-#include <PN532.h>
-#include <NfcAdapter.h>
-#define PN532_SCK     13    // SPI Clock shared with VS1053, SD card and NFC breakout board
-#define PN532_MISO    12    // Input data from VS1053, SD card and NFC breakout board
-#define PN532_MOSI    11    // Output data to VS1053, SD card and NFC breakout board
-#define PN532_SS      10    // NFC breakout board chip select pin
-PN532_SPI pn532spi(SPI, PN532_SS);
-NfcAdapter nfc = NfcAdapter(pn532spi);
+  // these includes are sued for the NDEF implementation
+  #include <PN532_SPI.h>
+  #include <PN532.h>
+  #include <NfcAdapter.h>
+  #define PN532_SCK     13    // SPI Clock shared with VS1053, SD card and NFC breakout board
+  #define PN532_MISO    12    // Input data from VS1053, SD card and NFC breakout board
+  #define PN532_MOSI    11    // Output data to VS1053, SD card and NFC breakout board
+  #define PN532_SS      10    // NFC breakout board chip select pin
+  PN532_SPI pn532spi(SPI, PN532_SS);
+  NfcAdapter nfc = NfcAdapter(pn532spi);
 #endif

 #ifdef NFCTRACKDB
-// INCLUDE Adafruit NFC LIbrary here
+  // INCLUDE Adafruit NFC LIbrary here
 #endif

@@ -186,7 +210,7 @@
 // include IR Remote Control
 //
 #ifdef IRREMOTE
-#include <IRremote.h>
+  #include <IRremote.h>
 #endif

@@ -200,59 +224,92 @@
 char plrCurrentFolder[]     = "system00";                // directory containing the currently played tracks - system00 is the system message directory
 char filename[]             = "/system00/track001.mp3";  // path and filename of the track to play - we start with the welcome track
 byte firstTrackToPlay       = 1;                         // the track number to play (used for the loop)
-byte nextTrackToPlay        = 1;                         // the track number to play next (can also be the previos number or a -1 in case of an error)
+char nextTrackToPlay        = 1;                         // the track number to play next (can also be the previos number or a -1 in case of an error)

 // file to hold the last played album (aka directory) name - from here we may retrieve other data from the trackDb
-const char lastPlayedSessionFile[] = "/trackdb0/LASTPLAY.TDB";
+#ifdef RESUMELAST
+  const char lastPlayedSessionFile[] = "/trackdb0/LASTPLAY.TDB";
+#endif

 // trackDb on the SD card - this is where we store the NFC TAG <-> Directory connection and the track to start playback with
-const char trackDbDir[]     = "/trackdb0";               // where do we store the files for each album
-const char trackDbFile[]    = "/trackdb0/albumnfc.txt";  // path to the file that holds the connection between an NFC tag UID and the corresponding directory / file name
-char tDirFile[sizeof(trackDbFile)];                      // a char array to hold the path to the file with track and directory infos (name is shared with directory name plus .txt
-char trackDbEntry[35];                                   // will hold a nfc <-> album info connection in the form of [NFC Tag UID]:[album]:[Track] e.g.: 43322634231761291:larsrent:1
-
-
-// NFC Tag data
 #ifdef NFCTRACKDB
-byte uid[] = { 0, 0, 0, 0, 0, 0, 0 };    // Buffer to store the returned UID
-char charUid[22];                        // char representation of the UID
-byte uidLength;                          // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
+  const char trackDbDir[]     = "/trackdb0";               // where do we store the files for each album
+  const char trackDbFile[]    = "/trackdb0/albumnfc.txt";  // path to the file that holds the connection between an NFC tag UID and the corresponding directory / file name
+  char tDirFile[sizeof(trackDbFile)];                      // a char array to hold the path to the file with track and directory infos (name is shared with directory name plus .txt
+  char trackDbEntry[35];                                   // will hold a nfc <-> album info connection in the form of [NFC Tag UID]:[album]:[Track] e.g.: 43322634231761291:larsrent:1
+
+  // NFC Tag data
+  byte uid[] = { 0, 0, 0, 0, 0, 0, 0 };    // Buffer to store the returned UID
+  char charUid[22];                        // char representation of the UID
+  byte uidLength;                          // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
 #endif

 // volume control variables for the analog poti
 #ifdef VOLUMEPOT
-const byte volPotPin     = A0;      // the analog input pin that we use for the potentiometer
-word lastVolSensorValue  = 0;       // keeps the last read sensor value
+  const byte volPotPin     = A0;      // the analog input pin that we use for the potentiometer
+  word lastVolSensorValue  = 0;       // keeps the last read sensor value
 #endif

 // control buttons definition
 #ifdef BUTTONS
-const byte btnLinePin    = A1;      // pin on which the button line (4 buttons) is connected
-#endif
-
+  const byte btnLinePin    = A1;      // pin on which the button line (4 buttons) is connected
+
+  word btnVal;                        // stores the value we receive on the btnLinePin for comparance with the predefined analog reads for the 4 buttons
+  const byte btnValDrift   = 5;       // maximum allowed difference + and - the predefined value for each button we allow
+  const word btnPressDelay = 500;     // delay in milliseconds to prevent double press detection
+  unsigned long btnPressTime = 0;     // time in millis() when the button was pressed
+  const word btnLightValue = 1021;    // 33 Ohm  - The value we receive from analog input if the Light On/Off Button is pressed
+  const word btnPauseValue = 933;     // 1K Ohm  - The value we receive from analog input if the Pause Button is pressed
+  const word btnNextValue  = 1002;    // 220 Ohm - The value we receive from analog input if the Next (aka Fast Forward) Button is pressed
+  const word btnPrevValue  = 991;     // 330 Ohm - The value we receive from analog input if the Previos (aka Prev or Rewind) Button is pressed
+  const word minBtnValue   = 800;     // we use this value to determine, whether or not to check the buttons. Set to lower val than smallest of buttons
+#endif

 // IR remote control
 #ifdef IRREMOTE
-const byte iRRemotePin   = A4;      // the pin the IR remote control diode (receiver) is connected to
-IRrecv irrecv(iRRemotePin);         // define an object to read infrared sensor on pin A4
-decode_results results;             // make sure decoded values from IR are stored
+  const byte iRRemotePin   = A4;      // the pin the IR remote control diode (receiver) is connected to
+
+  // IR Remote control
+  // to reduce PROGMEM size I decided to not use the whole decimal value for each button on the remote control but instead do a calculation
+  // which reduces the needed size of the variable to hold the value but still creates different values for each button
+  // Function  Original code   Minus         DIV   code I use
+  // right:    2011291898    - 2011000000) / 100 = 2919
+  // left:     2011238650    - 2011000000) / 100 = 2387
+  // Up:       2011287802    - 2011000000) / 100 = 2878
+  // Down:     2011279610    - 2011000000) / 100 = 2796
+  // Middle:   2011282170    - 2011000000) / 100 = 2822
+  // Pause:    2011265786    - 2011000000) / 100 = 2658
+  // Menu:     2011250938    - 2011000000) / 100 = 2509
+  const uint16_t nextVal    = 2919; // decoded value if button  NEXT  is pressed on remote
+  const uint16_t prevVal    = 2387; // decoded value if button  PREV  is pressed on remote
+  const uint16_t volUpVal   = 2878; // decoded value if button  UP    is pressed on remote
+  const uint16_t volDwnVal  = 2796; // decoded value if button  DOWN  is pressed on remote
+  const uint16_t lightVal   = 2822; // decoded value if button  HOME  is pressed on remote
+  const uint16_t pauseVal   = 2658; // decoded value if button  PAUSE is pressed on remote
+  const uint16_t menuVal    = 2509; // decoded value if button  MENU  is pressed on remote
+
+  IRrecv irrecv(iRRemotePin);         // define an object to read infrared sensor on pin A4
+  decode_results results;             // make sure decoded values from IR are stored
 #endif

 // battery control
 #ifdef LOWBAT
-const byte lowBatPin   = A2;      // pulled high to BAT but when the charger detects a low voltage (under 3.2V) the pin will drop down to 0V (LOW)
-boolean lowBatWarn     = true;    // we use this bool so we may only tell the user every 5 Minite sthat the Battery is low
+  const byte lowBatPin   = A2;      // pulled high to BAT but when the charger detects a low voltage (under 3.2V) the pin will drop down to 0V (LOW)
+  boolean lowBatWarn     = true;    // we use this bool so we may only tell the user every 5 Minite sthat the Battery is low
 #endif

 // LIGHT EFFECTS
-unsigned long lightStartUpTime = 0; // millis() the operations light started
-const byte infoLedPin    = 5;       // the pin to which the operation led is connected to
+#ifdef OPRLIGHT
+  #ifdef OPRLIGHTTIME
+    unsigned long lightStartUpTime = 0; // millis() the operations light started
+  #endif
+  const byte infoLedPin    = 5;       // the pin to which the operation led is connected to
+  boolean lightOn          = true;    // if true, the operations light fader is active. is set to false via a button, or after a maxLightTime (see below) is reached
+#endif
 const byte warnLedPin    = 8;       // the pin to which the warning led is connected to
 const byte errorLedPin   = 9;       // the pin to which the error led is connected to
-boolean lightOn          = true;    // if true, the operations light fader is active. is set to false via a button, or after a maxLightTime (see below) is reached
-

@@ -267,31 +324,42 @@
 static boolean getDirAndTrackToPlay(boolean);  // retrieve the directory and track number either from the Tag (true) or from last played session file (false)
 static boolean writeTrackDbEntry(void);        // store Tag UID, plrCurrentFolder and firstTrackToPlay in the trackDb (files on SD)

+
+// prototype for NFC check for tag presence
+#ifdef NFCTRACKDB
+  static boolean checkTag(void);        // check if the tag is still on the reader - returns true or falce
+#endif
+
+// prototype for volume control via potentiometer
+#ifdef VOLUMEPOT
+  static void plrAdjustVolume(void);    // function to check for changes on the volume control and adjust volume accrodingly
+#endif
+
+
 // these are the prototypes for the mp3 player controller
-#ifdef VOLUMEPOT
-static void plrAdjustVolume(void);       // function to check for changes on the volume control and adjust volume accrodingly
-#endif
-static void plrStop(void);               // stops the player and return 0
-static void plrTogglePause(void);        // pause and unpause the player and return 0
-static char playAlbum(byte);             // plays the album from plrCurrentFolder: returns -1 for error or a higher
-static char playTrack(byte, char);       // plays a track as defined by the global vars: returns -1 for error, 0 for success and track number to play next
+static void plrStop(void);              // stops the player and return 0
+static void plrTogglePause(void);       // pause and unpause the player and return 0
+static char playAlbum(byte);            // plays the album from plrCurrentFolder: returns -1 for error or a higher
+static char playTrack(byte);            // plays a track as defined by the global vars: returns -1 for error, 0 for success and track number to play next

 // prototype for warning
 static void issueWarning(const char[], const char[], boolean); // the new warning method

+
 // these are the prototypes to work on files and general helpers
-//void printDirectory(File, byte);  // print out the content of specified directory on serial console
-static byte countFiles(File);              // return the number of files in a directory passed as a File descriptor
+static byte countFiles(File);           // return the number of files in a directory passed as a File descriptor
+

 // helper functions to set global vars
-static boolean setFileNameToPlay(byte);    // sets filename of the track to play from global vars plrCurrentFolder and plrCurrentFile and returns true if it exists
+static boolean setFileNameToPlay(byte); // sets filename of the track to play from global vars plrCurrentFolder and plrCurrentFile and returns true if it exists
 static void setTrackDbEntry(void);

 // these are the prototypes for the led
-static void switchLightState(void);        // switch the boolean var lightOn from true to false and vice versa - in case light is lightOn is set to true, lightStartUpTime is set to millis()
-
+#ifdef OPRLIGHT
+  static void switchLightState(void);   // switch the boolean var lightOn from true to false and vice versa - in case light is lightOn is set to true, lightStartUpTime is set to millis()
+#endif

 //
 //       SSSSSS  EEEEEE  TTTTTTTT  UU   UU   PPPPP
@@ -305,20 +373,22 @@

   // set the buttons as input
   #ifdef VOLUMEPOT
-  pinMode(volPotPin, INPUT);       // connects to the potentiometer that shall control the volume
+    pinMode(volPotPin, INPUT);       // connects to the potentiometer that shall control the volume
   #endif
   #ifdef BUTTONS
-  pinMode(btnLinePin, INPUT);      // connects to the 4 buttons with different resistors (set the value down in function playTrack())
+    pinMode(btnLinePin, INPUT);      // connects to the 4 buttons with different resistors (set the value down in function playTrack())
   #endif
   #ifdef LOWBAT
-  pinMode(lowBatPin, INPUT);     // connects to the LBO pin of the Adafruit PowerBoost 1000c
+    pinMode(lowBatPin, INPUT);     // connects to the LBO pin of the Adafruit PowerBoost 1000c
   #endif
   #ifdef IRREMOTE
-  pinMode(iRRemotePin, INPUT);     // connects to the output port of the remote control (decoded values for each button in function playTrack())
+    pinMode(iRRemotePin, INPUT);     // connects to the output port of the remote control (decoded values for each button in function playTrack())
   #endif

   // and the leds as output
-  pinMode(infoLedPin, OUTPUT);     // connect to blue LED
+  #ifdef OPRLIGHT
+    pinMode(infoLedPin, OUTPUT);     // connect to blue LED
+  #endif
   pinMode(warnLedPin, OUTPUT);     // connect to orange LED
   pinMode(errorLedPin, OUTPUT);    // connect to a red LED

@@ -349,16 +419,16 @@

   // WELCOME SOUND
   #ifdef VOLUMEPOT
-  plrAdjustVolume();            // initiallly adjust volume
-  #endif
-  if (playTrack(1, 1) == -1) {  // play the welcome sound
-    issueWarning("Error playing welcome-sound", "", false);
+    plrAdjustVolume();            // initiallly adjust volume
+  #endif
+  if (playTrack(1) == -1) {  // play the welcome sound
+    issueWarning("HELLO error", "", false);
   }

   // now as the last thing, start the nfc reader either the simple one with NDEF support
   #ifdef NFCNDEF
-  nfc.begin();
+    nfc.begin();
   #endif

   // or the one which allows for resume and rescan etc. but needs the trackDB as no NDEF messages are supported
@@ -368,15 +438,17 @@

   // ALL DONE
   delay(100); // wait some time for everything to settle
-  digitalWrite(infoLedPin, LOW); // turn off the info led
-  delay(100); // wait some time for everything to settle
-  digitalWrite(infoLedPin, HIGH); // turn off the info led
-  delay(100); // wait some time for everything to settle
-  digitalWrite(infoLedPin, LOW); // turn off the info led
-  delay(100); // wait some time for everything to settle
-  digitalWrite(infoLedPin, HIGH); // turn off the info led
-  delay(100); // wait some time for everything to settle
-  digitalWrite(infoLedPin, LOW); // turn off the info led
+  #ifdef OPRLIGHT
+    digitalWrite(infoLedPin, LOW); // turn off the info led
+    delay(100); // wait some time for everything to settle
+    digitalWrite(infoLedPin, HIGH); // turn off the info led
+    delay(100); // wait some time for everything to settle
+    digitalWrite(infoLedPin, LOW); // turn off the info led
+    delay(100); // wait some time for everything to settle
+    digitalWrite(infoLedPin, HIGH); // turn off the info led
+    delay(100); // wait some time for everything to settle
+    digitalWrite(infoLedPin, LOW); // turn off the info led
+  #endif

   // check our current time, so we know when to stop
   //startUpTime = millis();
@@ -397,6 +469,21 @@
   boolean weHaveATag = false;              // is set to true if a tag is present and false, if not
   boolean loopWarningMessageNoAlbumInfos = true;  // make sure we get the "no album info on tag" message at least once
   boolean loopWarningMessageNoFilesInDir = true;  // make sure we get the "no files in dir" message at least once
+
+  // this allows for the pause/resume button to be pressed without a tag being present
+  // in this case the last played album is resumed
+  #ifdef RESUMELAST
+    #ifdef BUTTONS
+      btnVal = analogRead(btnLinePin);
+      if (btnVal > minBtnValue && (millis()-btnPressTime) > btnPressDelay) {
+        if ( ((btnVal - btnValDrift) < btnPauseValue) && ((btnVal + btnValDrift) > btnPauseValue) ) {
+          #ifdef DEBUG
+            Serial.println(F("Pause Button Pressed"));
+          #endif
+        }
+      }
+    #endif
+  #endif

   #ifdef DEBUG
     Serial.print(F("."));
@@ -405,9 +492,6 @@
   // if a tag is found, we continue
   weHaveATag = nfc.tagPresent(1000);
   if (weHaveATag) {
-    // on startup, make sure all leds are off
-    //digitalWrite(infoLedPin, LOW); digitalWrite(warnLedPin, LOW); digitalWrite(errorLedPin, LOW);
-
     #ifdef DEBUG
       Serial.println(F(" tag found!"));
     #endif
@@ -444,7 +528,9 @@
     } // end of directory plus track retrieved from nfc tag

     // finally turn off the info led
-    if (lightOn) digitalWrite(infoLedPin, LOW);
+    #ifdef OPRLIGHT
+      if (lightOn) digitalWrite(infoLedPin, LOW);
+    #endif
   } // end of tag is present

   delay(1000); // throttle the loop for 1 second
@@ -542,7 +628,9 @@
   #ifdef DEBUG
     Serial.print(F("Folder: ")); Serial.print(plrCurrentFolder); Serial.print(F(" / Files: ")); Serial.println(numberOfFiles);
   #endif
-  lightStartUpTime = millis();          // store the time in millis when the  playback-for-loop started, so we can later check, whether or not the light shall continue to be on
+  #ifdef OPRLIGHTTIME
+    lightStartUpTime = millis();          // store the time in millis when the  playback-for-loop started, so we can later check, whether or not the light shall continue to be on
+  #endif
   for (byte curTrack = firstTrackToPlay; curTrack <= numberOfFiles; curTrack++) {
     digitalWrite(warnLedPin, LOW); // in each for-loop, we make sure that the warning LED is NOT lit up
     #ifdef DEBUG
@@ -578,12 +666,10 @@
     //         0  success - the file was played
     //     1-127  any positive number for the next track to play
     //            from an album standpoint this can also be a previous track on the album to play next
-    playTrack(curTrack, numberOfFiles);
+    playTrack(curTrack);
     if (nextTrackToPlay == -1) {
       issueWarning("playback failed", "/system00/playfail.mp3", false);
       break;
-    //} else if (nextTrackToPlay == 0) {
-    //  return(0);
     } else if (nextTrackToPlay == 1) {
       curTrack = 1;
     } else {
@@ -594,43 +680,46 @@
   return(0);
 }

-static char playTrack(byte trackNo, char numberOfTracks) {
-  const unsigned long maxLightTime = 1800000L;  // how long shall the light stay on while nothing is playing - default 900000 = 15 Minutes
+static char playTrack(byte trackNo) {
+  #ifdef OPRLIGHTTIME
+    const unsigned long maxLightTime = 1800000L;  // how long shall the light stay on while nothing is playing - default 900000 = 15 Minutes
+  #endif
   const unsigned int checkInterval = 10000L;    // time in milliseconds between checks for battery status, if the tag ist still present and if the max light time is reached
-
+  /*
   #ifdef BUTTONS
-  // the 4 control buttons
-  word btnVal;                        // stores the value we receive on the btnLinePin for comparance with the predefined analog reads for the 4 buttons
-  const byte btnValDrift   = 5;       // maximum allowed difference + and - the predefined value for each button we allow
-  const word btnPressDelay = 500;     // delay in milliseconds to prevent double press detection
-  unsigned long btnPressTime;         // time in millis() when the button was pressed
-  const word btnLightValue = 1021;    // 33 Ohm  - The value we receive from analog input if the Light On/Off Button is pressed
-  const word btnPauseValue = 933;     // 1K Ohm  - The value we receive from analog input if the Pause Button is pressed
-  const word btnNextValue  = 1002;    // 220 Ohm - The value we receive from analog input if the Next (aka Fast Forward) Button is pressed
-  const word btnPrevValue  = 991;     // 330 Ohm - The value we receive from analog input if the Previos (aka Prev or Rewind) Button is pressed
-  const word minBtnValue   = 800;     // we use this value to determine, whether or not to check the buttons. Set to lower val than smallest of buttons
-  #endif
-
+    // the 4 control buttons
+    word btnVal;                        // stores the value we receive on the btnLinePin for comparance with the predefined analog reads for the 4 buttons
+    const byte btnValDrift   = 5;       // maximum allowed difference + and - the predefined value for each button we allow
+    const word btnPressDelay = 500;     // delay in milliseconds to prevent double press detection
+    unsigned long btnPressTime = 0;     // time in millis() when the button was pressed
+    const word btnLightValue = 1021;    // 33 Ohm  - The value we receive from analog input if the Light On/Off Button is pressed
+    const word btnPauseValue = 933;     // 1K Ohm  - The value we receive from analog input if the Pause Button is pressed
+    const word btnNextValue  = 1002;    // 220 Ohm - The value we receive from analog input if the Next (aka Fast Forward) Button is pressed
+    const word btnPrevValue  = 991;     // 330 Ohm - The value we receive from analog input if the Previos (aka Prev or Rewind) Button is pressed
+    const word minBtnValue   = 800;     // we use this value to determine, whether or not to check the buttons. Set to lower val than smallest of buttons
+  #endif
+
   #ifdef IRREMOTE
-  // IR Remote control
-  // to reduce PROGMEM size I decided to not use the whole decimal value for each button on the remote control but instead do a calculation
-  // which reduces the needed size of the variable to hold the value but still creates different values for each button
-  // Function  Original code   Minus         DIV   code I use
-  // right:    2011291898    - 2011000000) / 100 = 2919
-  // left:     2011238650    - 2011000000) / 100 = 2387
-  // Up:       2011287802    - 2011000000) / 100 = 2878
-  // Down:     2011279610    - 2011000000) / 100 = 2796
-  // Middle:   2011282170    - 2011000000) / 100 = 2822
-  // Pause:    2011265786    - 2011000000) / 100 = 2658
-  // Menu:     2011250938    - 2011000000) / 100 = 2509
-  const uint16_t nextVal    = 2919; // decoded value if button  NEXT  is pressed on remote
-  const uint16_t prevVal    = 2387; // decoded value if button  PREV  is pressed on remote
-  const uint16_t volUpVal   = 2878; // decoded value if button  UP    is pressed on remote
-  const uint16_t volDwnVal  = 2796; // decoded value if button  DOWN  is pressed on remote
-  const uint16_t lightVal   = 2822; // decoded value if button  HOME  is pressed on remote
-  const uint16_t pauseVal   = 2658; // decoded value if button  PAUSE is pressed on remote
-  const uint16_t menuVal    = 2509; // decoded value if button  MENU  is pressed on remote
-  #endif
+    // IR Remote control
+    // to reduce PROGMEM size I decided to not use the whole decimal value for each button on the remote control but instead do a calculation
+    // which reduces the needed size of the variable to hold the value but still creates different values for each button
+    // Function  Original code   Minus         DIV   code I use
+    // right:    2011291898    - 2011000000) / 100 = 2919
+    // left:     2011238650    - 2011000000) / 100 = 2387
+    // Up:       2011287802    - 2011000000) / 100 = 2878
+    // Down:     2011279610    - 2011000000) / 100 = 2796
+    // Middle:   2011282170    - 2011000000) / 100 = 2822
+    // Pause:    2011265786    - 2011000000) / 100 = 2658
+    // Menu:     2011250938    - 2011000000) / 100 = 2509
+    const uint16_t nextVal    = 2919; // decoded value if button  NEXT  is pressed on remote
+    const uint16_t prevVal    = 2387; // decoded value if button  PREV  is pressed on remote
+    const uint16_t volUpVal   = 2878; // decoded value if button  UP    is pressed on remote
+    const uint16_t volDwnVal  = 2796; // decoded value if button  DOWN  is pressed on remote
+    const uint16_t lightVal   = 2822; // decoded value if button  HOME  is pressed on remote
+    const uint16_t pauseVal   = 2658; // decoded value if button  PAUSE is pressed on remote
+    const uint16_t menuVal    = 2509; // decoded value if button  MENU  is pressed on remote
+  #endif
+  */

   if (!musicPlayer.startPlayingFile(filename)) {
     nextTrackToPlay = -1;
@@ -644,18 +733,11 @@
   while (musicPlayer.playingMusic || musicPlayer.paused()) {
     // file is now playing in the 'background' so now's a good time
     // to do something else like handling LEDs or buttons :)
-
-    // check if we shall still fade the info light - depends on max light time and light startup time and also on the light button state
-    if (((millis()-lightStartUpTime) > maxLightTime) && lightOn) {
-      #ifdef DEBUG
-        Serial.println(F("light off"));
-      #endif
-      switchLightState();
-    }
-
-    // fade the light
-    if (lightOn && musicPlayer.paused()) analogWrite(infoLedPin, 5);
-    if (lightOn && !musicPlayer.paused()) analogWrite(infoLedPin, 128 + 127 * cos(2 * PI / 20000 * millis()));
+    #ifdef OPRLIGHT
+      // fade the light
+      if (lightOn && musicPlayer.paused()) analogWrite(infoLedPin, 5);
+      if (lightOn && !musicPlayer.paused()) analogWrite(infoLedPin, 128 + 127 * cos(2 * PI / 20000 * millis()));
+    #endif

     // every ten seconds we do some checks
     if ((millis()-checkTime) > checkInterval) {
@@ -664,21 +746,24 @@
       #endif

       // check if we shall still fade the info light - depends on max light time and light startup time and also on the light button state
-      if (((millis()-lightStartUpTime) > maxLightTime) && lightOn) {
-        #ifdef DEBUG
-          //Serial.println(F("Max Light Time reached, turn light off"));
-        #endif
-        switchLightState();
-      }
+      #ifdef OPRLIGHTTIME
+        if (((millis()-lightStartUpTime) > maxLightTime) && lightOn) {
+          #ifdef DEBUG
+            //Serial.println(F("Max Light Time reached, turn light off"));
+          #endif
+          switchLightState();
+        }
+      #endif

+      // TODO: check if this really works this way
       // check if the battery is still good
       #ifdef LOWBAT
         if (digitalRead(lowBatPin == LOW)) digitalWrite(errorLedPin, HIGH);
       #endif

-      // TODO: check if we can read the tag and if not, stop/pause the playback
+      // check if we can still read the tag and if not, stop/pause the playback
       #ifdef NFCTRACKDB
-        // checkTagPresence();
+        if (!checkTag()) plrTogglePause();
       #endif

       checkTime = millis(); // reset checktime so we can wait another 10 seconds aka 10000 ms
@@ -686,142 +771,147 @@

     // check for changes to volume and adjust accordingly
     #ifdef VOLUMEPOT
-    plrAdjustVolume();
+      plrAdjustVolume();
     #endif

     // check for button presses to pause, play next or previous track or turn lights on/off
     #ifdef BUTTONS
-    btnVal = analogRead(btnLinePin);
-    if (btnVal > minBtnValue && (millis()-btnPressTime) > btnPressDelay) {
-      btnPressTime = millis();
-      #ifdef DEBUG
-        //Serial.print(F("VALUE: "));Serial.print(btnVal - btnValDrift); Serial.print(F(" < ")); Serial.print(btnVal); Serial.print(F(" < ")); Serial.print(btnVal + btnValDrift);
-      #endif
-      //
-      //       Button Layout on the box:
-      //
-      //   +-------+  +-------+  +-------+  +-------+
-      //   | PAUSE |  | <PREV |  | NEXT> |  | LIGHT |
-      //   +-------+  +-------+  +-------+  +-------+
-      //
-      // PAUSE
-      if ( ((btnVal - btnValDrift) < btnPauseValue) && ((btnVal + btnValDrift) > btnPauseValue) ) {
+      btnVal = analogRead(btnLinePin);
+      if (btnVal > minBtnValue && (millis()-btnPressTime) > btnPressDelay) {
+        btnPressTime = millis();
         #ifdef DEBUG
-          Serial.println(F(" - Pause Button Pressed"));
+          //Serial.print(F("VALUE: "));Serial.print(btnVal - btnValDrift); Serial.print(F(" < ")); Serial.print(btnVal); Serial.print(F(" < ")); Serial.print(btnVal + btnValDrift);
         #endif
-        plrTogglePause();
-        //musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
-      }
-
-      // PREV
-      if ( ((btnVal - btnValDrift) < btnPrevValue)  && ((btnVal + btnValDrift) > btnPrevValue)  ) {
-        plrStop();
-        if (trackNo > 2) nextTrackToPlay = trackNo - 2;
-        else nextTrackToPlay = 0;
-        #ifdef DEBUG
-          Serial.print(F(" - Prev  Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
-        #endif
-        musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
-        return(nextTrackToPlay);
-      }
-
-      // NEXT
-      if ( ((btnVal - btnValDrift) < btnNextValue)  && ((btnVal + btnValDrift) > btnNextValue)  ) {
-        plrStop();
-        nextTrackToPlay = trackNo;
-        #ifdef DEBUG
-          Serial.print(F(" - Next  Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
-        #endif
-        musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
-        return(nextTrackToPlay);
-      }
-
-      // LIGHT
-      if ( ((btnVal - btnValDrift) < btnLightValue) && ((btnVal + btnValDrift) > btnLightValue) ) {
-        #ifdef DEBUG
-          Serial.println(F(" - Light Button Pressed"));
-        #endif
-        switchLightState();
-        //musicPlayer.sineTest(0x40, 100);    // Make a tone to indicate button press
-      }
-    }
-    #endif
-
-    #ifdef IRREMOTE
-    // IR Remote Control
-    //               +-------+
-    //               |  UP   |
-    //               +-------+
-    //    +-------+  +-------+  +-------+
-    //    | LEFT  |  | HOME  |  | RIGHT |
-    //    +-------+  +-------+  +-------+
-    //               +-------+
-    //               | DOWN  |
-    //               +-------+
-    //      +-------+        +-------+
-    //      | PAUSE |        |  MENU |
-    //      +-------+        +-------+
-    // chek for IR Remote Control action
-    if (irrecv.decode(&results)) { // get data from IR Remote
-      switch ((results.value-2011000000)/100) {
-        // PREV
-        case prevVal:
-          #ifdef DEBUG
-            Serial.print(F(" - Prev  Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
-          #endif
-          plrStop();
-          musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
-          if (trackNo > 2) nextTrackToPlay = trackNo - 2; else nextTrackToPlay = 0;
-          return(nextTrackToPlay);
-          break;
-        // NEXT
-        case nextVal:
-          #ifdef DEBUG
-            Serial.print(F(" - Next  Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
-          #endif
-          plrStop();
-          musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
-          nextTrackToPlay = trackNo;
-          return(nextTrackToPlay);
-          break;
+        //
+        //       Button Layout on the box:
+        //
+        //   +-------+  +-------+  +-------+  +-------+
+        //   | PAUSE |  | <PREV |  | NEXT> |  | LIGHT |
+        //   +-------+  +-------+  +-------+  +-------+
+        //
         // PAUSE
-        case pauseVal:
+        if ( ((btnVal - btnValDrift) < btnPauseValue) && ((btnVal + btnValDrift) > btnPauseValue) ) {
           #ifdef DEBUG
             Serial.println(F(" - Pause Button Pressed"));
           #endif
           plrTogglePause();
-          break;
+          //musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
+        }
+
+        // PREV
+        if ( ((btnVal - btnValDrift) < btnPrevValue)  && ((btnVal + btnValDrift) > btnPrevValue)  ) {
+          plrStop();
+          if (trackNo > 2) nextTrackToPlay = trackNo - 2;
+          else nextTrackToPlay = 0;
+          #ifdef DEBUG
+            Serial.print(F(" - Prev Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
+          #endif
+          musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
+          return(nextTrackToPlay);
+        }
+
+        // NEXT
+        if ( ((btnVal - btnValDrift) < btnNextValue)  && ((btnVal + btnValDrift) > btnNextValue)  ) {
+          plrStop();
+          nextTrackToPlay = trackNo;
+          #ifdef DEBUG
+            Serial.print(F(" - Next Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
+          #endif
+          musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
+          return(nextTrackToPlay);
+        }
+
         // LIGHT
-        case lightVal:
-          #ifdef DEBUG
-            Serial.println(F(" - Light Button Pressed"));
+        #ifdef OPRLIGHT
+          if ( ((btnVal - btnValDrift) < btnLightValue) && ((btnVal + btnValDrift) > btnLightValue) ) {
+            #ifdef DEBUG
+              Serial.println(F(" - Light Button Pressed"));
+            #endif
+            switchLightState();
+            //musicPlayer.sineTest(0x40, 100);    // Make a tone to indicate button press
+          }
+        #endif
+      }
+    #endif
+
+    #ifdef IRREMOTE
+      // IR Remote Control
+      //               +-------+
+      //               |  UP   |
+      //               +-------+
+      //    +-------+  +-------+  +-------+
+      //    | LEFT  |  | HOME  |  | RIGHT |
+      //    +-------+  +-------+  +-------+
+      //               +-------+
+      //               | DOWN  |
+      //               +-------+
+      //      +-------+        +-------+
+      //      | PAUSE |        |  MENU |
+      //      +-------+        +-------+
+      // chek for IR Remote Control action
+      if (irrecv.decode(&results)) { // get data from IR Remote
+        switch ((results.value-2011000000)/100) {
+          // PREV
+          case prevVal:
+            #ifdef DEBUG
+              Serial.print(F(" - Prev Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
+            #endif
+            plrStop();
+            musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
+            if (trackNo > 2) nextTrackToPlay = trackNo - 2; else nextTrackToPlay = 0;
+            return(nextTrackToPlay);
+            break;
+          // NEXT
+          case nextVal:
+            #ifdef DEBUG
+              Serial.print(F(" - Next Button Pressed, track "));Serial.print(nextTrackToPlay);Serial.println(F(" set"));
+            #endif
+            plrStop();
+            musicPlayer.sineTest(0x42, 100);    // Make a tone to indicate button press
+            nextTrackToPlay = trackNo;
+            return(nextTrackToPlay);
+            break;
+          // PAUSE
+          case pauseVal:
+            #ifdef DEBUG
+              Serial.println(F(" - Pause Button Pressed"));
+            #endif
+            plrTogglePause();
+            break;
+          // LIGHT
+          #ifdef OPRLIGHT
+            case lightVal:
+              #ifdef DEBUG
+                Serial.println(F(" - Light Button Pressed"));
+              #endif
+              switchLightState();
+              break;
           #endif
-          switchLightState();
-          break;
-        // VOL UP
-        case volUpVal:
-          #ifdef DEBUG
-            Serial.println(F(" - Volume Up Button Pressed"));
-          #endif
-          break;
-        // VOL DOWN
-        case volDwnVal:
-          #ifdef DEBUG
-            Serial.println(F(" - Volume Down Button Pressed"));
-          #endif
-          break;
-        // MENU
-        case menuVal:
-          #ifdef DEBUG
-            Serial.println(F(" - Menu Button Pressed"));
-          #endif
-          break;
-        default:
-          break;
-      }
-      delay(50);
-      irrecv.resume();
-    }
+          // VOL UP
+          case volUpVal:
+            #ifdef DEBUG
+              Serial.println(F(" - Volume Up Button Pressed"));
+            #endif
+            break;
+          // VOL DOWN
+          case volDwnVal:
+            #ifdef DEBUG
+              Serial.println(F(" - Volume Down Button Pressed"));
+            #endif
+            break;
+          // MENU
+          // CURRENTLY NO FUNCTION FOR MENU
+          //case menuVal:
+          //  #ifdef DEBUG
+          //    Serial.println(F(" - Menu Button Pressed"));
+          //  #endif
+          //  break;
+          default:
+            break;
+        }
+        delay(50);
+        irrecv.resume();
+      }
     #endif

     // check if the player is still playing our sounds and is NOT paused - otherwise we return a 0 to indicate successfull end of playback
@@ -940,6 +1030,24 @@
 }
 #endif

+
+//
+//      NN    NN  FFFFFF  CCCCC
+//      NNN   NN  FF     CC
+//      NN NN NN  FFFF   CC
+//      NN   NNN  FF     CC
+//      NN    NN  FF      CCCCC
+//
+// check Tag presence is used in the loop() (to populate the char array with the uid of the tag) and in function playTrack() to see
+// if the tag is still on the reader - this can only be used with the Adafruit NFC library
+#ifdef NFCTRACKDB
+boolean checkTag() {
+  boolean sameTagPresent = true;
+
+  return(sameTagPresent);
+}
+#endif
+
 //
 //      HH    HH  EEEEEE  LL      PPPPPP    EEEEEE  RRRRRR
 //      HH    HH  EE      LL      PP    PP  EE      RR   RR
@@ -949,33 +1057,25 @@
 //
 // stores the file to play in the global var filename - it is created from the gloal vars plrCurrentFolder and current track
 static boolean setFileNameToPlay(byte trackNo) {
-  // convert the trackNo to a char array - we need it next to create the global var plrCurrentFile
+  // convert the trackNo to a char array - we need it next to create the filename of the track
   char curTrackCharNumber[4];
   sprintf(curTrackCharNumber, "%03d", trackNo);

-  // create the name of the track to play from the curTrack
-  //strcpy(plrCurrentFile, "");
-  //strcat(plrCurrentFile, "track");
-  //strcat(plrCurrentFile, curTrackCharNumber);
-  //strcat(plrCurrentFile, ".mp3");
-
   // create the filename of the track to play, including path, so we can feed it to the music player
   strcpy(filename, "");
   strcat(filename, "/");
   strcat(filename, plrCurrentFolder);
   strcat(filename, "/");
-  //strcat(filename, plrCurrentFile);
   strcat(filename, "track");
   strcat(filename, curTrackCharNumber);
   strcat(filename, ".mp3");
-
-
+
   // return true or false for the filename created - this is checked
   return (SD.exists(filename));
 }

-// store uid, plrCurrentFolder and firstTrackToPlay in the char trackDbEntry
+// store uid, plrCurrentFolder and firstTrackToPlay in the char array trackDbEntry[]
 // so we may write it to the track Db file
 #ifdef NFCTRACKDB
 static void setTrackDbEntry() {
@@ -1056,13 +1156,16 @@
 //  LLLLLL  EEEEEE  DDDDDD
 //
 // switches the value of lightOn between true and false
+#ifdef OPRLIGHT
 static void switchLightState(void) {
   if (!lightOn) {
     #ifdef DEBUG
       Serial.println(F("Switching light off -> ON"));
     #endif
     lightOn = true;
-    lightStartUpTime = millis(); // also sets the lightStartUpTime
+    #ifdef OPRLIGHTTIME
+      lightStartUpTime = millis(); // also sets the lightStartUpTime
+    #endif
   } else {
     #ifdef DEBUG
       Serial.println(F("Switching light on -> OFF"));
@@ -1071,4 +1174,4 @@
     digitalWrite(infoLedPin, LOW);   // also turns off the info led
   }
 }
-
+#endif


A little tinkering

A little tinkering

--- laserharp.ino
+++ laserharp.ino
@@ -110,7 +110,8 @@
 	if (height > 119) return 4;
 	if (height > 100) return 3;
 	if (height > 80) return 2;
-	if (height > 65) return 1;
+	//My speaker gets weird at the low values. So I commented that one out.
+//	if (height > 65) return 1;
 	return 0;
 }

@@ -119,10 +120,10 @@
 void checkSonar() {
 	int height = analogRead(1);

-	//if (debug) {
-	Serial.print("Distance:");
-	Serial.println(height);
-	//}
+	if (debug) {
+		Serial.print("Height:");
+		Serial.println(height);
+	}

 	if (height > 170) {
 		return;
@@ -204,15 +205,15 @@
 	//and hope the player gets his act straight.
 	int firstNote = -1;
 	int secondNote = -1;
-	if (harpNoteDetector.getNotes(firstNote, secondnote, pluckedNotes)) {
+	if (harpNoteDetector.getNotes(firstNote, secondNote, pluckedNotes)) {
 		if (debug) {
 			if (firstNote >= 0) {
 				Serial.print("==============PLUCKED 1: ");
 				Serial.println(firstNote);
 			}
-			if (secondnote >= 0) {
+			if (secondNote >= 0) {
 				Serial.print("==============PLUCKED 2: ");
-				Serial.println(secondnote);
+				Serial.println(secondNote);
 			}
 		}
 		playNote(firstNote, secondNote);
@@ -264,6 +265,8 @@
 		checkNotes(reflectedLightValues, pluckedNotes);
 	}

+	checkButtons();
+
 	//It just read item 7. So going backwards, read items 6 through zero.
 	for (int i = numberNotes - 2; i >= 0; i--) {
 		reflectedLightValues[i] = stepTheMotorAndGetLightReading(BACKWARD);


Use array for instruments

Use array for instruments

Use an array to store instruments, allowing us to cycle between instruments
with the press of a button. The nice thing is you can add more instruments
relatively easily, as long as timidity supports it.

If timidity has no output, you may need to install an extended sound font
for timidty, such as Fluid General MIDI SoundFont

This commit also fixes some glitches with button presses, although this code
is likely to not work, because it has not been tested on real hardware.

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -32,6 +32,11 @@
 int note1 = 0x3C;

 int buttonState = 0;
+int currentInstrument = 0;
+
+// Piano, Harpsichord, Pizzacato strings, Flute, Violin, Accordian
+// Sounds provided by MIDI synthesizer, so you may need to install it
+int instrumentArray[6] = {0x01, 0x07, 0x2E, 0x4A, 0x29, 0x16};

 /* Flag values for each laser. These values will operate on the bit
  * levels, directly with binary. They work together with the
@@ -140,12 +145,26 @@
   // 8 ports, from 0 to 7
   for (int i = 0; i <= LASTPORT; i++) {
     if(digitalRead(BUTTONPORT) == HIGH) {
+      // Make sure that this is the first time that the button
+      // has been pressed
       if (buttonState == 0) {
+        // Send MIDI command to change instrument
         Serial.write(CHANGEINSTRUMENT);
-        Serial.write(STRING);
+        // Max number of instruments, so wrap around
+        if (currentInstrument >= 5) {
+          currentInstrument = 0;
+        } else {
+          // Increment current instrument
+          currentInstrument++;
+        }
+        // Write the current instrument
+        Serial.write(instrumentArray[currentInstrument];
+        // Set the button state so this won't fire when holding down
+        // the button
         buttonState = 1;
       }
     } else {
+      // Button is no longer pressed, so reset the button state.
       buttonState = 0;
     }
     if(analogRead(i) > THRESHOLD) {


Added command handling via dummy Modules.

--- ROVMain/ROVMain.ino
+++ ROVMain/ROVMain.ino
@@ -9,12 +9,13 @@
  * @author: Aleksander Lidtke
  * @email: alekasdner.lidtke@gmail.com
  * @url: www.aleksanderlidtke.com
- * @since:  6 Sep 2015
- * @version: 2.0.0
+ * @since: 24 Sep 2015
+ * @version: 2.1.0
  *
  * CHANGELOG
  *  5 Sep 2015 - 1.0.0 - Alek Lidtke - released the first version.
  *  6 Sep 2015 - 2.0.0 - Alek & Artur Lidtke - derived motor class from the Module class.
+ * 24 Sep 2015 - 2.1.0 - Alek Lidtke - added command handling via dummy Modules.
  */

 // Custom includes.
@@ -47,15 +48,22 @@
 // Pins are pairs of close-by pins with PWM and digital ones.
 BrushlessDCMotor engine1 = BrushlessDCMotor("motorPortHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
 	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 9, 8);
-/*BrushlessDCMotor engine2 = BrushlessDCMotor("motorStbdHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 6, 7);
-BrushlessDCMotor engine3 = BrushlessDCMotor("motorPortVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 5, 4);
-BrushlessDCMotor engine4 = BrushlessDCMotor("motorStbdVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH, MOTOR_MIN_PULSE_WIDTH, 3, 2);
-*/
+BrushlessDCMotor engine2 = BrushlessDCMotor("motorStbdHor", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 6, 7);
+BrushlessDCMotor engine3 = BrushlessDCMotor("motorPortVer", THROTTLE_STEPS,MOTOR_MAX_PULSE_WIDTH,
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 5, 4);
+BrushlessDCMotor engine4 = BrushlessDCMotor("motorStbdVer", THROTTLE_STEPS, MOTOR_MAX_PULSE_WIDTH,
+	MOTOR_MIN_PULSE_WIDTH, MOTOR_ARM_PULSE_WIDTH, 3, 2);
+
 /* =============================================================================
  * MISC ACTUATOR DEFINITIONS.
  * =============================================================================
  */
-const char* LED_LABEL = "forwardLED"; // Whether forward illumination LED is on or of.
+Module sendSensorReadingsModule = Module("sendSensorReadings"); // Sends sensor readings over serial.
+
+Module refreshRate = Module("refreshRate"); // Changes the delay in the main loop.
+
+Module forwardLED = Module("forwardLED"); // Switches the forward illumination LED on or of.
 const int FORWARD_LED_PIN = 12; // When this is set HIGH the forward light will switch on.

 const int ON_LED_PIN = 13; // LED on the Arduino board that will be lit when the ROV is in the main loop.
@@ -71,8 +79,6 @@
  * TELECOMMAND PROTOCOL DEFINITION.
  * =============================================================================
  */
-const int REFRESH_RATE = 100; // How many milliseconds to wait before checking for input commands.
-
 // Input and output data buffers.
 #define DATABUFFERSIZE 80
 char inputDataBuffer[DATABUFFERSIZE+1]; // Where the received command will be temporarily held. Add 1 for NULL terminator at the end.
@@ -84,7 +90,7 @@
 const char END_CHAR = ';'; // End of the command message sent to and from the Arduino.
 const char DATA_DELIMITER[2] = ","; // Splits the command name and value. For some reason has to be size 2.

-Module* actuators[] = {&engine1/*, &engine2, &engine3, &engine4*/};
+Module* actuators[] = {&engine1, &engine2, &engine3, &engine4, &sendSensorReadingsModule, &refreshRate, &forwardLED};
 Module* sensors[] = {&depthSensor, &depthSensor2};

 /* =============================================================================
@@ -94,6 +100,8 @@
 void setup(void)
 /* Prepare to listen to commands over serial and start everything up. */
 {
+	refreshRate.setValue(100); // Set default delay in milliseconds in the main loop/
+
 	//TODO: do some system checks, like battery level, connections etc.

 	// Start serial comms at the same baud rate as the engines.
@@ -132,11 +140,14 @@
 		}
 	}

-	// Periodically send readings from all the sensors over serial.
-	sendSensorReadings();
+	// Send readings from all the sensors over serial after this has been requested by a command.
+	if(sendSensorReadingsModule.getValue()==1)
+	{
+		sendSensorReadings();
+	}

 	// Reduce rate at which stuff happens.
-	delay(REFRESH_RATE);
+	delay(refreshRate.getValue());
 }

 boolean getSerial(void)
@@ -211,7 +222,6 @@
   		Serial.print(actuators[nextActuatorIndex]->getIdentifier());
   		Serial.print(" to ");
   		Serial.println( String(int(atof(token))) );
-
   		actuators[nextActuatorIndex] -> setValue( int(atof(token)) );
   		// Indicate that on the next pass there is no value to read.
   		nextActuatorIndex = -1;


Reset reason formatting fixed.

Reset reason formatting fixed.

--- ntptask.ino
+++ ntptask.ino
@@ -21,7 +21,7 @@
   /* save reset reason */
   if ( preferences.getString("bootlog").equalsIgnoreCase("on") ) {
     char content[100];
-    snprintf( content, sizeof( content ), "%s,%s", resetString( 0 ), resetString( 1 ) );
+    snprintf( content, sizeof( content ), " %s,%s", resetString( 0 ), resetString( 1 ) );
     logger.appendToFile( "/reset_reasons.txt", HUMAN_TIME, content );
   }


v3.0 PID with combined velocity from timing and ticks

--- PID_test/PID_test.ino
+++ PID_test/PID_test.ino
@@ -17,7 +17,7 @@
 int period=50;        // PID sample timer period in ms
 double lv=0., rv=0., lvt=0., rvt=0. ;// motor speed innumber tics per period with two methods
 int ti=0;             // tic timer counter
-double lIn,rIn,lOut,rOut,lSet=20,rSet=20;   // PID Input Signal, Output command and Setting speed for each wheel
+double lIn,rIn,lOut,rOut,lSet=0,rSet=0;   // PID Input Signal, Output command and Setting speed for each wheel
 double lkp=0.5,lki=10,lkd=0.0;     // Left/right wheel PID constants. Can be modiffied while running with:
 double rkp=0.5,rki=10,rkd=0.0;     // s nnn (setting point), p nnn (kp), i nnn (ki), d nnn (kd). nnn is divided by 10 to get decimals nnn -> nn.n
 double kt=1000/period;            // number of periods/sec
@@ -43,8 +43,8 @@
   rmc0=rmc;
   lIn = lv*kt;
   rIn = rv*kt;
-  //lIn=abs(lvt)*sgn(lv);
-  //rIn=abs(rvt)*sgn(rv);
+  if(abs(lv)>=1) lIn=abs(lvt)*sgn(lv); // use timing to calculate velocity only if ticks are greater than one
+  if(abs(rv)>=1) rIn=abs(rvt)*sgn(rv); // to avoid problems with sign and inertia for a simple encoder (no quadrature)
   lPID.Compute();
   rPID.Compute();
   motion(lOut,rOut);
@@ -127,10 +127,10 @@
   pinMode(D4, OUTPUT); // 3A,4A aka D4
   pinMode(D5, INPUT);  // Left encoder
   pinMode(D6, INPUT);  // Right encoder
-  attachInterrupt(D5, lencode, CHANGE); // Setup Interrupt
-  attachInterrupt(D6, rencode, CHANGE); // Setup Interrupt
-  //attachInterrupt(D5, lencode, RISING);   // Setup Interrupt
-  //attachInterrupt(D6, rencode, RISING);   // Setup Interrupt
+  //attachInterrupt(D5, lencode, CHANGE); // Setup Interrupt
+  //attachInterrupt(D6, rencode, CHANGE); // Setup Interrupt
+  attachInterrupt(D5, lencode, RISING);   // Setup Interrupt
+  attachInterrupt(D6, rencode, RISING);   // Setup Interrupt
   sei();                                  // Enable interrupts
   os_timer_setfn(&myTimer, tic, NULL);
   os_timer_arm(&myTimer, period, true);   // timer in ms
@@ -192,10 +192,6 @@
     Serial.print(",");
     Serial.print(rIn);
     Serial.print(",");
-    Serial.print(lvt);
-    Serial.print(",");
-    Serial.print(rvt);
-    Serial.print(",");
     Serial.print(lOut);
     Serial.print(",");
     Serial.println(rOut);


add starting cal values for servos

add starting cal values for servos

--- CS26410.ino
+++ CS26410.ino
@@ -22,6 +22,10 @@
 #define Ping4 11
 #define SharpIrEnable 12
 #define turret 13
+
+#define DrightStop 68
+#define DleftStop 84
+#define TurretCenter 84

 Servo Driveleft;
@@ -49,6 +53,7 @@
   pinMode(LEDRed, OUTPUT);

+
 }

 void loop(){


Update main.ino

Update main.ino

Lot of Changes !!!!!
Add a Screen
DEBUG ON/OFF option
Use less external libraries
Merge inputs and outputs in a same file
Add a file for Midi config

--- main/main.ino
+++ main/main.ino
@@ -6,565 +6,30 @@
    USB Midified ZoomMRT-3B for Traktor

 */
-#define MidiChannel  2 // channel 3 (channel 1 has value 0)
-#include "MIDIUSB.h"

-void controlChange(byte channel, byte control, byte value) {
-  Serial.print("CC: ");
-  Serial.print(channel);
-  Serial.print("| ");
-  Serial.print(control);
-  Serial.print("| ");
-  Serial.println(value);
-
-  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
-  MidiUSB.sendMIDI(event);
-}
-
-
-#include "inputs.h"
-#include "outputs.h"
-
-
-
-
-//Pulse per quarter note. Each beat has 24 pulses.
-//Tempo is based on software inner BPM.
-// int ppqn = 0; //not yet implemented
+#define ENABLE_DEBUG  0  // Set to 1 to enable serial debug out
+#include "screen.h"
+#include "minimidi.h"
+#include "IOS.h"

 void setup() {
+#if ENABLE_DEBUG
   Serial.begin(115200);
   Serial.println("start setup");
-
+#endif
+  screeninit(); // set screen
+  outputsinit(); // set outputs
   inputsinit(); // set inputs
-  outputsinit(); // set outputs
+#if ENABLE_DEBUG
   Serial.println("setup end");
-
-
+#endif
+  clearscreen();
 }

 void loop() {
-
-
+  //  Serial.println("L00P");
   getMidiIn();
+  readJogWheel();
   setMidiOut();
-
-
+  readDataWheel();
 }
-
-
-
-void getMidiIn() {
-
-
-  midiEventPacket_t rx;
-  rx = MidiUSB.read();
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 70) { // SongLed
-        digitalWrite(SongLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 71) { // PatternLed
-        digitalWrite(PatternLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 72) { // KitLed
-        digitalWrite(KitLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 73) { // MinusLed
-        digitalWrite(MinusLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 74) { // PlusLed
-        digitalWrite(PlusLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 75) { // TempoLed
-        digitalWrite(TempoLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 76) { // PlayLed
-        digitalWrite(PlayLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 77) { // RecLed
-        digitalWrite(RecLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 78) { // BankLed
-        digitalWrite(BankLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 79) { // CrashLed
-        digitalWrite(CrashLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 80) { // CupLed
-        digitalWrite(CupLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 81) { // RideLed
-        digitalWrite(RideLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 82) { // FunctionLed
-        digitalWrite(FunctionLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 83) { // KickLed
-        digitalWrite(KickLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 84) { // SnareLed
-        digitalWrite(SnareLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 85) { // ClosedHatLed
-        digitalWrite(ClosedHatLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-  if ((rx.header >> 4) == MidiChannel) { // channel 3 (channel 1 has value 0)
-    if ((rx.header & 0b1111) == 0b1011) { // control change
-      if (rx.byte1 == 86) { // OpenHatLed
-        digitalWrite(OpenHatLed, rx.byte2 >> 6); // 0 >> 6 = 0 and 127 >> 6 = 1
-      }
-    }
-  }
-
-
-}
-
-void setMidiOut() {
-
-
-  // read both inputs of Jog Wheel
-
-  int a = digitalRead(JogWheelPinA);
-  int b = digitalRead(JogWheelPinB);
-
-  if (a == b ) { // b is leading a (counter-clockwise)
-    valJogWheel--;
-    currentDirection = COUNTER_CLOCKWISE;
-  }
-  else { // a is leading b (clockwise)
-    valJogWheel++;
-    currentDirection = CLOCKWISE;
-  }
-
-  valJogWheel = valJogWheel % CPR; // track 0 to 400
-  if (valJogWheel >= JogWheelToggle) { //Prevent Intempestive Move or flickering
-    controlChange(MidiChannel, 63, 127); // Send CC For JogWheel Activity
-    mappedvalJogWheel = map(abs(valJogWheel), 0, JogWheelMaxval, 0, 127); //map Jog Wheel value from 0 to 127
-    JogWheelActive = 1;
-    if (currentDirection = CLOCKWISE) {
-      controlChange(MidiChannel, 61, mappedvalJogWheel); // Send CC For JogWheel FORWARD Direction
-    }
-    if (currentDirection = COUNTER_CLOCKWISE) {
-      controlChange(MidiChannel, 62, mappedvalJogWheel); // Send CC For JogWheel REWARD Direction
-    }
-    MidiUSB.flush(); // Be sure CC is Send
-    valJogWheel = 0;
-  }
-
-  valSongSwitch = digitalRead(SongSwitch); // Read Analog Input
-  if (valSongSwitch != lastSongSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastSongSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valSongSwitch != SongSwitchState) {
-      SongSwitchState = valSongSwitch;
-      if (SongSwitchState == LOW) {
-        Serial.print("CC 40 Song Switch: ");
-        Serial.println(valSongSwitch);
-        controlChange(MidiChannel, 40, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastSongSwitch = valSongSwitch;
-      }
-    }
-  }
-  valPatternSwitch = digitalRead(PatternSwitch); // Read Analog Input
-  if (valPatternSwitch != lastPatternSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastPatternSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valPatternSwitch != PatternSwitchState) {
-      PatternSwitchState = valPatternSwitch;
-      if (PatternSwitchState == LOW) {
-        controlChange(MidiChannel, 41, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastPatternSwitch = valPatternSwitch;
-      }
-    }
-  }
-  valKitSwitch = digitalRead(KitSwitch); // Read Analog Input
-  if (valKitSwitch != lastKitSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastKitSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valKitSwitch != KitSwitchState) {
-      KitSwitchState = valKitSwitch;
-      if (KitSwitchState == LOW) {
-        controlChange(MidiChannel, 42, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastKitSwitch = valKitSwitch;
-      }
-    }
-  }
-  valInsertSwitch = digitalRead(InsertSwitch); // Read Analog Input
-  if (valInsertSwitch != lastInsertSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastInsertSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valInsertSwitch != InsertSwitchState) {
-      InsertSwitchState = valInsertSwitch;
-      if (InsertSwitchState == LOW) {
-        controlChange(MidiChannel, 43, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastInsertSwitch = valInsertSwitch;
-      }
-    }
-  }
-  valDeleteSwitch = digitalRead(DeleteSwitch); // Read Analog Input
-  if (valDeleteSwitch != lastDeleteSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastDeleteSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valDeleteSwitch != DeleteSwitchState) {
-      DeleteSwitchState = valDeleteSwitch;
-      if (DeleteSwitchState == LOW) {
-        controlChange(MidiChannel, 44, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastDeleteSwitch = valDeleteSwitch;
-      }
-    }
-  }
-  valMinusSwitch = digitalRead(MinusSwitch); // Read Analog Input
-  if (valMinusSwitch != lastMinusSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastMinusSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valMinusSwitch != MinusSwitchState) {
-      MinusSwitchState = valMinusSwitch;
-      if (MinusSwitchState == LOW) {
-        controlChange(MidiChannel, 45, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastMinusSwitch = valMinusSwitch;
-      }
-    }
-  }
-  valPlusSwitch = digitalRead(PlusSwitch); // Read Analog Input
-  if (valPlusSwitch != lastPlusSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastPlusSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valPlusSwitch != PlusSwitchState) {
-      PlusSwitchState = valPlusSwitch;
-      if (PlusSwitchState == LOW) {
-        controlChange(MidiChannel, 46, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastPlusSwitch = valPlusSwitch;
-      }
-    }
-  }
-  valTempoSwitch = digitalRead(TempoSwitch); // Read Analog Input
-  if (valTempoSwitch != lastTempoSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastTempoSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valTempoSwitch != TempoSwitchState) {
-      TempoSwitchState = valTempoSwitch;
-      if (TempoSwitchState == LOW) {
-        controlChange(MidiChannel, 47, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastTempoSwitch = valTempoSwitch;
-      }
-    }
-  }
-  valStopSwitch = digitalRead(StopSwitch); // Read Analog Input
-  if (valStopSwitch != lastStopSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastStopSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valStopSwitch != StopSwitchState) {
-      StopSwitchState = valStopSwitch;
-      if (StopSwitchState == LOW) {
-        controlChange(MidiChannel, 48, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastStopSwitch = valStopSwitch;
-      }
-    }
-  }
-  valPlaySwitch = digitalRead(PlaySwitch); // Read Analog Input
-  if (valPlaySwitch != lastPlaySwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastPlaySwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valPlaySwitch != PlaySwitchState) {
-      PlaySwitchState = valPlaySwitch;
-      if (PlaySwitchState == LOW) {
-        controlChange(MidiChannel, 49, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastPlaySwitch = valPlaySwitch;
-      }
-    }
-  }
-  valRecSwitch = digitalRead(RecSwitch); // Read Analog Input
-  if (valRecSwitch != lastRecSwitch) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastRecSwitchDebounceTime) > debounceSwitchDelay) { // Only send Midi CC if switch is pressed
-    if (valRecSwitch != RecSwitchState) {
-      RecSwitchState = valRecSwitch;
-      if (RecSwitchState == LOW) {
-        controlChange(MidiChannel, 50, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastRecSwitch = valRecSwitch;
-      }
-    }
-  }
-  valBankPad = digitalRead(BankPad); // Read Analog Input
-  if (valBankPad != lastBankPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastBankPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valBankPad != BankPadState) {
-      BankPadState = valBankPad;
-      if (BankPadState == LOW) {
-        controlChange(MidiChannel, 51, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastBankPad = valBankPad;
-      }
-    }
-  }
-  valCrashPad = digitalRead(CrashPad); // Read Analog Input
-  if (valCrashPad != lastCrashPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastCrashPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valCrashPad != CrashPadState) {
-      CrashPadState = valCrashPad;
-      if (CrashPadState == LOW) {
-        Serial.println("SEND CRASH!!!!!!!!!!!!!!!!!!!!!");
-        controlChange(MidiChannel, 52, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastCrashPad = valCrashPad;
-      }
-    }
-  }
-  valCupPad = digitalRead(CupPad); // Read Analog Input
-  if (valCupPad != lastCupPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastCupPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valCupPad != CupPadState) {
-      CupPadState = valCupPad;
-      if (CupPadState == LOW) {
-        controlChange(MidiChannel, 53, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastCupPad = valCupPad;
-      }
-    }
-  }
-
-  valRidePad = digitalRead(RidePad); // Read Analog Input Shift Function
-  if (valRidePad != lastRidePad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastRidePadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valRidePad != RidePadState) {
-      digitalWrite(RideLed, LOW);
-      Serial.println("RIDE PUSHH!!!  ");
-      Serial.println(valRidePad);
-      RidePadState = valRidePad;
-
-      while (valRidePad == 0) {
-        valKickPad = digitalRead(KickPad);
-        valSnarePad = digitalRead(SnarePad);
-        valClosedHatPad = digitalRead(ClosedHatPad);
-        valOpenHatPad = digitalRead(OpenHatPad);
-        if (RidePadState == LOW && valKickPad == HIGH) {
-          controlChange(MidiChannel, 64, 127); // Send CC
-          MidiUSB.flush(); // Be sure CC is Send
-          lastRidePad = valRidePad;
-        }
-        if (RidePadState == LOW && valSnarePad == LOW) {
-          controlChange(MidiChannel, 65, 127); // Send CC
-          MidiUSB.flush(); // Be sure CC is Send
-          lastRidePad = valRidePad;
-        }
-        if (RidePadState == LOW && valClosedHatPad == LOW) {
-          controlChange(MidiChannel, 66, 127); // Send CC
-          MidiUSB.flush(); // Be sure CC is Send
-          lastRidePad = valRidePad;
-        }
-        if (RidePadState == LOW && valOpenHatPad == LOW) {
-          controlChange(MidiChannel, 67, 127); // Send CC
-          MidiUSB.flush(); // Be sure CC is Send
-          lastRidePad = valRidePad;
-        }
-        valRidePad = digitalRead(RidePad);
-      }
-    } else {
-      digitalWrite(RideLed, HIGH);
-    }
-  }
-
-
-  valFunctionPad = digitalRead(FunctionPad); // Read Analog Input
-  if (valFunctionPad != lastFunctionPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastFunctionPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valFunctionPad != FunctionPadState) {
-      FunctionPadState = valFunctionPad;
-      if (FunctionPadState == LOW) {
-        controlChange(MidiChannel, 55, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastFunctionPad = valFunctionPad;
-      }
-    }
-  }
-  valKickPad = digitalRead(KickPad); // Read Analog Input
-  if (valKickPad != lastKickPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastKickPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valKickPad != KickPadState) {
-      KickPadState = valKickPad;
-      if (KickPadState == LOW) {
-        controlChange(MidiChannel, 56, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastKickPad = valKickPad;
-      }
-    }
-  }
-  valSnarePad = digitalRead(SnarePad); // Read Analog Input
-  if (valSnarePad != lastSnarePad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastSnarePadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valSnarePad != SnarePadState) {
-      SnarePadState = valSnarePad;
-      if (SnarePadState == LOW) {
-        controlChange(MidiChannel, 57, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastSnarePad = valSnarePad;
-      }
-    }
-  }
-  valClosedHatPad = digitalRead(ClosedHatPad); // Read Analog Input
-  if (valClosedHatPad != lastClosedHatPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastClosedHatPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valClosedHatPad != ClosedHatPadState) {
-      ClosedHatPadState = valClosedHatPad;
-      if (ClosedHatPadState == LOW) {
-        controlChange(MidiChannel, 58, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastClosedHatPad = valClosedHatPad;
-      }
-    }
-  }
-  valOpenHatPad = digitalRead(OpenHatPad); // Read Analog Input
-  if (valOpenHatPad != lastOpenHatPad) {
-    // reset the debouncing timer
-    lastDebounceTime = millis();
-  }
-  if ((millis() - lastOpenHatPadDebounceTime) > debouncePadDelay) { // Only send Midi CC if switch is pressed
-    if (valOpenHatPad != OpenHatPadState) {
-      OpenHatPadState = valOpenHatPad;
-      if (OpenHatPadState == LOW) {
-        controlChange(MidiChannel, 59, 127); // Send CC
-        MidiUSB.flush(); // Be sure CC is Send
-        lastOpenHatPad = valOpenHatPad;
-      }
-    }
-  }
-
-
-}


Added delay per character

Added delay per character

--- Arduino/LlamaLlipsum/LlamaLlipsum.ino
+++ Arduino/LlamaLlipsum/LlamaLlipsum.ino
@@ -66,6 +66,7 @@

 int cols = 40;
 int rows = 5;
+long wait = 0;

 /////////////////////////////////////////
 // row, col, baud settings
@@ -116,9 +117,22 @@
   Serial.println( " baud." );

   Serial.end();
-  delay( 100 );
+  delay( 10 );
   Serial.begin( baud );
   while( !Serial );   // leonardo fix
+}
+
+void newWait( long w )
+{
+  if( w < 0 ) {
+    Serial.println( F( "Bad number." ));
+    return;
+  }
+
+  wait = w;
+
+  Serial.print( w, DEC );
+  Serial.println( " ms wait." );
 }

@@ -136,8 +150,11 @@
   Serial.println( "Ready." );
   Serial.println( "" );

+  clearLine();
+
+  newRows( 10 );
+  newWait( 0 );
   newCols( 80 );
-  clearLine();
 }

 /////////////////////////////////////////
@@ -203,6 +220,7 @@

 void printText( )
 {
+  const char * cp;
   int idx = 0;
   int ncols = 0;
   int nrows = 0;
@@ -226,7 +244,17 @@
         Serial.print( " " );
         ncols++;
       }
-      Serial.print( lipsum[idx] );
+
+      if( wait > 0 ) {
+        cp = lipsum[idx];
+        while( *cp != '\0' ) {
+          Serial.write( *cp );
+          cp++;
+          delay( wait );
+        }
+      } else {
+        Serial.print( lipsum[idx] );
+      }
       ncols += w;
     }

@@ -284,14 +312,15 @@
     Serial.println( F("       t - text") );
     Serial.println( F("       ? - settings") );
     Serial.println( F("  c<n> - cols") );
+    Serial.println( F("  r<n> - rows") );
     Serial.println( F("  b<n> - baud") );
-    Serial.println( F("  r<n> - rows") );
+    Serial.println( F("  w<n> - wait in ms") );
   }

   else if( !strcmp( line, "?" )) {
-    newCols( cols );
     newRows( rows );
     newBaud( baud );
+    newCols( cols );
   }

   else if( line[0] == 'b' ) {
@@ -300,6 +329,8 @@
     newCols( atol( &line[1] ));
   } else if( line[0] == 'r' ) {
     newRows( atol( &line[1] ));
+  } else if( line[0] == 'w' ) {
+    newWait( atol( &line[1] ));
   }


implemtend mirco stepping and tested 	modified:   mcu_main/mcu_main.ino


Update ATSDashboard.ino

Update ATSDashboard.ino

--- Wemos/ATSDashboard.ino
+++ Wemos/ATSDashboard.ino
@@ -44,6 +44,7 @@
 #endif

 void setup()   {
+  bool mile = true;
   Serial.begin(9600);

   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
@@ -65,21 +66,25 @@
 WiFiClient client1;
   const int httpPort = 80;

-  while (true)
-  {
   if (!client1.connect(host, httpPort)) {
     Serial.println("connection failed");
     return;
   }
+
+  while (true)
+  {
   // We now create a URI for the request
-  String url = "/data.php?key=speed";
+  String url = "/data.php";
+  if (mile)
+  {
+    url += "?m=";
+  }
   Serial.print("Requesting URL: ");
   Serial.println(url);

-  // This will send the request to the server
   client1.print(String("GET ") + url + " HTTP/1.1\r\n" +
                "Host: " + host + "\r\n" +
-               "Connection: close\r\n\r\n");
+               "Connection: Keep-Alive\r\n\r\n");
   delay(500);

   String thing = "";
@@ -89,52 +94,69 @@
     thing = thing + line;
     Serial.print(line);
   }
-  String thespeed = thing.substring(thing.indexOf("<val>") + 5, thing.lastIndexOf("</val>"));
-
+  if (thing == "")
+  {
   if (!client1.connect(host, httpPort)) {
     Serial.println("connection failed");
     return;
   }
-  // We now create a URI for the request
-  String url1 = "/data.php?key=speedLimit";
-  Serial.print("Requesting URL: ");
-  Serial.println(url1);
-
-  // This will send the request to the server
-  client1.print(String("GET ") + url1 + " HTTP/1.1\r\n" +
-               "Host: " + host + "\r\n" +
-               "Connection: close\r\n\r\n");
-  delay(500);
-
-  String thing1 = "";
-
-  while(client1.available()){
-    String line = client1.readString();
-    thing1 = thing1 + line;
-    Serial.print(line);
   }
-  String thespeedlimit = thing1.substring(thing1.indexOf("<val>") + 5, thing1.lastIndexOf("</val>"));
+  else
+  {
+  int thespeed = thing.substring(thing.indexOf("<s>") + 3, thing.lastIndexOf("</s>")).toInt();
+  int thespeedlimit = thing.substring(thing.indexOf("<l>") + 3, thing.lastIndexOf("</l>")).toInt();
+  String engineState = thing.substring(thing.indexOf("<e>") + 3, thing.lastIndexOf("</e>"));
+  bool IsOverLimit = (thespeed > thespeedlimit);

   display.clearDisplay();
   display.setTextSize(1);
   display.setTextColor(WHITE);
   display.setCursor(0,0);
   display.println("Speed:");
+  if (engineState=="0")
+  {
+  display.print("Engine off");
+  }
+  else
+  {
   display.setTextSize(2);
-
-  display.print(thespeed.substring(0, thespeed.indexOf(".")));
+  if (IsOverLimit)
+  {
+  display.setTextColor(BLACK, WHITE);
+  }
+  display.print(thespeed);
   display.setTextSize(1);
+  if (mile)
+  {
+  display.print("mph");
+  }
+  else
+  {
   display.print("km/h");
+  }
+  if (IsOverLimit)
+  {
+  display.setTextColor(WHITE, BLACK);
+  }
+  }
   display.setTextSize(2);
-  display.println(" ");
+  display.println("");
   display.setTextSize(1);
   display.println("Limit: ");
   display.setTextSize(2);
   display.print(thespeedlimit);
   display.setTextSize(1);
+  if (mile)
+  {
+  display.print("mph");
+  }
+  else
+  {
   display.print("km/h");
+  }
   display.display();
-  delay(250);
+  //delay(250);
+  }
   }
 }


still need to fine tune timing, but good enough now

timing still can be fine tuned, b/c a longer click stills goes past one
cycle, but will continue to auto moving map now


Fix os_timer_disarm()

Fix os_timer_disarm()

--- watermeter/core.ino
+++ watermeter/core.ino
@@ -98,7 +98,7 @@
   if (hotInt == 0) {
     hotInt++;
     hotTimeBounce = millis();
-  }
+  } else os_timer_disarm(&hotTimer);
   os_timer_arm(&hotTimer, TIME_BOUNCE, true);
 }

@@ -108,12 +108,11 @@
   if (coldInt == 0) {
     coldInt++;
     coldTimeBounce = millis();
-  }
+  } else os_timer_disarm(&coldTimer);
   os_timer_arm(&coldTimer, TIME_BOUNCE, true);
 }

 void hotTimerCallback(void *pArg) {
-
   /* If a long low level, then retiming hotTimeBounce */
   if (!digitalRead(HOT_PIN)) {
     hotTimeBounce = millis();
@@ -122,7 +121,7 @@

   if (digitalRead(HOT_PIN) && hotTimeBounce + TIME_BOUNCE > millis()) return;

-  os_timer_disarm (&hotTimer);
+  os_timer_disarm(&hotTimer);

   hotInt = 0;

@@ -130,7 +129,7 @@
 }

 void coldTimerCallback(void *pArg) {
-
+
   if (!digitalRead(COLD_PIN)) {
     coldTimeBounce = millis();
     return;
@@ -138,7 +137,7 @@

   if (digitalRead(COLD_PIN) && coldTimeBounce + TIME_BOUNCE > millis()) return;

-  os_timer_disarm (&coldTimer);
+  os_timer_disarm(&coldTimer);

   coldInt = 0;


Remember to store the item when you push to a list

--- alarm.ino
+++ alarm.ino
@@ -50,6 +50,7 @@
 static inline void push_behind(linked_list_t * pos_before, void * item) {
     linked_list_t * self = MALLOC_TYPE(linked_list_t);
     self->next = pos_before->next;
+    self->item = item;
     pos_before->next = self;
 }


Removing lfsr_example from the src directory, it is now in the examples directory.

--- src/lfsr_example.ino
+++ src/lfsr_example.ino
@@ -1,15 +0,0 @@
-
-
-#include "XLR8_LFSR.h"
-
-void setup() {
-  Serial.begin(115200);
-  XLR8_LFSR.set_seed(0x55);
-  XLR8_LFSR.set_freerunning_mode(false);
-}
-
-void loop() {
-  Serial.println(XLR8_LFSR.get_lfsr(), BIN);
-  delay(1000);
-}
-


remove unneeded includes

remove unneeded includes

--- examples/DMX2Ethernet/DMX2Ethernet.ino
+++ examples/DMX2Ethernet/DMX2Ethernet.ino
@@ -43,15 +43,10 @@
 #if defined ( ETHERNET_SHIELD_V2 )
 #include <Ethernet2.h>
 #include <EthernetUdp2.h>
-#include <utility/w5500.h>
 #else
 #include <Ethernet.h>
 #include <EthernetUdp.h>
-#include <utility/w5100.h>
 #endif
-
-#include <IPAddress.h>
-

 #include <LXDMXEthernet.h>
 #include <LXArtNet.h>


Fix SimpleSensor example

Fix SimpleSensor example

--- examples/SimpleSensor/SimpleSensor.ino
+++ examples/SimpleSensor/SimpleSensor.ino
@@ -9,7 +9,7 @@
 }

 void loopHandler() {
-  if ((millis() - last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) && !shutters->moving()) {
+  if ((millis() - last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0)) {
     float temperature = 22;
     Serial.print("Temperature: ");
     Serial.print(temperature);


Implement soil sensor formulas

Implement soil sensor formulas

Implement soil sensor formulas

--- rusk-r002.ino
+++ rusk-r002.ino
@@ -24,10 +24,10 @@
 double POWR3V = 0; //Watts

 int SOILT = A6;
-int SOILTV = 0; //Raw 0-4095
+float SOILTV = 0; //Celsius: Temperature (C) = Vout*41.67-40 :: Temperature (F) = Vout*75.006-40

 int SOILH = A7;
-int SOILHV = 0; //Raw 0-4095
+float SOILHV = 0; //Volumetric Water Content (VWC): http://www.vegetronix.com/TechInfo/How-To-Measure-VWC.phtml

 bool BMP180OK = false;
 float BMP180Pressure = 0; //hPa
@@ -56,7 +56,7 @@
 // These values are mapped and updated in the postSensingVariableMap() function
 char Sound[63] = "0";
 char Power[63] = "0.00 0.00 0.00";
-char SoilTnH[63] = "0 0";
+char SoilTnH[63] = "0.00 0.00";
 char PreTAlt[63] = "0.00 0.00 0.00";
 char AmbiTnH[63] = "0.00 0.00";
 char UVVisIR[63] = "0.00 0.00 0.00";
@@ -88,12 +88,10 @@
 //********************************************************************************
 //********************************************************************************

-/*
 float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
 {
   return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
 }
-*/

 void setPinsMode() {
     pinMode(I2CEN, OUTPUT);
@@ -161,13 +159,41 @@
 }

 int readSoilTemperature() {
-    SOILTV = analogRead(SOILT);
+    //Formula basd on THERM200 documentation (Voltage Output Equation)
+    //http://www.vegetronix.com/Products/THERM200/
+
+    SOILTV = (mapFloat(analogRead(SOILT), 0, 4095, 0, 3.3) * 41.67) - 40;

     return 1;
 }

 int readSoilHumidity() {
-    SOILHV = analogRead(SOILH);
+    // Formula based on VH400 documentation (Voltage Output Curves)
+    // http://vegetronix.com/Products/VH400/VH400-Piecewise-Curve.phtml
+
+    float voltage = mapFloat(analogRead(SOILH), 0, 4095, 0, 3.3);
+
+    if (0 < voltage && voltage <= 1.1)
+    {
+        SOILHV = (10 * voltage) - 1;
+    }
+    else if (1.1 < voltage && voltage <= 1.3)
+    {
+        SOILHV = (25 * voltage) - 17.5;
+    }
+    else if (1.3 < voltage && voltage <= 1.82)
+    {
+        SOILHV = (48.08 * voltage) - 47.5;
+    }
+    else if (1.82 < voltage && voltage <= 2.2)
+    {
+        SOILHV = (26.32 * voltage) - 7.89;
+    }
+    else
+    {
+        // All undocumented and out of range values get a value of -1
+        SOILHV = -1;
+    }

     return 2;
 }
@@ -231,7 +257,7 @@
 void postSensingVariableMap() {
     sprintf(Sound, "%i", SOUNDV);
     sprintf(Power, "%.2f %.2f %.2f", POWR1V, POWR2V, POWR3V);
-    sprintf(SoilTnH, "%i %i", SOILTV, SOILHV);
+    sprintf(SoilTnH, "%.2f %.2f", SOILTV, SOILHV);
     sprintf(PreTAlt, "%.2f %.2f %.2f", BMP180Pressure, BMP180Temperature, BMP180Altitude);
     sprintf(AmbiTnH, "%.2f %.2f", Si7020Temperature, Si7020Humidity);
     sprintf(UVVisIR, "%.2f %.2f %.2f", Si1132UVIndex, Si1132Visible, Si1132InfraRd);


added volume control and some docs

added volume control and some docs

--- TeensyChordPlayer.ino
+++ TeensyChordPlayer.ino
@@ -8,6 +8,10 @@
 //A simple chord player for teensy + audio which allows
 // selection of the most common chords in pop
 // (e.g. I, ii, IV, V, vi) with some decorations.
+
+// Hardware setup:
+// * 4 potentiometers A0 - A3.  A3 could be logarithmic, as it is for volume.
+// * 4 buttons connecting p3-p6 to ground (configures them to use internal pullup resistors)

 // GUItool: begin automatically generated code
 AudioSynthSimpleDrum     drum2;          //xy=58,80
@@ -210,8 +214,8 @@
   sgtl5000_1.volume(0.5);

   AudioInterrupts();
-
-}
+}
+
 void showButtonStates() {
     Serial.print("buttons ");
     Serial.print(buttonStates[0]);
@@ -226,6 +230,9 @@

   if (millis() == next)
   {
+    float volume = map(analogRead(A3), 0, 1023, 0, 60) / 100.0;
+    sgtl5000_1.volume(volume); //TODO: consider updating volume more often.
+
     for(int bn = 0; bn < 4; bn++){
       buttonStates[bn] = digitalRead(3+bn)==LOW;
     }
@@ -254,7 +261,7 @@
     }
     num++;

-    Serial.print("Diagnostics (Audio CPU and Audio Mem max usages: ");
+    Serial.print("Teensy Chord Player - Diagnostics (Audio CPU and Audio Mem max usages: ");
     Serial.print(AudioProcessorUsageMax());
     Serial.print(" ");
     Serial.println(AudioMemoryUsageMax());


game 1 working

game 1 working

preliminary game working, now just have to tweak on the timing

--- game_one/game_one.ino
+++ game_one/game_one.ino
@@ -26,7 +26,14 @@
 unsigned int ptr1 = 0;
 unsigned int ptr_max = 16; //when pointer gets to index 15 we know that is the last part of map

+int val0 = 0;
+int val1 = 0;
+int user0 = 0;
+int user1 = 0;
+
+boolean correct_press();//checks to see if the user pressed the correct buttons
 void map_display();//const unsigned int& map0, const unsigned int& map1, unsigned int& p0, unsigned int& p1);
+

 void setup()
 {
@@ -49,6 +56,7 @@
     lcd.print(blank_writer);
     delay(200);
     map_display();
+    delay(500);
 }

 //map display function
@@ -56,6 +64,24 @@
 {
   lcd.setCursor(0,0);
   int i = 0;
+  //setting val0 and val1
+  val0 = map_0[ptr0];
+  val1 = map_1[ptr1];
+  /*lcd.setCursor(0,0);
+  lcd.print("val0:");
+  lcd.print(val0);
+  lcd.setCursor(0,1);
+  lcd.print("val1:");
+  lcd.print(val1);
+  delay(700);
+  lcd.setCursor(0,0);
+  lcd.print("usr0:");
+  lcd.print(user0);
+  lcd.setCursor(0,1);
+  lcd.print("usr1:");
+  lcd.print(user1);
+  delay(700);*/
+  //displaying map
   for(;i<16;++i)
   {
     lcd.setCursor(i,0);
@@ -69,17 +95,75 @@
     else
       lcd.print(" ");
   }
+  //delay(700);
+}
+
+boolean correct_press()
+{
+  /*lcd.setCursor(0,0);
+  lcd.print(user0);
+  lcd.setCursor(0,1);
+  lcd.print(user1);
+  delay(700);
+   if(user0==val0 && user1==val1)
+   {
+     tone(buzz_pin, 1500, 400);
+     lcd.setCursor(0,0);
+     lcd.print("CORRECT");
+     delay(900);
+   }
+   else{
+     //tone(buzz_pin, 2000, 300);
+     //tone(buzz_pin, 400, 400);
+     lcd.setCursor(0,0);
+     lcd.print("~~~~~~");
+     lcd.setCursor(0,1);
+     lcd.print("~~~~~~");
+     delay(900);
+   }*/
+   //delay(100);
+   return (user0==val0 && user1==val1);
 }

 void loop()
 {
-  while(ptr0<ptr_max)
+  button_state = digitalRead(button_pin);
+  touch_state = digitalRead(touch_pin);
+//  lcd.setCursor(0,0);
+//  lcd.print(touch_state);
+//  lcd.setCursor(0,1);
+//  lcd.print(button_state);
+//  delay(100);
+//  tone(buzz_pin, 900, 40);
+  if(button_state == HIGH)
+  {
+    user1 = 1;
+    /*tone(buzz_pin, 900, 200);
+    lcd.setCursor(0,1);
+    lcd.print("HIHIHIHI");*/
+  }
+  else
+    user1 = 0;
+  if(touch_state == HIGH)
+  {
+    user0 = 1;
+    /*tone(buzz_pin, 1800, 40);
+    lcd.setCursor(0,0);
+    lcd.print("00000");*/
+  }
+  else
+    user0 = 0;
+  if(correct_press())
+  {
+    ++ptr0;
+    ++ptr1;
+  }
+  if(ptr0<ptr_max)
   {
-   delay(700);
-    ++ptr0;
-    ++ptr1;
+   //delay(100);
     map_display();
   }
+
   if(ptr0>=ptr_max)
   {
     lcd.setCursor(0,0);
@@ -87,8 +171,11 @@
     lcd.print(blank_writer);
     lcd.setCursor(0,0);
     lcd.print("DONE! GAME OVER");
+    lcd.setCursor(0,1);
+    lcd.print(blank_writer);
     while(true){}
   }
+  delay(10);
 }

 /*********************************************************************************************************


Added line to fix strange bug

Added line to fix strange bug

--- examples/SimpleList/SimpleList.ino
+++ examples/SimpleList/SimpleList.ino
@@ -10,6 +10,7 @@

 */
 #include "QList.h"
+#include "QList.cpp" // For strange bug fix
 QList<String> myList;
 void setup()
 {


Create canLOAD.ino

Create canLOAD.ino


Use IPAddress.h instead of Ethernet.h

Use IPAddress.h instead of Ethernet.h

--- examples/IniFileExample/IniFileExample.ino
+++ examples/IniFileExample/IniFileExample.ino
@@ -1,7 +1,7 @@
 #include <SD.h>

 #include <SPI.h>
-#include <Ethernet.h>
+#include <IPAddress.h>
 #include <IniFile.h>

 // The select pin used for the SD card


more vestiges

more vestiges

--- MainLaunch/Sanity.ino
+++ MainLaunch/Sanity.ino
@@ -20,7 +20,6 @@
     }
   }

-<<<<<<< Updated upstream
   //RockBlock Sanity
 //  int err = isbd.getSignalQuality(signalQuality);
 //  if (!rockb){
@@ -33,11 +32,8 @@
 //    Serial.print("RockBlock signal quality is ");
 //    Serial.println(signalQuality);
 //  }
-=======
-<<<<<<< Updated upstream
   //  if(!Serial1.available()){
 //    Serial.println("gps sending no data");
->>>>>>> Stashed changes
 //  }

   if(!Serial1.available()){
@@ -45,7 +41,6 @@
    }

   sane = imu && sd;
-=======
   //RockBlock Sanity
   int err = isbd.getSignalQuality(signalQuality);
   if (!rockb){
@@ -65,6 +60,5 @@
    }

   sane = imu && sd&&rockb;
->>>>>>> Stashed changes
 }


change to run over weekend and fill to only 21gal

--- SBR/SBR.ino
+++ SBR/SBR.ino
@@ -338,12 +338,14 @@
 void normalsequence(){//10 hrs
   DateTime now = rtc.now();
   realstarttime = now.unixtime();
-  fillplusair(25,1);
+  fillplusair(21,1);
   now = rtc.now();
   delay(2000);
-  aeration(120,24);//thirtysecaeration(60, 24);
-  delay(2000);
-  settle(180, 24);
+  thirtysecaeration(60, 19);
+  delay(2000);
+  aeration(60,19);
+  delay(2000);
+  settle(180, 19);
   delay(2000);
   decant(6);
   delay(2000);
@@ -351,18 +353,18 @@
 void oldsequence(){
   DateTime now = rtc.now();
   realstarttime = now.unixtime();
-  if (tank<23){
+  if (tank<20){
     fillup();
   }
   now = rtc.now();
   delay(2000);
-  aeration(240, 24);
-  delay(2000);
-  settle(60, 24);
+  aeration(240, 19);
+  delay(2000);
+  settle(60, 19);
   delay(2000);
   skim(60);
   delay(2000);
-  settle(120,24);
+  settle(120,19);
   delay(2000);
   decant(6);
   delay(2000);
@@ -413,8 +415,6 @@
   loading(18);
   loading(20);
   loading(21);
-  loading(23);
-  loading(25);
 }

 void loop() {
@@ -429,22 +429,22 @@
   lcd.setCursor(0,1);
   lcd.print(tank);
   while (x<1){
-   //RASfill(7);//normalsequence();//decant(4);//loading();
+   decant(6);//loading();
     x++;}
     //write conditions for running sequence here and add functions
   if (now.dayOfTheWeek()== 1){//"Monday"
-    if (now.hour()>9 && now.hour()<11){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 2){//"Tuesday"
     if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 3){//"Wednesday"
-    if (now.hour()>6 && now.hour()<8){normalsequence();}}//normalsequence();}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 4){//"thursday"
-    if (now.hour()>6 && now.hour()<8){normalsequence();}}//normalsequence();}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 5){//"Friday"
     if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 6){//"Saturday"
-    if (now.hour()>6 && now.hour()<8){fillplusair(25,1);}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}//fillplusair(21,1);thirtysecaeration(100,10);}}
   if (now.dayOfTheWeek()== 0){//"Sunday"
-    weekend();}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}//weekend();}
   delay(20000);
   weekend();}


change airation cycle again

change airation cycle again

air 30 sec  2 hrs
air 1 min on 3 off 1 hr
5 on 5 off 1 hr
all on 1 hr

--- SBR/SBR.ino
+++ SBR/SBR.ino
@@ -284,6 +284,37 @@
     }
     digitalWrite(air, LOW);
 }
+void oneonthreeoffair(float airduration, int lvl){//duration in min check depth and keep air on and pumps off for time period
+  airduration=airduration*60*1000;
+  lcd.clear();
+  lcd.setCursor(0,0);
+  lcd.print("halftimeAir ");
+  lcd.setBacklight(GREEN);
+  measurevol();
+  lcd.setCursor(0,1);
+  lcd.print(tank);
+  float starttime = millis();
+  delay(100);
+  while (((millis()-starttime)<airduration)&&(tank>lvl)){  //2 min
+    digitalWrite(air, HIGH);
+    delay(30000);
+    delay(30000);
+    digitalWrite(air, LOW);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    int timedisplay = round((airduration-(millis()-starttime))/60/1000);
+    measurevol();
+    lcd.setCursor(0,1);
+    lcd.print(tank);lcd.print("gal  ");
+    lcd.print(timedisplay);lcd.print("min  ");
+    //delay(20000);
+    }
+    digitalWrite(air, LOW);
+}
 void settle(float duration, int lvl){//everything off just timer
   duration=duration*60*1000;
   lcd.clear();
@@ -397,15 +428,18 @@
   delay(2000);
   thirtysecaeration(120, 19);
   delay(2000);
+  oneonthreeoffair(60,19);
+  delay(2000);
   halftimeair(60,19);
   delay(2000);
-  aeration(120,19);
+  aeration(60,19);
   delay(2000);
   settle(180, 19);
   delay(2000);
   decant(6);
   delay(2000);
 }
+
 void oldsequence(){
   DateTime now = rtc.now();
   realstarttime = now.unixtime();


Make entry into binary comm also open up all filtering. SavvyCAN has no means of setting or using hardware filters.

--- M2RET.ino
+++ M2RET.ino
@@ -237,6 +237,7 @@
     //delay(5000); //just for testing. Don't use in production

     Serial.begin(115200);
+
     Wire.begin();

     loadSettings();
@@ -733,6 +734,7 @@
             else if (in_byte == 0xE7) {
                 settings.useBinarySerialComm = true;
                 SysSettings.lawicelMode = false;
+                setPromiscuousMode(); //going into binary comm will set promisc. mode too.
             } else {
                 console.rcvCharacter((uint8_t)in_byte);
             }


COH-77: WIP

COH-77: WIP

--- COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -1,6 +1,8 @@
 // Uncomment exactly one of the following CONFIG_... lines to select which board is being built for.
-//#define CONFIG_Trial2013Winter_Round2_CC1HUB // REV2 cut4 as CC1 hub.
-#define CONFIG_REV9 // REV9 as CC1 relay, cut 2 of the board.
+#define CONFIG_Trial2013Winter_Round2_CC1HUB // REV2 cut4 as CC1 hub.
+//#define CONFIG_REV9 // REV9 as CC1 relay, cut 2 of the board.
+
+#define DEBUG // Uncomment for debug output.

 #include <Arduino.h>
 #include <Wire.h>
@@ -542,7 +544,6 @@

   const uint8_t firstByte = msg[0];

-#ifdef ENABLE_FS20_ENCODING_SUPPORT
   switch(firstByte)
     {
     default: // Reject unrecognised leading type byte.
@@ -663,10 +664,9 @@
       }
 #endif // ALLOW_CC1_SUPPORT_RELAY
     }
-#endif // ENABLE_FS20_ENCODING_SUPPORT

   // Unparseable frame: drop it; possibly log it as an error.
-#if 0 && defined(DEBUG) && !defined(ENABLE_TRIMMED_MEMORY)
+#if 1 && defined(DEBUG) && !defined(ENABLE_TRIMMED_MEMORY)
   p->print(F("!RX bad msg, len+prefix: ")); OTRadioLink::printRXMsg(p, msg-1, min(msglen+1, 8));
 #endif
   return;
@@ -734,7 +734,7 @@

   if(needsToListen)
     {
-#if 1 && defined(DEBUG) && defined(ENABLE_RADIO_RX) && !defined(ENABLE_TRIMMED_MEMORY)
+#if 1 && defined(DEBUG) // && defined(ENABLE_RADIO_RX) && !defined(ENABLE_TRIMMED_MEMORY)
     for(uint8_t lastErr; 0 != (lastErr = PrimaryRadio.getRXErr()); )
       {
       DEBUG_SERIAL_PRINT_FLASHSTRING("!RX err ");
@@ -871,8 +871,7 @@
 static bool FilterRXISR(const volatile uint8_t *buf, volatile uint8_t &buflen)
   {
   if((buflen < 8) || (OTRadioLink::FTp2_CC1PollAndCmd != buf[0])) { return(false); }
-  buflen = 8; // Truncate message to correct size for efficiency.
-  // TODO: filter on inbound address/housecode as FHT8V.getHC{1,2}() are thread-safe.
+  // TODO: filter for only this unit address/housecode as FHT8V.getHC{1,2}() are thread-safe.
   return(true); // Accept message.
   }
 #elif defined(ALLOW_CC1_SUPPORT_HUB)
@@ -882,7 +881,7 @@
   if(buflen < 8) { return(false); }
   const uint8_t t = buf[0];
   if((OTRadioLink::FTp2_CC1Alert != t) && (OTRadioLink::FTp2_CC1PollResponse != t)) { return(false); }
-  buflen = 8; // Truncate message to correct size for efficiency.
+  // TODO: filter for only associated relay address/housecodes.
   return(true); // Accept message.
   }
 #endif