Using a EPR param for enable/disable EEPROM save/retrieve Add 7segment brigtness control with 22k potentiometer on pin A3

--- Timerino.ino
+++ Timerino.ino
@@ -35,8 +35,8 @@
  D1:
  D(2, 3, 4, 5, 6, 7, 8, 9): Keypad
  D10: progression switch (linear or f/stop) - maybe superfluous?
- D11: Relay
- D12: Buzzer
+ D12: Relay
+ D11: Buzzer
  D13: main button (pedal/pushbutton)
  A(0, 1): Ledbar
  A2: 7 segment display
@@ -48,8 +48,8 @@
  D1:
  D(2, 3, 4, 5, 6, 7, 8, 9): Keypad
  D10: progression switch (linear or f/stop) - maybe superfluous?
- D11: Relay
- D12: Buzzer
+ D12: Relay
+ D11: Buzzer
  D13: main button (pedal/pushbutton)
  A0-A6: LCD

@@ -69,7 +69,9 @@
 #define MYMODEL 0
 // change to LOW the following if you want relay be (de)activated on
 // pushbutton *release* instead of *press*
-#define ACTIONSIGNAL HIGH
+#define ACTIONSIGNAL LOW
+
+#define EPR 0 // Set to 1 if you want store in to the eeprom last using val and retrieve it at the new power on

 #include <Keypad.h>
 #include <avr/eeprom.h>
@@ -90,7 +92,7 @@
   #include <SoftwareSerial.h>
   SoftwareSerial Serial7Segment(1,A2);
   const byte lcdrxpin = A2;
-  const byte brightness = 16;  // change this to control 7-Segment brightness
+  const byte lumpin = A3; //Luminosity control
 #elif 1 == MYMODEL
   #include <LiquidCrystal.h>
   LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
@@ -127,6 +129,7 @@

 // Variables
 int i = 0;
+int brightness = 0;
 int time = 0;
 int time_succ;
 int appo_time;
@@ -134,13 +137,15 @@
 int time_dds;
 int time_fsttest;
 int time_fstdown;
-byte timer_mode = MODLINFREE; // timer mode (0 = lin.A, 1 = lin.B, 2 = lin.C, 3 = lin.D, 4 = fst.A, 5 = fst.B, 6 = fst.C, 7 = fst.D)
+byte timer_mode = MODLINFREE;
 long last_time = 0;
 long errlet = 0;
 int btnstatus = 0;         // main button status
 int lastbtnstatus = LOW;     // last main button status
 int selstatus = LOW;
 int lastselstatus = LOW;
+long lum;
+int lastlum;
 boolean running = false;
 boolean btnhigh = false;
 boolean firstpress = true;
@@ -168,7 +173,7 @@
 }
 void metronome() {
   if (running && time%10 == 0) {
-    beep(tone_down, 50);
+    beep(tone_down, 80);
   }
 }

@@ -203,8 +208,13 @@
     // Setup 7SegmentDisplay
     Serial7Segment.begin(9600); // Connect to 7-Segment display in serial mode
     Serial7Segment.write(0x76); // Display reset - brings cursors to the first char
+
+    lum = analogRead(lumpin);
+    brightness = 100*lum/1024;
     Serial7Segment.write(0x7A);  // Brightness control command
     Serial7Segment.write((byte) brightness);
+    lastlum = lum;
+
     Serial7Segment.write('A');
     LEDBar_set_LED_Index(0b000000111111111);
     delay(scrollTime);
@@ -402,7 +412,9 @@
   #endif
   say_clearprecis();
   say_cleartime();
