speed up demo mode

speed up demo mode

--- src/monitor-firmware.ino
+++ src/monitor-firmware.ino
@@ -20,7 +20,7 @@

 // HACK: demo
 unsigned long next_demo_loop_at = 0;
-const long DEMO_LOOP_PERIOD = 250; // milliseconds
+const long DEMO_LOOP_PERIOD = 100; // milliseconds

 DebouncedSwitch mode_switch(BTN_MODE);
 DebouncedSwitch select_switch(BTN_SELECT);


feito funcoes para modularizar o update dos estados dos botoes

--- codigo.ino
+++ codigo.ino
@@ -250,24 +250,36 @@
 }

-
-void loop()
-{
-    // If button pressed, send the code.
-
-    //========================================================
+void re_enable_IRIn_if_button_released(){
+
+    if (check_button_released(0) | check_button_released(1))
+    {
+        Serial.println("Released a button");
+        irrecv.enableIRIn(); // Re-enable receiver
+    }
+    return;
+}
+
+void update_state_of_buttons(){
     buttons_list[0].button_state = digitalRead(FIRST_BUTTON_PIN);
     buttons_list[1].button_state = digitalRead(SECOND_BUTTON_PIN);
+}
+void update_last_state_of_buttons(){
+    buttons_list[0].last_button_state = buttons_list[0].button_state;
+    buttons_list[1].last_button_state = buttons_list[1].button_state;
+}
+
+void loop()
+{
+    // If button pressed, send the code.
+    update_state_of_buttons();
+    //========================================================

     // int secondButtonState = digitalRead(SECOND_BUTTON_PIN);
     // int thirdButtonState = digitalRead(THIRD_BUTTON_PIN);
     //========================================================

-    if (check_button_released(0))
-    {
-        Serial.println("Released");
-        irrecv.enableIRIn(); // Re-enable receiver
-    }
+    re_enable_IRIn_if_button_released();

     if (check_button_pressed(0))
     {
@@ -286,7 +298,7 @@
         irrecv.resume(); // resume receiver
         digitalWrite(STATUS_PIN, LOW);
     }
-    buttons_list[0].last_button_state = buttons_list[0].button_state;
-
-
-}
+
+    update_last_state_of_buttons();
+
+}


added print_strln() function

added print_strln() function

--- beanWheelwriterControl/beanWheelwriterControl.ino
+++ beanWheelwriterControl/beanWheelwriterControl.ino
@@ -113,11 +113,13 @@
         print_str(",./?");
         send_return(4);*/

-        print_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
-        send_return(52);
-
-        print_str("done.");
-        send_return(5);
+        //print_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+        //send_return(52);
+
+        //print_str("done.");
+        //send_return(5);
+
+        print_strln("The quick brown fox jumps over the lazy dog.");
         /*
         sendByteOnPin(0b00000000);
         delayMicroseconds(60);*/
@@ -134,6 +136,12 @@
   while (*s != '\0') {
     send_letter(asciiTrans[*s++]);
   }
+}
+
+void print_strln(char *s) {
+  // prints a line and then a carriage return
+  print_str(s);
+  send_return(strlen(s));
 }

 inline void sendByteOnPin(int command) {


Arduino file for project

Arduino file for project

code to enable communication between the components of the project
(1sheeld arduino shield, arduino uno  and  the ultrasonic sensor).


Move pingGoogle.py to ~/Python/; editor main comment

--- RouterReset_Yun/RouterReset_Yun.ino
+++ RouterReset_Yun/RouterReset_Yun.ino
@@ -1,4 +1,4 @@
-/* Testing an Arduino Yun: light up green or red when internet is on
+/* Router Reset for Arduino Yun
  *
  * red LED (internet down): pin 6
  * green LED (internet up): pin 5
@@ -7,7 +7,7 @@
  * power switch tail:       pin 9
  * switch:                  pin 12
  *
- * needs checkInternet.py installed in /usr/bin in Yun Linino
+ * needs ~/Python/pingGoogle.py on Yun Linino
  */

 #include <Process.h>
@@ -96,7 +96,7 @@

   digitalWrite(yellowLED, HIGH);

-  internetCheck.runShellCommand("/usr/bin/pingGoogle.py");
+  internetCheck.runShellCommand("~/Python/pingGoogle.py");

   result = "";
   while(internetCheck.available() > 0) {


Change baud rate to 9600.

Change baud rate to 9600.

--- Arduino/ADXL335/ADXL335.ino
+++ Arduino/ADXL335/ADXL335.ino
@@ -6,7 +6,7 @@
 int xpin = A5;

 void setup() {
-  Serial.begin(115200);
+  Serial.begin(9600);
   pinMode(vinpin, OUTPUT); digitalWrite(vinpin, HIGH);
   pinMode(gndpin, OUTPUT); digitalWrite(gndpin, LOW);
   pinMode(voutpin, INPUT);


AD7173.ino fixed enable_adc_channel AINs

--- AD7173.ino
+++ AD7173.ino
@@ -143,11 +143,11 @@
 #define SPS_15625 0x06
 #define SPS_31250 0x00

-/* ADC setup coding (unipolar, bipolar) */
+/* ADC setup coding modes */
 #define BIPOLAR_CODED_OUTPUT 1
 #define UNIPOLAR_CODED_OUTPUT 0

-/* ADC data modes */
+/* ADC data conversion modes */
 #define CONTINUOUS_READ_MODE 0
 #define SINGLE_CONVERSION_MODE 1
 #define CONTINUOUS_CONVERSION_MODE 2
@@ -208,7 +208,7 @@
 =========================================
 */
 int set_adc_register(byte reg, byte *value, int write_len) {
-    /* when specified register is invalid */
+    /* when desired register is invalid */
     if (reg < 0x00 || reg > 0x3F) {
         if (DEBUG_ENABLED) {
             print_byte(reg);
@@ -218,9 +218,9 @@
     }
     /* send communication register id 0x00 */
     SPI.transfer(0x00);
-    /* send write command to the specified register 0x00 - 0xFF */
+    /* send write command to the desired register 0x00 - 0xFF */
     SPI.transfer(0x00 | reg);
-    /* write the specified amount of bytes */
+    /* write the desired amount of bytes */
     for (int i = 0; i < write_len; i++) {
         SPI.transfer(value[i]);
     }
@@ -247,7 +247,7 @@
 =============================================
 */
 int get_adc_register(byte reg, byte *value, int read_len) {
-    /* when specified register is invalid */
+    /* when desired register is invalid */
     if (reg < 0x00 || reg > 0x3F) {
         if (DEBUG_ENABLED) {
             print_byte(reg);
@@ -257,9 +257,9 @@
     }
     /* send communication register id 0x00 */
     SPI.transfer(0x00);
-    /* send read command to the specified register 0x00 - 0xFF */
+    /* send read command to the desired register 0x00 - 0xFF */
     SPI.transfer(0x40 | reg);
-    /* read the specified amount of bytes */
+    /* read the desired amount of bytes */
     for (int i = 0; i < read_len; i++) {
         value[i] = SPI.transfer(0x00);
     }
@@ -278,16 +278,18 @@
 }

 /*
-=================================
+=====================================
 enables or disables ADC channels
 @param byte - channel
 @param bool - status
+@param byte - optional analog input 1
+@param byte - optional analog input 2
 @return int - error code
-=================================
-*/
-int enable_adc_channel(byte channel, bool status, byte ain1 = NULL, byte ain2 = NULL) {
+=====================================
+*/
+int enable_adc_channel(int channel, bool status, byte ain1 = NULL, byte ain2 = NULL) {
     /* when channel out of range */
-    if (channel < 0x10 || channel > 0x1F) {
+    if (channel < 0 || channel > 15) {
         if (DEBUG_ENABLED) {
             print_byte(channel);
             Serial.println("enable channel out of range");
@@ -295,35 +297,43 @@
         return 1;
     }
     byte value[2];
-    /* read specified channel configuration */
-    get_adc_register(channel, value, 2);
+    /* convert channel number to channel register value */
+    byte channel_reg = 0x10 | channel;
+    /* read desired channel configuration */
+    get_adc_register(channel_reg, value, 2);
     /* clear the enable bit */
     value[0] &= ~(1 << 7);
     /* enable or disable this channel */
     value[0] |= (status << 7);
-    /* set the correct analog inputs */
-    byte ain = ((channel & 0x0F) << 1);
+    /* define the default analog input */
+    byte ain = (channel << 1);
     /* set default AINs */
+    value[0] = 0xFC;
     value[1] = 0x00;

-    /* user desired values */
+    /* user desired analog input values */
     if (ain1 != NULL) {
+        value[0] |= (ain1 >> 3);
         value[1] |= (ain1 << 5);
-        /* when 2 AINs set */
+        /* when 2 analog input values were set */
         if (ain2 != NULL) {
             value[1] |= ain2;
         }
     /* set automatic values for BIPOLAR output */
     } else if (adc_setup_coding_output == BIPOLAR_CODED_OUTPUT) {
+        value[0] |= (ain >> 3);
         value[1] |= (ain << 5);
         value[1] |= (ain + 1);
     /* set automatic value for UNIPOLAR output */
     } else {
-        value[1] |= (ain << 5);
-    }
-
-    /* update specified channel configuration */
-    set_adc_register(channel, value, 2);
+        value[0] |= (channel >> 3);
+        value[1] |= (channel << 5);
+        value[1] |= channel;
+    }
+    print_byte(value[1]);
+
+    /* update desired channel configuration */
+    set_adc_register(channel_reg, value, 2);
     /* return error code */
     return 0;
 }
@@ -454,11 +464,12 @@
 @return int - error code
 ===================================
 */
-int get_current_adc_data_channel(byte &channel) {
+int get_current_adc_data_channel(int &channel) {
     byte value[1];
     /* read ADC status register */
     get_adc_register(STATUS_REG, value, 1);
-    channel = value[0];
+    /* filter out channel register value */
+    channel = value[0] & 0x0F;
     /* return error code */
     return 0;
 }
@@ -502,19 +513,25 @@
 void setup() {
     /* initiate serial communication */
     Serial.begin(115200);
-    /* initiate ADC */
+    /* initiate ADC, return true if device ID is valid */
     init_adc();
-    /* reset ADC to default state */
+    /* reset ADC registers to the default state */
     reset_adc();
     /* set ADC configuration */
-    /* enable ch0 and ch1 */
-    enable_adc_channel(CH0_REG, true, AIN0, AIN1);
-    enable_adc_channel(CH1_REG, true, AIN2, AIN3);
+    /* enable ch0 and ch1 and connect each to 2 analog inputs for bipolar input */
+    /* AIN0, AIN1, AIN2, AIN3, AIN4, AIN5, AIN6, AIN7, AIN8, AIN9, AIN10, AIN11, AIN12 */
+    /* AIN13, AIN14, AIN15, AIN16, REF_POS, REF_NEG, TEMP_SENSOR_POS, TEMP_SENSOR_NEG */
+    enable_adc_channel(0, true, AIN8, AIN9);
+    enable_adc_channel(1, true, AIN10, AIN11);
     /* set the ADC data mode */
+    /* CONTINUOUS_READ_MODE, SINGLE_CONVERSION_MODE, CONTINUOUS_CONVERSION_MODE */
     set_adc_data_mode(CONTINUOUS_READ_MODE);
     /* set the ADC filter samplingrate to 1007 Hz*/
+    /* SPS_1, SPS_2, SPS_5, SPS_10, SPS_16, SPS_20, SPS_50, SPS_60, SPS_100, SPS_200 */
+    /* SPS_381, SPS_504, SPS_1007, SPS_2597, SPS_5208, SPS_10417, SPS_15625, SPS_31250 */
     set_adc_filter_speed(FILTCON0_REG, SPS_1007);
     /* set the ADC setup coding to BIPLOAR output*/
+    /* BIPOLAR_CODED_OUTPUT, UNIPOLAR_CODED_OUTPUT */
     set_adc_setup_codig(SETUPCON0_REG, BIPOLAR_CODED_OUTPUT);
     /* wait for ADC */
     delay(10);
@@ -525,11 +542,12 @@
     /* when ADC conversion is finished */
     if (DATA_READY) {
         /* read ADC conversion result */
-        get_adc_data(data);
-        byte current_channel;
-        get_current_adc_data_channel(current_channel);
-        if (current_channel == CH0_REG) {
+        //get_adc_data(data);
+        int current_channel = 1;
+        //get_current_adc_data_channel(current_channel);
+        if (current_channel == 0) {
             /* something lol... */
+            Serial.println("channel 0 read");
         }
         //Serial.write(data[0]);
         //Serial.write(data[1]);


Clean up.

Clean up.

--- examples/Pins/CosaPins/CosaPins.ino
+++ examples/Pins/CosaPins/CosaPins.ino
@@ -94,9 +94,6 @@
 InputPin onoffPin(Board::D7);
 AnalogPin levelPin(Board::A0);

-// Dummy event handler
-Event::Handler handler;
-
 void setup()
 {
   // Start trace output stream on the serial port
@@ -120,6 +117,9 @@
   TRACE(sizeof(PWMPin));
   TRACE(sizeof(Watchdog));

+  // Start the watchdog
+  Watchdog::begin();
+
   // Check interrupt pin; enable and print interrupt counter
   PinChangeInterrupt::begin();
   TRACE(int0Pin.get_counter());
@@ -130,18 +130,14 @@
   int2Pin.enable();
   TRACE(extPin.get_counter());
   extPin.enable();
+}

-  // Start the watchdog ticks counter (1 second pulse)
-  Watchdog::begin(1024);
-  Watchdog::push_timeout_events(&handler);
-}
+Watchdog::Clock clock;

 void loop()
 {
-  // Wait for the next event. Allow a low power sleep
-  Event event;
-  Event::queue.await(&event);
-  TRACE(event.get_type());
+  // Wait for the next seconds tick
+  clock.await();

   // Print the time index
   INFO("ms = %d", Watchdog::millis());


It helps if you set your jeelib back default

Caught out by pin change interrupt setting in the library again. I wish
we had a better way to switch between the two.

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -695,7 +695,7 @@
 /// i.e. allowable frequencies and their use when selecting your operating frequencies.
 ///
           if (value) {
-            if ((value > 95) && (value < 3904)) {  // 96 - 3903 is the range of values supported by the RFM12B
+            if ((value > 95) & (value < 3904)) {  // 96 - 3903 is the range of values supported by the RFM12B
               frequency = value;
               Serial.print(">");
               Serial.println(frequency);
@@ -881,7 +881,7 @@
 #endif
   Serial.begin(SERIAL_BAUD);
   displayVersion(0);
-  activityLed(0);
+  activityLed(1);

   if (rf12_config())
     initialize();


Configurable roof speed

Configurable roof speed

--- KomaRoof.ino
+++ KomaRoof.ino
@@ -72,6 +72,7 @@
 static Scheduler taskScheduler;
 static RoofState roofState = STOPPED;
 static Phase phase = IDLE;
+static int roofSpeed = FULL_SPEED;
 static int countSincePhase;
 static int direction;
 static float temperature = DEVICE_DISCONNECTED_C;
@@ -105,6 +106,7 @@
     handler.registerCommand("OPEN", open);
     handler.registerCommand("CLOSE", close);
     handler.registerCommand("STOP", stop);
+    handler.registerCommand("SETSPEED", setspeed);

     taskScheduler.init();
     taskScheduler.addTask(motorTask);
@@ -231,16 +233,16 @@

     switch (phase) {
         case RAMP_UP: {
-            int power = FULL_SPEED * countSincePhase / RAMP_LENGTH;
-            if (power > FULL_SPEED)
-                power = FULL_SPEED;
+            int power = roofSpeed * countSincePhase / RAMP_LENGTH;
+            if (power > roofSpeed)
+                power = roofSpeed;
             motorShield.setM1Speed(power * direction);
-            if (power == FULL_SPEED)
+            if (power == roofSpeed)
                 phase = MOVE_UNTIL_NEAR;
             break;
         }
         case RAMP_DOWN: {
-            int power = FULL_SPEED - FULL_SPEED * countSincePhase / RAMP_LENGTH;
+            int power = roofSpeed - roofSpeed * countSincePhase / RAMP_LENGTH;
             int minimumPower = (roofState == CLOSING ? CLOSING_SPEED : 0);
             if (power < minimumPower)
                 power = minimumPower;
@@ -318,7 +320,7 @@
         roofState = STOPPING;
         phase = RAMP_DOWN;
         // start mid-ramp if we were not running at full speed
-        countSincePhase = RAMP_LENGTH - RAMP_LENGTH * motorShield.getM1Speed() / FULL_SPEED;
+        countSincePhase = RAMP_LENGTH - RAMP_LENGTH * motorShield.getM1Speed() / roofSpeed;
     }
     if (roofState == ERROR) {
         roofState = STOPPED;
@@ -352,3 +354,8 @@
     }
     serial.print(message);
 }
+
+void setspeed(const String& speedAsString) {
+    roofSpeed = atoi(speedAsString.c_str());
+    serial.print("SETSPEED,OK");
+}


some serial color output

some serial color output

--- VeronicaLedLamp.ino
+++ VeronicaLedLamp.ino
@@ -163,11 +163,18 @@
         for(int i = 0; i < server.args(); ++i) {
             if ( server.argName(i) == "a" ) { // Current color
                 EEPROM.write( 25, server.arg(i).toInt() % 255 );
-                char preset[3], color[6];
+                char color[6];
+                byte preset[3];
                 EEPROM.get(1 + server.arg(i).toInt() % 8 * 3, preset);
-                snprintf(color, 6, "%02x%02x%02x", preset[0], preset[1], preset[2]);
-                Serial.print('b');
-                Serial.println(color);
+//                snprintf(color, 6, "%02x%02x%02x", preset[0], preset[1], preset[2]);
+//                Serial.print('b');
+//                Serial.println(color);
+                Serial.print("c ");
+                Serial.print(int(preset[0]));
+                Serial.print(" ");
+                Serial.print(int(preset[1]));
+                Serial.print(" ");
+                Serial.println(int(preset[2]));
             } else if ( server.argName(i) == "m") { // Current mode
                 int wmode = server.arg(i).toInt() % 255;
                 if ( wmode == 7 ) { // Speed Toggle


Improve hello_world, implement /led and add /iterations and /multiply - remove /hello_world - something bad happens which makes the arduino spew out garbage.

--- arduino/libraries/SequantoAutomation/examples/hello_world/hello_world.ino
+++ arduino/libraries/SequantoAutomation/examples/hello_world/hello_world.ino
@@ -6,37 +6,51 @@
  *
  * BEGIN AUTOMATION
  *
- * function /hello hello_world
+ * function /mult multiply
  * property /led led_get led_set
+ * property /iterations iterations_get
  *
  * END AUTOMATION
  */

+const int LED = 13;
+
+int multiply(int a, int b)
+{
+  return a*b;
+}
+
 static SQBool s_led = SQ_FALSE;

-SQBool led_get ()
+SQBool led_get ( void )
 {
   return s_led;
 }

-void led_get ( SQBool v )
+void led_set ( SQBool v )
 {
   s_led = v;
+  digitalWrite ( LED, s_led == SQ_TRUE ? HIGH : LOW );
 }

-char * hello_world ( const char * _name )
+static int s_iterations = 0;
+
+int iterations_get ( void )
 {
-    char * ret = (char*) malloc ( 20 );
-    sprintf ( ret, "Hello %s!", _name );
-    return ret;
+  return s_iterations;
 }

 void setup ()
 {
     SequantoAutomation::init();
+    pinMode ( LED, OUTPUT );
+    s_led = SQ_FALSE;
+    digitalWrite ( LED, LOW );
+    s_iterations = 0;
 }

 void loop ()
 {
+    s_iterations ++;
     SequantoAutomation::poll();
 }


Incluído o modo tempestade na luminária do aquário

--- CoreArduino/CoreArduino.ino
+++ CoreArduino/CoreArduino.ino
@@ -3,7 +3,7 @@
 *    Comunicação Serial para Envio e Recebimento de infomações                *
 *    pela porta Serial                                                        *
 *                                                                             *
-*    Versão: 0.0.2                                                            *
+*    Versão: 0.1.0                                                            *
 *    Data: 21/08/2014                                                         *
 *    Autor: Alex Ishida                                                       *
 *    Site: http://alexishida.com                                              *
@@ -40,11 +40,19 @@
 int canal_06_valor = 0;
 int canal_07_valor = 0;

+/* Seta o valor máximo do pwm*/
+int pwm_maximo = 200;

 /* Define o led de status */
 int led_stautus_pin = 13;
 bool led_status = false;

+/* Variaveis dos modo tempestade */
+bool tempestade = false;
+int temp_led_raio = 200;
+int temp_leds = 15;
+unsigned long temp_tempo_espera = 0L;
+
 /******************************************************************/
 /* Definição de Variáveis                                         */
 /******************************************************************/
@@ -59,12 +67,13 @@
  /*
    Aqui eu altero a frequência dos timer 1,2,3,4
    Se alterar o timer 0 irá influenciar nas funções de controle de tempo do Arduino ex.: delay();
-*/
+  */
+
   TCCR1B = (TCCR1B & 0xF8) | 0x01; // 31.374 KHz
   TCCR2B = (TCCR2B & 0xF8) | 0x01; // 31.374 KHz
   TCCR3B = (TCCR3B & 0xF8) | 0x01; // 31.374 KHz
   TCCR4B = (TCCR4B & 0xF8) | 0x01; // 31.374 KHz
-
+

   pinMode(canal_01, OUTPUT);
   pinMode(canal_02, OUTPUT);
@@ -76,8 +85,6 @@

   pinMode(led_stautus_pin, OUTPUT);

-
-/*  delay(1000);//Aguarda 1 seg antes de acessar as informações do sensor */
  Serial.println("conectado;");
 }

@@ -94,7 +101,17 @@
      else if(comando.startsWith("luzes")) {

       obtemLuzes(comando);
-       Serial.println("luzes;true");
+      Serial.println("luzes;true");
+
+     }
+     else if(comando.startsWith("tempestade;ON")) {
+        tempestade = true;
+       Serial.println("tempestade;ON");
+
+     }
+     else if(comando.startsWith("tempestade;OFF")) {
+        tempestade = false;
+       Serial.println("tempestade;OFF");

      }

@@ -107,13 +124,18 @@

      }

-  atualizaLuzes();
-
+    if(tempestade)
+    {
+      modoTempestade();
+    }
+    else {
+     atualizaLuzes();
+    }
 }

 void ledStatus() {
-  delay(500);
+ /* delay(500);
   if(led_status) {
     digitalWrite(led_stautus_pin, HIGH);
     led_status = false;
@@ -121,23 +143,179 @@
     digitalWrite(led_stautus_pin, LOW);
     led_status = true;
   }
-
+*/
+}
+
+
+/*
+
+1 - Violeta
+2 - Branco
+3 - Vermelho
+4 - Azul
+5 - Violeta
+6 - Aquitinium
+7 - Verde
+
+tempestade;ON
+tempestade;OFF
+*/
+
+
+
+void modoTempestade() {
+
+
+
+
+  if(comparaTempo(temp_tempo_espera)) {
+
+  temp_tempo_espera = random(7,15);
+  Serial.println(temp_tempo_espera);
+  temp_tempo_espera = (temp_tempo_espera * 1000);
+  temp_tempo_espera = temp_tempo_espera + millis();
+
+  int modo = random(1,10);
+
+  atualizaLuzesTempestade(temp_leds);
+
+  if(modo <= 5) {
+   analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(40);
+   atualizaLuzesTempestade(temp_leds);
+   delay(40);
+   analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(40);
+  atualizaLuzesTempestade(temp_leds);
+   delay(40);
+     analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(40);
+  atualizaLuzesTempestade(temp_leds);
+   delay(100);
+   analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(100);
+atualizaLuzesTempestade(temp_leds);
+
+
+      Serial.println("modo1");
+      Serial.println("----------");
+
+  } else {
+
+   analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(80);
+atualizaLuzesTempestade(temp_leds);
+   delay(80);
+   analogWrite(canal_01,temp_led_raio);
+   analogWrite(canal_02,temp_led_raio);
+   analogWrite(canal_06,temp_led_raio);
+   delay(80);
+atualizaLuzesTempestade(temp_leds);
+
+
+       Serial.println("modo2");
+      Serial.println("----------");
+
+  }
+  }
+
+
+}
+
+
+void atualizaLuzesTempestade(int valor) {
+
+  if(canal_01_valor >= valor) {
+    analogWrite(canal_01, valor);
+  }
+  else {
+    analogWrite(canal_01, valorMaximo(canal_01_valor));
+  }
+
+  if(canal_02_valor >= valor) {
+    analogWrite(canal_02, valor);
+  }
+  else {
+    analogWrite(canal_02, valorMaximo(canal_02_valor));
+  }
+
+  if(canal_03_valor >= valor) {
+    analogWrite(canal_03, valor);
+  }
+  else {
+    analogWrite(canal_03, valorMaximo(canal_03_valor));
+  }
+
+
+   if(canal_04_valor >= valor) {
+    analogWrite(canal_04, valor);
+  }
+  else {
+    analogWrite(canal_04, valorMaximo(canal_04_valor));
+  }
+
+
+     if(canal_05_valor >= valor) {
+    analogWrite(canal_05, valor);
+  }
+  else {
+    analogWrite(canal_05, valorMaximo(canal_05_valor));
+  }
+
+
+
+  if(canal_06_valor >= valor) {
+    analogWrite(canal_06, valor);
+  }
+  else {
+    analogWrite(canal_06, valorMaximo(canal_06_valor));
+  }
+
+
+ if(canal_07_valor >= valor) {
+    analogWrite(canal_07, valor);
+  }
+  else {
+    analogWrite(canal_07, valorMaximo(canal_07_valor));
+  }
+
+
 }

 void atualizaLuzes() {

-   analogWrite(canal_01, canal_01_valor);
-   analogWrite(canal_02, canal_02_valor);
-   analogWrite(canal_03, canal_03_valor);
-   analogWrite(canal_04, canal_04_valor);
-   analogWrite(canal_05, canal_05_valor);
-   analogWrite(canal_06, canal_06_valor);
-   analogWrite(canal_07, canal_07_valor);
-
-
-}
+   analogWrite(canal_01, valorMaximo(canal_01_valor));
+   analogWrite(canal_02, valorMaximo(canal_02_valor));
+   analogWrite(canal_03, valorMaximo(canal_03_valor));
+   analogWrite(canal_04, valorMaximo(canal_04_valor));
+   analogWrite(canal_05, valorMaximo(canal_05_valor));
+   analogWrite(canal_06, valorMaximo(canal_06_valor));
+   analogWrite(canal_07, valorMaximo(canal_07_valor));
+
+}
+
+int valorMaximo(int canal_valor) {
+
+  if(canal_valor > pwm_maximo ) {
+    return pwm_maximo;
+  }
+  else {
+    return canal_valor;
+  }
+}
+

 void obtemLuzes(String dados) {
@@ -197,14 +375,25 @@
 void obtemDHT11() {

     DHT.read11(dht_dpin); //Lê as informações do sensor
+
     Serial.print(DHT.temperature);
     Serial.print(";");
     Serial.print(DHT.humidity);
     Serial.print("\n");
-
-    /*delay(2000);  //Não diminuir muito este valor. O ideal é a leitura a cada 2 segundo */
-}
-
-
-
-
+}
+
+
+bool comparaTempo(unsigned long antigo) {
+  unsigned long atual = millis();
+
+  if(atual>=antigo) {
+    return true;
+  }
+  else {
+    return false;
+  }
+
+}
+
+
+


updated parallel out 2

updated parallel out 2

--- proj/parallel_out_test_2/parallel_out_test_2.ino
+++ proj/parallel_out_test_2/parallel_out_test_2.ino
@@ -47,7 +47,7 @@

   for (uint8_t ss = 0; ss < NUM_STRIPS; ss++) {
-    fill_solid(&(leds[ss*NUM_LED]), NUM_LED, CHSV(ss*16, 192, 55));
+    fill_solid(&(leds[ss*NUM_LED]), NUM_LED, CHSV(2*ss*16, 255, 200));
   }

   //LEDS.setBrightness(32);


Added timestamp to status message and newly renamed GETALL message

--- arduino/brew_kettle/brew_kettle.ino
+++ arduino/brew_kettle/brew_kettle.ino
@@ -42,12 +42,12 @@
   kCOMM_ERROR = 000,
   kSTATUS = 001,
   kTEMPERATURE = 002,
-  kINOUTSET = 003,
+  kGETALL = 003,
   kSEND_CMDS_END, // Mustnt delete this line
 };

-#define STATMSG "1,"
-#define INOUTSETMSG "3,"
+#define STATMSG "1," << currentMillis << ","
+#define GETALLMSG "3," << currentMillis << ","
 #define ENDMSG ";\r\n"

 // Commands we send from the PC and want to recieve on the Arduino.
@@ -58,7 +58,7 @@
   temp_msg, // 005
   heater_msg, // 006
   setPIDonoff_msg, // 007
-  getINOUTSET_msg, // 008
+  getGETALL_msg, // 008
   changeSET_msg, // 009
   NULL
 };
@@ -109,9 +109,9 @@
   }
 }

-void getINOUTSET_msg() {
+void getGETALL_msg() {
   Serial << STATMSG << "Get Input Output Setpoint msg received" << ENDMSG;
-  Serial << INOUTSETMSG << temperature << "," << dutyCycle << "," \
+  Serial << GETALLMSG << temperature << "," << dutyCycle << "," \
 	 << setpoint << ENDMSG;
 }

@@ -265,7 +265,7 @@
   cmdMessenger.attach(5, temp_msg);
   cmdMessenger.attach(6, heater_msg);
   cmdMessenger.attach(7, setPIDonoff_msg);
-  cmdMessenger.attach(8, getINOUTSET_msg);
+  cmdMessenger.attach(8, getGETALL_msg);
   cmdMessenger.attach(9, changeSET_msg);
   arduino_ready();
 }


Delete GPSLCD.ino

Delete GPSLCD.ino

--- GPSLCD.ino
+++ GPSLCD.ino
@@ -1,653 +0,0 @@
-/* GPS LCD
-
-    By GK Grotsky
-    8/30/16
-
-  This program communicate with the u-blox NEO-6M GPS module
-  through a software serial interface. It then displays certain GPS
-  parameters on a I2C 16x2 (or 20x4) character LCD display module. The
-  GPS messages are received by the on-board Arduino UART circuit using
-  the SoftwareSerial library. It then uses the TinyGPS++ library to
-  decode the GPS NMEA messages. The parameters are then displayed on a
-  16x4 (or 20x4) LCD using the LiquidCrystal_I2C library.
-
-  Note: Both the 16x2 and 20x4 LCDs are supported as these are the most popular
-        LCDs available.
-*/
-#include "GPSLCD.h"
-#include <TinyGPS++.h>
-#include <SoftwareSerial.h>
-#include <LiquidCrystal_I2C.h>
-
-TinyGPSPlus gps; // This is the GPS object that will pretty much do all the grunt work with the NMEA data
-SoftwareSerial GPSModule(10, 11); // RX, TX
-LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); // Initializes class variables and defines the I2C address of the LCD
-bool dataValid; // Data is valid from the GPS module
-GPSStruct GPSData; // Holds the GPS data coming from the GPS module
-
-// The setup (runs once at start up)
-void setup()
-{
-  pinMode(BACKLIGHT_SW, INPUT);
-
-#ifdef _16x2
-  // Selects either speed or heading to be displayed
-  pinMode(SPEED_ALTITUDE_SW, INPUT);
-#else
-  // Selects either altitude or the date/time to be displayed
-  pinMode(ALTITUDE_DATE_TIME_SW, INPUT);
-#endif
-
-#ifdef DEBUG
-  Serial.begin(9600); // This opens up communications to the serial monitor in the Arduino IDE
-  Serial.flush();
-#endif
-  GPSModule.begin(9600); // This opens up communications to the software serial tx and rx lines
-  GPSModule.flush();
-
-  lcd.begin (COLUMN, ROW); // Defines LCD type
-  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); // Sets the pin to control the backlight
-  lcd.clear(); // Clear the LCD
-  lcd.home (); // Go to the home position on the LCD
-} // setup
-
-// The loop (runs forever and a day :-))
-void loop()
-{
-  static uint32_t pastSatellites = 0;
-  static uint8_t initializingCounter = 0;
-  static unsigned long prevInitializationTime = INITIALIZATION_INTERVAL;
-  static unsigned long prevCreditTime = TOGGLETIME_INTERVAL;
-  static unsigned long prevInvalidSatellitesTime = TOGGLETIME_INTERVAL;
-  static bool leftInitialization = false;
-  static bool creditToggle = true;
-  static bool InvalidSatellitesToggle = true;
-#ifndef _16x2
-  static unsigned long prevDateTime = TOGGLETIME_INTERVAL;
-  static unsigned long prevHeadingTime = TOGGLETIME_INTERVAL;
-  static bool dateTimeToggle = true;
-  static bool headingToggle = true;
-#endif
-#ifdef DEBUG
-  static unsigned long prevDebugTime = 0;
-#endif
-#ifdef DATA_VALID_OVERRIDE
-  const bool dataValidOverride = true; // Set true to override data valid for debugging
-#else
-  const bool dataValidOverride = false; // Set false not to override data valid
-#endif
-#ifdef BACKLIGHT_OVERRIDE
-  // Override LCD backlight switch
-  // Force LCD backlight on/off
-  lcd.setBacklight(BACKLIGHT_ONOFF);
-#else
-  // Turn LCD backlight on/off
-  lcd.setBacklight(digitalRead(BACKLIGHT_SW));
-#endif
-  unsigned long now = millis();
-
-  while (GPSModule.available()) // While there are characters to come from the GPS
-  {
-    bool b = gps.encode(GPSModule.read()); // This feeds the serial NMEA data into the GPS library one char at a time
-  }
-
-  // Get the GPS data valid flags
-  dataValid =
-    gps.location.isValid()   &&
-    gps.speed.isValid()      &&
-    gps.altitude.isValid()   &&
-    gps.course.isValid()     &&
-    gps.date.isValid()       &&
-    gps.time.isValid()       &&
-    gps.satellites.isValid() &&
-    gps.hdop.isValid();
-
-  // Check if the GPS data is valid or data valid override is set (for debugging)
-  if (dataValid || dataValidOverride) {
-#ifndef DATA_VALID_OVERRIDE
-    // Store the real GPS data
-    GPSData.satellites = gps.satellites.value();
-    GPSData.lat        = gps.location.lat();
-    GPSData.lon        = gps.location.lng();
-    GPSData.speed      = gps.speed.mph();
-    GPSData.altitude   = gps.altitude.feet();
-#ifndef _16x2
-    GPSData.heading    = gps.course.deg();
-    GPSData.hdop       = gps.hdop.value();
-    GPSData.year       = gps.date.year();
-    GPSData.month      = gps.date.month();
-    GPSData.day        = gps.date.day();
-    GPSData.hour       = gps.time.hour();
-    GPSData.minute     = gps.time.minute();
-    GPSData.second     = gps.time.second();
-#endif // #ifndef _16x2
-#else // #ifndef DATA_VALID_OVERRIDE
-    // Store the fake GPS data (for debugging)
-    GPSData.satellites = 0; // Invalid satellites
-    GPSData.lat        = 39.16d; // East coast
-    GPSData.lon        = -77.07d; //   "
-    GPSData.speed      = 55.0d;
-    GPSData.altitude   = 555.0d;
-#ifndef _16x2
-    GPSData.heading    = 60.0d; // ENE or NE (16 cardinal points or 8 cardinal points)
-    GPSData.hdop       = 240;
-    GPSData.year       = 2016;
-    GPSData.month      = 11; // Day before ST starts
-    GPSData.day        = 5;  //      "
-    GPSData.hour       = 23; // 7pm my local time
-    GPSData.minute     = 10;
-    GPSData.second     = 25;
-#endif // #ifndef _16x2
-#endif // #ifndef DATA_VALID_OVERRIDE
-    // Clear the screen once when leaving initialization
-    if (!leftInitialization) {
-      leftInitialization = true;
-      lcd.clear(); // Clear the LCD
-    }
-    // Display the latest info from the gps object which it derived from the data sent by the GPS unit
-    // Send data to the LCD
-#ifdef _16x2 //------------------------------------------------------
-    lcd.home (); // Go to 1st line
-    lcd.print("Lat: ");
-    lcd.print(GPSData.lat);
-    lcd.setCursor (11, 0);
-    lcd.print("SV:");
-    if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0)) {
-      pastSatellites = GPSData.satellites;
-      if (GPSData.satellites == 0) {
-        // Toggle invalid satellites indicator every TOGGLETIME_INTERVAL seconds
-        if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL / 4) {
-          prevInvalidSatellitesTime = now;
-          if (InvalidSatellitesToggle) {
-            InvalidSatellitesToggle = false;
-            lcd.print("XX");
-          }
-          else {
-            InvalidSatellitesToggle = true;
-            lcd.print("  ");
-          } // if (InvalidSatellitesToggle)
-        } // if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL)
-      } // if (GPSData.satellites == 0)
-      else if (GPSData.satellites <= 9) {
-        lcd.print(" "); // Blank leading char
-        lcd.print(GPSData.satellites);
-      }
-      else {
-        lcd.print(GPSData.satellites);
-      }
-    } // if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0))
-    lcd.setCursor (0, 1); // Go to 2nd line
-    lcd.print("Lon: ");
-    lcd.print(GPSData.lon);
-    if ((digitalRead(SPEED_ALTITUDE_SW))) {
-      lcd.setCursor (12, 1);
-      if (GPSData.speed < SPEED_CUTOUT) {
-        lcd.print("0  ");
-      }
-      else {
-        lcd.print((int16_t)GPSData.speed);
-        lcd.print(" "); // Clear the extra char
-      }
-    }
-    else {
-      lcd.print("     "); // Clear the extra chars
-      if (GPSData.altitude <= 99.9) {
-        lcd.setCursor (14, 1);
-      }
-      else {
-        lcd.setCursor (13, 1);
-      }
-      lcd.print((int16_t)GPSData.altitude); // Altitude
-      // Toggle credit every TOGGLETIME_INTERVAL seconds
-      if (now - prevCreditTime > (TOGGLETIME_INTERVAL / 2)) {
-        prevCreditTime = now;
-        if (creditToggle) { // Display credit
-          creditToggle = false;
-          lcd.print("     "); // Clear the extra chars
-          lcd.print(CREDIT); // Yours truly :-)
-        }
-        else {
-          creditToggle = true;
-          lcd.print("        "); // Clear the extra chars
-        }
-      } // if (now - prevCreditTime > TOGGLETIME_INTERVAL)
-    } // if ((digitalRead(SPEED_ALTITUDE_SW)))
-#else // 20x4 ----------------------------------------------------
-    lcd.home (); // Go to 1st line
-    lcd.print("Lat: ");
-    lcd.print(GPSData.lat);
-    lcd.setCursor (15, 0);
-    lcd.print("SV:");
-    if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0)) {
-      pastSatellites = GPSData.satellites;
-      if (GPSData.satellites == 0) {
-        // Toggle invalid satellites indicator every TOGGLETIME_INTERVAL seconds
-        if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL / 3) {
-          prevInvalidSatellitesTime = now;
-          if (InvalidSatellitesToggle) {
-            InvalidSatellitesToggle = false;
-            lcd.print("XX");
-          }
-          else {
-            InvalidSatellitesToggle = true;
-            lcd.print("  ");
-          } // if (InvalidSatellitesToggle)
-        } // if (now - prevInvalidSatellitesTime > TOGGLETIME_INTERVAL)
-      } // if (GPSData.satellites == 0)
-      else if (GPSData.satellites <= 9) {
-        lcd.print(" "); // Blank leading char
-        lcd.print(GPSData.satellites);
-      }
-      else {
-        lcd.print(GPSData.satellites);
-      }
-    } // if ((pastSatellites != GPSData.satellites) || (GPSData.satellites == 0))
-    lcd.setCursor (0, 1); // Go to 2nd line
-    lcd.print("Lon: ");
-    lcd.print(GPSData.lon);
-#ifndef CONVERT_TO_LOCAL
-    // Only display if time/date is selected
-    if (!(digitalRead(ALTITUDE_DATE_TIME_SW))) {
-      lcd.print("      "); // Clear the extra chars
-      uint8_t DOW = dayOfWeek(GPSData.year, GPSData.month, GPSData.day);
-      if (IsDST(GPSData.day, GPSData.month, DOW)) {
-        lcd.print("DST");
-      }
-      else {
-        lcd.print(" ST");
-      }
-    }
-    else {
-      lcd.print("         "); // Clear the extra chars
-    }
-#else // #ifndef CONVERT_TO_LOCAL
-    //Dis[lay HDOP with the format X.X (it comes in from the GPS module as XXX)
-    uint32_t hdopInteger = GPSData.hdop / 100;
-    uint32_t hdopFarction = (GPSData.hdop - (hdopInteger * 100)) / 10;
-    lcd.print(" Hdop:");
-    lcd.print(hdopInteger);
-    lcd.print(".");
-    lcd.print(hdopFarction);
-#endif // #ifndef CONVERT_TO_LOCAL
-    lcd.setCursor (0, 2); // Go to 3rd line
-    lcd.print("Spd: ");
-    if (GPSData.speed < SPEED_CUTOUT) {
-      lcd.print("0  ");
-    }
-    else {
-      lcd.print((int16_t)GPSData.speed);
-      lcd.print(" "); // Clear the extra chars
-    }
-    lcd.setCursor (12, 2);
-    lcd.print("Hdg: ");
-    if (GPSData.speed < SPEED_CUTOUT) {
-      lcd.print("0  ");
-    }
-    else {
-      // Toggle heading every TOGGLETIME_INTERVAL seconds
-      if (now - prevHeadingTime > TOGGLETIME_INTERVAL) {
-        prevHeadingTime = now;
-        if (headingToggle) { // Display cardinal heading
-          headingToggle = false;
-          lcd.print(cardinal(GPSData.heading));
-        }
-        else { // Display degrees heading
-          headingToggle = true;
-          lcd.print((int16_t)GPSData.heading);
-          if (GPSData.heading <= 99.9) lcd.print(" "); // Clear the extra char
-        } // if (headingToggle)
-      } // if (now - prevHeadingTime > TOGGLETIME_INTERVAL)
-    } // if (GPSData.speed < SPEED_CUTOUT)
-    lcd.setCursor (0, 3); // Go to 4th line
-    if ((digitalRead(ALTITUDE_DATE_TIME_SW))) {
-      lcd.print("Alt: ");
-      lcd.print((int16_t)GPSData.altitude);
-      // Toggle credit every TOGGLETIME_INTERVAL seconds
-      if (now - prevCreditTime > (TOGGLETIME_INTERVAL / 2)) {
-        prevCreditTime = now;
-        if (creditToggle) { // Display credit
-          creditToggle = false;
-          lcd.print("         "); // Clear the extra chars
-          lcd.print(CREDIT); // Yours truly :-)
-        }
-        else {
-          creditToggle = true;
-          lcd.print("            "); // Clear the extra chars
-        }
-      } // if (now - prevCreditTime > TOGGLETIME_INTERVAL)
-      prevDateTime = TOGGLETIME_INTERVAL;
-      dateTimeToggle = true; // Default first to display date
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
-    else {
-      // Toggle date/time every TOGGLETIME_INTERVAL seconds
-      if (now - prevDateTime > TOGGLETIME_INTERVAL) {
-        prevDateTime = now;
-        if (dateTimeToggle) {
-          // Display date
-          dateTimeToggle = false;
-          lcd.print("Date: ");
-          uint8_t hour = GPSData.hour;
-          uint8_t day  = GPSData.day;
-          uint8_t month = GPSData.month;
-          uint16_t year = GPSData.year;
-#ifdef CONVERT_TO_LOCAL
-          // Convert UTC date to local date
-          bool DST = convertToLocal (&hour, &year, &month,
-                                     &day, GPSData.lon, true); // true means date conversion
-#endif // #ifdef CONVERT_TO_LOCAL
-          if (month < 10) lcd.print("0");
-          lcd.print(month);
-          lcd.print("/");
-          if (day < 10) lcd.print("0");
-          lcd.print(day);
-          lcd.print("/");
-          lcd.print(year);
-          printDay (dayOfWeek (year, month, day));
-        } // if (dateTimeToggle)
-        else {
-          // Display time
-          dateTimeToggle = true;
-          lcd.print("Time: ");
-          uint8_t hour = GPSData.hour;
-          uint8_t day  = GPSData.day;
-          uint8_t month = GPSData.month;
-          uint16_t year = GPSData.year;
-#ifdef CONVERT_TO_LOCAL
-          // Convert UTC time to local time (no need to convert the date)
-          bool DST = convertToLocal (&hour, &year, &month,
-                                     &day, GPSData.lon, false); // false means no date conversion
-#else // #ifdef CONVERT_TO_LOCAL
-#ifdef DISPLAY_12_HOUR
-          if (hour == 0) { // 12 hour clocks don't display 0
-            hour = 12;
-          }
-#endif // #ifdef DISPLAY_12_HOUR
-#endif // #ifdef CONVERT_TO_LOCAL
-#ifdef DISPLAY_12_HOUR
-          char AMPM[] = "am";
-          if (hour >= 12) { // Convert to 12 hour format
-            if (hour > 12) hour -= 12;
-            strcpy (AMPM, "pm");
-          }
-#endif
-          if (hour < 10) lcd.print("0");
-          lcd.print(hour);
-          lcd.print(":");
-          if (GPSData.minute < 10) lcd.print("0");
-          lcd.print(GPSData.minute);
-          lcd.print(":");
-          if (GPSData.second < 10) lcd.print("0");
-          lcd.print(GPSData.second);
-#ifdef DISPLAY_12_HOUR
-          lcd.print(AMPM);
-#endif // #ifdef DISPLAY_12_HOUR
-#ifdef CONVERT_TO_LOCAL
-#ifdef DISPLAY_12_HOUR
-          (DST) ? lcd.print(" DST") : lcd.print("  ST");
-#else // #ifdef DISPLAY_12_HOUR
-          (DST) ? lcd.print("   DST") : lcd.print("    ST");
-#endif // #ifdef DISPLAY_12_HOUR
-#endif // #ifndef CONVERT_TO_LOCAL
-#ifndef CONVERT_TO_LOCAL
-#ifdef DISPLAY_12_HOUR
-          lcd.print(" UTC");
-#else // #ifdef DISPLAY_12_HOUR
-          lcd.print("   UTC");
-#endif // #ifdef DISPLAY_12_HOUR
-#endif // #ifndef CONVERT_TO_LOCAL
-        } // if (dateTimeToggle)
-      } // if (now - prevDateTime > TOGGLETIME_INTERVAL)
-    } // if ((digitalRead(ALTITUDE_DATE_TIME_SW)))
-#endif //------------------------------------------------------------
-  } // if (dataValid)
-  else {
-    // GPS data is not valid, so it must be initializing
-#ifdef _16x2 //------------------------------------------------------
-    // Display initialization screen once every INITIALIZATION_INTERVAL
-    if (now - prevInitializationTime > INITIALIZATION_INTERVAL) {
-      prevInitializationTime = now;
-      lcd.setCursor (6, 0); // Go to 1st line
-      lcd.print("GPS");
-      lcd.setCursor (11, 0);
-      lcd.print("v");
-      lcd.print(VERSION);
-      lcd.setCursor (2, 1); // Go to 2nd line
-      lcd.print("Initializing");
-      lcd.setCursor (15, 1);
-      if (++initializingCounter > 9) initializingCounter = 1; // Limit 1 - 9
-      lcd.print(initializingCounter);
-      leftInitialization = false;
-    }
-#else // 20x4 -------------------------------------------------------
-    // Display initialization screen once every INITIALIZATION_INTERVAL
-    if (now - prevInitializationTime > INITIALIZATION_INTERVAL) {
-      prevInitializationTime = now;
-      lcd.setCursor (8, 0); // Go to 1st line
-      lcd.print("GPS");
-      lcd.setCursor (14, 0);
-      lcd.print("v");
-      lcd.print(VERSION);
-      lcd.setCursor (4, 1); // Go to 2nd line
-      lcd.print("Initializing");
-      lcd.setCursor (6, 2); // Go to 3rd line
-      lcd.print("Data Not");
-      lcd.setCursor (7, 3); // Go to 4th line
-      lcd.print("Valid");
-      lcd.setCursor (19, 3);
-      if (++initializingCounter > 9) initializingCounter = 1; // Limit 1 - 9
-      lcd.print(initializingCounter);
-      leftInitialization = false;
-    }
-#endif //------------------------------------------------------------
-  } // GPS data is not valid
-#ifdef DEBUG
-  // Display debug info to the serial monitor (if DEBUG is enabled)
-  // Display debug data once every DEBUG_INTERVAL
-  if (now - prevDebugTime > DEBUG_INTERVAL) {
-    prevDebugTime = now;
-    displayDebugData();
-  }
-#endif // #ifdef DEBUG
-} // loop
-
-#ifndef _16x2
-/* Helper functions start here
-
-  Ripped off from Electrical Engineering Stack Exchange
-  http://electronics.stackexchange.com/questions/66285/how-to-calculate-day-of-the-week-for-rtc
-  ------------------------------------------------------------
-   Returns the number of days to the start of the specified year, taking leap
-   years into account, but not the shift from the Julian calendar to the
-   Gregorian calendar. Instead, it is as though the Gregorian calendar is
-   extrapolated back in time to a hypothetical "year zero".
-*/
-uint16_t leap (uint16_t year)
-{
-  return year * 365 + (year / 4) - (year / 100) + (year / 400);
-}
-/* Returns a number representing the number of days since March 1 in the
-   hypothetical year 0, not counting the change from the Julian calendar
-   to the Gregorian calendar that occurred in the 16th century. This
-   algorithm is loosely based on a function known as "Zeller's Congruence".
-   This number MOD 7 gives the day of week, where 0 = Monday and 6 = Sunday.
-*/
-uint16_t zeller (uint16_t year, uint8_t month, uint8_t day)
-{
-  year += ((month + 9) / 12) - 1;
-  month = (month + 9) % 12;
-  return leap (year) + month * 30 + ((6 * month + 5) / 10) + day + 1;
-}
-
-// Returns the day of week for a given date.
-uint8_t dayOfWeek (uint16_t year, uint8_t month, uint8_t day)
-{
-  return (zeller (year, month, day) % 7) + 1;
-}
-//----------------------------------------------------------
-
-// Print the day of the week on the LCD
-void printDay(uint8_t day)
-{
-  if (day == 7) day = 0;
-  switch (day)
-  {
-    case 0:  lcd.print(" Mon"); break;
-    case 1:  lcd.print(" Tue"); break;
-    case 2:  lcd.print(" Wed"); break;
-    case 3:  lcd.print(" Thu"); break;
-    case 4:  lcd.print(" Fri"); break;
-    case 5:  lcd.print(" Sat"); break;
-    case 6:  lcd.print(" Sun"); break;
-    default: lcd.print(" Err");
-  }
-}
-
-// Compute the cardinal points of the compass
-const char* cardinal(double course)
-{
-#ifdef _16CARDINAL
-  const char* directions[] = {"N  ", "NNE", "NE ", "ENE", "E  ", "ESE", "SE ", "SSE",
-                              "S  ", "SSW", "SW ", "WSW", "W  ", "WNW", "NW ", "NNW"
-                             };
-#else
-  const char* directions[] = {"N  ", "N  ", "NE ", "NE ", "E  ", "E  ", "SE ", "SE ",
-                              "S  ", "S  ", "SW ", "SW ", "W  ", "W  ", "NW ", "NW "
-                             };
-#endif // #ifdef _16CARDINAL
-  uint8_t direction = (uint8_t)((course + 11.25d) / 22.5d);
-  return directions[direction % 16];
-}
-
-/* Ripped off from Stackoverflow
-  http://stackoverflow.com/questions/5590429/calculating-daylight-saving-time-from-only-date
-
-  Check to see if it's Daylight Savings Time (DST)
-*/
-bool IsDST(uint8_t day, uint8_t month , uint8_t DOW)
-{
-  // Make Day of Week (DOW) match with what Stackoverflow suggests
-  // for DOW (Sunday = 0 to Saturday = 6)
-  switch (DOW)
-  {
-    case 6:  DOW = 0; break; // Sun
-    case 7:  DOW = 1; break; // Mon
-    case 1:  DOW = 2; break; // Tue
-    case 2:  DOW = 3; break; // Wed
-    case 3:  DOW = 4; break; // Thu
-    case 4:  DOW = 5; break; // Fri
-    case 5:  DOW = 6; break; // Sat
-    default: break;
-  }
-  // January, February, and December are out
-  if (month < 3 || month > 11) {
-    return false;
-  }
-  // April to October are in
-  if (month > 3 && month < 11) {
-    return true;
-  }
-  int8_t previousSunday = (int8_t)(day - DOW);
-  // In march, we are DST if our previous Sunday was on or after the 8th
-  if (month == 3) {
-    return previousSunday >= 8;
-  }
-  // In November we must be before the first Sunday to be DST
-  // That means the previous Sunday must be before the 1st
-  return previousSunday <= 0;
-}
-
-#ifdef CONVERT_TO_LOCAL
-/* Convert UTC time and date to local time and date
-   Difference between UTC time/date (at Greenwich) and local time/date is 15 minutes
-   per 1 degree of longitude. See the following:
-   http://www.edaboard.com/thread101516.html
-*/
-bool convertToLocal (uint8_t* hour, uint16_t* year, uint8_t* month,
-                     uint8_t* day, const double lon, bool convertDate) {
-
-  uint8_t DaysAMonth [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-  // Get Day of Week (DOW)
-  uint8_t DOW = dayOfWeek(*year, *month, *day);
-  // Get Daylight Saving Time (DST) or Standard Time (ST)
-  bool DST = IsDST(*day, *month, DOW);
-  // Compute local time (hours)
-  int8_t UTCOffset = (int8_t)(lon / 15.0d); // UTC offset
-  if (UTCOffset < 0) {
-    // West of Greenwich, subtract
-    UTCOffset = abs(UTCOffset); // Make offset positive
-    if (DST) --UTCOffset; // Compensate for DST
-    if (*hour <= UTCOffset) *hour += 24;
-    *hour = *hour - UTCOffset; // Subtract offset
-  }
-  else {
-    // East of Greenwich, add
-    if (DST) ++UTCOffset; // Compensate for DST
-    if (*hour <= UTCOffset) *hour += 24;
-    *hour = *hour + UTCOffset; // Add offset
-  }
-  // Convert date if convertDate flag is set
-  // Portions of the following code (with some modifications) ripped off from Instructables
-  // http://www.instructables.com/id/GPS-time-UTC-to-local-time-conversion-using-Arduin/?ALLSTEPS
-  if (convertDate) {
-    if ((24 - *hour) <= UTCOffset) { // A new UTC day started
-      if (*year % 4 == 0) DaysAMonth[1] = 29; //leap year check (the simple method)
-      if (*hour < 24) {
-        *day -= 1;
-        if (*day < 1) {
-          if (*month == 1) {
-            *month = 12;
-            *year -= 1;
-          } // if (*month == 1)
-          else {
-            *month -= 1;
-          }
-          *day = DaysAMonth[*month - 1];
-        } // if (*day < 1)
-      } // if (*hour < 24)
-      else if (*hour >= 24) {
-        day += 1;
-        if (*day > DaysAMonth[*month - 1]) {
-          *day = 1;
-          *month += 1;
-          if (*month > 12) *year += 1;
-        } // if (*day > DaysAMonth[*month - 1])
-      } // if (*hour >= 24)
-    } // if ((24 - *hour) <= UTCOffset)
-  } // if (convertDate)
-  return (DST);
-}
-#endif // #ifdef CONVERT_TO_LOCAL
-#endif // #ifndef _16x2
-
-#ifdef DEBUG
-// Displays debug data to the serial monitor
-void displayDebugData() {
-  Serial.print("Version: ");
-  Serial.println(VERSION);
-  Serial.print("Satellite Count: ");
-  Serial.println(GPSData.satellites);
-  Serial.print("Latitude: ");
-  Serial.println(GPSData.lat, 6);
-  Serial.print("Longitude: ");
-  Serial.println(GPSData.lon, 6);
-  Serial.print("Speed MPH: ");
-  Serial.println(GPSData.speed);
-  Serial.print("Altitude Feet: ");
-  Serial.println(GPSData.altitude);
-#ifdef _16x2
-  Serial.print("Alt/SPD: ");
-  Serial.println((digitalRead(SPEED_ALTITUDE_SW)) ? "Speed" : "Altitude");
-#else
-  Serial.print("Altitude/Date: ");
-  Serial.println(!(digitalRead(ALTITUDE_DATE_TIME_SW)) ? "Date/Time" : "Altitude");
-#endif
-  Serial.println((digitalRead(BACKLIGHT_SW)) ? "Backlight On" : "Backlight Off");
-  Serial.print("Data valid: ");
-  Serial.println(dataValid);
-  uint8_t DOW = dayOfWeek(GPSData.year, GPSData.month, GPSData.day);
-  Serial.print("DST = ");
-  Serial.println(IsDST(GPSData.day, GPSData.month, DOW));
-  Serial.println("");
-}
-#endif


test file update with pin 9 to be output


Use MEASURE macro when possible.

Use MEASURE macro when possible.

--- examples/Canvas/CosaCanvasDemo/CosaCanvasDemo.ino
+++ examples/Canvas/CosaCanvasDemo/CosaCanvasDemo.ino
@@ -165,226 +165,212 @@
 void loop()
 {
   static uint8_t direction = Canvas::PORTRAIT;
-  uint32_t start, ms;

   // Test#1: Fill screen
-  start = RTC::micros();
+  MEASURE("test#1:fill screen:", 1) {
+    tft.set_canvas_color(Canvas::WHITE);
+    tft.fill_screen();
+  }
+
+  // Test#2: Use the display as an output stream
+  MEASURE("test#2:output stream:", 1) {
+    textbox.set_text_color(Canvas::BLUE);
+    textbox.set_text_scale(1);
+    textbox.set_text_port(2, 2, tft.WIDTH, tft.HEIGHT);
+    console.print(PSTR("CosaCanvasDemo: started"));
+    console.println();
+    console.printf(PSTR("text_color(%od)\n"), textbox.get_text_color().rgb);
+    console.printf(PSTR("text_scale(%d)\n"), textbox.get_text_scale());
+    uint16_t x, y;
+    textbox.get_cursor(x, y);
+    console.printf(PSTR("cursor(x = %d, y = %d)\n"), x, y);
+    textbox.set_text_color(Canvas::RED);
+    textbox.set_text_scale(2);
+    console.print(PSTR("  Hello\n  World"));
+    console.println();
+    textbox.set_text_color(Canvas::BLACK);
+    textbox.set_text_scale(1);
+  }
+  sleep(2);
+
+  // Test#3: Scroll text port
+  tft.set_canvas_color(tft.shade(Canvas::WHITE, 50));
+  tft.fill_screen();
   tft.set_canvas_color(Canvas::WHITE);
-  tft.fill_screen();
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#1:fill screen: %ul ms", ms);
-
-  // Test#2: Use the display as an output stream
-  start = RTC::micros();
-  textbox.set_text_color(Canvas::BLUE);
-  textbox.set_text_scale(1);
-  textbox.set_text_port(2, 2, tft.WIDTH, tft.HEIGHT);
-  console.print(PSTR("CosaCanvasDemo: started"));
-  console.println();
-  console.printf(PSTR("test#1:fill screen %ul ms\n"), ms);
-  console.println();
-  console.printf(PSTR("text_color(%od)\n"), textbox.get_text_color().rgb);
-  console.printf(PSTR("text_scale(%d)\n"), textbox.get_text_scale());
-  uint16_t x, y;
-  textbox.get_cursor(x, y);
-  console.printf(PSTR("cursor(x = %d, y = %d)\n"), x, y);
-  textbox.set_text_color(Canvas::RED);
-  textbox.set_text_scale(2);
-  console.print(PSTR("  Hello\n  World"));
-  console.println();
-  ms = (RTC::micros() - start) / 1000L;
-  textbox.set_text_color(Canvas::BLACK);
-  textbox.set_text_scale(1);
-  console.printf(PSTR("test#2:output stream: %ul ms\n"), ms);
-  INFO("test#2:output stream: %ul ms", ms);
-  sleep(2);
-
-  // Test#3: Scroll text port
-  start = RTC::micros();
-  tft.set_canvas_color(tft.shade(Canvas::WHITE, 50));
-  tft.fill_screen();
-  tft.set_canvas_color(Canvas::WHITE);
+  MEASURE("test#3:scroll text mode:", 1) {
 #if defined(USE_TFT_ST7735)
-  tft.draw_rect(4, 4, tft.WIDTH-8, tft.HEIGHT-8);
-  textbox.set_text_port(5, 5, tft.WIDTH-10, tft.HEIGHT-10);
+    tft.draw_rect(4, 4, tft.WIDTH-8, tft.HEIGHT-8);
+    textbox.set_text_port(5, 5, tft.WIDTH-10, tft.HEIGHT-10);
 #endif
 #if defined(USE_TFT_ILI9341)
-  tft.draw_rect(tft.WIDTH/4+4, tft.HEIGHT/4+4,
-		tft.WIDTH/2-8, tft.HEIGHT/2-8);
-  textbox.set_text_port(tft.WIDTH/4+5, tft.HEIGHT/4+5,
-			tft.WIDTH/2-10, tft.HEIGHT/2-10);
-#endif
-  console.print('\f');
-  console.print(&tft, 200, IOStream::hex,
-		tft.get_orientation() == Canvas::PORTRAIT ? 3 : 5);
-  ms = (RTC::micros() - start) / 1000L;
-  console.printf(PSTR("%ul ms"), ms);
-  INFO("test#3:scroll text mode: %ul ms", ms);
+    tft.draw_rect(tft.WIDTH/4+4, tft.HEIGHT/4+4,
+		  tft.WIDTH/2-8, tft.HEIGHT/2-8);
+    textbox.set_text_port(tft.WIDTH/4+5, tft.HEIGHT/4+5,
+			  tft.WIDTH/2-10, tft.HEIGHT/2-10);
+#endif
+    console.print('\f');
+    console.print(&tft, 200, IOStream::hex,
+		  tft.get_orientation() == Canvas::PORTRAIT ? 3 : 5);
+  }
   sleep(2);

   // Test#4: Grid with draw pixel
   tft.fill_screen();
-  tft.set_pen_color(Canvas::BLACK);
-  start = RTC::micros();
-  for (uint16_t x = 0; x < tft.WIDTH; x += 2) {
-    for (uint16_t y = 0; y < tft.HEIGHT; y += 2) {
-      tft.draw_pixel(x, y);
-    }
-  }
-  tft.set_pen_color(Canvas::RED);
-  tft.fill_rect(20, 20, 20, 20);
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#4:draw pixel grid: %ul ms", ms);
+  MEASURE("test#4:draw pixel grid:", 1) {
+    tft.set_pen_color(Canvas::BLACK);
+    for (uint16_t x = 0; x < tft.WIDTH; x += 2) {
+      for (uint16_t y = 0; y < tft.HEIGHT; y += 2) {
+	tft.draw_pixel(x, y);
+      }
+    }
+    tft.set_pen_color(Canvas::RED);
+    tft.fill_rect(20, 20, 20, 20);
+  }
   sleep(2);

   // Test#5: Grid with draw rectangle
-  tft.set_pen_color(Canvas::BLACK);
-  start = RTC::micros();
-  for (uint16_t x = 0; x < tft.WIDTH; x += 20) {
-    for (uint16_t y = 0; y < tft.HEIGHT; y += 20) {
-      tft.draw_rect(x, y, 20, 20);
-    }
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#5:draw rect grid: %ul ms", ms);
+  MEASURE("test#5:draw rect grid:", 1) {
+    tft.set_pen_color(Canvas::BLACK);
+    for (uint16_t x = 0; x < tft.WIDTH; x += 20) {
+      for (uint16_t y = 0; y < tft.HEIGHT; y += 20) {
+	tft.draw_rect(x, y, 20, 20);
+      }
+    }
+  }
   sleep(2);

   // Test#6: Fill some of the rectangles
-  tft.set_pen_color(Canvas::WHITE);
-  start = RTC::micros();
-  for (uint16_t x = 0; x < tft.WIDTH; x += 20) {
-    for (uint16_t y = x; y < tft.HEIGHT; y += 40) {
-      tft.fill_rect(x + 1, y + 1, 19, 19);
-    }
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#6:fill rect grid: %ul ms", ms);
+  MEASURE("test#6:fill rect grid:", 1) {
+    tft.set_pen_color(Canvas::WHITE);
+    for (uint16_t x = 0; x < tft.WIDTH; x += 20) {
+      for (uint16_t y = x; y < tft.HEIGHT; y += 40) {
+	tft.fill_rect(x + 1, y + 1, 19, 19);
+      }
+    }
+  }
   sleep(2);

   // Test#7: Fill circles
   tft.fill_screen();
-  tft.set_text_color(Canvas::WHITE);
-  tft.set_text_scale(1);
-  start = RTC::micros();
-  uint16_t color = Canvas::BLUE;
-  for (uint16_t x = 0; x < tft.WIDTH; x += 30) {
-    for (uint16_t y = 0; y < tft.HEIGHT; y += 30) {
-      tft.set_pen_color(tft.shade(color, y * 100/tft.HEIGHT));
-      tft.fill_circle(x, y, 12);
-      tft.set_cursor(x - 2, y - 3);
-      tft.draw_char('A' + (x*(tft.HEIGHT+30))/900 + y/30);
-      tft.set_pen_color(Canvas::BLACK);
-      tft.draw_circle(x, y, 12);
-    }
-    color <<= 3;
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#7:draw circle grid: %ul ms", ms);
+  MEASURE("test#7:draw circle grid:", 1) {
+    tft.set_text_color(Canvas::WHITE);
+    tft.set_text_scale(1);
+    uint16_t color = Canvas::BLUE;
+    for (uint16_t x = 0; x < tft.WIDTH; x += 30) {
+      for (uint16_t y = 0; y < tft.HEIGHT; y += 30) {
+	tft.set_pen_color(tft.shade(color, y * 100/tft.HEIGHT));
+	tft.fill_circle(x, y, 12);
+	tft.set_cursor(x - 2, y - 3);
+	tft.draw_char('A' + (x*(tft.HEIGHT+30))/900 + y/30);
+	tft.set_pen_color(Canvas::BLACK);
+	tft.draw_circle(x, y, 12);
+      }
+      color <<= 3;
+    }
+  }
   sleep(2);

   // Test#8: Draw lines
   tft.set_canvas_color(tft.shade(Canvas::WHITE, 20));
   tft.fill_screen();
-  start = RTC::micros();
-  tft.set_pen_color(Canvas::RED);
-  for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
-    tft.draw_line(0, 0, x, tft.HEIGHT - 1);
-  }
-  tft.set_pen_color(Canvas::GREEN);
-  for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
-    tft.draw_line(0, 0, tft.WIDTH - 1, y);
-  }
-  tft.set_pen_color(Canvas::BLUE);
-  for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
-    tft.draw_line(tft.WIDTH - 1, 0, x, tft.HEIGHT - 1);
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#8:draw lines: %ul ms", ms);
+  MEASURE("test#8:draw lines:", 1) {
+    tft.set_pen_color(Canvas::RED);
+    for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
+      tft.draw_line(0, 0, x, tft.HEIGHT - 1);
+    }
+    tft.set_pen_color(Canvas::GREEN);
+    for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
+      tft.draw_line(0, 0, tft.WIDTH - 1, y);
+    }
+    tft.set_pen_color(Canvas::BLUE);
+    for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
+      tft.draw_line(tft.WIDTH - 1, 0, x, tft.HEIGHT - 1);
+    }
+  }
   sleep(2);

   // Test#9: Draw more lines
-  start = RTC::micros();
   tft.set_pen_color(Canvas::BLACK);
   tft.fill_screen();
-  tft.set_pen_color(Canvas::YELLOW);
-  for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
-    tft.draw_line(0, tft.HEIGHT - 1, tft.WIDTH - 1, y);
-  }
-  for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
-    tft.draw_line(tft.WIDTH - 1, tft.HEIGHT - 1, x, 0);
-  }
-  for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
-    tft.draw_line(tft.WIDTH - 1, tft.HEIGHT - 1, 0, y);
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#9:draw more lines: %ul ms", ms);
+  MEASURE("test#9:draw more lines:", 1) {
+    tft.set_pen_color(Canvas::YELLOW);
+    for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
+      tft.draw_line(0, tft.HEIGHT - 1, tft.WIDTH - 1, y);
+    }
+    for (uint16_t x = 0; x < tft.WIDTH; x += 6) {
+      tft.draw_line(tft.WIDTH - 1, tft.HEIGHT - 1, x, 0);
+    }
+    for (uint16_t y = 0; y < tft.HEIGHT; y += 6) {
+      tft.draw_line(tft.WIDTH - 1, tft.HEIGHT - 1, 0, y);
+    }
+  }
   sleep(2);

   // Test#10: Display polygons