-  eeprom_write_byte(0, MODLINFREE);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODLINFREE);
+  #endif
 }
 void say_up(){
   #if 0 == MYMODEL
@@ -417,7 +429,10 @@
   #endif
   say_clearprecis();
   say_time();
-  eeprom_write_byte(0, MODLINUP);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODLINUP);
+  #endif
+
 }
 void say_down(){
   #if 0 == MYMODEL
@@ -432,7 +447,9 @@
   #endif
   say_clearprecis();
   say_time();
-  eeprom_write_byte(0, MODLINDOWN);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODLINDOWN);
+  #endif
 }
 void say_dds() {
   #if 0 == MYMODEL
@@ -447,7 +464,9 @@
   #endif
   say_clearprecis();
   say_time();
-  eeprom_write_byte(0, MODLINDDS);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODLINDDS);
+  #endif
 }
 void say_fstop(){
   #if 0 == MYMODEL
@@ -462,7 +481,9 @@
     say_cleartime();
   #endif
   say_prec();
-  eeprom_write_byte(0, MODFSTFREE);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODFSTFREE);
+  #endif
 }
 void say_precis() {
   #if 0 == MYMODEL
@@ -477,7 +498,9 @@
     say_cleartime();
   #endif
   say_prec();
-  eeprom_write_byte(0, MODFSTPREC);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODFSTPREC);
+  #endif
 }
 void say_test_strip() {
   #if 0 == MYMODEL
@@ -492,7 +515,9 @@
   #endif
   say_prec();
   say_time();
-  eeprom_write_byte(0, MODFSTTEST);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODFSTTEST);
+  #endif
 }
 void say_fstopdown() {
   #if 0 == MYMODEL
@@ -507,7 +532,9 @@
   #endif
   say_prec();
   say_time();
-  eeprom_write_byte(0, MODFSTDOWN);
+  #if 1 == EPR
+    eeprom_write_byte(0, MODFSTDOWN);
+  #endif
 }
 void say_timermode() {
   switch (timer_mode) {
@@ -580,19 +607,21 @@
   appo_time = 0;
 }

-void load_eeprom() {
-  timer_mode = eeprom_read_byte(0);
-  // if mode is not valid set the first one and return
-  if ((timer_mode & 0b11000) > 0) {
-    timer_mode = MODLINFREE;
-    return;
-  }
-  time_countdown = eeprom_read_word((uint16_t *)1);  // 2 byte
-  time_dds = eeprom_read_word((uint16_t *)3);        // 2 byte
-  time_fsttest = eeprom_read_word((uint16_t *)5);    // 2 byte
-  time_fstdown = eeprom_read_word((uint16_t *)7);    // 2 byte
-  precis = eeprom_read_word((uint16_t *)9);          // 2 byte
-}
+#if 1 == EPR
+  void load_eeprom() {
+    timer_mode = eeprom_read_byte(0);
+    // if mode is not valid set the first one and return
+    if ((timer_mode & 0b11000) > 0) {
+      timer_mode = MODLINFREE;
+      return;
+    }
+    time_countdown = eeprom_read_word((uint16_t *)1);  // 2 byte
+    time_dds = eeprom_read_word((uint16_t *)3);        // 2 byte
+    time_fsttest = eeprom_read_word((uint16_t *)5);    // 2 byte
+    time_fstdown = eeprom_read_word((uint16_t *)7);    // 2 byte
+    precis = eeprom_read_word((uint16_t *)9);          // 2 byte
+  }
+#endif

 void init_timermode() {
   switch (timer_mode) {
@@ -656,6 +685,8 @@
           time = 1;
         appo_time = time;
         say_time();
+      } else if (timer_mode == MODLINUP || timer_mode == MODLINDOWN || timer_mode == MODLINDDS || timer_mode == MODFSTTEST) {
+        reset();
       }
       break;

@@ -679,16 +710,56 @@
         say_time();
       } else if (timer_mode == MODFSTPREC) { // Imposta precisione decodifico i numeri
         switch (key) {
-          case 1:  precis = 1; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 2:  precis = 2; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 3:  precis = 3; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 4:  precis = 4; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 5:  precis = 6; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 6:  precis = 8; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 7:  precis = 12; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 8:  precis = 24; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case 9:  precis = 32; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
-          case '0':  precis = 48; say_prec(); eeprom_write_word((uint16_t *)9, precis); break;
+          case 1:  precis = 1; say_prec();
+                    #if 1 == EPR
+                      eprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 2:  precis = 2; say_prec();
+                   #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                   #endif
+                   break;
+          case 3:  precis = 3; say_prec();
+                   #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                   #endif
+                   break;
+          case 4:  precis = 4; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 5:  precis = 6; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 6:  precis = 8; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 7:  precis = 12; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 8:  precis = 24; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case 9:  precis = 32; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
+          case '0':  precis = 48; say_prec();
+                    #if 1 == EPR
+                      eeprom_write_word((uint16_t *)9, precis);
+                    #endif
+                    break;
           default: break;
         }
       } else {
@@ -708,8 +779,8 @@
 }

 void setup() {
-  //Serial.begin(9600);
-  //Serial.println(">>> Debug <<<");
+//  Serial.begin(9600);
+//  Serial.println(">>> Debug <<<");

 #if 0 == MYMODEL
   // init LED Bar
@@ -721,16 +792,24 @@
   pinMode(A0, OUTPUT);
   pinMode(A1, OUTPUT);
   pinMode(A2, OUTPUT);
+
+#if 0 == MYMODEL
+  pinMode(lumpin, INPUT);
+#elif 1 == MYMODEL
   pinMode(A3, OUTPUT);
+#endif
+
   pinMode(A4, OUTPUT);
   pinMode(A5, OUTPUT);
   pinMode(buzzer, OUTPUT);      // Buzzer pin in Output
-  pinMode(relay, OUTPUT);      // Relé pin in Output
+  pinMode(relay, OUTPUT);      // Rel� pin in Output
   pinMode(mainbtn, INPUT);       // Pedale/pulsante pin in Input
-  pinMode(selector, INPUT);       // Selettore modalità (lineare/fstop) in Input
+  pinMode(selector, INPUT);       // Selettore modalit� (lineare/fstop) in Input

   // read from EEPROM stored values
-  load_eeprom();
+  #if 1 == EPR
+    load_eeprom();
+  #endif

   // Setup display
   setup_display();
@@ -777,6 +856,17 @@
     timer_mode = (selstatus == HIGH) ? MODFSTFREE : MODLINFREE;
     say_timermode();
   }
+
+  lum = analogRead(lumpin);
+
+
+  if (lum < lastlum-10 || lum > lastlum+10) {
+
+    brightness = 100*lum/1024;
+    Serial7Segment.write(0x7A);  // Brightness control command
+    Serial7Segment.write((byte) brightness);
+    lastlum = lum;
+  }

   if (running && btnhigh) {
     // shut down the relay and pause the timer
@@ -830,7 +920,9 @@
         break;
       case MODLINDOWN:
         time_countdown = appo_time;
-        eeprom_write_word((uint16_t *)1, time_countdown);
+        #if 1 == EPR
+          eeprom_write_word((uint16_t *)1, time_countdown);
+        #endif
         if (time > 0) {
           digitalWrite(relay, HIGH); // powerup the relay
           running = true;
@@ -840,7 +932,9 @@
         break;
       case MODLINDDS:
         time_dds = appo_time;
-        eeprom_write_word((uint16_t *)3, time_dds);
+        #if 1 == EPR
+             eeprom_write_word((uint16_t *)3, time_dds);
+        #endif
         if (time > 0) {
           digitalWrite(relay, HIGH); // powerup the relay
           running = true;
@@ -857,7 +951,9 @@
         break;
       case MODFSTTEST:
         time_fsttest = appo_time;
-        eeprom_write_word((uint16_t *)5, time_fsttest);
+        #if 1 == EPR
+             eeprom_write_word((uint16_t *)5, time_fsttest);
+        #endif
         digitalWrite(relay, HIGH); // powerup the relay
         running = true;
         last_time = millis(); // reset timer counter
@@ -869,7 +965,9 @@
         break;
       case MODFSTDOWN:
         time_fstdown = appo_time;
-        eeprom_write_word((uint16_t *)7, time_fstdown);
+        #if 1 == EPR
+             eeprom_write_word((uint16_t *)7, time_fstdown);
+        #endif
         if (time > 0) {
           digitalWrite(relay, HIGH); // powerup the relay
           running = true;


commit nul! a pas prendre

commit nul! a pas prendre

--- calibrateur.ino
+++ calibrateur.ino
@@ -8,7 +8,7 @@

 //a faire pour prochaine fois : pendant les grandes course vérifier si avec le nouveauc compteur qui peut etre négatif ça marche bien.
-autre point de suspissionde bug : la vitesse qui est trop élevé et que le servo n'arrive pas à suivre.
+autre point de suspissionde bug : la vitesse qui est trop élevé et que le servo n'arrive pas à suivre.--> il suffit de baisser VITESSEMAXSERVO (passé de 3500 à 2500)

 //afaire : faire un réinit propre car si on fait 2 étalonnage à la suite ca marche pas
@@ -315,8 +315,8 @@
                     //----------------------------------------------------------
                     //find max
                     compteur=compteurRef;
-                    while (compteur>compteurRef-ERREURCOMPTAGE\
-                            && compteur<compteurRef+ERREURCOMPTAGE)
+                    while (abs(compteur)>(abs(compteurRef)-ERREURCOMPTAGE)\
+                            && abs(compteur)<(abs(compteurRef)+ERREURCOMPTAGE))
                         {
                             Serial.print("M+.....");
                             compteur=0;
@@ -333,8 +333,8 @@
                     //----------------------------------------------------------
                     //find mmin
                     compteur=compteurRef;
-                    while (compteur>compteurRef-ERREURCOMPTAGE\
-                            && compteur<compteurRef+ERREURCOMPTAGE  )
+                    while (abs(compteur)>(abs(compteurRef)-ERREURCOMPTAGE)\
+                            && abs(compteur)<(abs(compteurRef)+ERREURCOMPTAGE))
                         {
                             Serial.print(F("M-......"));
                             compteur=0;
@@ -630,7 +630,8 @@
 void loop ()
 {
     mySCoop.sleep(1);
-    if (millis()>5000+temp)
+    /*
+	if (millis()>5000+temp)
         {
             temp=millis();
 			Serial.println();
@@ -639,6 +640,7 @@
 			Serial.print("freeRam=");
             Serial.println(freeRam());
         }
-
-}
-
+	*/
+
+}
+


minor improvements

minor improvements

- wait for serial init
- show status of ODB-connection

--- ED_BMSdiag.ino
+++ ED_BMSdiag.ino
@@ -1,5 +1,5 @@
 //--------------------------------------------------------------------------------//
-// ED BMSdiag, v0.2
+// ED BMSdiag, v0.21
 // Retrieve battery diagnostic data from your smart electric drive EV.
 //
 // (c) 2016 by MyLab-odyssey
@@ -104,6 +104,8 @@
 void setup()
 {
   Serial.begin(115200);
+  while (!Serial); // while the serial stream is not open, do nothing:
+  Serial.println();

   pinMode(CS, OUTPUT);
   pinMode(CS_SD, OUTPUT);
@@ -123,6 +125,13 @@
   Serial.println(SPACER);
   Serial.println(F("--- ED Battery Management Diagnostics ---"));
   Serial.println(SPACER);
+
+  Serial.println(F("Connect to OBD port - Waiting for CAN-Bus "));
+  do {
+    Serial.print(F("."));
+    delay(1000);
+  } while (digitalRead(2));
+  Serial.println(F("CONNECTED"));
 }

 void WaitforSerial() {
@@ -477,7 +486,7 @@
    //Wait for start via serial terminal
    WaitforSerial();
    clearSerialBuffer();
-
+   Serial.println(SPACER);
    delay(500);

    fOK = ReadSOC();


Contrast control working

Contrast control working

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -15,6 +15,7 @@
 #include <EEPROM.h>

+//#define RESET   // define if resetting all EEPROM data
 #define DEBUG   // define if debugging

@@ -44,7 +45,7 @@
 const int re_pinB = 3;     // encoder B pin
 const int re_pinPush = 4;  // encoder pushbutton pin

-// define Teensy pin controlling contrast
+// define pin controlling contrast
 const byte mc_Contrast = 6;

 // max and min frequency showable
@@ -102,6 +103,10 @@
 #define vfo_Click     5
 #define vfo_HoldClick 6

+// default LCD contrast
+const int DefaultLcdContrast = 50;
+
+
 ////////////////////////////////////////////////////////////////////////////////
 // The VFO state variables and typedefs
 ////////////////////////////////////////////////////////////////////////////////
@@ -113,6 +118,8 @@
 SelOffset VfoSelectDigit;   // selected column index, zero at the right

 typedef byte VFOEvent;
+
+int LcdContrast;

 ////////////////////////////////////////////////////////////////////////////////
@@ -630,11 +637,15 @@
 const int AddressSelDigit = AddressFreq + AddressFreqSize;
 const int AddressSelDigitSize = sizeof(int);

+// address for byte 'contrast'
+const int AddressContrast = AddressSelDigit + AddressSelDigitSize;
+const int AddressContrastSize = sizeof(LcdContrast);
+
 // number of frequency save slots in EEPROM
 const int NumSaveSlots = 10;

 const int SaveFreqSize = sizeof(long);
-const int SaveFreqBase = AddressSelDigit + AddressSelDigitSize;
+const int SaveFreqBase = AddressContrast + AddressContrastSize;
 const int SaveFreqBaseSize = NumSaveSlots * SaveFreqSize;

 //also save the offset for each frequency
@@ -650,6 +661,7 @@
 {
   EEPROM.put(AddressFreq, VfoFrequency);
   EEPROM.put(AddressSelDigit, VfoSelectDigit);
+  EEPROM.put(AddressContrast, LcdContrast);
 }

 // restore VFO state from EEPROM
@@ -657,6 +669,7 @@
 {
   EEPROM.get(AddressFreq, VfoFrequency);
   EEPROM.get(AddressSelDigit, VfoSelectDigit);
+  EEPROM.get(AddressContrast, LcdContrast);
 }

 // given slot number, return freq/offset
@@ -684,17 +697,20 @@
 {
   Frequency ulong;
   SelOffset offset;
+  int contrast;

   EEPROM.get(AddressFreq, ulong);
   EEPROM.get(AddressSelDigit, offset);
+  EEPROM.get(AddressContrast, contrast);
   Serial.println("=================================================");
-  Serial.print("dump_eeprom: VfoFrequency="); Serial.print(ulong);
-  Serial.print(", AddressSelDigit="); Serial.println(offset);
+  Serial.print("dump_eeprom: VfoFrequency="); Serial.println(ulong);
+  Serial.print("             AddressSelDigit="); Serial.println(offset);
+  Serial.print("             LcdContrast="); Serial.println(contrast);

   for (int i = 0; i < NumSaveSlots; ++i)
   {
     get_slot(i, ulong, offset);
-    Serial.print(i); Serial.print(": ");
+    Serial.print("Slot "); Serial.print(i); Serial.print(": ");
     Serial.print(ulong); Serial.print(", ");
     Serial.println(offset);
   }
@@ -734,6 +750,8 @@
   // zero the frequency+selected values
   VfoFrequency = MIN_FREQ;
   VfoSelectDigit = 0;
+  LcdContrast = DefaultLcdContrast;
+
   save_to_eeprom();

   for (int i = 0; i < NumSaveSlots; ++i)
@@ -745,6 +763,11 @@
 void setup(void)
 {
   Serial.begin(115200);
+
+#ifdef RESET
+  zero_slots();
+  Serial.println("All EEPROM data reset");
+#endif

   // initialize the display
   lcd.begin(NUM_COLS, NUM_COLS);      // define display size
@@ -754,7 +777,7 @@

   // initialize contrast control
   pinMode(mc_Contrast, OUTPUT);
-  analogWrite(mc_Contrast, 75);
+  analogWrite(mc_Contrast, DefaultLcdContrast);

   // get state back from EEPROM
   restore_from_eeprom();
@@ -765,7 +788,12 @@
   // show program name and version number
 #ifndef DEBUG
   banner();
+  if (pop_event() == vfo_HoldClick)
+    Serial.println("Would reset here");
 #endif
+
+  // we sometimes see random events on powerup, flush them here
+  flush_events();

   // dump EEPROM values
 #ifdef DEBUG
@@ -806,12 +834,17 @@
 Menu delete_menu = {menu_items[2], savresdel_display, delete_select,
                     NumSaveSlots, NULL};

-//const char *settings_items[] = {"Contrast"};
-//#define NumSettingsMenuItems (sizeof(settings_items)/sizeof(const char *))
-//
-//Menu settings_menu = {menu_items[3], settings_display, settings_select,
-//                      NumSettingsMenuItems, settings_items};
-
+const char *settings_items[] = {"Brightness", "Contrast"};
+#define NumSettingsMenuItems (sizeof(settings_items)/sizeof(const char *))
+
+Menu settings_menu = {menu_items[3], menu_display, settings_select,
+                      NumSettingsMenuItems, settings_items};
+
+const char *contrast_items[] = {"Decrease", "Increase"};
+#define NumContrastMenuItems (sizeof(settings_items)/sizeof(const char *))
+
+Menu contrast_menu = {settings_items[1], menu_display, contrast_select,
+                      NumContrastMenuItems, contrast_items};

 void menu_display(Menu *menu, int slot_num)
 {
@@ -852,6 +885,10 @@
   else if (strcmp(action_text, menu->items[2]) == 0)
   {
       show_menu(&delete_menu);
+  }
+  else if (strcmp(action_text, menu->items[3]) == 0)
+  {
+      show_menu(&settings_menu);
   }
   else
   {
@@ -939,6 +976,30 @@
   put_slot(slot_num, 0L, 0);

   savresdel_display(menu, slot_num);
+}
+
+void settings_select(Menu *menu, int slot_num)
+{
+  Serial.print("settings_select() called, slot_num="); Serial.println(slot_num);
+  show_menu(&contrast_menu);
+}
+
+void contrast_select(Menu *menu, int slot_num)
+{
+  if (slot_num == 0)
+      LcdContrast += 5;
+  else if (slot_num == 1)
+      LcdContrast -= 5;
+  else
+    abort("Bad slot numvber");
+
+  if (LcdContrast < 0)
+    LcdContrast = 0;
+  if (LcdContrast > 125)
+    LcdContrast = 125;
+  analogWrite(mc_Contrast, LcdContrast);
+  save_to_eeprom();
+  action_flash();
 }

 //----------------------------------------------------------
@@ -993,6 +1054,7 @@
       case vfo_HoldClick:
         Serial.println("Got vfo_HoldClick: calling show_menu()");
         show_menu(&main_menu);
+//        save_to_eeprom();
         dump_queue("After show_menu()");
         show_main_screen();
         break;


Minor version to '.2' for next release

Minor version to '.2' for next release

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -47,7 +47,7 @@
 // Digital VFO program name & version
 const char *ProgramName = "DigitalVFO";
 const char *Version = "1.7";
-const char *MinorVersion = ".1";
+const char *MinorVersion = ".2";
 const char *Callsign = "ac3dn";

 // display constants - below is for ubiquitous small HD44780 16x2 display
@@ -250,8 +250,8 @@
 const int MaxOffsetDigits = 5;

 // battery voltage limits
-const float OverVoltage = 7.90;   // battery voltage for CHARGING & FULL
-const float MaxVoltage = 7.80;    // battery voltage for "100% full"
+const float OverVoltage = 8.30;   // battery voltage for CHARGING & FULL
+const float MaxVoltage = 7.90;    // battery voltage for "100% full"
 const float MinVoltage = 6.50;    // battery voltage for "0% full"
                                   // BMS disconnects at around 6.40v
 const float NoBattVoltage = 5.5;  // if at or below this, no battery


add support for BMP280

add support for BMP280

--- ScoutWeatherStation/scout_weather_station/scout_weather_station.ino
+++ ScoutWeatherStation/scout_weather_station/scout_weather_station.ino
@@ -18,6 +18,7 @@
 #define USING_BME 1
 #define USING_BMP 2
 #define USING_DHT 3
+#define USING_BMP280 4

 // display choices
 #define USING_LCD 1
@@ -37,6 +38,7 @@
 #define OLED_RESET 0
 #define BME_ADDRESS 0x76
 #define BMP_ADDRESS 0x77
+#define BMP280_ADDRESS 0x76
 #define LCD_ADDRESS 0x27
 #define OLED_ADDRESS 0x3C
 #define DHTPIN 4
@@ -79,6 +81,7 @@
 #include <Adafruit_Sensor.h>
 #include <Adafruit_BMP085_U.h>
 #include <Adafruit_BME280.h>
+#include <Adafruit_BMP280.h>

 #include <Adafruit_GFX.h>
 #include <Adafruit_SSD1306.h>
@@ -119,6 +122,10 @@
 Adafruit_BMP085_Unified sensor = Adafruit_BMP085_Unified(10085);

 sensors_event_t event;
+#endif
+
+#if SENSOR == USING_BMP280
+Adafruit_BMP280 sensor;
 #endif

 //Variables
@@ -241,6 +248,15 @@
 #if SENSOR == USING_BMP
   Serial.println("Using BMP180 I2C Sensor");
   sensor.begin();
+#endif
+
+
+#if SENSOR == USING_BMP280
+  Serial.println("Using BMP280 I2C Sensor");
+  if (!sensor.begin(0x76)) {
+    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
+    while (1);
+  }
 #endif

 #if SENSOR == USING_DHT
@@ -362,6 +378,14 @@
   display.println("mbar");

 #endif // BME
+
+#if SENSOR == USING_BMP280
+  display.setCursor(18, 43);
+  display.print("Pres: ");
+  display.print(hpascals_to_mbar(pressure), 2);
+  display.println("mbar");
+
+#endif // BMP280

 #if SENSOR == USING_BMP
   display.setCursor(18, 43);
@@ -558,6 +582,11 @@
     humidity = 0.0;
 #endif

+#if SENSOR == USING_BMP280
+    humidity = 0.0;
+    temperature = sensor.readTemperature();
+    pressure = sensor.readPressure();
+#endif
 }


Kleuren voor snelheden gefixt

Kleuren voor snelheden gefixt

should work

--- LightTrain.ino
+++ LightTrain.ino
@@ -13,7 +13,16 @@
 #define IDLE_TIME 300*1000
 #define WIT pixels.Color(255,255,255)
 #define UIT pixels.Color(0,0,0)
-#define KLEUR pixels.Color(200, 100, 0)
+
+#if (delayval >= 200)
+  #define KLEUR pixels.Color(0, 150, 0)
+#elif (delayval < 200)
+  #define KLEUR pixels.Color(200,144,0)
+#elif (delayval < 150)
+  #define KLEUR pixels.Color(200, 100, 0)
+#else
+  #define KLEUR pixels.Color(200, 0, 0)
+#endif

 // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
 // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest


+ Did some more code editing... let's hope that this string concat works.

--- ClydeClock/TouchyFeely.ino
+++ ClydeClock/TouchyFeely.ino
@@ -1,7 +1,7 @@
 // note, cycleRGB is defined in Behaviour.ino
 // Update: we require also a "double-touch" to avoid false positive triggers.
-uint32_t last_touch_time[ 6 ] = {0};
-uint8_t touch_counts[ 6 ] = {0};
+//uint32_t last_touch_time[ 6 ] = {0};
+//uint8_t touch_counts[ 6 ] = {0};

 // multitouch:
 // - use an array to record which legs have been touched
@@ -51,7 +51,7 @@

 void clydeReleased( uint8_t l ){
 #ifdef TOUCHY_FEELY_DEBUG
-  Serial << "Callback- released!" << l << endl;
+  Serial << "TouchyFeely: released! " << l << endl;
 #endif
   //checkTouch( l );
   addToTouchArray( l );
@@ -59,13 +59,13 @@

 void clydeTouched(uint8_t l) {
 #ifdef TOUCHY_FEELY_DEBUG
-  Serial << "Callback- touched!" << l << endl;
+  Serial << "TouchyFeely: touched! " << l << endl;
 #endif
 }

 void clydeDetected(uint8_t l) {
 #ifdef TOUCHY_FEELY_DEBUG
-  Serial << "Callback- Detected!" << l << endl;
+  Serial << "TouchyFeely: Detected! " << l << endl;
 #endif
 }

@@ -111,28 +111,36 @@
   // shift all values in the array
   for( int current_idx = 6; current_idx >= 0; current_idx-- ){
     Serial << "copy " << touch_array_touched_leg[ current_idx ] << " from " << current_idx << endl;
-    touch_array_touched_leg[ ( current_idx + 1 ) ] = touch_array_touched_leg[ current_idx ];
+    touch_array_touched_leg[( current_idx + 1 )] = touch_array_touched_leg[current_idx];
   }
   Serial << "done copying" << endl;
   // add the leg number to the stack and record the last touch time.
-  touch_array_touched_leg[ 0 ] = leg+1;
+  touch_array_touched_leg[0] = (leg+1);
   touch_array_last_touch_time = millis();
 }

 void evalTouchTimeArray(){
   // get the most recent entry in touch_array_times
-  if( ( millis() - touch_array_last_touch_time ) > TOUCH_TRIGGER_DELAY ){
+  if( touch_array_last_touch_time > 0 && ( millis() - touch_array_last_touch_time ) > TOUCH_TRIGGER_DELAY ){
     // evaluate the stack.
     // go through the array and report all duplets (i.e. double touches of the same leg)
     uint8_t lastleg=0;
-    char touch_string[4]; // should be touch_array_touched_leg/2
+    char touch_string[4]=""; // should be touch_array_touched_leg/2
     for( int i=0; i < 8; i++ ){
       if( lastleg!=touch_array_touched_leg[ i ] ){
 	lastleg = touch_array_touched_leg[ i ];
       }else{
+	// means the last record also touched this leg.
 	if( lastleg!=0 ){
 	  #ifdef TOUCHY_FEELY_DEBUG
 	  Serial << "evalTouchTimeArray: got twice " << lastleg << endl;
+	  #endif
+	  // append to the touch_string
+	  char current_leg_string[2]="";
+	  sprintf( current_leg_string, "%d", lastleg );
+	  strcat( touch_string, current_leg_string );
+	  #ifdef TOUCHY_FEELY_DEBUG
+	  Serial << "evalTouchTimeArray: the touch string is now " << touch_string << endl;
 	  #endif
 	  // report the lastleg, maybe add to character string?
 	  //int aInt = 368;
@@ -143,9 +151,15 @@
 	  //sprintf( num_str, "%d", lastleg );
 	  //strcat( touch_string, num_str );
 	}
-	lastleg = 0;  // set that to 31, so we're looking for a new duplet.
+	lastleg = 0;  // set that to 0, so we're looking for a new duplet.
       }
+      // reset the value...
+      touch_array_touched_leg[ i ] = 0;
     }
+#ifdef TOUCHY_FEELY_DEBUG
+    Serial << "evalTouchTimeArray: FINAL touch string: " << touch_string << endl;
+#endif
+
     //    if( strcmp( touch_string, "1" )==0 ){
     //#ifdef TOUCHY_FEELY_DEBUG
       //Serial << "evalTouchArray! got 1: " << touch_string << endl;
@@ -163,8 +177,5 @@
     // compare strings: strcmp( stringa, stringb), returns 0 if they are equal.
     // make a switch thing
     // reset the stack!
-    for( int i=0; i < 8; i++ ){
-      touch_array_touched_leg[ i ] = 0;
-    }
   }
 }


updated pretty_wifi_info.lua script path

--- hardware/arduino/avr/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino
+++ hardware/arduino/avr/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino
@@ -16,7 +16,7 @@
 void loop() {
   Process wifiCheck;    // initialize a new process

-  wifiCheck.runShellCommand("lua /usr/lib/lua/pretty_wifi_info.lua");        // command you want to run
+  wifiCheck.runShellCommand("lua /arduino/pretty_wifi_info.lua");        // command you want to run

   // while there's any characters coming back from the
   // process, print them to the serial monitor:


Finalized first version

Finalized first version

--- ArcReactor.ino
+++ ArcReactor.ino
@@ -90,12 +90,12 @@
     {
       strip.setPixelColor(i, cyan);
     }
-    strip.setPixelColor((wanderPos - 1) % RING_LEDS, halfWhite);
+    strip.setPixelColor((RING_LEDS + wanderPos - 1) % RING_LEDS, halfWhite);
     strip.setPixelColor(wanderPos, white);
     strip.setPixelColor((wanderPos + 1) % RING_LEDS, halfWhite);
     strip.show();

-    delay(500);
+    delay(750);

     wanderPos = (wanderPos + 1) % RING_LEDS;
   }
@@ -135,6 +135,6 @@
   strip.begin();
   strip.show();

-  //startUp();
+  startUp();
 }


Passed the test for USB Mode function

Passed the test for USB Mode function

Modified My_USBMode() a little and passed the test without the dongle
I'll try it with a dongle later

--- c_I2C.ino
+++ c_I2C.ino
@@ -512,10 +512,10 @@
     //power off camera
     buf[0] = 3; buf[1] = 'P'; buf[2] = 'W'; buf[3] = 0x00;
     SendBufToCamera();
-
-    //detach Mewpro
-    pinMode(BPRDY, INPUT);
-    delay(500);
+    tdDone = false;
+
+    //wait for some time
+    delay(5000);

     //power on camera
     pinMode(PWRBTN, OUTPUT);
@@ -523,6 +523,10 @@
     delay(1000);
     tdDone = false;     //maybe comment this later
     pinMode(PWRBTN, INPUT);
+
+    //detach Mewpro
+    pinMode(BPRDY, INPUT);
+    delay(1000);

 //DO NOT UNCOMMENT codes below (not tested yet)
 /*
@@ -536,6 +540,8 @@
 */

     noInterrupts(); //mask all interrupts so that no more SMARTY commands will be sent
+    __debug(F("Plug in USB cable now"));
+    Serial.flush();
     while(1);       //dead loop to make sure Mewpro won't interfere USB transmission

 }
@@ -591,6 +597,17 @@
           }
         }
         return;
+
+        case '^':
+        bufp = 1;
+        __debug(F("Getting into USB Mode"));
+        My_USBMode();
+        while (inputAvailable()) {
+          if (myRead() == '\n') {
+            return;
+          }
+        }
+        return;

 //*************************End of custom commands***********************************


Sensors calibrated

Sensors calibrated

--- OpenRocket.ino
+++ OpenRocket.ino
@@ -8,7 +8,7 @@
 */

 #define HW__VERSION_CODE 10724 // SparkFun "9DOF Sensor Stick" version "SEN-10724" (HMC5883L magnetometer)
-#define OUTPUT__BAUD_RATE 9600
+#define OUTPUT__BAUD_RATE 115200
 #define OUTPUT__DATA_INTERVAL 20  // in milliseconds
 #define WRITE__DATA_INTERVAL 1000  // in milliseconds

@@ -41,12 +41,12 @@

 // Magnetometer (standard calibration)
 // "magn x,y,z (min/max) = X_MIN/X_MAX  Y_MIN/Y_MAX  Z_MIN/Z_MAX"
-#define MAGN_X_MIN ((float) -600)
-#define MAGN_X_MAX ((float) 600)
-#define MAGN_Y_MIN ((float) -600)
-#define MAGN_Y_MAX ((float) 600)
-#define MAGN_Z_MIN ((float) -600)
-#define MAGN_Z_MAX ((float) 600)
+#define MAGN_X_MIN ((float) -250)
+#define MAGN_X_MAX ((float) 354)
+#define MAGN_Y_MIN ((float) -420)
+#define MAGN_Y_MAX ((float) 220)
+#define MAGN_Z_MIN ((float) -400)
+#define MAGN_Z_MAX ((float) 248)

 // Magnetometer (extended calibration)
 // Uncommend to use extended magnetometer calibration (compensates hard & soft iron errors)
@@ -56,9 +56,9 @@

 // Gyroscope
 // "gyro x,y,z (current/average) = .../OFFSET_X  .../OFFSET_Y  .../OFFSET_Z
-#define GYRO_AVERAGE_OFFSET_X ((float) 0.0)
-#define GYRO_AVERAGE_OFFSET_Y ((float) 0.0)
-#define GYRO_AVERAGE_OFFSET_Z ((float) 0.0)
+#define GYRO_AVERAGE_OFFSET_X ((float) 21.86)
+#define GYRO_AVERAGE_OFFSET_Y ((float) -31.37)
+#define GYRO_AVERAGE_OFFSET_Z ((float) -5.04)

 /*
 // Calibration example:
@@ -392,7 +392,7 @@
 {
   Calculate_Events();

-  Serial.println((vector_module(accel)*0.04205)/9.8-1);
+  Serial.println((vector_module(accel)*0.04205)/9.8);
   delay(100);

   if((millis() - timestamp) >= OUTPUT__DATA_INTERVAL)


line endings?

line endings?

--- WhatWayIno.ino
+++ WhatWayIno.ino
@@ -1,51 +1,51 @@
-#include <Wire.h>
-#include <SPI.h>
-#include <SD.h>
+#include <Wire.h>
+#include <SPI.h>
+#include <SD.h>
 #include <Adafruit_GFX.h>		// Source: https://github.com/adafruit/Adafruit-GFX-Library
-#include <Adafruit_ST7735.h>	// Source: https://github.com/adafruit/Adafruit-ST7735-Library
-#include "WhatWayGame.h"
-
-#define SD_CS	 4
+#include <Adafruit_ST7735.h>	// Source: https://github.com/adafruit/Adafruit-ST7735-Library
+#include "WhatWayGame.h"
+
+#define SD_CS	 4
 #define TFT_CS	10
 #define TFT_RST  8
-#define TFT_DC	 9
-
-const int chipSelect = 4;
-Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
-
-WhatWayGame game;
-
-void setup()
-{
+#define TFT_DC	 9
+
+const int chipSelect = 4;
+Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
+
+WhatWayGame game;
+
+void setup()
+{
 	Serial.begin(9600);
-	Wire.begin();
-	initDisplay();
-	initSD();
-
-	game = WhatWayGame();
-	game.Start();
-}
-
-void loop(void)
-{
-	game.Update();
-	game.Render(&tft);
-}
-
-void initDisplay()
-{
+	Wire.begin();
+	initDisplay();
+	initSD();
+
+	game = WhatWayGame();
+	game.Start();
+}
+
+void loop(void)
+{
+	game.Update();
+	game.Render(&tft);
+}
+
+void initDisplay()
+{
 	tft.initR(INITR_BLACKTAB);
 	delay(500);
-	tft.fillScreen(ST7735_BLACK);
-}
-
-void initSD()
-{
-	Serial.print("Initializing SD card...");
-	if (!SD.begin(SD_CS))
-	{
-		Serial.println("failed!");
-		return;
-	}
-	Serial.println("OK!");
+	tft.fillScreen(ST7735_BLACK);
+}
+
+void initSD()
+{
+	Serial.print("Initializing SD card...");
+	if (!SD.begin(SD_CS))
+	{
+		Serial.println("failed!");
+		return;
+	}
+	Serial.println("OK!");
 }


WIP cleaning up code

WIP cleaning up code


Change baud rate to use default one for RC communication

--- Arduino/MS561101BA_altitude/MS561101BA_altitude.ino
+++ Arduino/MS561101BA_altitude/MS561101BA_altitude.ino
@@ -43,7 +43,7 @@

 void setup() {
   Wire.begin();
-  Serial.begin(115200);
+  Serial.begin(57600);
   delay(1000);

   // Suppose that the CSB pin is connected to GND.


remove light related stuff from master

remove light related stuff from master

--- src/neurite.ino
+++ src/neurite.ino
@@ -1230,8 +1230,6 @@
 void neurite_user_setup(void)
 {
 	log_dbg("\n\r");
-	pinMode(14, OUTPUT);
-	analogWrite(14, 1023);
 }

 /* called once on mqtt message received */
@@ -1242,48 +1240,12 @@
 		char *subtopic = topic + strlen(nd->topic_private) - 2;
 		char *token = NULL;
 		token = strtok(subtopic, "/");
-		/* check for something like: /neuro/neurite-000c1636/io */
 		if (strcmp(token, "io") == 0) {
 			log_dbg("hit io, payload: %c\n\r", payload[0]);
-			if (payload[0] == '0')
-				analogWrite(14, 0);
-			else
-				analogWrite(14, 1023);
 		}
 	}
 	if (strcmp(topic, nd->cfg.topic_from) == 0) {
-		if (length >= 7 &&
-		    payload[0] == 'l' &&
-		    payload[1] == 'i' &&
-		    payload[2] == 'g' &&
-		    payload[3] == 'h' &&
-		    payload[4] == 't' &&
-		    payload[5] == ' ' &&
-		    payload[6] == 'o')
-			if (payload[7] == 'n')
-				analogWrite(14, 0);
-			else
-				analogWrite(14, 1023);
-	}
-	char *token = NULL;
-	char *msg = (char *)malloc(MQTT_MSG_LEN);
-	__bzero(msg, sizeof(msg));
-	for (int i = 0; i < length; i++)
-		msg[i] = payload[i];
-	msg[length] = '\0';
-	token = strtok(msg, " ");
-	if (token == NULL) {
-		log_warn("no payload, ignore\n\r");
-	} else if (strcmp(token, "light:") == 0) {
-		token = strtok(NULL, "\0");
-		if (token) {
-			int val = atoi(token);
-			log_dbg("hit light, msg(value): %s(%d)\n\r", token, val);
-			analogWrite(14, val);
-		}
-	} else {
-	}
-	free(msg);
+	}
 }

 /* time_ms: the time delta in ms of button press/release cycle. */
@@ -1297,9 +1259,9 @@
 			char buf[4];
 			val = 1 - val;
 			if (val)
-				mqtt_cli.publish("/neuro/chatroom", "light on");
+				mqtt_cli.publish(nd->cfg.topic_to, "light on");
 			else
-				mqtt_cli.publish("/neuro/chatroom", "light off");
+				mqtt_cli.publish(nd->cfg.topic_to, "light off");
 		}
 	}
 }


Delete example.ino

Delete example.ino

--- example.ino
+++ example.ino
@@ -1,390 +0,0 @@
-/*------------------------------------------------------------------------
-  POV LED double staff sketch.  Uses the following Adafruit parts
-  (X2 for two staffs):
-
-  - Pro Trinket 5V https://www.adafruit.com/product/2000
-  - 2200 mAh Lithium Ion Battery https://www.adafruit.com/product/1781
-  - LiPoly Backpack https://www.adafruit.com/product/2124
-  - Tactile On/Off Switch with Leads https://www.adafruit.com/product/1092
-  - 144 LED/m DotStar strip (#2328 or #2329)
-    (ONE METER is enough for ONE STAFF, TWO METERS for TWO staffs)
-  - Infrared Sensor: https://www.adafruit.com/product/157
-  - Mini Remote Control: https://www.adafruit.com/product/389
-    (only one remote is required for multiple staffs)
-
-  Needs Adafruit_DotStar library: github.com/adafruit/Adafruit_DotStar
-
-  This is based on the LED poi code (also included in the repository),
-  but ATtiny-specific code has been stripped out for brevity, since the
-  staffs pretty much require Pro Trinket or better (lots more LEDs here).
-
-  Adafruit invests time and resources providing this open source code,
-  please support Adafruit and open-source hardware by purchasing
-  products from Adafruit!
-
-  Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
-  MIT license, all text above must be included in any redistribution.
-  See 'COPYING' file for additional notes.
-  ------------------------------------------------------------------------*/
-
-#include <Arduino.h>
-#include <Adafruit_DotStar.h>
-#include <avr/power.h>
-#include <avr/sleep.h>
-#include <SPI.h>
-
-typedef uint16_t line_t;
-
-// CONFIGURABLE STUFF ------------------------------------------------------
-
-#include "graphics.h" // Graphics data is contained in this header file.
-// It's generated using the 'convert.py' Python script.  Various image
-// formats are supported, trading off color fidelity for PROGMEM space.
-// Handles 1-, 4- and 8-bit-per-pixel palette-based images, plus 24-bit
-// truecolor.  1- and 4-bit palettes can be altered in RAM while running
-// to provide additional colors, but be mindful of peak & average current
-// draw if you do that!  Power limiting is normally done in convert.py
-// (keeps this code relatively small & fast).
-
-// Ideally you use hardware SPI as it's much faster, though limited to
-// specific pins.  If you really need to bitbang DotStar data & clock on
-// different pins, optionally define those here:
-//#define LED_DATA_PIN  0
-//#define LED_CLOCK_PIN 1
-
-// Empty and full thresholds (millivolts) used for battery level display:
-#define BATT_MIN_MV 3350 // Some headroom over battery cutoff near 2.9V
-#define BATT_MAX_MV 4000 // And little below fresh-charged battery near 4.1V
-
-boolean autoCycle = true; // Set to true to cycle images by default
-#define CYCLE_TIME 15     // Time, in seconds, between auto-cycle images
-
-#define IR_PIN     3      // MUST be INT1 pin!
-
-// Adafruit IR Remote Codes:
-//   Button       Code         Button  Code
-//   -----------  ------       ------  -----
-//   VOL-:        0x0000       0/10+:  0x000C
-//   Play/Pause:  0x0001       1:      0x0010
-//   VOL+:        0x0002       2:      0x0011
-//   SETUP:       0x0004       3:      0x0012
-//   STOP/MODE:   0x0006       4:      0x0014
-//   UP:          0x0005       5:      0x0015
-//   DOWN:        0x000D       6:      0x0016
-//   LEFT:        0x0008       7:      0x0018
-//   RIGHT:       0x000A       8:      0x0019
-//   ENTER/SAVE:  0x0009       9:      0x001A
-//   Back:        0x000E
-
-#define BTN_BRIGHT_UP    0x0002
-#define BTN_BRIGHT_DOWN  0x0000
-#define BTN_RESTART      0x0001
-#define BTN_BATTERY      0x0004
-#define BTN_FASTER       0x0005
-#define BTN_SLOWER       0x000D
-#define BTN_OFF          0x0006
-#define BTN_PATTERN_PREV 0x0008
-#define BTN_PATTERN_NEXT 0x000A
-#define BTN_NONE         0xFFFF
-#define BTN_AUTOPLAY     0x0009
-
-// -------------------------------------------------------------------------
-
-#if defined(LED_DATA_PIN) && defined(LED_CLOCK_PIN)
-// Older DotStar LEDs use GBR order.  If colors are wrong, edit here.
-Adafruit_DotStar strip = Adafruit_DotStar(NUM_LEDS,
-  LED_DATA_PIN, LED_CLOCK_PIN, DOTSTAR_BGR);
-#else
-Adafruit_DotStar strip = Adafruit_DotStar(NUM_LEDS, DOTSTAR_BGR);
-#endif
-
-void     imageInit(void),
-         IRinterrupt(void),
-         showBatteryLevel(void);
-uint16_t readVoltage(void);
-
-void setup() {
-  strip.begin(); // Allocate DotStar buffer, init SPI
-  strip.clear(); // Make sure strip is clear
-  strip.show();  // before measuring battery
-
-  showBatteryLevel();
-  imageInit();   // Initialize pointers for default image
-
-  attachInterrupt(1, IRinterrupt, CHANGE); // IR remote interrupt
-}
-
-void showBatteryLevel(void) {
-  // Display battery level bargraph on startup.  It's just a vague estimate
-  // based on cell voltage (drops with discharge) but doesn't handle curve.
-  uint16_t mV  = readVoltage();
-  uint8_t  lvl = (mV >= BATT_MAX_MV) ? NUM_LEDS : // Full (or nearly)
-                 (mV <= BATT_MIN_MV) ?        1 : // Drained
-                 1 + ((mV - BATT_MIN_MV) * NUM_LEDS + (NUM_LEDS / 2)) /
-                 (BATT_MAX_MV - BATT_MIN_MV + 1); // # LEDs lit (1-NUM_LEDS)
-  for(uint8_t i=0; i<lvl; i++) {                  // Each LED to batt level...
-    uint8_t g = (i * 5 + 2) / NUM_LEDS;           // Red to green
-    strip.setPixelColor(i, 4-g, g, 0);
-    strip.show();                                 // Animate a bit
-    delay(250 / NUM_LEDS);
-  }
-  delay(1500);                                    // Hold last state a moment
-  strip.clear();                                  // Then clear strip
-  strip.show();
-}
-
-// GLOBAL STATE STUFF ------------------------------------------------------
-
-uint32_t lastImageTime = 0L, // Time of last image change
-         lastLineTime  = 0L;
-uint8_t  imageNumber   = 0,  // Current image being displayed
-         imageType,          // Image type: PALETTE[1,4,8] or TRUECOLOR
-        *imagePalette,       // -> palette data in PROGMEM
-        *imagePixels,        // -> pixel data in PROGMEM
-         palette[16][3];     // RAM-based color table for 1- or 4-bit images
-line_t   imageLines,         // Number of lines in active image
-         imageLine;          // Current line number in image
-volatile uint16_t irCode = BTN_NONE; // Last valid IR code received
-
-const uint8_t PROGMEM brightness[] = { 15, 31, 63, 127, 255 };
-uint8_t bLevel = sizeof(brightness) - 1;
-
-// Microseconds per line for various speed settings
-const uint16_t PROGMEM lineTable[] = { // 375 * 2^(n/3)
-  1000000L /  375, // 375 lines/sec = slowest
-  1000000L /  472,
-  1000000L /  595,
-  1000000L /  750, // 750 lines/sec = mid
-  1000000L /  945,
-  1000000L / 1191,
-  1000000L / 1500  // 1500 lines/sec = fastest
-};
-uint8_t  lineIntervalIndex = 3;
-uint16_t lineInterval      = 1000000L / 750;
-
-void imageInit() { // Initialize global image state for current imageNumber
-  imageType    = pgm_read_byte(&images[imageNumber].type);
-  imageLines   = pgm_read_word(&images[imageNumber].lines);
-  imageLine    = 0;
-  imagePalette = (uint8_t *)pgm_read_word(&images[imageNumber].palette);
-  imagePixels  = (uint8_t *)pgm_read_word(&images[imageNumber].pixels);
-  // 1- and 4-bit images have their color palette loaded into RAM both for
-  // faster access and to allow dynamic color changing.  Not done w/8-bit
-  // because that would require inordinate RAM (328P could handle it, but
-  // I'd rather keep the RAM free for other features in the future).
-  if(imageType == PALETTE1)      memcpy_P(palette, imagePalette,  2 * 3);
-  else if(imageType == PALETTE4) memcpy_P(palette, imagePalette, 16 * 3);
-  lastImageTime = millis(); // Save time of image init for next auto-cycle
-}
-
-void nextImage(void) {
-  if(++imageNumber >= NUM_IMAGES) imageNumber = 0;
-  imageInit();
-}
-
-void prevImage(void) {
-  imageNumber = imageNumber ? imageNumber - 1 : NUM_IMAGES - 1;
-  imageInit();
-}
-
-// MAIN LOOP ---------------------------------------------------------------
-
-void loop() {
-  uint32_t t = millis(); // Current time, milliseconds
-
-  if(autoCycle) {
-    if((t - lastImageTime) >= (CYCLE_TIME * 1000L)) nextImage();
-    // CPU clocks vary slightly; multiple poi won't stay in perfect sync.
-    // Keep this in mind when using auto-cycle mode, you may want to cull
-    // the image selection to avoid unintentional regrettable combinations.
-  }
-
-  // Transfer one scanline from pixel data to LED strip:
-
-  // If you're really pressed for graphics space and need just a few extra
-  // scanlines, and know for a fact you won't be using certain image modes,
-  // you can comment out the corresponding blocks below.  e.g. disabling
-  // PALETTE8 and TRUECOLOR support can free up nearly 200 bytes of extra
-  // image storage.
-
-  switch(imageType) {
-
-    case PALETTE1: { // 1-bit (2 color) palette-based image
-      uint8_t  pixelNum = 0, byteNum, bitNum, pixels, idx,
-              *ptr = (uint8_t *)&imagePixels[imageLine * NUM_LEDS / 8];
-      for(byteNum = NUM_LEDS/8; byteNum--; ) { // Always padded to next byte
-        pixels = pgm_read_byte(ptr++);  // 8 pixels of data (pixel 0 = LSB)
-        for(bitNum = 8; bitNum--; pixels >>= 1) {
-          idx = pixels & 1; // Color table index for pixel (0 or 1)
-          strip.setPixelColor(pixelNum++,
-            palette[idx][0], palette[idx][1], palette[idx][2]);
-        }
-      }
-      break;
-    }
-
-    case PALETTE4: { // 4-bit (16 color) palette-based image
-      uint8_t  pixelNum, p1, p2,
-              *ptr = (uint8_t *)&imagePixels[imageLine * NUM_LEDS / 2];
-      for(pixelNum = 0; pixelNum < NUM_LEDS; ) {
-        p2  = pgm_read_byte(ptr++); // Data for two pixels...
-        p1  = p2 >> 4;              // Shift down 4 bits for first pixel
-        p2 &= 0x0F;                 // Mask out low 4 bits for second pixel
-        strip.setPixelColor(pixelNum++,
-          palette[p1][0], palette[p1][1], palette[p1][2]);
-        strip.setPixelColor(pixelNum++,
-          palette[p2][0], palette[p2][1], palette[p2][2]);
-      }
-      break;
-    }
-
-    case PALETTE8: { // 8-bit (256 color) PROGMEM-palette-based image
-      uint16_t  o;
-      uint8_t   pixelNum,
-               *ptr = (uint8_t *)&imagePixels[imageLine * NUM_LEDS];
-      for(pixelNum = 0; pixelNum < NUM_LEDS; pixelNum++) {
-        o = pgm_read_byte(ptr++) * 3; // Offset into imagePalette
-        strip.setPixelColor(pixelNum,
-          pgm_read_byte(&imagePalette[o]),
-          pgm_read_byte(&imagePalette[o + 1]),
-          pgm_read_byte(&imagePalette[o + 2]));
-      }
-      break;
-    }
-
-    case TRUECOLOR: { // 24-bit ('truecolor') image (no palette)
-      uint8_t  pixelNum, r, g, b,
-              *ptr = (uint8_t *)&imagePixels[imageLine * NUM_LEDS * 3];
-      for(pixelNum = 0; pixelNum < NUM_LEDS; pixelNum++) {
-        r = pgm_read_byte(ptr++);
-        g = pgm_read_byte(ptr++);
-        b = pgm_read_byte(ptr++);
-        strip.setPixelColor(pixelNum, r, g, b);
-      }
-      break;
-    }
-  }
-
-  if(++imageLine >= imageLines) imageLine = 0; // Next scanline, wrap around
-
-  while(((t = micros()) - lastLineTime) < lineInterval) {
-    if(irCode != BTN_NONE) {
-      if(!strip.getBrightness()) { // If strip is off...
-        // Set brightness to last level
-        strip.setBrightness(pgm_read_byte(&brightness[bLevel]));
-        // and ignore button press (don't fall through)
-        // effectively, first press is 'wake'
-      } else {
-        switch(irCode) {
-         case BTN_BRIGHT_UP:
-          if(bLevel < (sizeof(brightness) - 1))
-            strip.setBrightness(pgm_read_byte(&brightness[++bLevel]));
-          break;
-         case BTN_BRIGHT_DOWN:
-          if(bLevel)
-            strip.setBrightness(pgm_read_byte(&brightness[--bLevel]));
-          break;
-         case BTN_FASTER:
-          if(lineIntervalIndex < (sizeof(lineTable) / sizeof(lineTable[0]) - 1))
-            lineInterval = pgm_read_word(&lineTable[++lineIntervalIndex]);
-          break;
-         case BTN_SLOWER:
-          if(lineIntervalIndex)
-            lineInterval = pgm_read_word(&lineTable[--lineIntervalIndex]);
-          break;
-         case BTN_RESTART:
-          imageNumber = 0;
-          imageInit();
-          break;
-         case BTN_BATTERY:
-          strip.clear();
-          strip.show();
-          delay(250);
-          strip.setBrightness(255);
-          showBatteryLevel();
-          strip.setBrightness(pgm_read_byte(&brightness[bLevel]));
-          break;
-         case BTN_OFF:
-          strip.setBrightness(0);
-          break;
-         case BTN_PATTERN_PREV:
-          prevImage();
-          break;
-         case BTN_PATTERN_NEXT:
-          nextImage();
-          break;
-         case BTN_AUTOPLAY:
-	  autoCycle = !autoCycle;
-          break;
-        }
-      }
-      irCode = BTN_NONE;
-    }
-  }
-
-  strip.show(); // Refresh LEDs
-  lastLineTime = t;
-}
-
-
-void IRinterrupt() {
-  static uint32_t pulseStartTime = 0, pulseDuration = 0;
-  static uint8_t  irValue, irBits, irBytes, irBuf[4];
-  uint32_t t = micros();
-  if(PIND & 0b00001000) { // Low-to-high (start of new pulse)
-    pulseStartTime = t;
-  } else {                // High-to-low (end of current pulse)
-    uint32_t pulseDuration = t - pulseStartTime;
-    if((pulseDuration > 4000) && (pulseDuration < 5000)) { // ~4.5 ms?
-      irValue = irBits = irBytes = 0; // IR code start, reset counters
-    } else if(pulseDuration < 2500) { // Data bit?
-      irValue >>= 1;                  // Shift data in, LSB first
-      if(pulseDuration >= 1125) irValue |= 0x80; // Longer pulse = 1
-      if((++irBits == 8) && (irBytes < 4)) { // Full byte recv'd?
-        irBuf[irBytes] = irValue;            // Store byte
-        irValue = irBits = 0;                // and reset counters
-        if((++irBytes == 4) && ((irBuf[2] ^ irBuf[3]) == 0xFF)) {
-          uint16_t code = 0xFFFF;
-          if((irBuf[0] ^ irBuf[1]) == 0xFF) {
-            irCode = (irBuf[0] << 8) | irBuf[1];
-          } else if((irBuf[0] == 0) && (irBuf[1] == 0xBF)) {
-            irCode = irBuf[2];
-          }
-        }
-      }
-    }
-  }
-}
-
-// Battery monitoring idea adapted from JeeLabs article:
-// jeelabs.org/2012/05/04/measuring-vcc-via-the-bandgap/
-// Code from Adafruit TimeSquare project, added Trinket support.
-// In a pinch, the poi code can work on a 3V Trinket, but the battery
-// monitor will not work correctly (due to the 3.3V regulator), so
-// maybe just comment out any reference to this code in that case.
-uint16_t readVoltage() {
-  int      i, prev;
-  uint8_t  count;
-  uint16_t mV;
-
-  // Select AVcc voltage reference + Bandgap (1.8V) input
-  ADMUX  = _BV(REFS0) |
-           _BV(MUX3)  | _BV(MUX2) | _BV(MUX1);
-  ADCSRA = _BV(ADEN)  |                          // Enable ADC
-           _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // 1/128 prescaler (125 KHz)
-  // Datasheet notes that the first bandgap reading is usually garbage as
-  // voltages are stabilizing.  It practice, it seems to take a bit longer
-  // than that.  Tried various delays, but still inconsistent and kludgey.
-  // Instead, repeated readings are taken until four concurrent readings
-  // stabilize within 10 mV.
-  for(prev=9999, count=0; count<4; ) {
-    for(ADCSRA |= _BV(ADSC); ADCSRA & _BV(ADSC); ); // Start, await ADC conv.
-    i  = ADC;                                       // Result
-    mV = i ? (1100L * 1023 / i) : 0;                // Scale to millivolts
-    if(abs((int)mV - prev) <= 10) count++;   // +1 stable reading
-    else                          count = 0; // too much change, start over
-    prev = mV;
-  }
-  ADCSRA = 0; // ADC off
-  return mV;
-}


Revert "Display startup message at dxl_monitor.ino"

--- arduino/opencr_arduino/opencr/libraries/DynamixelSDK/examples/protocol2.0/dxl_monitor/dxl_monitor.ino
+++ arduino/opencr_arduino/opencr/libraries/DynamixelSDK/examples/protocol2.0/dxl_monitor/dxl_monitor.ino
@@ -21,7 +21,6 @@
 void setup()
 {
   CMD_SERIAL.begin(57600);
-  while(!CMD_SERIAL);
 }

 void loop()
@@ -381,7 +380,6 @@
     while(1);
   }