-  start = RTC::micros();
   tft.set_canvas_color(Canvas::WHITE);
   tft.fill_screen();
-  static const int8_t polygon[] __PROGMEM = {
-    100, 100,
-    -100, 0,
-    50, -50,
-    0, 50,
-    50, 50,
-    -10, -10,
-    0, 0
-  };
-  for (uint16_t x = 10; x < tft.WIDTH - 40; x += 10) {
-    tft.set_pen_color(tft.shade(Canvas::GREEN, 20 + x));
-    tft.set_cursor(10 + x, 50);
-    tft.draw_poly_P(polygon);
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#10:polygon: %ul ms", ms);
+  MEASURE("test#10:polygon:", 1) {
+    static const int8_t polygon[] __PROGMEM = {
+      100, 100,
+      -100, 0,
+      50, -50,
+      0, 50,
+      50, 50,
+      -10, -10,
+      0, 0
+    };
+    for (uint16_t x = 10; x < tft.WIDTH - 40; x += 10) {
+      tft.set_pen_color(tft.shade(Canvas::GREEN, 20 + x));
+      tft.set_cursor(10 + x, 50);
+      tft.draw_poly_P(polygon);
+    }
+  }
   sleep(2);

   // Test#11: Display stroke
-  start = RTC::micros();
   tft.set_canvas_color(Canvas::WHITE);
   tft.fill_screen();
-  static const int8_t stroke[] __PROGMEM = {
-    20, -100,
-    20, 100,
-    -30, -50,
-    20, 0,
-    0, 0
-  };
-  for (uint16_t x = 10; x < tft.WIDTH - 40; x += 10) {
-    tft.set_pen_color(tft.shade(Canvas::RED, 20 + x));
-    tft.set_cursor(x, 120);
-    tft.draw_stroke_P(stroke);
-  }
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#11:stroke: %ul ms", ms);
+  MEASURE("test#11:stroke:", 1) {
+    static const int8_t stroke[] __PROGMEM = {
+      20, -100,
+      20, 100,
+      -30, -50,
+      20, 0,
+      0, 0
+    };
+    for (uint16_t x = 10; x < tft.WIDTH - 40; x += 10) {
+      tft.set_pen_color(tft.shade(Canvas::RED, 20 + x));
+      tft.set_cursor(x, 120);
+      tft.draw_stroke_P(stroke);
+    }
+  }
   sleep(2);

   // Test#12: Display the Arduino Icons
   tft.set_canvas_color(tft.shade(Canvas::WHITE, 10));
   tft.fill_screen();
   tft.set_pen_color(tft.shade(Canvas::CYAN, 80));
-  tft.draw_icon((tft.WIDTH-34)/2, (tft.HEIGHT-32)/2, arduino_icon_34x32);
-  sleep(2);
-  tft.fill_screen();
-  tft.draw_icon((tft.WIDTH-64)/2, (tft.HEIGHT-64)/2, arduino_icon_64x64);
-  sleep(2);
-  tft.fill_screen();
-  start = RTC::micros();
-  tft.draw_icon((tft.WIDTH-96)/2, (tft.HEIGHT-32)/2, arduino_icon_96x32);
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#12:draw arduino icon: %ul ms", ms);
+  MEASURE("test#12a:draw arduino icon 34x32:", 1) {
+    tft.draw_icon((tft.WIDTH-34)/2, (tft.HEIGHT-32)/2, arduino_icon_34x32);
+  }
+  sleep(2);
+  tft.fill_screen();
+  MEASURE("test#12b:draw arduino icon 64x64:", 1) {
+    tft.draw_icon((tft.WIDTH-64)/2, (tft.HEIGHT-64)/2, arduino_icon_64x64);
+  }
+  sleep(2);
+  tft.fill_screen();
+  MEASURE("test#12c:draw arduino icon 96x32:", 1) {
+    tft.draw_icon((tft.WIDTH-96)/2, (tft.HEIGHT-32)/2, arduino_icon_96x32);
+  }
   sleep(2);

   // Test#13: Grid with draw image
   tft.fill_screen();
-  start = RTC::micros();
-  Grid grid(tft.WIDTH, tft.HEIGHT, Canvas::RED);
-  tft.draw_image(0, 0, &grid);
-  ms = (RTC::micros() - start) / 1000L;
-  INFO("test#13:draw grid image: %ul ms", ms);
+  MEASURE("test#13:draw grid image:", 1) {
+    Grid grid(tft.WIDTH, tft.HEIGHT, Canvas::RED);
+    tft.draw_image(0, 0, &grid);
+  }
   sleep(2);

   // Rotate display


fixed #14

fixed #14

--- Modules/Sensor/ImpactSensor/ArduinoCodes/ImpactSensorATtiny/ImpactSensorATtiny.ino
+++ Modules/Sensor/ImpactSensor/ArduinoCodes/ImpactSensorATtiny/ImpactSensorATtiny.ino
@@ -52,7 +52,7 @@
   {
     //whenever the vibration sensor is hit
     //the output pin would be as high as the input pin for 100ms and then 0 again.
-    analogWrite(output_pin, analogRead(input_pin)/4);
+    analogWrite(output_pin, input_val/4);
     delay(250);
     analogWrite(output_pin, 0);
   }


Added function to test stepper

Added function to test stepper

--- SIPO.ino
+++ SIPO.ino
@@ -9,8 +9,18 @@
 void loop() {
   //BitCounter(5);
   //SendByte(1);
-  Send2Bytes(2,1);
+  //Send2Bytes(2,1);
+  Step(250); // Worked at 10
+  //delayMicroseconds(250);
 }
+
+void Step(int delayTime){
+  SendByte(1);
+  delayMicroseconds(delayTime);
+  SendByte(3);
+  delayMicroseconds(delayTime);
+}
+

 void SendByte(int K)
 {


preparation for splitting the randomizer into a separate local library.

--- Helios.ino
+++ Helios.ino
@@ -64,16 +64,11 @@
   int randColor = rand() % 3 + 1;
   int randPix = rand() % strip.numPixels();
   //Serial.println(randColor);
-  if(randColor == 1) {
-  //  if(!(currentColors[randPix][0] == day2[0] && currentColors[randPix][1] == day2[1] && currentColors[randPix][2] == day2[2])) {
-    //  Serial.print("Changing color on pixel ");
-   //  Serial.println(randPix);
-    //  fadeToColor(currentColors[randPix], day2, randPix);
-      for(int i = 0; i < sizeof(currentColors[randPix]); i++)
-        currentColors[randPix][i] = day1[i];
-    //}
-  }
   delay(2000);
+}
+
+void randomFlare(int rCol, rPix) {
+
 }

 uint8_t splitColor ( uint32_t c, char value )


added button

added button

--- examples/slight_LiquidCristalDummy_test/slight_LiquidCristalDummy_test.ino
+++ examples/slight_LiquidCristalDummy_test/slight_LiquidCristalDummy_test.ino
@@ -16,7 +16,7 @@
 		~ slight_LiquidCristalDummy
 			written by stefan krueger (s-light),
 				github@s-light.eu, http://s-light.eu, https://github.com/s-light/
-			cc by sa, Apache License Version 2.0, MIT
+			MIT
 		~ slight_ButtonInput
 			written by stefan krueger (s-light),
 				github@s-light.eu, http://s-light.eu, https://github.com/s-light/
@@ -28,6 +28,7 @@

 	changelog / history
 		05.10.2015 10:10 created
+		06.10.2015 20:37 should work :-)

 	TO DO:
@@ -69,8 +70,8 @@

 #include <LiquidCrystal.h>

-// #include <slight_LiquidCrystalDummy.h>
-#include "slight_LiquidCrystalDummy.h"
+#include <slight_LiquidCrystalDummy.h>
+// #include "slight_LiquidCrystalDummy.h"

 #include <slight_ButtonInput.h>

@@ -169,59 +170,6 @@

 LiquidCrystalDummy lcd(lcd_raw);

-// based on
-// DualWrite from pYro_65 read more at: http://forum.arduino.cc/index.php?topic=200975.0
-// class LCDTester : public LiquidCrystal {
-// 	public:
-// 		DualWriteLC(
-// 			LiquidCrystal &p_Out1,
-// 			LiquidCrystalDummy &p_Out2
-// 		) :
-// 			OutputA( p_Out1 ),
-// 			OutputB( p_Out2 )
-// 		{}
-//
-// 		void begin(uint8_t cols, uint8_t rows) {
-// 			OutputA.begin(cols, rows);
-// 			OutputB.begin(cols, rows);
-// 		}
-//
-// 		void setCursor(uint8_t col, uint8_t row) {
-// 			OutputA.begin(col, row);
-// 			OutputB.begin(col, row);
-// 		}
-//
-// 		size_t write( uint8_t u_Data ) {
-// 			OutputA.write( u_Data );
-// 			OutputB.write( u_Data );
-// 			return 0x01;
-// 		}
-//
-// 	protected:
-// 		LiquidCrystal &OutputA;
-// 		LiquidCrystalDummy &OutputB;
-// }
-//
-//
-// DualWriteLC multiLCD( lcd, lcdDummy);
-
-
-// DualWrite from pYro_65 read more at: http://forum.arduino.cc/index.php?topic=200975.0
-class DualWriter : public Print{
-	public:
-		DualWriter( Print &p_Out1, Print &p_Out2 ) : OutputA( p_Out1 ), OutputB( p_Out2 ){}
-
-		size_t write( uint8_t u_Data ) {
-			OutputA.write( u_Data );
-			OutputB.write( u_Data );
-			return 0x01;
-		}
-	protected:
-		Print &OutputA;
-		Print &OutputB;
-};
-
-// DualWriter dwOUT( Serial, Serial1);

 /**************************************************/
 /**  slight ButtonInput                          **/