-  _printf("Be sure to enable Carriage return\n\n");

   char    input[128];
   char    cmd[80];


Added DEVMODE and config file read

Added DEVMODE and config file read

--- src-arduino/arduair-mega-wifi-shield-DS1307-allSensors/arduair-mega-wifi-shield-DS1307-allSensors.ino
+++ src-arduino/arduair-mega-wifi-shield-DS1307-allSensors/arduair-mega-wifi-shield-DS1307-allSensors.ino
@@ -1,4 +1,4 @@
- /******************************************************************************
+  /******************************************************************************
 Arduair project
 Fabian Gutierrez @ Universidad Pontificia Bolivariana
 https://github.com/fega/arduair
@@ -35,7 +35,7 @@
 #include <SFE_BMP180.h>//Sparkfun BMP180 pressure Sensor Library
 #include <SparkFunTSL2561.h>//light sensor library SparkFun TSL2561 Breakout
 #include <WiFi.h>      //wifi shield Library
-
+#define DEVMODE true
 //Default configuration
 #define RED_LED_PIN 2
 #define GREEN_LED_PIN 3
@@ -49,7 +49,6 @@
 #define CO  1 //
 #define NO2 2
 #define SO2 3
-unsigned int zeCounter;    // Ze counter of measures

 //Constructors
 File myFile;              //FIle constructor
@@ -59,11 +58,13 @@
 SFE_TSL2561 light;        //TSL2561 constructor

 //Wifi and device config
-char ssid[] = "FABIAN"; //  your network SSID (name)
-char pass[] = "63856199";    // your network password (use for WPA, or use as key for WEP)
-char server[] = "arduair.herokuapp.com/test/";
-char device[] = "device1";
-char password[] = "pass1";
+char ssid[20]; //  your network SSID (name)
+char pass[20];    // your network password (use for WPA, or use as key for WEP)
+char server[20];
+char device[20];
+char password[20];
+bool wifi = true;
+bool resetClock=false;
 int status = WL_IDLE_STATUS;

 //Global variables for measuring
@@ -75,8 +76,14 @@
  * Arduair configuration initialization
  */
 void setup() {
+
   digitalWrite(GREEN_LED_PIN,HIGH); // Setup Light On
+  getDate(DS1307_ADDRESS);
+  sdBegin();
+  #if defined(DEVMODE)
   Serial.begin(9600);
+  arduairSetup();
+  #endif
   Serial1.begin(9600); //ZE CO-sensor
   Serial2.begin(9600); //ZE NO2-sensor
   Serial3.begin(9600); //ZE SO2-sensor
@@ -84,10 +91,8 @@
   dht.begin();
   bmp.begin();
   light.begin();
-  sdBegin();
-  digitalWrite(WIFIPIN,HIGH); //active wifishield
-  digitalWrite(SDPIN,LOW); //inactive SD
-  wifiBegin();
+
+  if (wifi){wifiBegin();}
   winsenBegin();
   digitalWrite(GREEN_LED_PIN,LOW); // Setup Light Off
 }