@@ -229,7 +177,7 @@

 slight_ButtonInput myButton(
 	42, // uint8_t cbID_New
-	6, // uint8_t cbPin_New,
+	A2, // uint8_t cbPin_New,
 	myButton_getInput, // tCbfuncGetInput cbfuncGetInput_New,
 	myButton_onEvent, // tcbfOnEvent cbfCallbackOnEvent_New,
 	  30, // const uint16_t cwDuration_Debounce_New = 30,
@@ -686,6 +634,10 @@

 	lcd.setCursor(xPos, yPos);
 	xPos += lcd.print(millis()/1000);
+
+	// lcd.setCursor(16-3, yPos);
+	// xPos += lcd.print(";-)");
+	// xPos += lcd.print("   ");
 }

@@ -722,19 +674,23 @@
 			Serial.println();
 		} break;*/
 		// click
-		/*case slight_ButtonInput::event_Down : {
-			Serial.println(F("the button is pressed down! do something.."));
-		} break;*/
+		case slight_ButtonInput::event_Down : {
+			Serial.println(F("down"));
+			lcd.setCursor(16-3, 1);
+			lcd.print(";-)");
+		} break;
 		/*case slight_ButtonInput::event_HoldingDown : {
 			Serial.print(F("duration active: "));
 			Serial.println((*pInstance).getDurationActive());
 		} break;*/
-		/*case slight_ButtonInput::event_Up : {
+		case slight_ButtonInput::event_Up : {
 			Serial.println(F("up"));
-		} break;*/
-		case slight_ButtonInput::event_Click : {
-			Serial.println(F("click"));
+			lcd.setCursor(16-3, 1);
+			lcd.print("   ");
 		} break;
+		// case slight_ButtonInput::event_Click : {
+		// 	Serial.println(F("click"));
+		// } break;
 		// case slight_ButtonInput::event_ClickLong : {
 		// 	Serial.println(F("click long"));
 		// } break;


replaced the semi-jank palette declaration with a differently jank one.

one of these days i'll remember C++

--- fireplace.ino
+++ fireplace.ino
@@ -16,16 +16,17 @@

 Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

-uint32_t Black = strip.Color(0, 0, 0);
-uint32_t Maroon = strip.Color(128, 0, 0);
-uint32_t Red = strip.Color(255, 0, 0);
-uint32_t DarkRed = strip.Color(139, 0, 0);
-uint32_t Orange = strip.Color(255, 165, 0);
-uint32_t DarkOrange = strip.Color(255, 140, 0);
-uint32_t Gold = strip.Color(255, 215, 0);
-uint32_t Yellow = strip.Color(255, 255, 0);
+uint32_t palette[8] = {
+    strip.Color(0, 0, 0), // Black
+    strip.Color(128, 0, 0), // Maroon
+    strip.Color(255, 0, 0), // Red
+    strip.Color(139, 0, 0), // DarkRed
+    strip.Color(255, 165, 0), // Orange
+    strip.Color(255, 140, 0), // DarkOrange
+    strip.Color(255, 215, 0), // Gold
+    strip.Color(255, 255, 0) // Yellow
+};

-uint32_t palette[8] = { Black, Maroon, Red, DarkRed, Orange, DarkOrange, Gold, Yellow };

 // used to 'turn off' the LEDs
 bool runLoop = true;


Fix typo

Fix typo

--- examples/Blynk.Inject/Template_MKR1010/Template_MKR1010.ino
+++ examples/Blynk.Inject/Template_MKR1010/Template_MKR1010.ino
@@ -13,7 +13,7 @@

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

-#define USE_MKR1000_BOARD
+#define USE_MKR1010_BOARD

 #define APP_DEBUG        // Comment this out to disable debug prints