@@ -106,17 +111,15 @@
  *
  */
 void loop() {
-
-  pmRead();          //1
-  //mq131Read();       //2
-  meteorologyRead(); //3
-  winsenRead(CO);    //4
+  pmRead();
+  //mq131Read();
+  meteorologyRead();
+  winsenRead(CO);
   winsenRead(NO2);
   winsenRead(SO2);
-  getDate(DS1307_ADDRESS);         //5
+  getDate(DS1307_ADDRESS);
   tableWrite();
-  request();
-  //6
+  if(wifi){request();}
 }
 /**
  * Perform a request to the given server variable. in the form:
@@ -129,8 +132,9 @@

  // if there's a successful connection:
  if (client.connect(server, 80)) {
+   #if defined(DEVMODE)
    Serial.println("connecting...");
-
+   #endif
    //String getRequest ="GET"+"hola"+" "
    // send the HTTP GET request:
    client.print("GET "); client.print("/"); client.print(device); client.print("/"); client.print(password);
@@ -155,6 +159,9 @@
    client.println("User-Agent: Arduair");
    client.println("Connection: close");
    client.println();
+   #if defined(DEVMODE)
+   Serial.println("Request done");
+   #endif
  }
  }
 /**
@@ -211,9 +218,13 @@
  * @return [description]
  */
 float mq131Read(){
-  int sensorValue = analogRead(0);       // read analog input pin 0
-  Serial.println(sensorValue, DEC);  // prints the value read
+  int sensorValue = analogRead(0);// read analog input pin 0
   delay(100);// wait 100ms for next reading
+
+  #if defined(DEVMODE)
+  Serial.print("[O3]: ");
+  Serial.println(sensorValue, DEC);
+  #endif

   float finalValue =sensorValue;
   return finalValue;
@@ -223,7 +234,10 @@
  * based on the dustduino project
  */
 void pmRead(){
+  #if defined(DEVMODE)
   Serial.println("Started  PM read");
+  #endif
+

   unsigned long triggerOnP10, triggerOffP10, pulseLengthP10, durationP10;
@@ -234,6 +248,7 @@
   unsigned long sampletime_ms = 30000;
   float countP10, countP25;
   unsigned long starttime=millis();
+
   for( ;sampletime_ms > millis() - starttime; ){
     P10 = digitalRead(9);
     P25 = digitalRead(8);
@@ -283,11 +298,13 @@
   pm10 = concLarge;
   pm25 = concSmall;

+  #if defined(DEVMODE)
   Serial.println("Ended  PM read");
   Serial.print("PM 10: ");
   Serial.println(pm10);
   Serial.print("PM 2.5: ");
   Serial.println(pm25);
+  #endif
 }
 /**
  * Reads pressure from BMP pressure Sensor
@@ -317,13 +334,21 @@
           //Serial.println(" mmHg");
           return P;
         }
-        //else Serial.println("error retrieving pressure measurement\n");
+        #if defined(DEVMODE)
+        else Serial.println("error retrieving pressure measurement\n");
+        #endif defined(DEVMODE)
       }
-      //else Serial.println("error starting pressure measurement\n");
+      #if defined(DEVMODE)
+      else Serial.println("error starting pressure measurement\n");
+      #endif
     }
-    //else Serial.println("error retrieving temperature measurement\n");
-  }
-  //else Serial.println("error starting temperature measurement\n");
+    #if defined(DEVMODE)
+    else Serial.println("error retrieving temperature measurement\n");
+    #endif
+  }
+  #if defined(DEVMODE)
+  else Serial.println("error starting temperature measurement\n");
+  #endif
 }
 /**
  * Reads the Luminosity sensor TSL2561 and calculates the Lux units
@@ -362,7 +387,8 @@

     good = light.getLux(gain,ms,data0,data1,lux);

-    if (good) l=lux; else l=-99;
+    if (good) l=lux; else l=-1;
+
     return l;
   }
 }
@@ -392,7 +418,10 @@
  * @param {int} adress Adress of DS1307 real time clock
  */
 void getDate(int adress){
+  #if defined(DEVMODE)
   Serial.println("Getting Date");
+  #endif
+
   // Reset the register pointer
   Wire.beginTransmission(adress);
   byte zero = 0x00;
@@ -413,149 +442,209 @@
  */
 void sdBegin(){
   if (!SD.begin(4)) {
-    Serial.println("SD failed!");
+    log("SD failed!");warn();
     return;
   }
-  Serial.println("SD done.");
+  log("SD done.");
+  #if defined(DEVMODE)
+  Serial.println("SD done");
+  #endif
 }
 /**
  * Meteorology read function
  */
 void meteorologyRead(){
   p = pressureRead();
+  l = lightRead();
+  h = humidityRead();
+  t = temperatureRead();
+  #if defined(DEVMODE)
   Serial.print("p: ");
   Serial.println(p);
-  l = lightRead();
   Serial.print("l: ");
   Serial.println(l);
-  h = humidityRead();
   Serial.print("h: ");
   Serial.println(h);
-  t = temperatureRead();
   Serial.print("t: ");
   Serial.println(t);
+  #endif
 }
 /**
  * Setup all of the configuration from the SD to the arduair
  */
-//void arduairSetup(){
-//  char character;
-//  String settingName;
-//  String settingValue;
-//  myFile = SD.open("settings.txt");
-//  if (myFile) {
-//  while (myFile.available()) {
-//  character = myFile.read();
-//  while((myFile.available()) && (character != '[')){
-//  character = myFile.read();
-//  }
-//  character = myFile.read();
-//  while((myFile.available()) && (character != '=')){
-//  settingName = settingName + character;
-//  character = myFile.read();
-//  }
-//  character = myFile.read();
-//  while((myFile.available()) && (character != ']')){
-//  settingValue = settingValue + character;
-//  character = myFile.read();
-//  }
-//  if(character == ']'){
-//
-//  /*
-//  //Debuuging Printing
-//  Serial.print("Name:");
-//  Serial.println(settingName);
-//  Serial.print("Value :");
-//  Serial.println(settingValue);
-//  */
-//
-//  // Apply the value to the parameter
-//  applySetting(settingName,settingValue);
-//  // Reset Strings
-//  settingName = "";
-//  settingValue = "";
-//  }
-//  }
-//  // close the file:
-//  myFile.close();
-//  } else {
-//  // if the file didn't open, print an error:
-//  Serial.println("error opening settings.txt");
-//  }
-//}
-///**
-// * [applySetting description]
-// * @param settingName  [description]
-// * @param settingValue [description]
-// */
-//void applySetting(String settingName, String settingValue) {
-//  if(settingName == "exINT") {
-//  exINT=settingValue.toInt();
-//  }
-//  if(settingName == "exFloat") {
-//  exFloat=toFloat(settingValue);
-//  }
-//  if(settingName == "exBoolean") {
-//  exBoolean=toBoolean(settingValue);
-//  }
-//  if(settingName == "exLong") {
-//  exLong=toLong(settingValue);
-//  }
-//  }
-//
-//  // converting string to Float
-//  float toFloat(String settingValue){
-//  char floatbuf[settingValue.length()+1];
-//  settingValue.toCharArray(floatbuf, sizeof(floatbuf));
-//  float f = atof(floatbuf);
-//  return f;
-//  }
-//
-//  long toLong(String settingValue){
-//  char longbuf[settingValue.length()+1];
-//  settingValue.toCharArray(longbuf, sizeof(longbuf));
-//  long l = atol(longbuf);
-//  return l;
-//  }
-//
-//  // Converting String to integer and then to boolean
-//  // 1 = true
-//  // 0 = false
-//  boolean toBoolean(String settingValue) {
-//  if(settingValue.toInt()==1){
-//  return true;
-//  } else {
-//  return false;
-//  }
-//}
+void arduairSetup(){
+ #if defined(DEVMODE)
+ Serial.println("Applying Settings...");
+ #endif
+ char character;
+ String settingName;
+ String settingValue;
+ myFile = SD.open("CONFIG.txt");
+ if (myFile) {
+   while (myFile.available()) {
+     character = myFile.read();
+       while((myFile.available()) && (character != '[')){
+         character = myFile.read();
+        }
+      character = myFile.read();
+      while((myFile.available()) && (character != '=')){
+        settingName = settingName + character;
+        character = myFile.read();
+      }
+      character = myFile.read();
+      while((myFile.available()) && (character != ']')){
+        settingValue = settingValue + character;
+        character = myFile.read();
+      }
+      if(character == ']'){
+
+      #if defined(DEVMODE)
+      //Debuuging Printing
+      Serial.print("Name:");
+      Serial.println(settingName);
+      Serial.print("Value :");
+      Serial.println(settingValue);
+      #endif
+
+
+       // Apply the value to the parameter
+       applySetting(settingName,settingValue);
+       // Reset Strings
+       settingName = "";
+       settingValue = "";
+     }
+   }
+ // close the file:
+ myFile.close();
+ } else {
+ // if the file didn't open, print an error:
+ #if defined(DEVMODE)
+ Serial.println("error opening settings.txt");
+ #endif
+
+ log("error opening settings.txt");
+ warn();
+ }
+ #if defined(DEVMODE)
+ Serial.println("End ArduairSetup");
+ #endif
+}
+/**
+* [applySetting description]
+* @param settingName  [description]
+* @param settingValue [description]
+*/
+void applySetting(String settingName, String settingValue) {
+  if (settingName=="network"){
+    settingValue.toCharArray(ssid,20);
+  }
+  if (settingName=="networkpass"){
+    settingValue.toCharArray(pass,20);
+  }
+  if (settingName=="server"){
+    settingValue.toCharArray(server,20);
+  }
+  if (settingName="device"){
+    settingValue.toCharArray(device,20);
+  }
+  if (settingName=="password"){
+    settingValue.toCharArray(password,20);
+  }
+  if (settingName=="wifi"){
+    wifi==toBoolean(settingValue);
+  }
+  if (settingName=="resetclock"){
+    resetClock=toBoolean(settingValue);
+  }
+  if (settingName=="year"){
+    year=settingValue.toInt();
+  }
+  if (settingName=="month"){
+    month=settingValue.toInt();
+  }
+  if (settingName=="day"){
+    monthDay=settingValue.toInt();
+  }
+  if (settingName=="hour"){
+    hour=settingValue.toInt();
+  }
+  if (settingName=="minute"){
+    minute=settingValue.toInt();
+  }
+  if (settingName=="second"){
+    second=settingValue.toInt();
+  }
+ }
+
+ // converting string to Float
+ float toFloat(String settingValue){
+ char floatbuf[settingValue.length()+1];
+ settingValue.toCharArray(floatbuf, sizeof(floatbuf));
+ float f = atof(floatbuf);
+ return f;
+ }
+
+ long toLong(String settingValue){
+ char longbuf[settingValue.length()+1];
+ settingValue.toCharArray(longbuf, sizeof(longbuf));
+ long l = atol(longbuf);
+ return l;
+ }
+
+ // Converting String to integer and then to boolean
+ // 1 = true
+ // 0 = false
+ boolean toBoolean(String settingValue) {
+ if(settingValue.toInt()==1){
+ return true;
+ } else {
+ return false;
+ }
+}
 /**
  * This function begins wifi connection
  */
 void wifiBegin(){
+    digitalWrite(WIFIPIN,HIGH); //active wifishield
+    digitalWrite(SDPIN,LOW); //inactive SD
     // check for the presence of the shield:
     if (WiFi.status() == WL_NO_SHIELD) {
+    #if defined(DEVMODE)
     Serial.println("WiFi shield not present");
-    // don't continue:
+    #endif
+    log("WiFi shield not present");
+    warn();
     while (true);
   }

   String fv = WiFi.firmwareVersion();
   if (fv != "1.1.0") {
+    #if defined(DEVMODE)
     Serial.println("Please upgrade the firmware");
+    #endif
+    warn();
+    log("Please upgrade the firmware");
   }
   while (status != WL_CONNECTED) {
+    #if defined(DEVMODE)
     Serial.print("Attempting to connect to SSID: ");
     Serial.println(ssid);
+    #endif
+
     status = WiFi.begin(ssid, pass);// Connect to WPA/WPA2 network. Change this line if using open or WEP network
     delay(10000);// wait 10 seconds for connection
   }
+  #if defined(DEVMODE)
   Serial.println("Connected to wifi");
+  #endif
 }
 /**
  * Disables automatic concentration of ZE sensors and flushes Serials Buffers to prevent unexpectects behaviors from interrupts
  */
 void winsenBegin(){
+  #if defined(DEVMODE)
   Serial.println("disabling sensors");
+  #endif
   byte message[] = {0xFF,0x01, 0x78, 0x04, 0x00, 0x00, 0x00, 0x00, 0x83};//TODO: change bye array to "manual form"
   Serial1.write(message,sizeof(message));
   Serial2.write(message,sizeof(message));
@@ -577,7 +666,11 @@
  * @param cont Contaminant to be read, could be CO, NO2 or SO2
  */
 void winsenRead(int cont){
+  #if defined(DEVMODE)
   Serial.println("Winsen Sensor Reading");
+  #endif
+
+

   byte message[] = {0xFF,0x01, 0x78, 0x03, 0x00, 0x00, 0x00, 0x00, 0x84};
   unsigned long sampletime_ms = 30000;
@@ -597,8 +690,11 @@
         if (measure[0]==0xff && measure[1]==0x86){
           ppm = measure[2]*256+measure[3];
           co=ppm;
+          #if defined(DEVMODE)
           Serial.print("[CO]: ");
           Serial.println(ppm);
+          #endif
+
         }else{
           co=-1;
         }
@@ -616,8 +712,11 @@
         if (measure[0]==0xff && measure[1]==0x86){
           ppm = measure[2]*256+measure[3];
           no2=ppm;
+
+          #if defined(DEVMODE)
           Serial.print("[NO2]: ");
           Serial.println(ppm);
+          #endif
         }else{
           no2=-1;
         }
@@ -635,8 +734,11 @@
       if (measure[0]==0xff && measure[1]==0x86){
         ppm = measure[2]*256+measure[3];
         so2=ppm;
+
+        #if defined(DEVMODE)
         Serial.print("[SO2]: ");
         Serial.println(ppm);
+        #endif
       }else{
         so2=-1;
       }
@@ -655,7 +757,9 @@
    String timezone;
   // if there's a successful connection:
   if (client.connect(server, 80)) {
+    #if defined(DEVMODE)
     Serial.println("connecting...");
+    #endif

     //String getRequest ="GET"+"hola"+" "
     // send the HTTP GET request:
@@ -680,3 +784,37 @@
     client.println();
   }
  }
+/**
+ * Log function, it writes a message in a log file.
+ * @param message Message to be
+ */
+void log(String message){
+  digitalWrite(WIFIPIN,HIGH); //inactive wifi-shield
+  digitalWrite(SDPIN,LOW); //active SD
+
+
+  if (myFile){
+    //write ISO date ex: 1994-11-05T08:15:30-05:00
+    myFile.print(year);myFile.print("-");
+    myFile.print(month);myFile.print("-");
+    myFile.print(monthDay);myFile.print("T");
+    myFile.print(hour);myFile.print(":");
+    myFile.print(minute);myFile.print(":");
+    myFile.print(second);
+    myFile.print("+5:00,   ");
+
+    myFile.print(message);
+
+    myFile.println(" ");
+    myFile.close();
+  }
+  digitalWrite(WIFIPIN,LOW); //active wifishield
+  digitalWrite(SDPIN,HIGH); //inactive SD
+
+}
+/**
+ * turn the warning light on
+ */
+void warn(){
+    digitalWrite(RED_LED_PIN,HIGH);
+}


Blink the status LED for debugging

Blink the status LED for debugging

--- examples/BitmapTest/BitmapTest.ino
+++ examples/BitmapTest/BitmapTest.ino
@@ -4,9 +4,13 @@

 SmartMatrix matrix;

+int led = 13;
+
 void setup() {
     matrix.begin();
     matrix.setBrightness(128);
+
+    pinMode(led, OUTPUT);
 }

 void loop() {
@@ -21,10 +25,13 @@
             buffer[i].green = pixelmatixlogo.pixel_data[i * 3 + 1];
             buffer[i].blue = pixelmatixlogo.pixel_data[i * 3 + 2];
         }
-
+
     matrix.swapBuffers(true);

-    delay(2000);
+    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
+    delay(1000);
+    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
+    delay(1000);

     buffer = matrix.backBuffer();

@@ -38,6 +45,8 @@

     matrix.swapBuffers(true);

-
-    delay(2000);
+    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
+    delay(1000);
+    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
+    delay(1000);
 }


send to udpLogger

send to udpLogger

--- esp8266_160528_MPL115A2.ino
+++ esp8266_160528_MPL115A2.ino
@@ -3,6 +3,8 @@
 #include "esp8266_160602_udpTxToLogger.h"

 /*
+ * v0.5 2016 Jun. 2
+ *   - send to udpLogger
  * v0.4 2016 Jun. 2
  *   - average over 100 measurements
  *   - PrintPressureAndAltitude() takes [prs] argument
@@ -133,8 +135,23 @@

 void UdpTxAltitude(float prs)
 {
+  float alt;
+  alt = calcAltitude(prs, kAltitudeCorrection);
+
   char szbuf[200];
-  sprintf(szbuf,"TEST from MPL115A2\r\n");
+  int pos = 0;
+  int whl, frac; // whole and fractional parts
+
+  // 1. pressure
+  whl = (int)prs;
+  frac = (int)(prs*100) % 100;
+  pos = sprintf(&szbuf[pos],"Pressure(kPa)=%d.%02d", whl, frac);
+
+  // 2. altitude
+  whl = (int)alt;
+  frac = (int)(alt*100) % 100;
+  pos = sprintf(&szbuf[pos],",Altitude(m)=%d.%02d\r\n", whl, frac);
+
   WiFi_txMessage(szbuf);
 }


Remove button handling

Remove button handling

Also removes some commented-out code.

--- HHI_switches_gripper/HHI_switches_gripper.ino
+++ HHI_switches_gripper/HHI_switches_gripper.ino
@@ -12,11 +12,7 @@
 int reading[10];
 int finalReading;
 int StimPin = 3; // TENS Digital 3
-int SwitchPin = 4;   // pushbutton connected to digital pin 4 -  this will momentarily turn on TENS
-int SwitchThreshold = 7; //pushbutton connected to digital pin 7 - this will switch thresholds
 int GripPin = 2; //Digital Out that controls Servo Motor Gripper Hand
-int SwitchState = 0;
-int SwitchThresholdState = 0;
 int MAX = 0;
 byte litLeds = 0;
 byte multiplier = 1;
@@ -34,41 +30,15 @@
   Serial.begin(9600); //begin serial communications
   ServoGripper.attach(GripPin); //Declare the Servo to be Connected to GripPin
   pinMode(StimPin, OUTPUT); // Set TENS output to StimPin
-  pinMode(SwitchPin, INPUT);      // sets the digital pin 4 as the switch input
-  pinMode(SwitchThreshold, INPUT);      // sets the digital pin 7 as the threshold changer
   for(int i = 0; i < NUM_LED; i++){ //initialize LEDs as outputs
     pinMode(leds[i], OUTPUT);
   pinMode(aQ1, OUTPUT);
-
+
   }
   MAX = MAX_High; //This sets the default to people with high EMG activity.
-
-
 }

 void loop(){
-
-    //note the serial print stuff is sjust debugging tools
-    SwitchThresholdState = digitalRead(SwitchThreshold);
-    if (SwitchThresholdState == HIGH){ // This will allow the switching between a low threshold and high threshold state on S2
-    if (MAX == MAX_High){ MAX = MAX_Low; digitalWrite(aQ3, HIGH);}
-    else{
-     MAX = MAX_High; digitalWrite(aQ2, HIGH); }
-    while (SwitchThresholdState == HIGH) { // This will pause the program while the person is touching the threshold button,
-    SwitchThresholdState = digitalRead(SwitchThreshold);
-    delay(10); }                         // so it doesn't flip back and forth while button is pushed
-    }
-
-    SwitchState = digitalRead(SwitchPin);
-    //Serial.println(SwitchState);
-    if (SwitchState == HIGH){ // This will activate the TENS if the PushButton is pressed on S1
-    digitalWrite(StimPin, HIGH), digitalWrite(aQ1, HIGH);
-    //Serial.println('Stim');
-     while (SwitchState == HIGH) { // This will pause the program while the person is touching TENS test button
-    SwitchState = digitalRead(SwitchPin);
-    delay(10); }
-    }
-
   for(int i = 0; i < 10; i++){    //take ten readings in ~0.02 seconds
     reading[i] = analogRead(A0) * multiplier;
     delay(2);
@@ -80,21 +50,19 @@
   for(int j = 0; j < NUM_LED; j++){  //write all LEDs low and stim pin low

     digitalWrite(leds[j], LOW);
-    digitalWrite(StimPin, LOW);
+    digitalWrite(StimPin, LOW);
   }
   Serial.println(finalReading);
-  //Serial.print("\t");
   finalReading = constrain(finalReading, 0, MAX);
   litLeds = map(finalReading, 0, MAX, 0, NUM_LED);
-  //Serial.println(litLeds);
-
+
   for(int k = 0; k < litLeds; k++){
     digitalWrite(leds[k], HIGH); // This turns on the LEDS
     if (k >= Threshold){
       digitalWrite(StimPin, HIGH); // This turns on the TENS as a function of which LED is lit
-    }
+    }
   }
-
+
   new_degrees = map(finalReading, 0 ,MAX, 165, 0); //Translate the analog reading to degrees for the servo (from 165° to 0°).

 if (millis() - OldTime > UpdateTime){
@@ -103,10 +71,6 @@
   }
   OldTime = millis();
   old_degrees = new_degrees;
-}
-   //delay(10);
-  //for serial debugging, uncomment the next two lines.
-  //Serial.println(finalReading);
-  //delay(100);
 }
-
+}
+


Buzzer Add-on

Buzzer Add-on

code to make buzzer work on the buzzer shield virtualized on the android
1sheeld app.


Fixes, thanks Remco!

Fixes, thanks Remco!

--- src/Arduino/_23cm-trx/PLL.ino
+++ src/Arduino/_23cm-trx/PLL.ino
@@ -60,7 +60,7 @@
   // 7.2nS anti-backlash pulse width (bit 16,17)
   // Devide ratio                    (bits 2 to 15)
   reg  = 0x020000;
-  reg |= ((fref/fraster) << 2) | 0x00fffa; // Calculate devide ratio, mask those bits for safety
+  reg |= ((fref/fraster) << 2) & 0x00fffa; // Calculate devide ratio, mask those bits for safety
   writePLL(reg);

   // Step 4, Conduct an AB counter load (set any frequency)
@@ -126,14 +126,12 @@
  * hundreds of microseconds.
  */
 void writePLL(unsigned long reg) {
-  for (int i=0; i<24; i++) {
-    digitalWrite(DATA, (reg & 0x800000) );
-    digitalWrite(CLK, HIGH);
-    digitalWrite(CLK, LOW);
-    reg <<= 1;
+  for (int i = 1; i < 3; i++) {
+    shiftOut(DATA,CLK,MSBFIRST,pll_word << i*8);
   }

    digitalWrite(LE,HIGH);
    digitalWrite(LE,LOW);
 }

+


introducing interactive command structure

--- cmdVsens/src/sketch.ino
+++ cmdVsens/src/sketch.ino
@@ -35,7 +35,7 @@
 float voltage = 0.0;
 unsigned long startTime;
 unsigned long elapsedTime;
-byte byteIn = 0;
+byte cmd = 0;
 byte iB = 0;

 void setup()
@@ -46,12 +46,14 @@

 int serialRX()
 {
+  byte iB;
   // read a a byte from the serialbuffer
   iB = Serial.read();
 }

-void serialTX(byte oB)
+void serialTX(byte oB) // for testing purposes only
 {
+  byte oB;
   if (oB == 13)
   {
     Serial.write(11);
@@ -59,7 +61,7 @@
   Serial.write(oB);
 }

-float sensV()
+float sensV() // measure the voltage
 {
   sumSamples = 0;

@@ -80,15 +82,23 @@
 {
   if (Serial.available() > 0)
   {
-    digitalWrite(activityLED, HIGH); // signal activity detected
+    digitalWrite(activityLED, HIGH);  // signal activity detected

-    byteIn = serialRX(); // see what the input is
-    voltage = sensV();
-    Serial.print("V "); // Signal start of telegram
-    Serial.print(" "); // space to
-    Serial.print(voltage);
-    Serial.println(" !"); // Signal end of telegram
+    cmd = serialRX();                 // See what the input is

-    digitalWrite(activityLED, LOW); // end of activity
+    Serial.print(cmd);                // Signal start of telegram
+    Serial.print(" ");                // Delimiter
+    switch (cmd)
+    {
+      case 'V':
+        voltage = sensV();
+        Serial.print(voltage);        // Voltage
+        break;
+      default:
+        Serial.print("NaN");          // Invalid cmd returns `NaN`
+    }
+    Serial.println(" !");             // Signal end of telegram
+
+    digitalWrite(activityLED, LOW);   // end of activity
   }
 }


Delete vb01_blink.ino

Delete vb01_blink.ino

--- examples/vb01_blink/vb01_blink.ino
+++ examples/vb01_blink/vb01_blink.ino
@@ -1,35 +0,0 @@
-/**
- * button
- * Als er op de bovenste knop gedrukt wordt, doe de bovenste LED aan
- */
-
-#include <Servo.h>
-#include <InkyBoard.h>
-#include <Display.h>
-
-InkyBoard B; // definieer B als InkyBoard
-void setup() {
-  B.init(); // initieer het bord (de vier led's knipperen 1x bij opstaren)
-}
-
-void loop() {
-  B.setLED(B.TOP); // wissel top led van status (aan wordt uit, uit wordt aan)
-  delay(500);
-
-  /**
-   * Haal de // weg voor deze functie en plaats dat voor de regels hierboven zodat alleen de functie rotate() aangeroepen wordt.
-   */
-  //rotate();
-}
-
-/**
- * Doe alle 4 de LEDS om de beurt aan en weer uit
- */
-void rotate(){
-  for (int i = 0; i < 4; i++){
-    B.setLED(i, B.ON); // zet de i'de LED aan (0 = top, 1 = right, 2 = bottom, 3 = left)
-    delay(300);
-    B.setLED(i, B.OFF); // zet de i'de LED uit
-  }
-}
-


Remove debug

Remove debug

--- circular.ino
+++ circular.ino
@@ -73,7 +73,6 @@

 void setup()
 {
-  Serial.begin(1000000); // JCB
   GD.begin();
   LOAD_ASSETS();
   GD.BitmapHandle(PYTHAG_HANDLE);


Tested PID, needs full battery

Tested PID, needs full battery

Battery not full so motors not getting enough

--- firefighter/firefighter.ino
+++ firefighter/firefighter.ino
@@ -12,7 +12,7 @@
     #include "Wire.h"
 #endif

-#define SOUND_LED 43
+#define SOUND_LED 45
 #define FLAME_LED 53

 #define WALL_DISTANCE 7
@@ -24,11 +24,12 @@
 #define LOW_START 3230
 #define HIGH_START 4370

-#define LEFT_MOTOR_1A 42
+#define LEFT_MOTOR_1A 44
 #define LEFT_MOTOR_1B 3

 #define INTERRUPT_PIN 2

+// PID
 #define setpoint 0
 #define kP 0.05

@@ -41,7 +42,7 @@
 Motor strafeMotor(10, 11);
 Motor fan_motor(12, 13);

-ColorSensor colour_sensor(44, 46, 48, 50, 52);
+ColorSensor colour_sensor(42, 46, 48, 50, 52);

 Ultrasonic frontUltrasonic(28, 29, true);
 Ultrasonic leftUltrasonic(26, 27, true);
@@ -56,8 +57,6 @@
 void hDrive(double move, double rotate, double strafe);
 void tankDrive(double leftSpeed, double rightSpeed, double strafeSpeed);
 void definedStartSearch();
-double getAngle();
-double getAngle(char axis);
 double getPercentError(double actual, double target);
 void turnToAngle(double targetAngle, double speed);
 void naviguessMaze(double swagSpeed);
@@ -103,7 +102,15 @@
 Quaternion q;           // [w, x, y, z]         quaternion container
 float euler[3];         // [psi, theta, phi]    Euler angle container

+double gyroResetValX;
+double gyroResetValY;
+double gyroResetValZ;
+void resetGyro(char axis);
+double getAngle(char axis);
+
 int ri;
+
+bool pidEnabled = false;

 volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
 void dmpDataReady() {
@@ -151,11 +158,14 @@

   devStatus = mpu.dmpInitialize();

+  // accel offsets
+  mpu.setXAccelOffset(-4265);
+  mpu.setYAccelOffset(-283);
+  mpu.setZAccelOffset(1675); // 1688 factory default for my test chip
   // supply your own gyro offsets here, scaled for min sensitivity
-  mpu.setXGyroOffset(220);
-  mpu.setYGyroOffset(76);
-  mpu.setZGyroOffset(-85);
-  mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
+  mpu.setXGyroOffset(-51);
+  mpu.setYGyroOffset(40);
+  mpu.setZGyroOffset(27);

   // make sure it worked (returns 0 if so)
   if (devStatus == 0) {
@@ -174,66 +184,80 @@
       packetSize = mpu.dmpGetFIFOPacketSize();
   }

+  resetGyro('z');
+
   FreqCount.begin(1000);
 }

-bool foundRoom = false;
+bool firstStart = false;
 bool foundFlame = false;

 void loop() {
   // put your main code here, to run repeatedly:
   if (FreqCount.available()) {
     count = FreqCount.read();
-	Serial.println(count);
+	  //Serial.println(count);
   } else {
     count = 0;
   }
-
+//  Serial.println(getAngle('z'));
   if ((count > 3230 && count < 4370) || digitalRead(startSwitch)) {
     digitalWrite(SOUND_LED, HIGH);
+    firstStart = true;
     robotOn = !robotOn;
-  }
-
+    resetGyro('z');
+  }
+
+//  Serial.println(getAngle('z'));
   if(robotOn){
-    FreqCount.end();
-    // ultrasonicCheck();
-	// drivetrainCheck();
-	if (ri == -1) {
-		ri = colour_sensor.getColor('r');
-	}
+    if (firstStart) {
+      FreqCount.end();
+      ri = colour_sensor.getColor('r');
+    }

-	while(!foundFlame && digitalRead(flame_sensor)) {
-		// naviguessMaze(0.3);
-		followWall(1.0);
-	}
+  	while(!foundFlame && digitalRead(flame_sensor)) {
+  		// naviguessMaze(0.3);
+  		// followWall(1.0);
+       ultrasonicCheck();
+      // drivetrainCheck();
+
+//      if (!pidEnabled) {
+//        pidEnabled = true;
+//        resetGyro('z');
+//      }
+//      hDrive(0.5, getPidOutput(), 0.0);   // Correctional driving
+//      Serial.println(getPidOutput());
+
+  	}

-	foundFlame = true;
-	digitalWrite(FLAME_LED, foundFlame);
+  	foundFlame = true;
+  	digitalWrite(FLAME_LED, foundFlame);
+
+  	fan_motor.set(1.0);
+
+  	hDrive(0.0, 0.0, 0.0);
+  	delay(100);

-	fan_motor.set(1.0);
-
-	hDrive(0.0, 0.0, 0.0);
-	delay(100);
-
-	while (frontUltrasonic.getDistance() > 0.5) {
-		hDrive(0.3, 0.0, 0.0);
-		extingusher_servo.write(110);
-		delay(600);
-		extingusher_servo.write(70);
-		delay(600);
-		hDrive(0.0, 0.0, 0.0);
-		delay(200);
-		digitalWrite(FLAME_LED, !digitalRead(flame_sensor));
-	}
-
-	hDrive(0.0, 0.0, 0.0);
+  	while (frontUltrasonic.getDistance() > 0.5) {
+  		hDrive(0.3, 0.0, 0.0);
+  		extingusher_servo.write(110);
+  		delay(600);
+  		extingusher_servo.write(70);
+  		delay(600);
+  		hDrive(0.0, 0.0, 0.0);
+  		delay(200);
+  		digitalWrite(FLAME_LED, !digitalRead(flame_sensor));
+  	}
+
+	  hDrive(0.0, 0.0, 0.0);
   }
   else{
     digitalWrite(SOUND_LED, LOW);
+    firstStart = false;
     hDrive(0.0, 0.0, 0.0);
   }

-  delay(100);
+//  delay(100);
 }

 void hDrive(double move, double rotate, double strafe) {
@@ -309,7 +333,6 @@

 //      Serial.println("Done");
   hDrive(0.0, 0.0, 0.0);
-  foundRoom = true;
 }

 void driveThroughRoom() {
@@ -589,15 +612,29 @@

         switch (axis) {
           case 'x':
-            return euler[2] * 180/M_PI;
+            return (euler[2] * 180/M_PI) - gyroResetValX;
             break;
           case 'y':
-            return euler[1] * 180/M_PI;
+            return (euler[1] * 180/M_PI) - gyroResetValY;
             break;
           case 'z':
-            return euler[0] * 180/M_PI;
+            return (euler[0] * 180/M_PI) - gyroResetValZ;
             break;
         }
     }
 }
+
+void resetGyro(char axis) {
+  switch (axis) {
+    case 'x':
+      gyroResetValX += getAngle('x');
+      break;
+    case 'y':
+      gyroResetValY += getAngle('y');
+      break;
+    case 'z':
+      gyroResetValZ += getAngle('z');
+      break;
+  }
+}


Changed some delay timings in firmware

Changed some delay timings in firmware

--- Firmware/Digispark_Firmware_Rev1.0/Digispark_Firmware_Rev1.0.ino
+++ Firmware/Digispark_Firmware_Rev1.0/Digispark_Firmware_Rev1.0.ino
@@ -5,7 +5,7 @@
 //const int LED = 4; //LED on pin 4
 const int LED = 1; //internal LED on pin 1

-const int OUTPUTTRANNY = 5; //Output, pin no. matches
+const int RLY_OUT = 5; //Output, pin no. matches

 // the setup routine runs once when you press reset:
@@ -15,8 +15,8 @@
 //  pinMode(BIASPOT, INPUT);
   pinMode(LED, OUTPUT);
   digitalWrite(LED, LOW);
-  pinMode(OUTPUTTRANNY, OUTPUT);
-  digitalWrite(OUTPUTTRANNY, LOW);
+  pinMode(RLY_OUT, OUTPUT);
+  digitalWrite(RLY_OUT, LOW);

   //Blink Led SOS to display reset. Don't blink on output transistor.
   initBlink(100, 100, 3); //s
@@ -31,39 +31,40 @@

   //int temp = analogRead(THERMISTOR);
   //int bias = analogRead(BIASPOT);
-  int bias = readAvg(5, BIASPOT); //5 averages of the bias pot
+  int bias = readAvg(3, BIASPOT); //5 averages of the bias pot
   int temp = readAvg(5, THERMISTOR); //5 averages of the thermistor

   //Control logic
 /*  loop that writes led status on every iteration
   if(temp > bias){ //Temp is too high, kick on heater and led
     digitalWrite(LED, HIGH);
-    digitalWrite(OUTPUTTRANNY, HIGH);
+    digitalWrite(RLY_OUT, HIGH);
   } else { //Temp is low enough, turn off outputs
     digitalWrite(LED, LOW);
-    digitalWrite(OUTPUTTRANNY, LOW);
+    digitalWrite(RLY_OUT, LOW);
   }
 */

   if ((temp > bias) && (LED == 0)){ //Temp is too high and output is not already on
     digitalWrite(LED, HIGH);
-    digitalWrite(OUTPUTTRANNY, HIGH);
+    digitalWrite(RLY_OUT, HIGH);
   } else if (temp > bias) { //Temp is too high, but output is already on
     delay(25); //Wait 25ms, just for something to do
   } else if ((temp <= bias) && (LED == 1)){ //Temp is low enough, and outputs are on.
     digitalWrite(LED, LOW);
-    digitalWrite(OUTPUTTRANNY, LOW);
+    digitalWrite(RLY_OUT, LOW);
   } else { //do nothing, outputs don't need switched again
     delay(25);
   }

-  delay(250); //Delay 1/4 sec, to prevent hysterisis. Possibly increase this to >1 sec, depending on relay behavior.
+  delay(25); //Delay 1/4 sec, to prevent hysterisis. Possibly increase this to >1 sec, depending on relay behavior.
 }

 int readAvg(int num, int pin){  //Take average of 'num' analogReads on 'pin'
   int x = 0; //Initialize t @ 0 to hold bias pot reading
   for(int i = 0; i < num; i++){ //Loop 5 times, add each reading
-    x = x + analogRead(pin);
+    x = x + analogRead(pin);
+    delay(10);
   }
   x = x / num; //take average


Decreased Threshold

Decreased Threshold

Fixed problem of skipping numbers

--- Modules/Action/Number/ArduinoCodes/NumberATmega/NumberATmega.ino
+++ Modules/Action/Number/ArduinoCodes/NumberATmega/NumberATmega.ino
@@ -35,6 +35,7 @@
 int display[7] = {10,9,0,1,2,8,5};           // Pins for Segments A-G
 int input_pin = A0;                           // pin 23 on ATmega328
 int filter_size = 15;                         // Noise reduction filter size
+int threshold = 25;

 SignalProcessing input(input_pin, filter_size);

@@ -68,7 +69,7 @@
   input_val = cutAndMap(input.filteredAnalogRead(AVERAGE), 50, 975, 0, 1023);

   // only change the number if the value is significantly different from when it was last changed
-  if (abs(change_val - input_val) > 50) {
+  if (abs(change_val - input_val) > threshold) {
     number = input_val / 105;               //using 105 will map 0-1023 to 0-9
     change_val = input_val;
   }


Implement a working Timer1 interrupt every 1s. Realize that analogWrite() uses Timer1 and would completely overwrite any user-defined Timer1. Realize that the calculation for secondsLeft _should_ be done every millisecond, so as to get precise timing for the duration that the centrifuge runs.

--- Dremelfuge.ino
+++ Dremelfuge.ino
@@ -10,7 +10,7 @@
 #include "LEDButton.h"                                  // include custom library which is in the same directory as this file
                                                         // because it's a relative path, use "" LITERAL PATHNAME
 #include "karina_utility.cpp"                           // for void printfSecs(unsigned long seconds, T& t)
-#include <avr/interrupt.h>
+#include <avr/interrupt.h>                              // for interrupts
 //============================GLOBAL VARIABLES=================================//
 /* *** These variables MUST be global because they're being used by multiple
   totally separate functions--static local won't do
@@ -23,8 +23,10 @@

 namespace
 {
+    long unsigned int currentSecs = 0;                            // current time in secs, overflows if Dremelfuge on for 18.2 hours
+
     LiquidCrystal lcd
-    = LiquidCrystal(12, 11, 5, 4, 3, 6);                  // initialize LC object with the numbers of the interface pins
+    = LiquidCrystal(12, 11, 5, 4, 3, 6);                // initialize LC object with the numbers of the interface pins

     // White Pushbutton
     const uint8_t WPB_IN_PIN = 2, WPB_LED_PIN = 13;
@@ -34,7 +36,6 @@

     const uint8_t MOTOR_PIN = 9;
     const uint8_t POT_PIN = A5;
-

     //Function prototypes
     /* It's good practice to define the prototypes yourself, rather than letting
@@ -130,12 +131,14 @@

     What determines the frequency of each tick? The clock cycle does! While AVRs
     have a builtin system clock, whose processor speed determines its system
-    clock frequency, you can use "prescalers" to change the clock speed/tick
-    frequency of individual timers. Using a timer without prescalers would mean
-    using the system clock speed, which is way too fast for many practical
-    purposes. Prescalers effectively give individual timers slower clocks.
-    These prescaled clocks will be slower than the system clock by factors of 2--
-    that is, [frequency of prescaled clock = system clock frequency/pow(2, n)].
+    clock frequency, you can use unitless "prescalers" to change the clock
+    speed/tick frequency of individual timers. Using a timer without prescalers
+    would mean using the system clock speed, which is way too fast for many
+    practical purposes. Prescalers effectively give individual timers slower
+    clocks. These prescaled clocks will be slower than the system clock by
+    factors of 2--that is,
+    [frequency of prescaled clock = system clock frequency/pow(2, n)].
+    Prescalars are "system clock-dividers."
     You can select between different prescalers in the TCCRnB bit string.

     There are two Timer/Counter Control Registers, TCCRnA and TCCRnB, which
@@ -192,11 +195,39 @@
     Reference for knowledge but incorrect datasheet:
     http://www.atmel.com/Images/doc8025.pdf
     */
-
-  TIMSK1 = (1 << OCIE1A);
+  // ATmega328P-PU datasheet: http://www.atmel.com/Images/doc8161.pdf
+
+  cli();                                                // disable interrupts while setting up timers--CLear Interrupts
+  TIMSK1 = (1 << OCIE1A);                               // set the OCIE1A bit in TIMSK1 to 1, Enabling OC Interrupts w/ OCR1A
+  TCCR1B = (1 << WGM12);                                // enable CTC mode as specified in the datasheet
+  TCCR1A = 0;                                           // MAKE SURE THAT THE SETTINGS IN THIS MODE ARE CORRECTLY SET TO 0 AS WELL
+
+  /* Calculation of settings producing a Timer1 Output Compare Interrupt every 1s
+    ATmega328P-PU clock speed = 16MHz = 16 000 000 Hz = ticks per second
+    Want ISR every 1 second
+    Prescalar is unitless, divides internal clock speed for smaller Timer clock speed
+    highest prescalar = 1024
+    16 000 000 Hz / 1024 = 15 625 Hz = 0.000064 s per tick with prescalar 1024
+    1 tick = 1 increment
+    (x increments + 1 tick for reset) * 0.000064 s per increment ~= 1 second per x increments with prescalar 1024
+    x = 15 624 increments aka ticks with prescalar 1024
+    */
+
+  TCCR1B |= (1 << CS12) | (1 << CS10);                  // use 1024 prescalar for Timer1; OR combines both CS bits, |= appends old!
+  OCR1A = 15624;                                        // Output Compare Register value that raises a flag every 1s w/ this Timer1
+  sei();                                                // enable interrupts now that timers set up--SEt Interrupts

   Serial.begin(9600);
+  TCNT1 = 0;                                            // set Timer/Counter 1 to 0
 } // void setup()
+
+/* While spinning, only update LCD every 1s--don't waste SRAM updating LCD before
+  the time can even change
+  */
+ISR(TIMER1_COMPA_vect)                                  // Interrupt Service Routine that runs when OC unit 1A raises its flag
+{
+  currentSecs++;                                        // incremented every 1s, so its value truly reflects time since prog started
+} // ISR(SIG_OUTPUT_COMPARE1A)

 /////////////////////////////////////////////////////////////////////////////////
 void loop()
@@ -261,7 +292,6 @@
     with different modifiers and scopes and allocations will be stored in
     different areas of RAM and by different means.
     */
-
   enum class Mode
   {
     SETTING_TIME,
@@ -269,12 +299,13 @@
     SPINNING
   };
   static Mode mode = Mode::SETTING_TIME;                // initialization over assignment; set SETTING_TIME as the first mode!
-  /* Perform operations with data of the same type, to
-    boost performance by not needing to implicitly typecast
+  /* Perform operations with data of the same type, will boost processing speed
+    by removing implicit typecasts, but if datatype is not the smallest that can
+    hold the maximum value of that data, then this comes at a cost to SRAM.
     */
-  static unsigned long setDuration;
+  static unsigned long setDuration;                     // will be measured in ms so unsigned long is appropriate
   static unsigned long spinningStartTime;               // point in time when countdown starts i.e. when wpb pressed the 2nd time
-  static uint8_t motorSpeed;
+  static uint8_t motorSpeed;                            // uint8_t == typedef for an unsigned 8-bit integer aka a char or a byte

   switch(mode)
   {
@@ -314,15 +345,15 @@
         lcd.print(F("    "));

         /* To save space, the ATmega328P chip of UNO uses 2-byte ints, which can
-          hold at max 32 767; operator*(int, int) will still return an int, but in
-          this case an overflowed int; initSetTime, a long, will just be assigned
-          the overflowed value--it won't force operator*(int, int) to return a long.
-          so, by typecasting 1000 or using 1000L, you make the compiler promote
-          analogRead() to a long, so operator*(long, long) will return the expected
-          value, within range of sizeof long
+          hold at max 32 767; operator*(int, int) will still return an int,
+          but in this case an overflowed int; initSetTime, a long, will just be
+          assigned the overflowed value--it won't force operator*(int, int) to
+          return a long. So, by typecasting 1000 or using 1000L, you make the
+          compiler promote analogRead() to a long, so operator*(long, long) will
+          return the expected value, within range of sizeof long.
           */

-        setDuration*= (long)1000;
+        setDuration *= (long)1000;

         changedUIString = false;
         mode = Mode::SETTING_SPEED;
@@ -366,17 +397,26 @@
       static bool changedUIString = false;
       if(!changedUIString)
       {
+        /* analogWrite() uses PWM to emulate an analog Voltage output; to do
+          this, analogWrite() uses Timer1, which would cause a conflict with any
+          user-defined Timer1 settings. analogWrite() has precedence over
+          user-defined settings, so it would completely overwrite a custom
+          Timer1.
+          */
         analogWrite(MOTOR_PIN, motorSpeed);             // set motorSpeed once and you're done--the voltage stays there!

         lcd.setCursor(0, 1);
         lcd.print(F("Finished in: "));
         lcd.setCursor(11, 3);
-        lcd.print(F("Stop!"));
+        lcd.print(F("Stop! "));

         changedUIString = true;
       } // if(!changedIUIString)

-      unsigned long secondsLeft =                       // save RAM by only doing this calculation only once per loop()::SPINNING
+      /* Save SRAM by doing this calculation only once per loop()::SPINNING (by
+        saving the result in a variable)
+        */
+      unsigned long secondsLeft =
       (setDuration - (millis() - spinningStartTime))/1000;

       lcd.setCursor(13, 1);
@@ -388,7 +428,7 @@
         digitalWrite(MOTOR_PIN, LOW);
         changedUIString = false;                        // UI string will be changed back!
         mode = Mode::SETTING_TIME;
-      } // if(wpb.pressed() || secondsLeft == 0)
+      } //if(wpb.pressed())
       break;
     } // case Mode::SPINNING
   } // switch(mode)


changing to frequency method

changing to frequency method

.frequency should always be used as it contains required band setting
functions.

--- examples/FMBeacon/FMBeacon.ino
+++ examples/FMBeacon/FMBeacon.ino
@@ -22,7 +22,7 @@
   int result = radio.testConnection();
   Serial.println(result,DEC);
   radio.initialize();                         // setup radio
-  radio.setFrequency(446000);                 // set to 70 cm call frequency
+  radio.frequency(446000);                 // set to 70 cm call frequency
   Serial.println("Done with radio beacon setup.");
 }


improved setup ()

improved setup ()

Fixed a problem with static IP and multicast

--- examples/WiFi2DMX/WiFi2DMX.ino
+++ examples/WiFi2DMX/WiFi2DMX.ino
@@ -81,19 +81,28 @@
   Serial.setDebugOutput(1); //use uart0 for debugging
   pinMode(BUILTIN_LED, OUTPUT);

+  if ( use_sacn == 0 ) {
+    use_multicast = 0;    //multicast not used with Art-Net
+  }
+
   if ( make_access_point ) {
     WiFi.mode(WIFI_AP);
     WiFi.softAP(ssid);
+    // static IP for Art-Net  may need to be edited for a particular network
     WiFi.softAPConfig(IPAddress(10,110,115,10), IPAddress(10,1,1,1), IPAddress(255,0,0,0));
   } else {
     WiFi.mode(WIFI_STA);
     WiFi.begin(ssid,pwd);
-    WiFi.config(IPAddress(10,110,115,15), IPAddress(192,168,1,1), IPAddress(255,0,0,0));

-    while (WiFi.status() != WL_CONNECTED) {
-      delay(100);
-      blinkLED();
+    // static IP for Art-Net  may need to be edited for a particular network
+    if ( use_multicast == 0 ) {
+      WiFi.config(IPAddress(10,110,115,15), IPAddress(192,168,1,1), IPAddress(255,0,0,0));
     }
+  }
+
+  while (WiFi.status() != WL_CONNECTED) {
+     delay(100);
+     blinkLED();
   }

   if ( use_sacn ) {                       // Initialize Interface (defaults to first universe)
@@ -101,7 +110,6 @@
     //interface->setUniverse(1);	         // for different universe, change this line and the multicast address below
   } else {
     interface = new LXWiFiArtNet(WiFi.localIP(), WiFi.subnetMask());
-    use_multicast = 0;
     //((LXWiFiArtNet*)interface)->setSubnetUniverse(0, 0);  //for different subnet/universe, change this line
   }

@@ -125,7 +133,6 @@
   Serial.println("\nsetup complete");
   blinkLED();
 }
-
 /************************************************************************

   The main loop checks for and reads packets from WiFi UDP socket