- use the same NRF connection as in the gcopeland 'scanner' example - explicitly enable auto acknowledgement in the NRF - use the exact size needed for the NRF transmit buffer

--- zg01/zg01.ino
+++ zg01/zg01.ino
@@ -15,7 +15,7 @@
 const int tries = 1;

 static uint8_t buffer[5];
-static RF24 rf(/*ce*/ 8, /*cs*/ 10);
+static RF24 rf(/*ce*/ 8, /*cs*/ 9);

 void setup(void)
 {
@@ -32,6 +32,7 @@

     // init RF24
     rf.begin();
+    rf.setAutoAck(true);
     rf.setRetries(15, 15);
     rf.enableDynamicPayloads();
     rf.openWritingPipe(address);
@@ -46,7 +47,7 @@
     bool data = (digitalRead(PIN_DATA) == HIGH);
     unsigned long ms = millis();
     bool ready = zg01_process(ms, data);
-
+
     // process data if ready
     if (ready) {
         // dump buffer to serial
@@ -66,19 +67,19 @@
         // send CO2 measurement over RF24
         if (buffer[0] == 'P') {
             // construct buffer: [length]"CO_2"[ppm high byte][ppm low byte]
-            uint8_t buf[8];
+            uint8_t buf[7];
             buf[0] = 6;
             memcpy(&buf[1], "CO_2", 4);
             memcpy(&buf[5], &buffer[1], 2);
             // dump send buffer
             Serial.print("Send:");
-            for (int i = 0; i < 6; i++) {
+            for (int i = 0; i < sizeof(buf); i++) {
+                Serial.print(" ");
                 Serial.print(buf[i], HEX);
-                Serial.print(" ");
             }
             Serial.println();
             // send it
-            rf.write(&buf, 7);
+            rf.write(&buf, sizeof(buf));
         }
     }


Updates batlog to use button API

Updates batlog to use button API

--- batlog.ino
+++ batlog.ino
@@ -46,7 +46,7 @@

     Serial.println("Press WAKE to print batlog");

-    while(digitalRead(10) == HIGH) {
+    while(button_pressed(BUTTON_WAKE) == 0) {
       millis_delta_t diff = millis() - startt;
       if (diff> 3000) {
         printlog = 0;


Changed example to toggle the LED instead

--- Button_Debouncing/Button_Debouncing.ino
+++ Button_Debouncing/Button_Debouncing.ino
@@ -2,6 +2,9 @@
 const int LED = 3;

 bool ledOn = false;
+
+bool buttonPressed = false;
+bool buttonReleased = false;

 void setup() {
   pinMode(BTN, INPUT);
@@ -9,7 +12,16 @@
 }

 void loop() {
+
   if (digitalRead(BTN)){
+    buttonPressed = true;
+  }
+
+  //check if button has been released
+  if (!digitalRead(BTN) && buttonPressed){
+    buttonPressed = false;
+
+    //toggle the state of the LED
     ledOn = !ledOn;
     if (ledOn){
       digitalWrite(LED, HIGH);


removed redundant include

removed redundant include


example working in arduino with NTP getting UTC time

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -1,88 +1,149 @@
-// Include library found at
-// https://docs.google.com/file/d/0Bwrp4uluZCpNdE9oWTY0M3BncTA/edit
-#include "SevSeg.h"
+/*
+ Udp NTP Client
+ Get the time from a Network Time Protocol (NTP) time server
+ Demonstrates use of UDP sendPacket and ReceivePacket
+ For more on NTP time servers and the messages needed to communicate with them,
+ see http://en.wikipedia.org/wiki/Network_Time_Protocol
+ created 4 Sep 2010
+ by Michael Margolis
+ modified 9 Apr 2012
+ by Tom Igoe
+ updated for the ESP8266 12 Apr 2015
+ by Ivan Grokhotkov
+ This code is in the public domain.
+ */

-#include <math.h>
-#define ANALOG_IN 0
-#define DRIVER_OUT 2
-#define TEMP_IN 5
-#define ALPHA 0.0001
-#define INTERVAL 5000
+#include <ESP8266WiFi.h>
+#include <WiFiUdp.h>
+
+char ssid[] = "BandelBorgraeveBGN";  //  your network SSID (name)
+char pass[] = "coucoucnous";       // your network password

-//Create an instance of the object.
-SevSeg sevseg;
-double temperature=0.;
-double smoothx = 0;
-unsigned long last_time = millis();
-unsigned long current_time = 0;
-unsigned int count =0;
+unsigned int localPort = 2390;      // local port to listen for UDP packets
+
+/* Don't hardwire the IP address or we won't get the benefits of the pool.
+ *  Lookup the IP address for the host name instead */
+//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
+IPAddress timeServerIP; // time.nist.gov NTP server address
+const char* ntpServerName = "time.nist.gov";
+
+const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
+
+byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
+
+// A UDP instance to let us send and receive packets over UDP
+WiFiUDP udp;
+
+void setup()
+{
+  Serial.begin(115200);
+  Serial.println();
+  Serial.println();
+
+  // We start by connecting to a WiFi network
+  Serial.print("Connecting to ");
+  Serial.println(ssid);
+  WiFi.mode(WIFI_STA);
+  WiFi.begin(ssid, pass);
+
+  while (WiFi.status() != WL_CONNECTED) {
+    delay(500);
+    Serial.print(".");
+  }
+  Serial.println("");
+
+  Serial.println("WiFi connected");
+  Serial.println("IP address: ");
+  Serial.println(WiFi.localIP());
+
+  Serial.println("Starting UDP");
+  udp.begin(localPort);
+  Serial.print("Local port: ");
+  Serial.println(udp.localPort());
+}
+
+void loop()
+{
+  //get a random server from the pool
+  WiFi.hostByName(ntpServerName, timeServerIP);
+
+  sendNTPpacket(timeServerIP); // send an NTP packet to a time server
+  // wait to see if a reply is available
+  delay(1000);
+
+  int cb = udp.parsePacket();
+  if (!cb) {
+    Serial.println("no packet yet");
+  }
+  else {
+    Serial.print("packet received, length=");
+    Serial.println(cb);
+    // We've received a packet, read the data from it
+    udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
+
+    //the timestamp starts at byte 40 of the received packet and is four bytes,
+    // or two words, long. First, esxtract the two words:
+
+    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
+    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
+    // combine the four bytes (two words) into a long integer
+    // this is NTP time (seconds since Jan 1 1900):
+    unsigned long secsSince1900 = highWord << 16 | lowWord;
+    Serial.print("Seconds since Jan 1 1900 = " );
+    Serial.println(secsSince1900);
+
+    // now convert NTP time into everyday time:
+    Serial.print("Unix time = ");
+    // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
+    const unsigned long seventyYears = 2208988800UL;
+    // subtract seventy years:
+    unsigned long epoch = secsSince1900 - seventyYears;
+    // print Unix time:
+    Serial.println(epoch);

-void setup() {
-  //Serial.begin(9600);
-  Serial.begin(115200);
-pinMode(DRIVER_OUT,OUTPUT);
-    // Set up pins
-  // Arguments :
-  // First 0 is for common cathode
-  // Following 0 to 11 numbers are for Arduino pins
-  // connected to display in the following order
-  // 1,2,3,4,A,B,C,D,E,F,G,DP
-  //byte digitPins[] ={2,3,4,5};
-  //byte segmentPins[]={13,11,7,8,10,12,6,9};
-  //sevseg.begin(COMMON_ANODE,4,digitPins,segmentPins);
-  //sevseg.setBrightness(10);
+    // print the hour, minute and second:
+    Serial.print("The UTC time is ");       // UTC is the time at Greenwich Meridian (GMT)
+    Serial.print((epoch  % 86400L) / 3600); // print the hour (86400 equals secs per day)
+    Serial.print(':');
+    if ( ((epoch % 3600) / 60) < 10 ) {
+      // In the first 10 minutes of each hour, we'll want a leading '0'
+      Serial.print('0');
+    }
+    Serial.print((epoch  % 3600) / 60); // print the minute (3600 equals secs per minute)
+    Serial.print(':');
+    if ( (epoch % 60) < 10 ) {
+      // In the first 10 seconds of each minute, we'll want a leading '0'
+      Serial.print('0');
+    }
+    Serial.println(epoch % 60); // print the second
+  }
+  // wait ten seconds before asking for the time again
+  delay(10000);
 }

-void thermistor(int RawADC) {
-  double Temp;
-  Temp = log(10000.0 * ((1024.0 / RawADC - 1)));
-  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp );
-  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
-  //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
-  temperature= Temp;
-  //temperature = temperature*(1-ALPHA)+Temp*10.*ALPHA;
+// send an NTP request to the time server at the given address
+unsigned long sendNTPpacket(IPAddress& address)
+{
+  Serial.println("sending NTP packet...");
+  // set all bytes in the buffer to 0
+  memset(packetBuffer, 0, NTP_PACKET_SIZE);
+  // Initialize values needed to form NTP request
+  // (see URL above for details on the packets)
+  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
+  packetBuffer[1] = 0;     // Stratum, or type of clock
+  packetBuffer[2] = 6;     // Polling Interval
+  packetBuffer[3] = 0xEC;  // Peer Clock Precision
+  // 8 bytes of zero for Root Delay & Root Dispersion
+  packetBuffer[12]  = 49;
+  packetBuffer[13]  = 0x4E;
+  packetBuffer[14]  = 49;
+  packetBuffer[15]  = 52;
+
+  // all NTP fields have been given values, now
+  // you can send a packet requesting a timestamp:
+  udp.beginPacket(address, 123); //NTP requests are to port 123
+  udp.write(packetBuffer, NTP_PACKET_SIZE);
+  udp.endPacket();
 }
-void loop() {
-current_time=millis();
-  /*if(current_time-last_time > INTERVAL){
-    count++;
-    last_time = current_time;
-    if(count%2){
-      digitalWrite(DRIVER_OUT, HIGH);
-    }else{digitalWrite(DRIVER_OUT, LOW);}
-  }*/
-
-  //thermistor(analogRead(ANALOG_IN));
-  //int tint = (int) temperature;
-  //int tint = (int) analogRead(ANALOG_IN);
-  //int tint = analogRead(ANALOG_IN);
-  int tint = analogRead(ANALOG_IN);
-  thermistor(tint);
-    //Serial.write( 0xff );
-  //Serial.write( (tint >> 8) & 0xff );
-  //Serial.write( tint & 0xff );
-  Serial.print("\n");
-  Serial.print(tint);
-  //Serial.print("t:");
-  //Serial.print(temperature);
-
-
-  // Prepare number to display, and dot position
-  // (0 to 3, other number means no dot)
-  //sevseg.setNumber(tint);
-  // Display number
-  //sevseg.refreshDisplay();
-  //delay(500);
-  // To maintain display with this wiring,
-  // we are forced to loop over those commands rapidly
-  //delay(500);
-
-  //sevseg.refreshDisplay(); // Must run repeatedly
-  /*int val = analogRead(ANALOG_IN);
-  Serial.write( 0xff );
-  Serial.write( (val >> 8) & 0xff );
-  Serial.write( val & 0xff );*/
-  //delay(1000);
-}


Update pulse lighting settings

Update pulse lighting settings

--- ino/light.ino
+++ ino/light.ino
@@ -6,7 +6,7 @@
 #define PIXEL_COUNT 7
 #define PIXEL_TYPE SK6812RGBW

-#define BRIGHTNESS 200 // 0 - 255
+#define BRIGHTNESS 255 // 0 - 255

 Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

@@ -99,10 +99,10 @@
 }

 void pulseLight(uint16_t pixel, uint32_t color) {
-  setPixelBrightness(pixel, color, 255);
+  setPixelBrightness(pixel, color, 150);
   strip.show();

-  delay(500);
+  delay(300);

   setPixelBrightness(pixel, color, BRIGHTNESS);
   strip.show();
@@ -110,11 +110,11 @@

 void pulseLights(uint16_t pixels[], int numPixels, uint32_t color) {
   for(int i = 0; i < numPixels; i++) {
-    setPixelBrightness(pixels[i], color, 255);
+    setPixelBrightness(pixels[i], color, 150);
   }
   strip.show();

-  delay(500);
+  delay(300);

   for(int i = 0; i < numPixels; i++) {
     setPixelBrightness(pixels[i], color, BRIGHTNESS);


Added pause motor command

Added pause motor command

Only process buttons at bottom of loop, so motor will always be at same
step.

--- laserharp.ino
+++ laserharp.ino
@@ -26,6 +26,8 @@
 //great stuff - but the code CRAWLS and the laser harp isn't great.
 const boolean debug = false;

+boolean gPauseMotor = false;
+
 // Create the motor shield object with the default I2C address
 Adafruit_MotorShield AFMS = Adafruit_MotorShield();
 // Or, create it with a different I2C address (say for stacking)
@@ -68,7 +70,12 @@
 boolean pluckedNotes[numberNotes];
 int reflectedLightValues[numberNotes];

-#define LOGLEVEL LOG_LEVEL_VERBOSE
+
+#define LOGLEVEL LOG_LEVEL_NOOUTPUT
+//#define LOGLEVEL LOG_LEVEL_ERRORS
+//#define LOGLEVEL LOG_LEVEL_INFOS
+//#define LOGLEVEL LOG_LEVEL_DEBUG
+//#define LOGLEVEL LOG_LEVEL_VERBOSE

 void setup()
 {
@@ -214,7 +221,8 @@
 //gives the sensor time to actually report the new reading.
 int stepTheMotorAndGetLightReading(int directionToStep)
 {
-  myMotor->step(stepSize, directionToStep, DOUBLE);
+  if (gPauseMotor == false)
+    myMotor->step(stepSize, directionToStep, DOUBLE);
   delay(delayBetweenSteps);
   int currentLightReading = analogRead(lightSensorPin);
   return currentLightReading;
@@ -274,15 +282,21 @@
 #else
   while (Serial.available() > 0)
   {
-    char c = Serial.peek();
-    if (c != 'f' && c != 'b')
+    char c = Serial.read();
+    switch (c)
     {
-      break;
-    }
-    else
-    {
-      myMotor->step(stepSize, c == 'b' ? BACKWARD : FORWARD, DOUBLE);
-      Serial.read();
+      case 'f':
+        myMotor->step(stepSize, FORWARD, DOUBLE);
+        break;
+      case 'b':
+        myMotor->step(stepSize, BACKWARD, DOUBLE);
+        break;
+      case 'p':
+        gPauseMotor = !gPauseMotor;
+        break;
+      default:
+        Log.Error("Ignorning unknown command: %c\n", c);
+
     }
   }
 #endif
@@ -308,17 +322,17 @@
     checkNotes(reflectedLightValues, pluckedNotes);
   }

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

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


some midi, split up motor step and note detect functions

--- laserharp.ino
+++ laserharp.ino
@@ -78,7 +78,10 @@
 //int gLogLevel = LOG_LEVEL_VERBOSE;

 int gAverageLightReading = 0;
-const unsigned long gBaud = 250000;
+const unsigned long gBaud = 115200;
+
+#define MIDICMD_NOTEON  0x90 // MIDI command (Note On, Channel 0)
+#define MIDICMD_NOTEOFF 0x80 // MIDI command (Note On, Channel 0)

 // buf must be an array with length > segmentCount. This function can write to buf[segmentCount]
 void drawMeter(int value, int maxValue, char * buf, char segmentSymbol = '=', size_t totalSegments = 80)
@@ -89,11 +92,28 @@
     buf[segmentCount] = 0;
 }

-void logMeter(Logging & Log, int value, int maxValue, char segmentSymbol = '=')
+void logMeter(Logging & Log, int value, int maxValue, int level = LOG_LEVEL_INFOS, char segmentSymbol = '=')
 {
   char buf[81] = {0};
   drawMeter(value, maxValue, buf, segmentSymbol, sizeof(buf) - 1);
-  Log.Info("%s\n", buf);
+  switch (level)
+  {
+    case LOG_LEVEL_ERRORS:
+      Log.Error("%s\n", buf);
+      break;
+    case LOG_LEVEL_INFOS:
+      Log.Info("%s\n", buf);
+      break;
+    case LOG_LEVEL_DEBUG:
+      Log.Debug("%s\n", buf);
+      break;
+    case LOG_LEVEL_VERBOSE:
+      Log.Verbose("%s\n", buf);
+      break;
+    case LOG_LEVEL_NOOUTPUT:
+    default:
+      break;
+  }
 }

 int sampleLight(int sampleCount, int interval=2)
@@ -108,7 +128,7 @@
     average /= i + 1;
     Log.Info("sample %d: %d, average - %d\n", i, sample, average);
   }
-  return (int)average;
+  return max(1, (int)average);
 }

 void setup()
@@ -252,26 +272,45 @@
 #endif
 }

-//Move the motor one step. Sleep, then take a light reading. The sleep
-//gives the sensor time to actually report the new reading.
-int stepTheMotorAndGetLightReading(int directionToStep)
+void SendMIDI(char cmd, char data1, char data2)
+{
+  Serial.print(cmd);
+  Serial.print(data1);
+  Serial.print(data2);
+}
+
+//Move the motor one step.
+void stepTheMotor(int directionToStep)
 {
   if (gPauseMotor == false)
     myMotor->step(stepSize, directionToStep, DOUBLE);
+}
+
+void waitForNote(int note)
+{
+  static bool noteStates[numberNotes] = {0};
+  bool detected = false;
+  bool currentlyOn = noteStates[note];
   unsigned long duration = millis() + delayBetweenSteps;
   while (millis() < duration)
   {
     int light = analogRead(lightSensorPin);
-    logMeter(Log, light, 600, '.');
-
-    if (light > (gAverageLightReading * 1.1))
+    logMeter(Log, light, 600, LOG_LEVEL_INFOS, '.');
+
+    detected = (light > (gAverageLightReading * 2));
+
+    if (currentlyOn != detected)
     {
-      Log.Info("Playing Note!\n");
+      Log.Info("Note %d %s!\n", note, detected ? "on" : "off");
+
+      SendMIDI(
+        currentlyOn ? MIDICMD_NOTEOFF : MIDICMD_NOTEON,
+        0x4a + note,
+        0x49);
     }
-  }
-  int currentLightReading = analogRead(lightSensorPin);
-
-  return currentLightReading;
+
+  }
+  noteStates[note] = detected;
 }

 void checkNotes(int reflectedLightValues[], boolean pluckedNotes[])
@@ -344,6 +383,12 @@
         //Log.Init(9600, gLogLevel);
         static const  char* levelStrings[]  = {"DISABLED","VERBOSE", "DEBUG", "INFO", "ERROR"};
         Serial.print("Log level is "); Serial.println(levelStrings[gLogLevel]);
+      case 'n':
+        SendMIDI(MIDICMD_NOTEON, 0x4a, 0x49);
+        break;
+      case 'm':
+        SendMIDI(MIDICMD_NOTEOFF, 0x4a, 0x49);
+        break;
       default:
         Log.Error("Ignorning unknown command: %c\n", c);

@@ -368,8 +413,8 @@
   //It's already read the zero item. So read array items 1 through 7.
   for (int i = 1; i < numberNotes; i++)
   {
-    reflectedLightValues[i] = stepTheMotorAndGetLightReading(FORWARD);
-    checkNotes(reflectedLightValues, pluckedNotes);
+    stepTheMotor(FORWARD);
+    waitForNote(i);
   }

   checkSonar();
@@ -377,8 +422,8 @@
   //It just read item 7. So going backwards, read items 6 through zero.
   for (int i = numberNotes - 2; i >= 0; i--)
   {
-    reflectedLightValues[i] = stepTheMotorAndGetLightReading(BACKWARD);
-    checkNotes(reflectedLightValues, pluckedNotes);
+    stepTheMotor(BACKWARD);
+    waitForNote(i);
   }

   checkButtons();


changed start time to later and 2 more hrs of air

--- SBR/SBR.ino
+++ SBR/SBR.ino
@@ -84,6 +84,9 @@

 void fill(int lvl, int airadd){//check depth and fill until level is 25gal plus stir
+  if (lvl<19){
+    digitalWrite(stir, HIGH);
+  }
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("FILL ");
@@ -112,7 +115,6 @@
   lcd.print("FILL ");
   lcd.setBacklight(TEAL);
   measurevol();
-  digitalWrite(air,LOW);
   lcd.setCursor(0,1);
   lcd.print(tank);lcd.print("gal");
   DateTime now = rtc.now();
@@ -126,6 +128,7 @@
       measurevol();
       lcd.setCursor(0,1);
       lcd.print(tank);lcd.print("gal");
+      //digitalWrite(air,LOW);
       if ((airadd == 1) && (millis()-lastair > 300000)){
        digitalWrite(air,HIGH);
        lastair = millis();
@@ -219,6 +222,50 @@
     digitalWrite(air, HIGH);
     delay(30000);
     digitalWrite(air, LOW);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+
+    int timedisplay = round((airduration-(millis()-starttime))/60/1000);
+    measurevol();
+    lcd.setCursor(0,1);
+    lcd.print(tank);lcd.print("gal  ");
+    lcd.print(timedisplay);lcd.print("min  ");
+    //delay(20000);
+    }
+    digitalWrite(air, LOW);
+}
+void halftimeair(float airduration, int lvl){//duration in min check depth and keep air on and pumps off for time period
+  airduration=airduration*60*1000;
+  lcd.clear();
+  lcd.setCursor(0,0);
+  lcd.print("halftimeAir ");
+  lcd.setBacklight(GREEN);
+  measurevol();
+  lcd.setCursor(0,1);
+  lcd.print(tank);
+  float starttime = millis();
+  delay(100);
+  while (((millis()-starttime)<airduration)&&(tank>lvl)){  //2 min
+    digitalWrite(air, HIGH);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    delay(30000);
+    digitalWrite(air, LOW);
+    delay(30000);
+    delay(30000);
     delay(30000);
     delay(30000);
     delay(30000);
@@ -338,22 +385,21 @@
   digitalWrite(en1, HIGH);
 }
 }
-void weekend(){//in reality would do some aeration if system was idle for 24hrs
-  rest(5);
+void weekend(){
+  aeration(5, 4);
+  rest(50);
 }
 void normalsequence(){//10 hrs
   DateTime now = rtc.now();
   realstarttime = now.unixtime();
-  fillplusair(21,0);
+  fillplusair(21,1);
   now = rtc.now();
   delay(2000);
-  aeration(.25,19);
-  delay(1000);
-  rest(30);
-  delay(2000);
-  thirtysecaeration(30, 19);
-  delay(2000);
-  aeration(60,19);
+  thirtysecaeration(120, 19);
+  delay(2000);
+  halftimeair(60,19);
+  delay(2000);
+  aeration(120,19);
   delay(2000);
   settle(180, 19);
   delay(2000);
@@ -439,26 +485,26 @@
   lcd.setCursor(0,1);
   lcd.print(tank);
   while (x<1){
-   //aeration(60,19);
-   //delay(1000);
-   //settle(180,18);
+   //thirtysecaeration(120,17);
+   delay(1000);
+   //aeration(60,17);
    //delay(1000);
    //decant(6);//loading();
     x++;}
     //write conditions for running sequence here and add functions
   if (now.dayOfTheWeek()== 1){//"Monday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 2){//"Tuesday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 3){//"Wednesday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 4){//"thursday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 5){//"Friday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}
   if (now.dayOfTheWeek()== 6){//"Saturday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}//fillplusair(21,1);thirtysecaeration(100,10);}}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}//fillplusair(21,1);thirtysecaeration(100,10);}}
   if (now.dayOfTheWeek()== 0){//"Sunday"
-    if (now.hour()>7 && now.hour()<9){normalsequence();}}//weekend();}
+    if (now.hour()>6 && now.hour()<8){normalsequence();}}//weekend();}
   delay(20000);
   weekend();}


Constrain

Constrain

--- battery_indicator/battery_indicator.ino
+++ battery_indicator/battery_indicator.ino
@@ -23,7 +23,7 @@
 void loop()
 {
   batteryUpdate();
-  delay(3000);
+  delay(100);
 }

 void batteryDraw()
@@ -39,16 +39,23 @@
   Robot.line(127, 1, 127, 5);
 }

-void batteryUpdate()
+int batteryUpdate()
 {
+
   Robot.noStroke();
   value_old = value;
-  value = readVcc();
-  int level = map(value, 4400, 5000, 1, 11);
+  value = batteryVcc();
+
+  if (value == value_old) {
+    // No need to redraw the same value to the screen.
+    return value;
+  }
+
+  int level = map(constrain(value, 4400, 5000), 4400, 5000, 1, 11);
   if (level < 3) {
     Robot.fill(255,0,0);
   } else if (level < 7) {
-    Robot.fill(0,0,255);
+    Robot.fill(255,255,0);
   } else {
     Robot.fill(0,255,0);
   }
@@ -67,10 +74,18 @@

   Robot.textSize(2);
   Robot.text("mV", 92, 58);
+
+
+
+  return value;
 }

-long readVcc()
+int batteryVcc()
 {
+  byte original_admux = ADMUX;
+  byte original_adcsra = ADCSRA;
+  byte original_adcsrb = ADCSRB;
+
   // Read 1.1V reference against AVcc
   // set the reference to Vcc and the measurement to the internal 1.1V reference
   #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
@@ -86,12 +101,17 @@
   delay(2); // Wait for Vref to settle
   ADCSRA |= _BV(ADSC); // Start conversion
   while (bit_is_set(ADCSRA,ADSC)); // measuring
-
+
   uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
   uint8_t high = ADCH; // unlocks both
-
+
   long result = (high<<8) | low;
+
+  // return registries to previous settings, just in case.
+  ADMUX = original_admux;
+  ADCSRA = original_adcsra;
+  ADCSRB = original_adcsrb;

   result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
-  return result; // Vcc in millivolts
+  return (int) result; // Vcc in millivolts
 }


Update main.ino

Update main.ino

--- main/main.ino
+++ main/main.ino
@@ -10,6 +10,7 @@
 #include "MIDIUSB.h"
 #include "inputs.h"
 #include "outputs.h"
+#include "interruptsfunctions.h"

 const int MidiChannel = 2; // channel 3 (channel 1 has value 0)

@@ -313,39 +314,3 @@
   }

 }
-
-void sendJogWheel()
-{
- // read both inputs
-  int a = digitalRead(JogWheelPinA);
-  int b = digitalRead(JogWheelPinB);
-
-  if (a == b )
-  {
-    // b is leading a (counter-clockwise)
-    valJogWheel--;
-    currentDirection = COUNTER_CLOCKWISE;
-  }
-  else
-  {
-    // a is leading b (clockwise)
-    valJogWheel++;
-    currentDirection = CLOCKWISE;
-  }
-
-  // track 0 to 400
-  valJogWheel = valJogWheel % CPR;
- if (valJogWheel >= JogWheelToggle) { //Prevent Intempestive Move
-  controlChange(MidiChannel, 63, 127); // Send CC For JogWheel Activity
-  mappedvalJogWheel = map(abs(valJogWheel), 0, JogWheelMaxval, 0, 127); //map Jog Wheel value from 0 to 127
-  JogWheelActive = 1;
-    if (currentDirection = CLOCKWISE) {
-     controlChange(MidiChannel, 61, mappedvalJogWheel); // Send CC For JogWheel Direction
-      }
-    if (currentDirection = COUNTER_CLOCKWISE) {
-     controlChange(MidiChannel, 62, mappedvalJogWheel); // Send CC For JogWheel Direction
-      }
-  MidiUSB.flush(); // Be sure CC is Send
-  valJogWheel = 0;
-  }
-}