Delete FirmataPlusDS.ino

Delete FirmataPlusDS.ino

--- FirmataPlus/source/libraries/FirmataPlusDS/examples/FirmataPlusDS/FirmataPlusDS.ino
+++ FirmataPlus/source/libraries/FirmataPlusDS/examples/FirmataPlusDS/FirmataPlusDS.ino
@@ -1,1221 +0,0 @@
-
-/*
-   Firmata is a generic protocol for communicating with microcontrollers
-   from software on a host computer. It is intended to work with
-   any host computer software package.
-
-   To download a host software package, please clink on the following link
-   to open the download page in your default browser.ser
-
-   http://firmata.org/wiki/Download
-*/
-
-/*
-  Copyright (C) 2006-2008 Hans-Christoph Steiner.  All rights reserved.
-  Copyright (C) 2010-2011 Paul Stoffregen.  All rights reserved.
-  Copyright (C) 2009 Shigeru Kobayashi.  All rights reserved.
-  Copyright (C) 2009-2011 Jeff Hoefs.  All rights reserved.
-  Copyright (C) 2013-2018 Alan Yorinks. All rights reserved.
-
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  See file LICENSE.txt for further informations on licensing terms.
-
-  formatted using the GNU C formatting and indenting
-*/
-
-/* This sketch provides additional functionality to StandardFirmata.
-   It provides support for:
-   Tone
-   Stepper
-   NewPing
-   Read of DS18B20 one wire temp sensor
-
-
-  /*
-  TODO: use Program Control to load stored profiles from EEPROM
-*/
-
-#include <Servo.h>
-#include <Wire.h>
-#include <FirmataPlusDS.h>
-#include <NewPing.h>
-#include <Stepper.h>
-#include <OneWire.h>
-#include <DallasTemperature.h>
-#include <avr/wdt.h>
-
-#define I2C_WRITE                   B00000000
-#define I2C_READ                    B00001000
-#define I2C_READ_CONTINUOUSLY       B00010000
-#define I2C_STOP_READING            B00011000
-#define I2C_READ_WRITE_MODE_MASK    B00011000
-#define I2C_10BIT_ADDRESS_MODE_MASK B00100000
-#define I2C_END_TX_MASK             B01000000
-#define I2C_STOP_TX                 1
-#define I2C_RESTART_TX              0
-#define I2C_MAX_QUERIES             8
-#define I2C_REGISTER_NOT_SPECIFIED  -1
-
-// the minimum interval for sampling analog input
-#define MINIMUM_SAMPLING_INTERVAL 1
-
-#define REGISTER_NOT_SPECIFIED -1
-
-#define INTER_PING_INTERVAL 40 // 40 ms.
-
-// SYSEX command sub specifiers
-#define TONE_TONE 0
-#define TONE_NO_TONE 1
-
-#define STEPPER_CONFIGURE 0
-#define STEPPER_STEP 1
-#define STEPPER_LIBRARY_VERSION 2
-
-
-
-/*==============================================================================
-   GLOBAL VARIABLES
-  ============================================================================*/
-
-#ifdef FIRMATA_SERIAL_FEATURE
-SerialFirmata serialFeature;
-#endif
-
-/* analog inputs */
-int analogInputsToReport = 0; // bitwise array to store pin reporting
-
-/* digital input ports */
-byte reportPINs[TOTAL_PORTS];       // 1 = report this port, 0 = silence
-byte previousPINs[TOTAL_PORTS];     // previous 8 bits sent
-
-/* pins configuration */
-byte pinConfig[TOTAL_PINS];         // configuration of every pin
-byte portConfigInputs[TOTAL_PORTS]; // each bit: 1 = pin in INPUT, 0 = anything else
-int pinState[TOTAL_PINS];           // any value that has been written
-
-/* timer variables */
-unsigned long currentMillis;        // store the current value from millis()
-unsigned long previousMillis;       // for comparison with currentMillis
-unsigned int samplingInterval = 19; // how often to run the main loop (in ms)
-unsigned long previousKeepAliveMillis = 0;
-unsigned int keepAliveInterval = 0;
-
-/* i2c data */
-struct i2c_device_info {
-  byte addr;
-  int reg;
-  byte bytes;
-  byte stopTX;
-};
-
-/* for i2c read continuous more */
-i2c_device_info query[I2C_MAX_QUERIES];
-
-byte i2cRxData[64];
-boolean isI2CEnabled = false;
-signed char queryIndex = -1;
-// default delay time between i2c read request and Wire.requestFrom()
-unsigned int i2cReadDelayTime = 0;
-
-boolean isResetting = false;
-
-
-/* utility functions */
-void wireWrite(byte data)
-{
-#if ARDUINO >= 100
-  Wire.write((byte)data);
-#else
-  Wire.send(data);
-#endif
-}
-
-byte wireRead(void)
-{
-#if ARDUINO >= 100
-  return Wire.read();
-#else
-  return Wire.receive();
-#endif
-}
-
-
-// Servos
-Servo servos[MAX_SERVOS];
-byte servoPinMap[TOTAL_PINS];
-byte detachedServos[MAX_SERVOS];
-byte detachedServoCount = 0;
-byte servoCount = 0;
-
-// Ping variables
-
-int numLoops = 0 ;
-int pingLoopCounter = 0 ;
-
-int numActiveSonars = 0 ; // number of sonars attached
-uint8_t sonarPinNumbers[MAX_SONARS] ;
-int nextSonar = 0 ; // index into sonars[] for next device
-
-// array to hold up to 6 instances of sonar devices
-NewPing *sonars[MAX_SONARS] ;
-
-uint8_t sonarTriggerPin;
-uint8_t sonarEchoPin ;
-uint8_t currentSonar = 0;            // Keeps track of which sensor is active.
-
-uint8_t pingInterval = 33 ;  // Milliseconds between sensor pings (29ms is about the min to avoid
-// cross- sensor echo).
-byte sonarMSB, sonarLSB ;
-
-
-// Stepper Motor
-
-Stepper *stepper = NULL;
-
-
-/*==============================================================================
-   FUNCTIONS
-  ============================================================================*/
-
-void attachServo(byte pin, int minPulse, int maxPulse)
-{
-  if (servoCount < MAX_SERVOS) {
-    // reuse indexes of detached servos until all have been reallocated
-    if (detachedServoCount > 0) {
-      servoPinMap[pin] = detachedServos[detachedServoCount - 1];
-      if (detachedServoCount > 0) detachedServoCount--;
-    } else {
-      servoPinMap[pin] = servoCount;
-      servoCount++;
-    }
-    if (minPulse > 0 && maxPulse > 0) {
-      servos[servoPinMap[pin]].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse);
-    } else {
-      servos[servoPinMap[pin]].attach(PIN_TO_DIGITAL(pin));
-    }
-  } else {
-    Firmata.sendString("Max servos attached");
-  }
-}
-
-void detachServo(byte pin)
-{
-  servos[servoPinMap[pin]].detach();
-  // if we're detaching the last servo, decrement the count
-  // otherwise store the index of the detached servo
-  if (servoPinMap[pin] == servoCount && servoCount > 0) {
-    servoCount--;
-  } else if (servoCount > 0) {
-    // keep track of detached servos because we want to reuse their indexes
-    // before incrementing the count of attached servos
-    detachedServoCount++;
-    detachedServos[detachedServoCount - 1] = servoPinMap[pin];
-  }
-
-  servoPinMap[pin] = 255;
-}
-
-void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX) {
-  // allow I2C requests that don't require a register read
-  // for example, some devices using an interrupt pin to signify new data available
-  // do not always require the register read so upon interrupt you call Wire.requestFrom()
-  if (theRegister != I2C_REGISTER_NOT_SPECIFIED) {
-    Wire.beginTransmission(address);
-    wireWrite((byte)theRegister);
-    Wire.endTransmission(stopTX); // default = true
-    // do not set a value of 0
-    if (i2cReadDelayTime > 0) {
-      // delay is necessary for some devices such as WiiNunchuck
-      delayMicroseconds(i2cReadDelayTime);
-    }
-  } else {
-    theRegister = 0;  // fill the register with a dummy value
-  }
-
-  Wire.requestFrom(address, numBytes);  // all bytes are returned in requestFrom
-
-  // check to be sure correct number of bytes were returned by slave
-  if (numBytes < Wire.available()) {
-    Firmata.sendString("I2C: Too many bytes received");
-  } else if (numBytes > Wire.available()) {
-    Firmata.sendString("I2C: Too few bytes received");
-  }
-
-  i2cRxData[0] = address;
-  i2cRxData[1] = theRegister;
-
-  for (int i = 0; i < numBytes && Wire.available(); i++) {
-    i2cRxData[2 + i] = wireRead();
-  }
-
-  // send slave address, register and received bytes
-  Firmata.sendSysex(SYSEX_I2C_REPLY, numBytes + 2, i2cRxData);
-}
-
-void outputPort(byte portNumber, byte portValue, byte forceSend)
-{
-  // pins not configured as INPUT are cleared to zeros
-  portValue = portValue & portConfigInputs[portNumber];
-  // only send if the value is different than previously sent
-  if (forceSend || previousPINs[portNumber] != portValue) {
-    Firmata.sendDigitalPort(portNumber, portValue);
-    previousPINs[portNumber] = portValue;
-  }
-}
-
-/* -----------------------------------------------------------------------------
-   check all the active digital inputs for change of state, then add any events
-   to the Serial output queue using Serial.print() */
-void checkDigitalInputs(void)
-{
-  /* Using non-looping code allows constants to be given to readPort().
-     The compiler will apply substantial optimizations if the inputs
-     to readPort() are compile-time constants. */
-  if (TOTAL_PORTS > 0 && reportPINs[0]) outputPort(0, readPort(0, portConfigInputs[0]), false);
-  if (TOTAL_PORTS > 1 && reportPINs[1]) outputPort(1, readPort(1, portConfigInputs[1]), false);
-  if (TOTAL_PORTS > 2 && reportPINs[2]) outputPort(2, readPort(2, portConfigInputs[2]), false);
-  if (TOTAL_PORTS > 3 && reportPINs[3]) outputPort(3, readPort(3, portConfigInputs[3]), false);
-  if (TOTAL_PORTS > 4 && reportPINs[4]) outputPort(4, readPort(4, portConfigInputs[4]), false);
-  if (TOTAL_PORTS > 5 && reportPINs[5]) outputPort(5, readPort(5, portConfigInputs[5]), false);
-  if (TOTAL_PORTS > 6 && reportPINs[6]) outputPort(6, readPort(6, portConfigInputs[6]), false);
-  if (TOTAL_PORTS > 7 && reportPINs[7]) outputPort(7, readPort(7, portConfigInputs[7]), false);
-  if (TOTAL_PORTS > 8 && reportPINs[8]) outputPort(8, readPort(8, portConfigInputs[8]), false);
-  if (TOTAL_PORTS > 9 && reportPINs[9]) outputPort(9, readPort(9, portConfigInputs[9]), false);
-  if (TOTAL_PORTS > 10 && reportPINs[10]) outputPort(10, readPort(10, portConfigInputs[10]), false);
-  if (TOTAL_PORTS > 11 && reportPINs[11]) outputPort(11, readPort(11, portConfigInputs[11]), false);
-  if (TOTAL_PORTS > 12 && reportPINs[12]) outputPort(12, readPort(12, portConfigInputs[12]), false);
-  if (TOTAL_PORTS > 13 && reportPINs[13]) outputPort(13, readPort(13, portConfigInputs[13]), false);
-  if (TOTAL_PORTS > 14 && reportPINs[14]) outputPort(14, readPort(14, portConfigInputs[14]), false);
-  if (TOTAL_PORTS > 15 && reportPINs[15]) outputPort(15, readPort(15, portConfigInputs[15]), false);
-}
-
-// -----------------------------------------------------------------------------
-/* sets the pin mode to the correct state and sets the relevant bits in the
-   two bit-arrays that track Digital I/O and PWM status
-*/
-void setPinModeCallback(byte pin, int mode)
-{
-  if (Firmata.getPinMode(pin) == PIN_MODE_IGNORE)
-    return;
-
-  if (Firmata.getPinMode(pin) == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) {
-    // disable i2c so pins can be used for other functions
-    // the following if statements should reconfigure the pins properly
-    disableI2CPins();
-  }
-  if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) {
-    if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) {
-      detachServo(pin);
-    }
-  }
-  if (IS_PIN_ANALOG(pin)) {
-    reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting
-  }
-  if (IS_PIN_DIGITAL(pin)) {
-    if (mode == INPUT || mode == PIN_MODE_PULLUP) {
-      portConfigInputs[pin / 8] |= (1 << (pin & 7));
-    } else {
-      portConfigInputs[pin / 8] &= ~(1 << (pin & 7));
-    }
-  }
-  Firmata.setPinState(pin, 0);
-  switch (mode) {
-    case PIN_MODE_ANALOG:
-      if (IS_PIN_ANALOG(pin)) {
-        if (IS_PIN_DIGITAL(pin)) {
-          pinMode(PIN_TO_DIGITAL(pin), INPUT);    // disable output driver
-#if ARDUINO <= 100
-          // deprecated since Arduino 1.0.1 - TODO: drop support in Firmata 2.6
-          digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
-#endif
-        }
-        Firmata.setPinMode(pin, PIN_MODE_ANALOG);
-      }
-      break;
-    case INPUT:
-      if (IS_PIN_DIGITAL(pin)) {
-        pinMode(PIN_TO_DIGITAL(pin), INPUT);    // disable output driver
-#if ARDUINO <= 100
-        // deprecated since Arduino 1.0.1 - TODO: drop support in Firmata 2.6
-        digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
-#endif
-        Firmata.setPinMode(pin, INPUT);
-      }
-      break;
-    case PIN_MODE_PULLUP:
-      if (IS_PIN_DIGITAL(pin)) {
-        pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP);
-        Firmata.setPinMode(pin, PIN_MODE_PULLUP);
-        Firmata.setPinState(pin, 1);
-      }
-      break;
-    case OUTPUT:
-      if (IS_PIN_DIGITAL(pin)) {
-        digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM
-        pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
-        Firmata.setPinMode(pin, OUTPUT);
-      }
-      break;
-    case PIN_MODE_PWM:
-      if (IS_PIN_PWM(pin)) {
-        pinMode(PIN_TO_PWM(pin), OUTPUT);
-        analogWrite(PIN_TO_PWM(pin), 0);
-        Firmata.setPinMode(pin, PIN_MODE_PWM);
-      }
-      break;
-    case PIN_MODE_SERVO:
-      if (IS_PIN_DIGITAL(pin)) {
-        Firmata.setPinMode(pin, PIN_MODE_SERVO);
-        if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) {
-          // pass -1 for min and max pulse values to use default values set
-          // by Servo library
-          attachServo(pin, -1, -1);
-        }
-      }
-      break;
-    case PIN_MODE_I2C:
-      if (IS_PIN_I2C(pin)) {
-        // mark the pin as i2c
-        // the user must call I2C_CONFIG to enable I2C for a device
-        Firmata.setPinMode(pin, PIN_MODE_I2C);
-      }
-      break;
-    case PIN_MODE_SERIAL:
-#ifdef FIRMATA_SERIAL_FEATURE
-      serialFeature.handlePinMode(pin, PIN_MODE_SERIAL);
-#endif
-      break;
-    case PIN_MODE_TONE:
-      Firmata.setPinMode(pin, PIN_MODE_TONE);
-      //pinConfig[pin] = TONE ;
-      break ;
-    case PIN_MODE_SONAR:
-      Firmata.setPinMode(pin, PIN_MODE_SONAR);
-      //pinConfig[pin] = SONAR ;
-      break ;
-    case PIN_MODE_STEPPER:
-      Firmata.setPinMode(pin, PIN_MODE_STEPPER);
-      //pinConfig[pin] = STEPPER ;
-      break ;
-    case PIN_MODE_ONEWIRE:
-      Firmata.setPinMode(pin, PIN_MODE_ONEWIRE);
-      break;
-    default:
-      Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM
-      break ;
-  }
-  // TODO: save status to EEPROM here, if changed
-}
-
-/*
-   Sets the value of an individual pin. Useful if you want to set a pin value but
-   are not tracking the digital port state.
-   Can only be used on pins configured as OUTPUT.
-   Cannot be used to enable pull-ups on Digital INPUT pins.
-*/
-void setPinValueCallback(byte pin, int value)
-{
-  if (pin < TOTAL_PINS && IS_PIN_DIGITAL(pin)) {
-    if (Firmata.getPinMode(pin) == OUTPUT) {
-      Firmata.setPinState(pin, value);
-      digitalWrite(PIN_TO_DIGITAL(pin), value);
-    }
-  }
-}
-
-void analogWriteCallback(byte pin, int value)
-{
-  if (pin < TOTAL_PINS) {
-    switch (Firmata.getPinMode(pin)) {
-      case PIN_MODE_SERVO:
-        if (IS_PIN_DIGITAL(pin))
-          servos[servoPinMap[pin]].write(value);
-        Firmata.setPinState(pin, value);
-        break;
-      case PIN_MODE_PWM:
-        if (IS_PIN_PWM(pin))
-          analogWrite(PIN_TO_PWM(pin), value);
-        Firmata.setPinState(pin, value);
-        break;
-    }
-  }
-}
-
-void digitalWriteCallback(byte port, int value)
-{
-  byte pin, lastPin, pinValue, mask = 1, pinWriteMask = 0;
-
-  if (port < TOTAL_PORTS) {
-    // create a mask of the pins on this port that are writable.
-    lastPin = port * 8 + 8;
-    if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS;
-    for (pin = port * 8; pin < lastPin; pin++) {
-      // do not disturb non-digital pins (eg, Rx & Tx)
-      if (IS_PIN_DIGITAL(pin)) {
-        // only write to OUTPUT and INPUT (enables pullup)
-        // do not touch pins in PWM, ANALOG, SERVO or other modes
-        if (Firmata.getPinMode(pin) == OUTPUT || Firmata.getPinMode(pin) == INPUT) {
-          pinValue = ((byte)value & mask) ? 1 : 0;
-          if (Firmata.getPinMode(pin) == OUTPUT) {
-            pinWriteMask |= mask;
-          } else if (Firmata.getPinMode(pin) == INPUT && pinValue == 1 && Firmata.getPinState(pin) != 1) {
-            // only handle INPUT here for backwards compatibility
-#if ARDUINO > 100
-            pinMode(pin, INPUT_PULLUP);
-#else
-            // only write to the INPUT pin to enable pullups if Arduino v1.0.0 or earlier
-            pinWriteMask |= mask;
-#endif
-          }
-          Firmata.setPinState(pin, pinValue);
-        }
-      }
-      mask = mask << 1;
-    }
-    writePort(port, (byte)value, pinWriteMask);
-  }
-}
-
-
-// -----------------------------------------------------------------------------
-/* sets bits in a bit array (int) to toggle the reporting of the analogIns
-*/
-//void FirmataClass::setAnalogPinReporting(byte pin, byte state) {
-//}
-void reportAnalogCallback(byte analogPin, int value)
-{
-  if (analogPin < TOTAL_ANALOG_PINS) {
-    if (value == 0) {
-      analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
-    } else {
-      analogInputsToReport = analogInputsToReport | (1 << analogPin);
-      // prevent during system reset or all analog pin values will be reported
-      // which may report noise for unconnected analog pins
-      if (!isResetting) {
-        // Send pin value immediately. This is helpful when connected via
-        // ethernet, wi-fi or bluetooth so pin states can be known upon
-        // reconnecting.
-        Firmata.sendAnalog(analogPin, analogRead(analogPin));
-      }
-    }
-  }
-  // TODO: save status to EEPROM here, if changed
-}
-
-void reportDigitalCallback(byte port, int value)
-{
-  if (port < TOTAL_PORTS) {
-    reportPINs[port] = (byte)value;
-    // Send port value immediately. This is helpful when connected via
-    // ethernet, wi-fi or bluetooth so pin states can be known upon
-    // reconnecting.
-    if (value) outputPort(port, readPort(port, portConfigInputs[port]), true);
-  }
-  // do not disable analog reporting on these 8 pins, to allow some
-  // pins used for digital, others analog.  Instead, allow both types
-  // of reporting to be enabled, but check if the pin is configured
-  // as analog when sampling the analog inputs.  Likewise, while
-  // scanning digital pins, portConfigInputs will mask off values from any
-  // pins configured as analog
-}
-
-/*==============================================================================
-   SYSEX-BASED commands
-  ============================================================================*/
-
-void sysexCallback(byte command, byte argc, byte *argv)
-{
-  byte mode;
-  byte stopTX;
-  byte slaveAddress;
-
-  byte data;
-  int slaveRegister;
-  unsigned int delayTime;
-  byte pin ;// used for tone
-  int frequency ;
-  int duration ;
-
-  switch (command) {
-    case I2C_REQUEST:
-      mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
-      if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
-        Firmata.sendString("10-bit addressing not supported");
-        return;
-      }
-      else {
-        slaveAddress = argv[0];
-      }
-
-      // need to invert the logic here since 0 will be default for client
-      // libraries that have not updated to add support for restart tx
-      if (argv[1] & I2C_END_TX_MASK) {
-        stopTX = I2C_RESTART_TX;
-      }
-      else {
-        stopTX = I2C_STOP_TX; // default
-      }
-
-      switch (mode) {
-        case I2C_WRITE:
-          Wire.beginTransmission(slaveAddress);
-          for (byte i = 2; i < argc; i += 2) {
-            data = argv[i] + (argv[i + 1] << 7);
-            wireWrite(data);
-          }
-          Wire.endTransmission();
-          delayMicroseconds(70);
-          break;
-        case I2C_READ:
-          if (argc == 6) {
-            // a slave register is specified
-            slaveRegister = argv[2] + (argv[3] << 7);
-            data = argv[4] + (argv[5] << 7);  // bytes to read
-            //readAndReportData(slaveAddress, (int)slaveRegister, data);
-          }
-          else {
-            // a slave register is NOT specified
-            slaveRegister = I2C_REGISTER_NOT_SPECIFIED;
-            data = argv[2] + (argv[3] << 7);  // bytes to read
-            //readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
-          }
-          readAndReportData(slaveAddress, (int)slaveRegister, data, stopTX);
-          break;
-        case I2C_READ_CONTINUOUSLY:
-          if ((queryIndex + 1) >= I2C_MAX_QUERIES) {
-            // too many queries, just ignore
-            Firmata.sendString("too many queries");
-            break;
-          }
-          if (argc == 6) {
-            // a slave register is specified
-            slaveRegister = argv[2] + (argv[3] << 7);
-            data = argv[4] + (argv[5] << 7);  // bytes to read
-          }
-          else {
-            // a slave register is NOT specified
-            slaveRegister = (int)I2C_REGISTER_NOT_SPECIFIED;
-            data = argv[2] + (argv[3] << 7);  // bytes to read
-          }
-          queryIndex++;
-          query[queryIndex].addr = slaveAddress;
-          query[queryIndex].reg = slaveRegister;
-          query[queryIndex].bytes = data;
-          query[queryIndex].stopTX = stopTX;
-          break;
-        case I2C_STOP_READING:
-          byte queryIndexToSkip;
-          // if read continuous mode is enabled for only 1 i2c device, disable
-          // read continuous reporting for that device
-          if (queryIndex <= 0) {
-            queryIndex = -1;
-          } else {
-            queryIndexToSkip = 0;
-            // if read continuous mode is enabled for multiple devices,
-            // determine which device to stop reading and remove it's data from
-            // the array, shifiting other array data to fill the space
-            for (byte i = 0; i < queryIndex + 1; i++) {
-              if (query[i].addr == slaveAddress) {
-                queryIndexToSkip = i;
-                break;
-              }
-            }
-
-            for (byte i = queryIndexToSkip; i < queryIndex + 1; i++) {
-              if (i < I2C_MAX_QUERIES) {
-                query[i].addr = query[i + 1].addr;
-                query[i].reg = query[i + 1].reg;
-                query[i].bytes = query[i + 1].bytes;
-                query[i].stopTX = query[i + 1].stopTX;
-              }
-            }
-            queryIndex--;
-          }
-          break;
-        default:
-          break;
-      }
-      break;
-    case I2C_CONFIG:
-      delayTime = (argv[0] + (argv[1] << 7));
-
-      if (delayTime > 0) {
-        i2cReadDelayTime = delayTime;
-      }
-
-      if (!isI2CEnabled) {
-        enableI2CPins();
-      }
-
-      break;
-    case SERVO_CONFIG:
-      if (argc > 4) {
-        // these vars are here for clarity, they'll optimized away by the compiler
-        byte pin = argv[0];
-        int minPulse = argv[1] + (argv[2] << 7);
-        int maxPulse = argv[3] + (argv[4] << 7);
-
-        if (IS_PIN_DIGITAL(pin)) {
-          if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) {
-            detachServo(pin);
-          }
-          attachServo(pin, minPulse, maxPulse);
-          setPinModeCallback(pin, PIN_MODE_SERVO);
-        }
-      }
-      break;
-    case KEEP_ALIVE:
-      keepAliveInterval = argv[0] + (argv[1] << 7);
-      previousKeepAliveMillis = millis();
-      break;
-    case SAMPLING_INTERVAL:
-      if (argc > 1) {
-        samplingInterval = argv[0] + (argv[1] << 7);
-        if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
-          samplingInterval = MINIMUM_SAMPLING_INTERVAL;
-        }
-        /* calculate number of loops per ping */
-        numLoops = INTER_PING_INTERVAL / samplingInterval ;
-        //numLoops = 1 ;
-      }
-      else {
-        //Firmata.sendString("Not enough data");
-      }
-      break;
-    case EXTENDED_ANALOG:
-      if (argc > 1) {
-        int val = argv[1];
-        if (argc > 2) val |= (argv[2] << 7);
-        if (argc > 3) val |= (argv[3] << 14);
-        analogWriteCallback(argv[0], val);
-      }
-      break;
-    case CAPABILITY_QUERY:
-      Firmata.write(START_SYSEX);
-      Firmata.write(CAPABILITY_RESPONSE);
-      for (byte pin = 0; pin < TOTAL_PINS; pin++) {
-        if (IS_PIN_DIGITAL(pin)) {
-          Firmata.write((byte)INPUT);
-          Firmata.write(1);
-          Firmata.write((byte)PIN_MODE_PULLUP);
-          Firmata.write(1);
-          Firmata.write((byte)OUTPUT);
-          Firmata.write(1);
-        }
-        if (IS_PIN_ANALOG(pin)) {
-          Firmata.write(PIN_MODE_ANALOG);
-          Firmata.write(10); // 10 = 10-bit resolution
-        }
-        if (IS_PIN_PWM(pin)) {
-          Firmata.write(PIN_MODE_PWM);
-          Firmata.write(DEFAULT_PWM_RESOLUTION);
-        }
-        if (IS_PIN_DIGITAL(pin)) {
-          Firmata.write(PIN_MODE_SERVO);
-          Firmata.write(14);
-        }
-        if (IS_PIN_I2C(pin)) {
-          Firmata.write(PIN_MODE_I2C);
-          Firmata.write(1);  // TODO: could assign a number to map to SCL or SDA
-        }
-#ifdef FIRMATA_SERIAL_FEATURE
-        serialFeature.handleCapability(pin);
-#endif
-        Firmata.write(127);
-      }
-      Firmata.write(END_SYSEX);
-      break;
-    case PIN_STATE_QUERY:
-      if (argc > 0) {
-        byte pin = argv[0];
-        Firmata.write(START_SYSEX);
-        Firmata.write(PIN_STATE_RESPONSE);
-        Firmata.write(pin);
-        if (pin < TOTAL_PINS) {
-          Firmata.write(Firmata.getPinMode(pin));
-          Firmata.write((byte)Firmata.getPinState(pin) & 0x7F);
-          if (Firmata.getPinState(pin) & 0xFF80) Firmata.write((byte)(Firmata.getPinState(pin) >> 7) & 0x7F);
-          if (Firmata.getPinState(pin) & 0xC000) Firmata.write((byte)(Firmata.getPinState(pin) >> 14) & 0x7F);
-        }
-        Firmata.write(END_SYSEX);
-      }
-      break;
-    case ANALOG_MAPPING_QUERY:
-      Firmata.write(START_SYSEX);
-      Firmata.write(ANALOG_MAPPING_RESPONSE);
-      for (byte pin = 0; pin < TOTAL_PINS; pin++) {
-        Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127);
-      }
-      Firmata.write(END_SYSEX);
-      break;
-
-    case SERIAL_MESSAGE:
-#ifdef FIRMATA_SERIAL_FEATURE
-      serialFeature.handleSysex(command, argc, argv);
-#endif
-      break;
-
-    case TONE_DATA:
-      byte toneCommand, pin;
-      int frequency, duration;
-
-      toneCommand = argv[0];
-      pin = argv[1];
-
-      if (toneCommand == TONE_TONE) {
-        frequency = argv[2] + (argv[3] << 7);
-        // duration is currently limited to 16,383 ms
-        duration = argv[4] + (argv[5] << 7);
-        tone(pin, frequency, duration);
-      }
-      else if (toneCommand == TONE_NO_TONE) {
-        noTone(pin);
-      }
-      break ;
-
-    // arg0 = trigger pin
-    // arg1 = echo pin
-    // arg2 = ping interval in milliseconds if 0, then set to 33
-    // arg3 = maxdistance lsb
-    // arg4 = maxdistance msb
-    case SONAR_CONFIG :
-      int max_distance ;
-      if ( numActiveSonars < MAX_SONARS)
-      {
-        sonarTriggerPin = argv[0] ;
-        sonarEchoPin = argv[1] ;
-        // set interval to a minium of 33 ms.
-        if ( argv[2] >= 33 ) {
-          pingInterval = argv[2] ;
-        }
-        else {
-          pingInterval = 33 ;
-        }
-        max_distance = argv[3] + (argv[4] << 7 ) ;
-        sonarPinNumbers[numActiveSonars] = sonarTriggerPin ;
-
-        setPinModeCallback(sonarTriggerPin, PIN_MODE_SONAR);
-        setPinModeCallback(sonarEchoPin, PIN_MODE_SONAR);
-        sonars[numActiveSonars] = new NewPing(sonarTriggerPin, sonarEchoPin, max_distance) ;
-        numActiveSonars++ ;
-      }
-      else {
-        Firmata.sendString("PING_CONFIG Error: Exceeded number of supported ping devices");
-      }
-      break ;
-
-    case STEPPER_DATA:
-      // determine if this a STEPPER_CONFIGURE command or STEPPER_OPERATE command
-      if (argv[0] == STEPPER_CONFIGURE)
-      {
-        int numSteps = argv[1] + (argv[2] << 7);
-        int pin1 = argv[3] ;
-        int pin2 = argv[4] ;
-        if ( argc == 5 )
-        {
-          // two pin motor
-          stepper = new Stepper(numSteps, pin1, pin2) ;
-        }
-        else if (argc == 7 ) // 4 wire motor
-        {
-          int pin3 = argv[5] ;
-          int pin4 = argv[6] ;
-          stepper =  new Stepper(numSteps, pin1, pin2, pin3, pin4) ;
-        }
-        else
-        {
-          Firmata.sendString("STEPPER CONFIG Error: Wrong Number of arguments");
-          printData((char*)"argc = ", argc) ;
-        }
-      }
-      else if ( argv[0] == STEPPER_STEP )
-      {
-        long speed = (long)argv[1] | ((long)argv[2] << 7) | ((long)argv[3] << 14);
-        int numSteps = argv[4] + (argv[5] << 7);
-        int direction = argv[6] ;
-        if (stepper != NULL )
-        {
-          stepper->setSpeed(speed) ;
-          if (direction == 0 )
-          {
-            numSteps *= -1 ;
-          }
-          stepper->step(numSteps) ;
-        }
-        else
-        {
-          Firmata.sendString("STEPPER OPERATE Error: MOTOR NOT CONFIGURED");
-        }
-      }
-      else if ( argv[0] == STEPPER_LIBRARY_VERSION )
-      {
-        if ( stepper != NULL )
-        {
-          int version = stepper->version() ;
-          Firmata.write(START_SYSEX);
-          Firmata.write(STEPPER_DATA);
-          Firmata.write(version & 0x7F);
-          Firmata.write(version >> 7);
-          Firmata.write(END_SYSEX);
-        }
-        else
-        {
-          // did not find a configured stepper
-          Firmata.sendString("STEPPER FIRMWARE VERSION Error: NO MOTORS CONFIGURED");
-        }
-        break ;
-      }
-      else
-      {
-        Firmata.sendString("STEPPER CONFIG Error: UNKNOWN STEPPER COMMAND");
-      }
-      break ;
-    case ONEWIRE_DATA:
-      for (uint8_t pin = 2; pin < TOTAL_PINS; pin++)
-      {
-        OneWire oneWire(pin);
-        DallasTemperature sensors(&oneWire);
-        sensors.begin();
-        uint8_t numSensors = sensors.getDS18Count();
-        Serial.print("Pin: ");
-        Serial.print(pin);
-        Serial.print("  Number of devices: ");
-        Serial.println(numSensors);
-        if (numSensors > 0)
-        {
-           devices[pin].oneWire = &oneWire;
-           devices[pin].sensor = &sensors;
-           devices[pin].numberOfDevices = numSensors;
-           sensors.setWaitForConversion(false);  // makes it async
-           sensors.requestTemperatures();
-      }
-
-  }
-
-
-
-      // agrv[0] = subcommand
-      switch (argv[0])
-      {
-        case DS_DISCOVER_DEVICES:
-        {
-          byte pin = argv[1];
-
-          {
-            OneWire oneWire(pin);
-            DallasTemperature sensors(&oneWire);
-    sensors.begin();
-    uint8_t numSensors = sensors.getDS18Count();
-    Serial.print("Pin: ");
-    Serial.print(pin);
-    Serial.print("  Number of devices: ");
-    Serial.println(numSensors);
-    if (numSensors > 0)
-    {
-      devices[pin].oneWire = &oneWire;
-      devices[pin].sensor = &sensors;
-      devices[pin].numberOfDevices = numSensors;
-      sensors.setWaitForConversion(false);  // makes it async
-      sensors.requestTemperatures();
-    }
-
-  }
-
-          for (uint8_t pin = 2; pin < num_pins; pin++)
-          {
-              if(findDevices(pin))
-              {
-                  setPinModeCallback(pin, PIN_MODE_ONEWIRE);
-              }
-          }
-          break;
-        }
-        case DS_REQUEST_TEMPERATURE:
-        {
-          byte pin = argv[1];
-          uint8_t index = argv[2] + (argv[3] << 7);
-
-          double temperature, fractional, integer;
-          uint8_t i_frac, i_int;
-
-          OneWire oneWire(pin);
-          DallasTemperature sensors(&oneWire);
-          sensors.begin();
-          sensors.requestTemperatures();
-          temperature = sensors.getTempCByIndex(index);
-
-          fractional = modf(temperature, &integer);
-          i_int = (int) integer;
-          i_frac = (int)(fractional * 100);
-
-          Firmata.write(START_SYSEX);
-          Firmata.write(ONEWIRE_DATA);
-          Firmata.write(DS_TEMPERATURE_REPLY);
-          Firmata.write(pin);
-          Firmata.write(index);
-          Firmata.write(i_int);
-          Firmata.write(i_frac);
-          if( temperature < 0.0)
-          {
-              Firmata.write((byte)1);
-          }
-          else
-          {
-              Firmata.write((byte)0);
-          }
-          Firmata.write(END_SYSEX);
-          break;
-        }
-      }
-      break;
-  }
-}
-
-void enableI2CPins()
-{
-  byte i;
-  // is there a faster way to do this? would probaby require importing
-  // Arduino.h to get SCL and SDA pins
-  for (i = 0; i < TOTAL_PINS; i++) {
-    if (IS_PIN_I2C(i)) {
-      // mark pins as i2c so they are ignore in non i2c data requests
-      setPinModeCallback(i, PIN_MODE_I2C);
-    }
-  }
-
-  isI2CEnabled = true;
-
-  // is there enough time before the first I2C request to call this here?
-  Wire.begin();
-}
-
-/* disable the i2c pins so they can be used for other functions */
-void disableI2CPins() {
-  isI2CEnabled = false;
-  // disable read continuous mode for all devices
-  queryIndex = -1;
-  // uncomment the following if or when the end() method is added to Wire library
-  // Wire.end();
-}
-
-/*==============================================================================
-   SETUP()
-  ============================================================================*/
-
-void systemResetCallback()
-{
-  isResetting = true;
-
-  // initialize a defalt state
-  // TODO: option to load config from EEPROM instead of default
-#ifdef FIRMATA_SERIAL_FEATURE
-  serialFeature.reset();
-#endif
-
-  if (isI2CEnabled) {
-    disableI2CPins();
-  }
-  for (byte i = 0; i < TOTAL_PORTS; i++) {
-    reportPINs[i] = false;    // by default, reporting off
-    portConfigInputs[i] = 0;  // until activated
-    previousPINs[i] = 0;
-  }
-  // pins with analog capability default to analog input
-  // otherwise, pins default to digital output
-  for (byte i = 0; i < TOTAL_PINS; i++) {
-    if (IS_PIN_ANALOG(i)) {
-      // turns off pullup, configures everything
-      setPinModeCallback(i, PIN_MODE_ANALOG);
-    }
-    else if ( IS_PIN_TONE(i)) {
-      noTone(i) ;
-    }
-    else {
-      // sets the output to 0, configures portConfigInputs
-      setPinModeCallback(i, OUTPUT);
-    }
-    servoPinMap[i] = 255;
-  }
-  // stop pinging
-  numActiveSonars = 0 ;
-  for (int i = 0; i < MAX_SONARS; i++) {
-    sonarPinNumbers[i] = PIN_MODE_IGNORE ;
-    if ( sonars[i] ) {
-      sonars[i] = NULL ;
-    }
-  }
-  numActiveSonars = 0 ;
-
-  // by default, do not report any analog inputs
-  analogInputsToReport = 0;
-
-  detachedServoCount = 0;
-  servoCount = 0;
-
-  // clear stepper pointer
-  stepper = NULL ;
-
-  /* send digital inputs to set the initial state on the host computer,
-     since once in the loop(), this firmware will only send on change */
-  /*
-    TODO: this can never execute, since no pins default to digital input
-        but it will be needed when/if we support EEPROM stored config
-    for (byte i=0; i < TOTAL_PORTS; i++) {
-    outputPort(i, readPort(i, portConfigInputs[i]), true);
-    }
-  */
-  isResetting = false;
-}
-
-void setup()
-{
-  Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
-
-  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
-  Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
-  Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
-  Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
-  Firmata.attach(SET_PIN_MODE, setPinModeCallback);
-  Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback);
-  Firmata.attach(START_SYSEX, sysexCallback);
-  Firmata.attach(SYSTEM_RESET, systemResetCallback);
-
-  // to use a port other than Serial, such as Serial1 on an Arduino Leonardo or Mega,
-  // Call begin(baud) on the alternate serial port and pass it to Firmata to begin like this:
-  // Serial1.begin(57600);
-  // Firmata.begin(Serial1);
-  // However do not do this if you are using SERIAL_MESSAGE
-
-  Firmata.begin(57600);
-  while (!Serial) {
-    ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101
-  }
-
-  systemResetCallback();  // reset to default config
-}
-
-// find ds devices
-uint8_t findDevices(int pin)
-{
-  OneWire ow(pin);
-
-  uint8_t address[8];
-  uint8_t count = 0;
-
-
-  if (ow.search(address))
-  {
-
-    // send a sysex message with pin number and address
-    Firmata.write(START_SYSEX);
-    Firmata.write(ONEWIRE_DATA) ;
-    Firmata.write(DS_DISCOVERY_REPLY) ;
-    Firmata.write(pin);
-    for (uint8_t i = 0; i < 8; i++)
-    {
-      Firmata.write(address[i] & 0x7F);
-      Firmata.write(address[i] >> 7);
-    }
-    Firmata.write(END_SYSEX);
-    return 1;
-  }
-  else
-  {
-    return 0;
-  }
-}
-
-/*==============================================================================
-   LOOP()
-  ============================================================================*/
-void loop()
-{
-  byte pin, analogPin;
-  int pingResult = 0;
-
-  /* DIGITALREAD - as fast as possible, check for changes and output them to the
-     FTDI buffer using Serial.print()  */
-  checkDigitalInputs();
-
-  /* STREAMREAD - processing incoming messagse as soon as possible, while still
-     checking digital inputs.  */
-  while (Firmata.available())
-    Firmata.processInput();
-
-  // TODO - ensure that Stream buffer doesn't go over 60 bytes
-
-  currentMillis = millis();
-  if (currentMillis - previousMillis > samplingInterval) {
-    previousMillis += samplingInterval;
-
-    if ( pingLoopCounter++ > numLoops)
-    {
-      pingLoopCounter = 0 ;
-      if (numActiveSonars)
-      {
-        unsigned int uS = sonars[nextSonar]->ping();
-        // Convert ping time to distance in cm and print
-        pingResult = uS / US_ROUNDTRIP_CM ;
-        currentSonar = nextSonar ;
-        if ( nextSonar++ >= numActiveSonars - 1)
-        {
-          nextSonar = 0 ;
-        }
-        sonarLSB = pingResult & 0x7f ;
-        sonarMSB = pingResult >> 7 & 0x7f ;
-
-        Firmata.write(START_SYSEX);
-        Firmata.write(SONAR_DATA) ;
-        Firmata.write(sonarPinNumbers[currentSonar]) ;
-        Firmata.write(sonarLSB) ;
-        Firmata.write(sonarMSB) ;
-        Firmata.write(END_SYSEX);
-      }
-    }
-
-
-    /* ANALOGREAD - do all analogReads() at the configured sampling interval */
-    for (pin = 0; pin < TOTAL_PINS; pin++) {
-      if (IS_PIN_ANALOG(pin) && Firmata.getPinMode(pin) == PIN_MODE_ANALOG) {
-        analogPin = PIN_TO_ANALOG(pin);
-        if (analogInputsToReport & (1 << analogPin)) {
-          Firmata.sendAnalog(analogPin, analogRead(analogPin));
-        }
-      }
-    }
-    // report i2c data for all device with read continuous mode enabled
-    if (queryIndex > -1) {
-      for (byte i = 0; i < queryIndex + 1; i++) {
-        readAndReportData(query[i].addr, query[i].reg, query[i].bytes, query[i].stopTX);
-      }
-    }
-
-    if ( keepAliveInterval ) {
-      currentMillis = millis();
-      if (currentMillis - previousKeepAliveMillis > keepAliveInterval * 1000) {
-        systemResetCallback();
-        wdt_enable(WDTO_15MS);
-        // systemResetCallback();
-        while (1)
-          ;
-      }
-    }
-  }
-}
-
-
-
-void printData(char * id,  int16_t data)
-{
-  char myArray[64] ;
-
-  String myString = String(data);
-  myString.toCharArray(myArray, 64) ;
-  Firmata.sendString(id) ;
-  Firmata.sendString(myArray);
-}


Added the 'a' option to change the lipsum text into A-Za-z

--- Arduino/LlamaLlipsum/LlamaLlipsum.ino
+++ Arduino/LlamaLlipsum/LlamaLlipsum.ino
@@ -7,6 +7,7 @@
  *
  *  yorgle@gmail.com
  *
+ *  v1.2 2016-03-08  AZ added to help decode word wrap ('a')
  *  v1.1 2016-02-29  Echo added
  *  v1.0 2016-02-24  Initial version
  */
@@ -279,6 +280,84 @@
   } while( nrows < rows );
 }

+int incrementingCH = 'a';
+
+void AZWrite( const char cp )
+{
+  if( cp >= 'a' && cp <= 'z' ) {
+    Serial.write( incrementingCH );
+    incrementingCH++;
+
+  } else if( cp >= 'A' && cp <= 'Z' ) {
+    Serial.write( incrementingCH - 0x20 );
+    incrementingCH++;
+
+  } else {
+    Serial.write( cp );
+  }
+
+
+  if( incrementingCH > 'z' ) {
+    incrementingCH = 'a';
+  }
+}
+
+void AZPrint( const char * cpw )
+{
+  while( *cpw ) {
+    AZWrite( *cpw );
+    cpw++;
+  }
+}
+
+void printAZText( )
+{
+  const char * cp;
+  int idx = 0;
+  int ncols = 0;
+  int nrows = 0;
+
+  int w = 0;
+
+  // only continue for the number of rows we want
+  do {
+    // see if it will fit on the line
+    w = strlen( lipsum[idx] );
+    if( ((ncols + w ) >= cols) || (w==0) ) {
+      Serial.println( "" );
+      ncols = 0;
+      nrows++;
+    }
+
+    // see if we're past rows
+    if( nrows < rows ) {
+      // put it on this row
+      if( ncols != 0 ) {
+        Serial.print( " " );
+        ncols++;
+      }
+
+      if( wait > 0 ) {
+        cp = lipsum[idx];
+        while( *cp != '\0' ) {
+          AZWrite( *cp );
+          cp++;
+          delay( wait );
+        }
+      } else {
+        AZPrint( lipsum[idx] );
+      }
+      ncols += w;
+    }
+
+    idx++;
+    if( lipsum[idx] == NULL ) {
+      idx = 0;
+    }
+
+  } while( nrows < rows );
+}
+

 /////////////////////////////////////////
 // serial port line reading
@@ -324,6 +403,7 @@

   if( !strcmp( line, "h" )) {
     Serial.println( F("       t - text") );
+    Serial.println( F("       a - a-z text") );
     Serial.println( F("       ? - settings") );
     Serial.println( F("  c<n> - cols") );
     Serial.println( F("  r<n> - rows") );
@@ -352,8 +432,8 @@
     else echoSet( 0 );
   }

-
   else if( !strcmp( line, "t" )) printText();
+  else if( !strcmp( line, "a" )) printAZText();

   else err = true;


Fix in the search function

Fix in the search function

--- examples/LCDKeyPadShieldAndRadioTEA5767Demo/LCDKeyPadShieldAndRadioTEA5767Demo.ino
+++ examples/LCDKeyPadShieldAndRadioTEA5767Demo/LCDKeyPadShieldAndRadioTEA5767Demo.ino
@@ -315,7 +315,7 @@
           }
           case 5: {
             byte isBandLimitReached;
-            if (selectedMenuItem == 0) {
+            if (selectedMenuItem == 1) {
               radio.setSearchUp();
               isBandLimitReached = radio.searchNextMuting();
               if (isBandLimitReached) {
@@ -373,7 +373,7 @@
           }
           case 5: {
             byte isBandLimitReached;
-            if (selectedMenuItem == 0) {
+            if (selectedMenuItem == 1) {
               radio.setSearchDown();
               isBandLimitReached = radio.searchNextMuting();
               if (isBandLimitReached) {
@@ -771,8 +771,16 @@
             break;
           }
           case 5: {
+            state = 0;

-            break;
+            lcd.setCursor(0,0);
+            lcd.print("      MHz        ");
+            lcd.setCursor(0,1);
+            lcd.print("                 ");
+
+            // Starts station
+            printSelectedFrequency(radio.readFrequencyInMHz());
+            break;
           }
           // Exit
           case 6:


fixing command parsing and handling

fixing command parsing and handling

--- RocketMegaChibiAVR/RocketMegaChibiAVR.ino
+++ RocketMegaChibiAVR/RocketMegaChibiAVR.ino
@@ -20,6 +20,8 @@
 #define GPS_BAUD 9600
 #define GPS_SERIAL Serial2
 #define GPS_BUFFER_SIZE 256
+#define COMMAND_SERIAL Serial // Serial1
+#define COMMAND_BUFFER_SIZE 32

 #define SD_CHIP_SELECT 48
 //#define SPI_MISO_PIN 50
@@ -43,6 +45,7 @@
 #define GYRO_ALPHA 0.50F
 #define GYRO_SAMPLE_RATE 0.1F
 #define GPS_SAMPLE_RATE 0.2F
+#define COMMAND_SAMPLE_RATE 0.2F
 #define ANALOG_SAMPLE_RATE 2.0F
 #define DECISION_SAMPLE_RATE 0.1F
 #define TELEM_RATE_SLOW 5.0F
@@ -50,6 +53,8 @@
 #define TELEM_RATE_FAST 0.5F

 #define RATE_TO_MS(A)   (int)(1000.0 * A)
+
+#define NUM_EVENTS 4 // number of pyro event pins

 #define PYRO_1_PIN 42
 #define PYRO_2_PIN 43
@@ -141,7 +146,6 @@
 #define MODE_TOUCHDOWN 6
 #define MODE_PAUSE 7

-
 // includes
 #include <Arduino.h>
 #include <SPI.h>
@@ -163,6 +167,7 @@
 HardwareSerial *DebugSerial = &DEBUG_SERIAL;
 HardwareSerial *TelemSerial = &TELEM_SERIAL;
 HardwareSerial *GpsSerial = &GPS_SERIAL;
+HardwareSerial *CommandSerial = &COMMAND_SERIAL;
 File logFile;
 boolean logSd = false;
 Adafruit_GPS GPS(GpsSerial); // gets read by printing thread
@@ -199,8 +204,10 @@
 float latitude = 0.0F;
 float longitude = 0.0F;

-int gpsBufferLoc = 0;
-char gpsBuffer[GPS_BUFFER_SIZE];
+static uint8_t gpsBufferLoc = 0;
+static char gpsBuffer[GPS_BUFFER_SIZE];
+static uint8_t cmdBufferLoc = 0;
+static char cmdBuffer[COMMAND_BUFFER_SIZE];

 static String printBuffer;

@@ -226,9 +233,8 @@
 float maxPressure = 0.0F;
 bool statsOut = false;

-// used for tracking times that relays are activated
-unsigned long drogueDeployStart = 0;
-unsigned long mainDeployStart = 0;
+// used for tracking times that pyros are activated
+unsigned long eventStart[4] = {0,0,0,0};

 volatile uint8_t mode = MODE_STARTUP;

@@ -241,8 +247,10 @@
 void modeDescent();
 void modeDescent2();
 void modeTouchdown();
-void deployMain();
-void deployDrogue();
+void startEvent(int eventNum);
+void stopEvent(int eventNum);
+void handleCommand(const char *cmd);
+bool startsWith(const char *pre, const char *str);

 /**
 * Linear version of a complimentary filter.
@@ -269,6 +277,8 @@
 */
 void beepWarning(int pulses)
 {
+    DebugSerial->print("WARN: ");
+    DebugSerial->println(pulses);
     for(int i = 0; i < pulses; i++)
     {
         digitalWrite(LED_PIN, HIGH);
@@ -289,7 +299,10 @@
     if (halt)
     {
         noInterrupts();
-    }
+        chSysHalt();
+    }
+    DebugSerial->print("ERROR: ");
+    DebugSerial->println(pulses);
     while(true)
     {
         for(int i = 0; i < pulses; i++)
@@ -350,7 +363,11 @@
     if (!SD.begin(SD_CHIP_SELECT))
 	{
 		TelemSerial->println("ERROR: SD Card init failed!");
-		return beepError(ERROR_SD, true);
+		#if __DEBUG
+        DebugSerial->println("ERROR: SD Card init failed!");
+        #endif
+		//chSysHalt();
+		return beepError(ERROR_SD, false);
 	}
 	else
 	{
@@ -654,6 +671,43 @@
     }
 }

+void readCommand()
+{
+    char ser;
+    while (CommandSerial->available())
+    {
+        ser = CommandSerial->read();
+        if (ser == 13 || ser == 10 || ser == ';')
+        {
+            if (cmdBufferLoc > 0)
+            {
+                cmdBuffer[cmdBufferLoc] = '\0';
+                #if __DEBUG
+                DebugSerial->print("$CMD,");
+                DebugSerial->println(cmdBuffer);
+                #endif
+                TelemSerial->print("$CMD,");
+                TelemSerial->println(cmdBuffer);
+                handleCommand(cmdBuffer);
+                cmdBufferLoc = 0;
+            }
+        }
+        else if (cmdBufferLoc >= COMMAND_BUFFER_SIZE)
+        {
+            #if __DEBUG
+            DebugSerial->println("ERROR: Command buffer overrun");
+            #endif
+            cmdBuffer[COMMAND_BUFFER_SIZE - 1] = '\0';
+            cmdBufferLoc = 0;
+        }
+        else
+        {
+            cmdBuffer[cmdBufferLoc] = ser;
+            cmdBufferLoc++;
+        }
+    }
+}
+
 /**
 * Test the analog continuity lines for voltage.
 */
@@ -769,6 +823,21 @@
         time += MS2ST(RATE_TO_MS(ANALOG_SAMPLE_RATE));
         testContinuity();
         testVoltage();
+        chThdSleepUntil(time);
+    }
+}
+
+/**
+* Read any incoming commands.
+*/
+static WORKING_AREA(commandThreadWa, 256);
+static msg_t CommandThread(void *arg)
+{
+    systime_t time = chTimeNow();
+    while(true)
+    {
+        time += MS2ST( RATE_TO_MS(COMMAND_SAMPLE_RATE));
+        readCommand();
         chThdSleepUntil(time);
     }
 }
@@ -815,6 +884,8 @@
     chThdCreateStatic(gpsThreadWa, sizeof(gpsThreadWa), NORMALPRIO, GpsThread, NULL); // gps
     delay(10);
     chThdCreateStatic(analogThreadWa, sizeof(analogThreadWa), NORMALPRIO, AnalogThread, NULL); // analog
+    delay(10);
+    chThdCreateStatic(commandThreadWa, sizeof(commandThreadWa), NORMALPRIO, CommandThread, NULL); // command

     // let sensor threads run for a few seconds to stabilize
     chThdSleepUntil(time += MS2ST(5000));
@@ -861,15 +932,12 @@

         // check relays
         unsigned long t = millis();
-        if (drogueDeployStart > 0 && (drogueDeployStart + PYRO_ON_TIME) < t)
-        {
-            digitalWrite(PYRO_2_PIN, LOW);
-            drogueDeployStart = 0;
-        }
-        if (mainDeployStart > 0 && (mainDeployStart + PYRO_ON_TIME) < t)
-        {
-            digitalWrite(PYRO_1_PIN, LOW);
-            mainDeployStart = 0;
+        for(int i = 0; i < NUM_EVENTS; i++)
+        {
+            if (eventStart[i] > 0 && (eventStart[i] + PYRO_ON_TIME) < t)
+            {
+                stopEvent(i+1);
+            }
         }

         // toggle LED
@@ -990,7 +1058,7 @@
 void modeApogee()
 {
 	// wait for altitude to start dropping?
-	deployDrogue();
+	startEvent(2);
 	mode = MODE_DESCENT;
 	String msg = "INFO: Descending";
 	#if __DEBUG
@@ -1015,7 +1083,7 @@
 	{
 		mode = MODE_DESCENT2;
 		mainTime = millis();
-		deployMain();
+		startEvent(1);
 		String msg = "INFO: Main Deploy";
         #if __DEBUG
         DebugSerial->println(msg);
@@ -1063,22 +1131,75 @@
     // low power mode?
 }

-/**
-* Deploy drogue chute
-*/
-void deployDrogue()
-{
-    digitalWrite(PYRO_2_PIN, HIGH);
-    drogueDeployStart = millis();
-}
-
-/**
-* Deploy main chute
-*/
-void deployMain()
-{
-    digitalWrite(PYRO_1_PIN, HIGH);
-    mainDeployStart = millis();
+void startEvent(int eventNum)
+{
+    switch(eventNum)
+    {
+        case 1: digitalWrite(PYRO_1_PIN, HIGH); break;
+        case 2: digitalWrite(PYRO_2_PIN, HIGH); break;
+        case 3: digitalWrite(PYRO_3_PIN, HIGH); break;
+        case 4: digitalWrite(PYRO_4_PIN, HIGH); break;
+        default: return;
+    }
+    eventStart[eventNum-1] = millis();
+}
+
+void stopEvent(int eventNum)
+{
+    switch(eventNum)
+    {
+        case 1: digitalWrite(PYRO_1_PIN, LOW); break;
+        case 2: digitalWrite(PYRO_2_PIN, LOW); break;
+        case 3: digitalWrite(PYRO_3_PIN, LOW); break;
+        case 4: digitalWrite(PYRO_4_PIN, LOW); break;
+        default: return;
+    }
+    eventStart[eventNum-1] = 0;
+}
+
+/**
+* Handle an incomming command.
+*/
+void handleCommand(const char *cmd)
+{
+    if (startsWith("deploy main", cmd))
+    {
+        startEvent(1);
+    }
+    else if (startsWith("deploy drogue", cmd))
+    {
+        startEvent(2);
+    }
+    else if (startsWith("deploy all", cmd))
+    {
+        startEvent(1);
+        startEvent(2);
+        startEvent(3);
+        startEvent(4);
+    }
+    else if (startsWith("deploy ", cmd) && strlen(cmd) > 7) // by number
+    {
+        startEvent(atoi(&(cmd[7])));
+    }
+    else if (startsWith("set mode", cmd) && strlen(cmd) > 9)
+    {
+        mode = atoi(&(cmd[9]));
+        #if __DEBUG
+        DebugSerial->print("INFO: MODE set to "); DebugSerial->print(mode);
+        #endif
+    }
+    else
+    {
+        #if __DEBUG
+        DebugSerial->print("ERROR: unknown command: ");
+        DebugSerial->println(cmd);
+        #endif
+    }
+}
+
+bool startsWith(const char *pre, const char *str)
+{
+    return strncmp(pre, str, strlen(pre)) == 0;
 }

 /**
@@ -1099,6 +1220,8 @@
     DebugSerial->print(chUnusedStack(gpsThreadWa, sizeof(gpsThreadWa)));
     DebugSerial->print(", ana:");
     DebugSerial->print(chUnusedStack(analogThreadWa, sizeof(analogThreadWa)));
+    DebugSerial->print(", cmd:");
+    DebugSerial->print(chUnusedStack(commandThreadWa, sizeof(commandThreadWa)));
     DebugSerial->print(", dec:");
     DebugSerial->print(chUnusedStack(decisionThreadWa, sizeof(decisionThreadWa)));
     DebugSerial->print(", main:");


update esp8266 sketch

update esp8266 sketch

--- Sketches/ESP8266ReuseConnectionSendLightData/ESP8266ReuseConnectionSendLightData.ino
+++ Sketches/ESP8266ReuseConnectionSendLightData/ESP8266ReuseConnectionSendLightData.ino
@@ -19,7 +19,7 @@
     USE_SERIAL.begin(115200);
    // USE_SERIAL.setDebugOutput(true);

-    USE_SERIAL.println();
+    USE_SERIAL.println("OK");
     USE_SERIAL.println();
     USE_SERIAL.println();

@@ -29,7 +29,7 @@
         delay(1000);
     }

-    WiFiMulti.addAP("SSID", "PASSWORD");
+    WiFiMulti.addAP("es", "asdfghjkl");

     // allow reuse (if server supports it)
     http.setReuse(true);
@@ -39,7 +39,7 @@
     // wait for WiFi connection
     if((WiFiMulti.run() == WL_CONNECTED)) {

-        http.begin("http://192.168.1.107/insertdata.php?t1="+String(analogRead(ANALOG_PIN)));
+        http.begin("http://192.168.1.106/insertdata.php?t1="+String(analogRead(ANALOG_PIN)));
         //http.begin("192.168.1.12", 80, "/test.html");

         int httpCode = http.GET();


Update Huzzah32_Wifi_Client_TouchscreenGui.ino

--- examples/Huzzah32_Wifi_Client_TouchscreenGui/Huzzah32_Wifi_Client_TouchscreenGui.ino
+++ examples/Huzzah32_Wifi_Client_TouchscreenGui/Huzzah32_Wifi_Client_TouchscreenGui.ino
@@ -24,9 +24,9 @@
     canvas.add(&terminal,0,0);

     // We start by connecting to a WiFi network
-    WiFiMulti.addAP("Linksys03507", "4antgxupkm");
-    WiFiMulti.addAP("Samsung Galaxy Note9_2618", "hvdl9798");
-    WiFiMulti.addAP("frulrom2319", "familiarullan2319");
+    WiFiMulti.addAP("ssid1", "pass1");
+    WiFiMulti.addAP("ssid2", "pass2");
+    WiFiMulti.addAP("ssid3", "pass3");

     terminal.print("Trying to connect to Wifi...");


Remove excessive debug info.

Remove excessive debug info.

--- SimpleJSON.ino
+++ SimpleJSON.ino
@@ -37,11 +37,7 @@
   char contentSizeString[50];
   char* content = createJSONString(importCode, timeStampString, value);

-  Serial.println(content);
-
   sprintf(contentSizeString, "%i", strlen(content));
-
-  Serial.println(contentSizeString);

   uint32_t ip = 0;

@@ -49,7 +45,7 @@
   ip = cc3000->IP2U32(HARD_CODED_IP);

   // Try looking up the website's IP address
-  Serial.print(WEBSITE); Serial.print(F(" -> "));
+  // Serial.print(WEBSITE); Serial.print(F(" -> "));
   while (ip == 0) {
     if (! cc3000->getHostByName(WEBSITE, &ip)) {
       Serial.println(F("Couldn't resolve!"));
@@ -58,7 +54,7 @@
     return 1;
   }

-  cc3000->printIPdotsRev(ip);
+  //cc3000->printIPdotsRev(ip);
   Serial.println();

   /* Try connecting to the website.
@@ -87,19 +83,16 @@

   free(content);

-  Serial.println(F("-------------------------------------"));
-
   /* Read data until either the connection is closed, or the idle timeout is reached. */
   unsigned long lastRead = millis();
   while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
     while (www.available()) {
       char c = www.read();
-      Serial.print(c);
+      //Serial.print(c);
       lastRead = millis();
     }
   }
   www.close();
-  Serial.println(F("-------------------------------------"));

   /* You need to make sure to clean up after yourself or the CC3000 can freak out */
   /* the next time your try to connect ... */


at least it compiles

at least it compiles

--- examples/Lesson3/new_Infrared_remote_control_car/new_Infrared_remote_control_car.ino
+++ examples/Lesson3/new_Infrared_remote_control_car/new_Infrared_remote_control_car.ino
@@ -1,5 +1,5 @@
 #include "Arduino.h"
-#define WOKE
+#include <IRremote.h>
 #include <EBot.h>

 #define A 16736925
@@ -8,35 +8,44 @@
 #define C 16720605
 #define D 16761405

-int ABS=150;
+int receiverpin = 12;
+int speed=150;
 unsigned long RED;
+IRrecv irrecv(receiverpin);
+decode_results results;

 EBot eBot = EBot();

 void setup() {
   pinMode(LED_BUILTIN, OUTPUT);
   Serial.begin(9600);
+  irrecv.enableIRIn();
   eBot.begin();
   eBot.setSpeed(speed);
   eBot.setDirection();
 }

 void loop() {
-  RED = eBot.getIR();
-  if(RED==A) {
-    Serial.println("A");
-    eBot.setDirection(EBot::FORWARD);
-  } else if(RED==B) {
-    Serial.println("B");
-    eBot.setDirection(EBot::BACKWARD);
-  } else if(RED==C) {
-    Serial.println("C");
-    eBot.setDirection(EBot::ROTATELEFT);
-  } else if(RED==D) {
-    Serial.println("D");
-    eBot.setDirection(EBot::ROTATERIGHT);
-  } else if(RED==X) {
-    Serial.println("X");
-    eBot.setDirection();
+  if (irrecv.decode(&results)) {
+    RED=results.value;
+    Serial.println(RED);
+    irrecv.resume();
+    delay(150);
+    if(RED==A) {
+      Serial.println("A");
+      eBot.setDirection(EBot::FORWARD);
+    } else if(RED==B) {
+      Serial.println("B");
+      eBot.setDirection(EBot::BACKWARD);
+    } else if(RED==C) {
+      Serial.println("C");
+      eBot.setDirection(EBot::ROTATELEFT);
+    } else if(RED==D) {
+      Serial.println("D");
+      eBot.setDirection(EBot::ROTATERIGHT);
+    } else if(RED==X) {
+      Serial.println("X");
+      eBot.setDirection();
+    }
   }
 }


update for WiFi and MQTT newer classes

update for WiFi and MQTT newer classes

--- T1/src/AFE-Firmware-T1.ino
+++ T1/src/AFE-Firmware-T1.ino
@@ -68,7 +68,7 @@
   Led.begin(0);

   /* If device in configuration mode then start LED blinking */
-  if (Device.getMode() != MODE_NORMAL) {
+  if (Device.getMode() == MODE_ACCESS_POINT) {
     Led.blinkingOn(100);
   }

@@ -91,7 +91,7 @@
     Mqtt.begin();
   }

-  Network.connect();
+  Network.listener();

   /* Initializing HTTP WebServer */
   WebServer.handle("/", handleHTTPRequests);
@@ -106,7 +106,7 @@
       if (Device.getMode() == MODE_NORMAL) {
         /* Connect to MQTT if not connected */
         if (Device.configuration.mqttAPI) {
-          Mqtt.connected() ? Mqtt.loop() : Mqtt.connect();
+          Mqtt.listener();
         }

         WebServer.listener();
@@ -116,25 +116,6 @@
           if (WebServer.httpAPIlistener()) {
             Led.on();
             processHTTPAPIRequest(WebServer.getHTTPCommand());
-            Led.off();
-          }
-        }
-
-        /* Relay related code */
-        if (Device.configuration.isRelay[0]) {
-
-          /* Relay turn off event launched */
-          if (Relay.autoTurnOff()) {
-            Led.on();
-            Mqtt.publish(Relay.getMQTTTopic(), "state", "off");
-            Led.off();
-          }
-
-          /* One of the switches has been shortly pressed */
-          if (Switch.isPressed() || ExternalSwitch.isPressed()) {
-            Led.on();
-            Relay.toggle();
-            MQTTPublishRelayState(); // MQTT Listener library
             Led.off();
           }
         }
@@ -184,7 +165,7 @@
         WebServer.listener();
       }
     } else { // Device not connected to WiFi. Reestablish connection
-      Network.connect();
+      Network.listener();
     }
   } else { // Access Point Mode
     Network.APListener();


missing commit

missing commit

--- sketches/Servo16_Adafruit/Servo16_Adafruit.ino
+++ sketches/Servo16_Adafruit/Servo16_Adafruit.ino
@@ -35,6 +35,8 @@
 #include <Wire.h>
 #include <Adafruit_PWMServoDriver.h>

+#define NUM_SERVOS 12
+
 // create the servo driver instance
 // change 0x40 to match your servo shield if necessary
 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
@@ -66,7 +68,7 @@
 }

 // the servo handler for Servorator
-void update_servo( int servo, int angle)
+void update_servo( int index, int angle)
 {
   if (index >= 0 && index < NUM_SERVOS)
   {
@@ -77,7 +79,7 @@
     // angle 1800 is 2,500 us
     long ticks = ((500L + (2000L*angle)/1800L)*4096L)/20000L;
     // update the servo channel with the new pusle
-    pwm.setPWM(servo, 0, ticks);
+    pwm.setPWM(index, 0, ticks);
   }
 }


works with Teensy 3.0 too

works with Teensy 3.0 too

change to adc-> methods instead of adc->adcX, so it works for boards
with one ADC (Teensy LC doesn't have a VREF though)
change resolution and speeds on ADC1 if it exists to detect smaller
changes

--- examples/internal_reference/internal_reference.ino
+++ examples/internal_reference/internal_reference.ino
@@ -5,6 +5,7 @@
 *   change voltage_target accordingly and run the program. The optimum trim value is printed at the end.
 *   The bisection algorithm prints some diagnostics while running.
 *   Additionally, the bandgap voltage is printed too, it should lie between 0.97 V and 1.03 V, with 1.00 V being the typical value.
+*   Because of noise, the trim value is not accurate to 1 step, it fluctuates +- 1 or 2 steps.
 */

 #include <ADC.h>
@@ -15,9 +16,9 @@
 //! change this value to your real input value, measured between AGND and 3.3V
 float voltage_target = 3.3;

-//! change the TOL (tolerance, minimum difference between voltage and target that matters)
-//! to refine even more, but not to less than 0.001 or 0.002
-const float TOL = 0.002;
+//! change the TOL (tolerance, minimum difference  in mV between voltage and target that matters)
+//! to refine even more, but not to less than 0.5 mV
+const float TOL = 1.0;
 // Maximum iterations of the algorithm, no need to change it.
 const uint8_t MAX_ITER = 100;

@@ -26,13 +27,13 @@
 float get_voltage(uint8_t trim) {
     VREF::trim(trim);
     VREF::waitUntilStable();
-    return 1.20/adc->adc1->analogRead(ADC_INTERNAL_SOURCE::VREF_OUT)*(adc->getMaxValue(ADC_1));
+    return 1.20/adc->analogRead(ADC_INTERNAL_SOURCE::VREF_OUT)*(adc->getMaxValue(ADC_0));
 }

 // Simple bisection method to get the optimum trim value
+// This method is not the bests for noisy functions...
 // Electrical datasheet: "The Voltage Reference (VREF) is intended to supply an accurate voltage output
 // that can be trimmed in 0.5 mV steps."
-// But it seems that the resolution of the ADC doesn't allow such fine tuning, 1 mV is the minimum
 int8_t optimumTrimValue(float voltage_target) {
     // https://en.wikipedia.org/wiki/Bisection_method#Algorithm
     // INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX
@@ -64,13 +65,13 @@

     while (niter < MAX_ITER) {
         midpoint = (a + b)/2;
-        cur_diff = get_voltage(midpoint) - voltage_target;
+        cur_diff = (get_voltage(midpoint) - voltage_target)*1000;

         Serial.print(niter, DEC); Serial.print(",\t");
         Serial.print(a, DEC); Serial.print(",\t");
         Serial.print(b, DEC); Serial.print(",\t");
         Serial.print(midpoint, DEC); Serial.print(",\t\t");
-        Serial.println(cur_diff*1000, 2);
+        Serial.println(cur_diff, 2);

         if (abs(cur_diff) <= TOL || b-a < 1) {
             return midpoint;
@@ -91,10 +92,17 @@
 void setup() {
     Serial.begin(9600);

+    // Best measurement conditions
     adc->setAveraging(32);
     adc->setResolution(16);
     adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED);
     adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_LOW_SPEED);
+    #if ADC_NUM_ADCS>1
+    adc->setAveraging(32, ADC_1);
+    adc->setResolution(16, ADC_1);
+    adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED, ADC_1);
+    adc->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_LOW_SPEED, ADC_1);
+    #endif // ADC_NUM_ADCS

     delay(2000);

@@ -105,41 +113,64 @@
     VREF::waitUntilStable();

     Serial.print("VREF value: ");
-    Serial.print(1.20/adc->adc1->analogRead(ADC_INTERNAL_SOURCE::VREF_OUT)*adc->getMaxValue(ADC_1), 5);
+    Serial.print(1.20/adc->analogRead(ADC_INTERNAL_SOURCE::VREF_OUT)*adc->getMaxValue(ADC_0), 5);
     Serial.println(" V.");

     Serial.print("Bandgap value: ");
-    Serial.print(3.3*adc->adc0->analogRead(ADC_INTERNAL_SOURCE::BANDGAP)/adc->getMaxValue(ADC_0), 5);
+    Serial.print(3.3*adc->analogRead(ADC_INTERNAL_SOURCE::BANDGAP)/adc->getMaxValue(ADC_0), 5);
     Serial.println(" V.");

     VREF::stop();
 }

-void loop() {}
+void loop() {
+}

-/* My output with a Teensy 3.6 connected to my laptop's USB.
+/*
+
+My output with a Teensy 3.6 connected to my laptop's USB.

 With a cheap multimeter I measured voltage_target = 3.29 V, the results are:

 niter,	a,	b,	midpoint,	diff (mV)
-0,		0,	63,	31,			27.84
-1,		31,	63,	47,			10.00
-2,		47,	63,	55,			1.15
-Optimal trim value: 55
-VREF value: 3.29115 V.
-Bandgap value: 1.00271 V.
+0,	    0,	63,	31,	    	38.62
+1,  	31,	63,	47,	    	17.06
+2,  	47,	63,	55,	    	6.81
+3,  	55,	63,	59,	    	1.42
+4,  	59,	63,	61,	    	-1.74
+5,  	59,	61,	60,	    	-0.50
+Optimal trim value: 60
+VREF value: 3.28977 V.
+Bandgap value: 1.00256 V.

 Using voltage_target = 3.3, which should be true:

 niter,	a,	b,	midpoint,	diff (mV)
-0,	    0,	63,	31,	    	26.83
-1,  	31,	63,	47,	    	0.00
-Optimal trim value: 47
-VREF value: 3.30000 V.
-Bandgap value: 1.00282 V.
+0,	    0,	63,	31,	    	28.48
+1,	    31,	63,	47,	    	7.20
+2,  	47,	63,	55,	    	-3.33
+3,	    47,	55,	51,	    	1.79
+4,	    51,	55,	53,	    	-0.84
+Optimal trim value: 53
+VREF value: 3.29874 V.
+Bandgap value: 1.00317 V.
+
+
+
+My output with a Teensy 3.0 connected to my laptop's USB.
+voltage_target = 3.22 V, the results are:
+
+niter,	a,	b,	midpoint,	diff (mV)
+0,  	0,	63,	31,		    37.34
+1,  	31,	63,	47,	    	16.56
+2,	    47,	63,	55,	    	5.54
+3,	    55,	63,	59,	    	-0.00
+Optimal trim value: 59
+VREF value: 3.21947 V.
+Bandgap value: 1.01978 V.

 */


BabelFish: 'B' to send list of decimal numbers as bytes

--- Utils/BabelFish/BabelFish.ino
+++ Utils/BabelFish/BabelFish.ino
@@ -575,6 +575,7 @@
             break;
   case 'U': doTransfer(NULL);                 break;
   case '.': doLine(&line[1]);                 break;
+  case 'B': doBytes(&line[1]);                break;
   case 'C': doEcho(!echo);                    break;
   case 'T': doTerminal();                     break;
   case 'W': sendController(~buttonUp,     2); break;
@@ -673,6 +674,7 @@
     Serial.println(":          [Hint: Use '.SAVE' for saving, not 'T'-mode!]");
     Serial.println(": U        Transfer object file from USB");
     Serial.println(": .<text>  Send text line as ASCII keystrokes");
+    Serial.println(": B<n>...  Send list of bytes");
     Serial.println(": C        Toggle echo mode (default off)");
     Serial.println(": T        Enter terminal mode");
     Serial.println(": W/A/S/D  Up/left/down/right arrow");
@@ -724,6 +726,20 @@
   // And terminal with a CR
   sendController('\n', 2);
   delay(50); // Allow Gigatron software to process line
+}
+
+// Send list of decimal numbers as bytes
+void doBytes(char *line)
+{
+  do {
+    if (*line >= '0') {
+      byte b = 0;
+      do
+        b = (10 * b) + (*line++ - '0');
+      while (*line >= '0');
+      sendController(b, 1);
+    }
+  } while (*line++ != '\0');
 }

 // In terminal mode we transfer every incoming character to


add more reports to bulk state response (for consistency)

--- Arduino/chorus_rf_laptimer/chorus_rf_laptimer.ino
+++ Arduino/chorus_rf_laptimer/chorus_rf_laptimer.ino
@@ -146,13 +146,13 @@
 #define SEND_MON_INTERVAL       10
 #define SEND_TIME_ADJUSTMENT    11
 #define SEND_API_VERSION        12
-#define SEND_END_SEQUENCE       13
+#define SEND_VOLTAGE            13
+#define SEND_THRESHOLD_SETUP_MODE 14
+#define SEND_END_SEQUENCE       15
 // following items don't participate in "send all items" response
 #define SEND_LAST_LAPTIMES          100
 #define SEND_TIME                   101
 #define SEND_CURRENT_RSSI           102
-#define SEND_VOLTAGE                103
-#define SEND_THRESHOLD_SETUP_MODE   104
 // special item that sends all subsequent items from 0 (see above)
 #define SEND_ALL_DEVICE_STATE       255

@@ -419,43 +419,7 @@
                     onItemSent();
                 }
                 break;
-            // Below is a termination case, to notify that data for CONTROL_GET_ALL_DATA is over.
-            // Must be the last item in the sequence!
-            case 13: // SEND_END_SEQUENCE
-                if (send4BitsToSerial(RESPONSE_END_SEQUENCE, 1)) {
-                    onItemSent();
-                    isSendingData = 0;
-                    shouldSendSingleItem = 1;
-                }
-                break;
-
-            //--------------------------------------------------------------------------------------
-            // Here is the gap in sequence between items that are sent as response to
-            // "CONTROL_GET_ALL_DATA" and items that are only sent individually
-            //--------------------------------------------------------------------------------------
-
-            case 100: // SEND_LAST_LAPTIMES
-                uint8_t idx;
-                idx = newLapIndex - lastLapsNotSent;
-                if (lastLapsNotSent == 0) {
-                    break;
-                }
-                if (sendLaptimeToSerial(RESPONSE_LAPTIME, idx, lapTimes[idx])) {
-                    lastLapsNotSent--;
-                    onItemSent();
-                }
-                break;
-            case 101: // SEND_CALIBR_TIME
-                if (sendLongToSerial(RESPONSE_TIME, millisUponRequest)) {
-                    onItemSent();
-                }
-                break;
-            case 102: // SEND_CURRENT_RSSI
-                if (sendIntToSerial(RESPONSE_RSSI, rssi)) {
-                    onItemSent();
-                }
-                break;
-            case 103: // SEND_VOLTAGE
+            case 13: // SEND_VOLTAGE
                 uint16_t voltage;
                 voltage = readVoltage();
                 if (voltage > VOLTAGE_ZERO_THRESHOLD) {
@@ -466,8 +430,44 @@
                     onItemSent();
                 }
                 break;
-            case 104: // SEND_THRESHOLD_SETUP_MODE
+            case 14: // SEND_THRESHOLD_SETUP_MODE
                 if (send4BitsToSerial(RESPONSE_THRESHOLD_SETUP, thresholdSetupMode)) {
+                    onItemSent();
+                }
+                break;
+            // Below is a termination case, to notify that data for CONTROL_GET_ALL_DATA is over.
+            // Must be the last item in the sequence!
+            case 15: // SEND_END_SEQUENCE
+                if (send4BitsToSerial(RESPONSE_END_SEQUENCE, 1)) {
+                    onItemSent();
+                    isSendingData = 0;
+                    shouldSendSingleItem = 1;
+                }
+                break;
+
+            //--------------------------------------------------------------------------------------
+            // Here is the gap in sequence between items that are sent as response to
+            // "CONTROL_GET_ALL_DATA" and items that are only sent individually
+            //--------------------------------------------------------------------------------------
+
+            case 100: // SEND_LAST_LAPTIMES
+                uint8_t idx;
+                idx = newLapIndex - lastLapsNotSent;
+                if (lastLapsNotSent == 0) {
+                    break;
+                }
+                if (sendLaptimeToSerial(RESPONSE_LAPTIME, idx, lapTimes[idx])) {
+                    lastLapsNotSent--;
+                    onItemSent();
+                }
+                break;
+            case 101: // SEND_CURRENT_TIME
+                if (sendLongToSerial(RESPONSE_TIME, millisUponRequest)) {
+                    onItemSent();
+                }
+                break;
+            case 102: // SEND_CURRENT_RSSI
+                if (sendIntToSerial(RESPONSE_RSSI, rssi)) {
                     onItemSent();
                 }
                 break;


displayASCII as a procedure

displayASCII as a procedure

For use in 'j' command as well as the '2x' command.

--- examples/RF12/RF12demo/RF12demo.ino
+++ examples/RF12/RF12demo/RF12demo.ino
@@ -805,11 +805,14 @@
             byte b = eeprom_read_byte(RF12_EEPROM_ADDR + ((value * 32) + i));
             showNibble(b >> 4);
             showNibble(b);
+            testbuf[i] = b;
             if (value == 42) {
              eeprom_write_byte((RF12_EEPROM_ADDR + RF12_EEPROM_SIZE) + i, b);
             }
         }
         Serial.println();
+        displayASCII(testbuf, RF12_EEPROM_SIZE);
+
         if (value == 42) Serial.println("Backed Up");

         if (value == 123) {
@@ -866,6 +869,21 @@
     showHelp();
 }

+static void displayASCII(volatile uint8_t* data, byte count) {
+    for (byte i = 0; i < count; ++i) {
+      if ((data[i] < 32) || (data[i] > 126))
+        {
+        Serial.print(" .");
+        }
+      else
+        {
+          Serial.print(" ");
+          Serial.print((char) data[i]);
+        }
+    }
+    Serial.println();
+}
+
 void displayVersion(uint8_t newline ) {
   Serial.print("\n[RF12demo.11]");
   if(newline!=0)  Serial.println();
@@ -958,7 +976,7 @@
         Serial.print(rf12_hdr & RF12_HDR_MASK);
         Serial.print("\n    ");
         nodes[(rf12_hdr & RF12_HDR_MASK)] = rf12_hdr & RF12_HDR_MASK;
-        for (byte i = 0; i < 32; ++i) {
+        for (byte i = 0; i < rf12_len; ++i) {  // variable n
           eeprom_write_byte(RF12_EEPROM_ADDR + ((rf12_hdr & RF12_HDR_MASK)*32) + i, rf12_data[i]);
         }
       }
@@ -978,19 +996,7 @@
     }
     Serial.print(" .");
     Serial.print(char((rf12_hdr & RF12_HDR_MASK) | 0x40)); // Convert node number into a letter, A to Z to undersore (1-31)
-
-    for (byte i = 0; i < n; ++i) {
-      if ((rf12_data[i] < 32) || (rf12_data[i] > 126))
-        {
-        Serial.print(" .");
-        }
-      else
-        {
-          Serial.print(" ");
-          Serial.print((char) rf12_data[i]);
-        }
-    }
-    Serial.println();
+    displayASCII(rf12_data, n);
   }
     if (rf12_crc == 0) {
       activityLed(1);


updated URLs

updated URLs

--- examples/RF12/syncRecv/syncRecv.ino
+++ examples/RF12/syncRecv/syncRecv.ino
@@ -1,6 +1,9 @@
 /// @dir syncRecv
 /// Try to receive periodic transmissions with minimal power consumption.
 /// @see http://jeelabs.org/2012/11/02/synchronised-reception/
+/// @see http://jeelabs.org/2012/11/03/losing-sync-is-bad/
+/// @see http://jeelabs.org/2012/11/04/predicting-the-next-packet-time/
+/// @see http://jeelabs.org/2012/11/05/verifying-synchronisation-over-time/
 // 2012-10-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

 #include <JeeLib.h>


Lengthen PWM cycle 0 duration to make grayscale great again

--- avr/avr.ino
+++ avr/avr.ino
@@ -50,7 +50,7 @@
 uint8_t col_i = 0;
 uint8_t row_i = 0;
 volatile uint8_t may_flip = 0;
-int pwm_planes[] = {0, 0, 0, 0, 1, 1, 2}; // PWM "plane" running sequence
+int pwm_planes[] = {0, 0, 0, 0, 0, 1, 1, 2}; // PWM "plane" running sequence
 int pwm_i = 0; // Current PWM cycle
 uint8_t *buf_pwm = buf_a[0];


Octave transposition method implemented, analog mux read methods added, to read the knobs values and the drums. Some ints where replaced by bytes to save space. Debug prints added to test some errors.

--- Pianoduino.ino
+++ Pianoduino.ino
@@ -8,47 +8,51 @@
 */

 //Arduino Pins
-static const int muxAPin = 5;
-static const int muxBPin = 4;
-static const int muxCPin = 3;
-static const int muxReadPin = A0;
-static const int inClkPin = 7; //Shift in clock
-static const int loadPin = 6; //Shift in or load input. When high data, shifted. When Low data is loaded from parallel inputs.
-static const int inEnPin = 8; //Active low
-static const int inReadPin = 9;
-static const int dataPin = 11;
-static const int outClkPin = 12;
-static const int latchPin = 10;
+static const byte muxAPin = 2;
+static const byte muxBPin = 3;
+static const byte muxCPin = 4;
+static const byte muxReadPin = A0;
+static const byte inClkPin = 7; //Shift in clock
+static const byte loadPin = 6; //Shift in or load input. When high data, shifted. When Low data is loaded from parallel inputs.
+static const byte inEnPin = 8; //Active low
+static const byte inReadPin = 9;
+static const byte dataPin = 11;
+static const byte outClkPin = 12;
+static const byte latchPin = 10;
 //If a Analog mux is added, just connect the control pins in parallel and add the En pin to the list.
-static const int muxEn [] = {2};
+static const byte muxEn [] = {5};

 //Constants
-int mask[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };//To read the columns values
-int blank = B00000000;//To send blank to the register.
+byte mask[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };//To read the columns values
+byte blank = B00000000;//To send blank to the register.
 byte noteOn = B10010000;
 byte noteOff = B10000000;
 byte pitchBend = B11100001;
 static const short sensitivity = 1000;
 static bool debug = false;
-static const byte  keyMidi[144] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                                   B00101000, B00101000, B00101001, B00101001, B00101010, B00101010, B00101011, B00101011, B00101100, B00101100, B00100111, B00100111,
-                                   B00101110, B00101110, B00101111, B00101111, B00110000, B00110000, B00101011, B00101011, B00101100, B00101100, B00101101, B00101101,
-                                   B00111010, B00111010, B00111011, B00111011, 0, 0, B00110111, B00110111, B00111000, B00111000, B00111001, B00111001,
-                                   B00110100, B00110100, B00110101, B00110101, B00110110, B00110110, B00110001, B00110001, B00110010, B00110010, B00110011, B00110011,
-                                   B01010010, B01010010, B01010011, B01010011, B01010100, B01010100, B01001111, B01001111, B01010000, B01010000, B01010001, B01010001,
-                                   B01001100, B01001100, B01001101, B01001101, B01001110, B01001110, B01001001, B01001001, B01001010, B01001010, B01001011, B01001011,
-                                   B01000110, B01000110, B01000111, B01000111, B01001000, B01001000, B01000011, B01000011, B01000100, B01000100, B01000101, B01000101,
-                                   B01000000, B01000000, B01000001, B01000001, B01000010, B01000010, B00111101, B00111101, B00111110, B00111110, B00111111, B00111111,
-                                   0, 0, 0, 0, B00111100, B00111100, 0, 0, 0, 0, 0, 0
-                                  };
+static const byte  keyMidiCons[144] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                                       B00101000, B00101000, B00101001, B00101001, B00101010, B00101010, B00101011, B00101011, B00101100, B00101100, B00100111, B00100111,
+                                       B00101110, B00101110, B00101111, B00101111, B00110000, B00110000, B00101011, B00101011, B00101100, B00101100, B00101101, B00101101,
+                                       B00111010, B00111010, B00111011, B00111011, 0, 0, B00110111, B00110111, B00111000, B00111000, B00111001, B00111001,
+                                       B00110100, B00110100, B00110101, B00110101, B00110110, B00110110, B00110001, B00110001, B00110010, B00110010, B00110011, B00110011,
+                                       B01010010, B01010010, B01010011, B01010011, B01010100, B01010100, B01001111, B01001111, B01010000, B01010000, B01010001, B01010001,
+                                       B01001100, B01001100, B01001101, B01001101, B01001110, B01001110, B01001001, B01001001, B01001010, B01001010, B01001011, B01001011,
+                                       B01000110, B01000110, B01000111, B01000111, B01001000, B01001000, B01000011, B01000011, B01000100, B01000100, B01000101, B01000101,
+                                       B01000000, B01000000, B01000001, B01000001, B01000010, B01000010, B00111101, B00111101, B00111110, B00111110, B00111111, B00111111,
+                                       0, 0, 0, 0, B00111100, B00111100, 0, 0, 0, 0, 0, 0
+                                      };
+

 //Variables
 static bool sValue[] = {0, 0, 0}; // S0, S1, S2 values
-long noteTime [72];
-bool keyState[144];
+long noteTime [sizeof(keyMidiCons) / sizeof(byte) / 2];
+bool keyState[sizeof(keyMidiCons) / sizeof(byte)];
 bool rowsRead [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+byte trans = 0;
+static byte  keyMidi[sizeof(keyMidiCons) / sizeof(byte)] = {};
+byte analogValue[(sizeof(muxEn) / sizeof(byte)) * 8];

 /**
    Method to setup the pins and stuffs of the pianoduino.
@@ -56,8 +60,11 @@
    @return void
 */
 void setup() {
-  int i;
+  byte i;
   Serial.begin(115200);
+  if(debug){
+    Serial.println("Setup Start");
+  }
   pinMode(muxAPin, OUTPUT);
   pinMode(muxBPin, OUTPUT);
   pinMode(muxCPin, OUTPUT);
@@ -77,8 +84,13 @@
   for (i = 0; i < sizeof(keyState) / sizeof(bool); i++) {
     keyState[i] = 0;
   }
+  readAnalog();
+  transpose(0);
   digitalWrite(loadPin, HIGH); //On HIGH is read ready
   delay(1000);
+  if (debug){
+    Serial.println("Setup Ready");
+  }
 }

@@ -88,12 +100,14 @@
    @param pMuxEn: the pin of the mux that you want to read from.
    @return void
 */
-void muxToPin(int pPin, int pMuxEn) {
+void muxToPin(byte pPin, byte pMuxEn) {
   sValue[0] = bitRead(pPin, 0);
   sValue[1] = bitRead(pPin, 1);
   sValue[2] = bitRead(pPin, 2);
-  for (int i = 0; i < sizeof(muxEn) / sizeof(int); i++) {
-    digitalWrite(muxEn[i], HIGH);
+  for (byte i = 0; i < sizeof(muxEn) / sizeof(byte); i++) {
+    if (pMuxEn != i) {
+      digitalWrite(muxEn[i], HIGH);
+    }
   }
   digitalWrite(pMuxEn, LOW);
   digitalWrite(muxAPin, sValue[0]);
@@ -106,7 +120,12 @@
    @param pColumn the column you wish to shift to.
    @return void
 */
-void shiftToColumn(int pColumn) {
+void shiftToColumn(byte pColumn) {
+  if(debug){
+    Serial.print("Shifting to column: ");
+    Serial.println(pColumn);
+    delay(10);
+  }
   digitalWrite(latchPin, LOW);
   if (pColumn < 8) {
     shiftOut(dataPin, outClkPin, MSBFIRST, mask[pColumn]);
@@ -118,7 +137,57 @@
     shiftOut(dataPin, outClkPin, MSBFIRST, blank);
   }
   digitalWrite(latchPin, HIGH);
+  if(debug){
+    Serial.println("Shift done.");
+  }
   delayMicroseconds(5);
+}
+
+/**
+   Method to transpose the notes
+   @param pDir direction to transpose
+*/
+void transpose(byte pDir) {
+  if (-3 < trans + pDir ) {
+    if (trans + pDir < 5) {
+      trans = trans + pDir;
+    } else {
+      trans = 4;
+    }
+  } else {
+    trans = -2;
+  }
+  for (byte i = 0; i <  sizeof(keyMidi) / sizeof(byte); i++) {
+    keyMidi[i] = keyMidiCons[i] + trans * 12;
+  }
+}
+
+/**
+   Method to read all the values of the knobs and other analog components. (Like the snaredrum.
+   Updates the analogValue array.
+*/
+void readAnalog() {
+  if(debug){
+    Serial.println("readAnalog start");
+  }
+  byte tmp = 0;
+  for (byte i = 0; i < sizeof(muxEn) / sizeof(byte); i++) {
+    for (byte y = 0; y < 8; y++) {
+      muxToPin(y, muxEn[i]);
+      tmp = map(analogRead(muxReadPin), 0, 1023, 0, 127);
+      if (tmp != analogValue[i * 8 + y]) {
+        analogValue[i * 8 + y] = tmp;
+        if (i * 8 + y < 15) {
+          //Send message with the knoobs
+        } else {
+          //Send message with the drums
+        }
+      }
+    }
+  }
+  if(debug){
+    Serial.println("readAnalog pass");
+  }
 }

 /**
@@ -127,23 +196,14 @@
    @return void
 */
 void loop() {
-  /**for(int i=0; i<8; i++){
-    Serial.print("Y");
-    Serial.print(i);
-    Serial.print(": ");
-    muxToPin(i, muxEn[0]);
-    delay(4000);
-    Serial.println( (map(analogRead(muxReadPin), 0, 1023, 0, 127)));
-    Serial.print(sValue[2]);
-    Serial.print(" ");
-    Serial.print(sValue[1]);
-    Serial.print(" ");
-    Serial.println(sValue[0]);
-    }*/
-  for (int i = 0; i < 16; i++) {
+  if(debug){
+    Serial.println("Loop start");
+  }
+  readAnalog();
+  for (byte i = 0; i < 16; i++) {
     shiftToColumn(i);
     scanRows();
-    for (int j = 0; j < sizeof(rowsRead) / sizeof(bool); j++) {
+    for (byte j = 0; j < sizeof(rowsRead) / sizeof(bool); j++) {
       if (i < 12 and j < 12) {
         if (rowsRead[j] && !keyState[i + 12 * j]) {
           keyState[i + 12 * j] = 1;
@@ -194,6 +254,9 @@
       }
     }
   }
+  if(debug){
+    Serial.println("Loop pass");
+  }
 }

 /**
@@ -201,7 +264,7 @@
    @param pPos the position of the note in the array.
    @param pMode 0 to turn off the note, 1 to update.
 */
-void updateVelocity(int pPos, byte pMode) {
+void updateVelocity(byte pPos, byte pMode) {
   if (pMode == 0) {
     noteTime[pPos] = 0;
   } else {
@@ -213,7 +276,7 @@
    Method that  updates the velocity of a note.
    @param pPos the position of the note in the array.
 */
-byte getVelocity(int pPos) {
+byte getVelocity(byte pPos) {
   if (noteTime[pPos] == 0) {
     noteTime[pPos] = millis();
     /* Serial.println("Time");
@@ -225,7 +288,7 @@
       delay(10);*/
     return 127;
   } else {
-    int tempVelocity = map(abs(millis() - noteTime[pPos]), 0, sensitivity, 127, 10);
+    byte tempVelocity = map(abs(millis() - noteTime[pPos]), 0, sensitivity, 127, 10);
     noteTime[pPos] = millis();
     if (tempVelocity < 10) {
       tempVelocity = 10;
@@ -251,6 +314,16 @@
    Method to scan the values of all the inputs of the shiftregisters
 */
 void scanRows() {
+  if(debug){
+    Serial.println("Scanning rows start");
+    Serial.print("Load pin: ");
+    Serial.println(loadPin);
+    Serial.print("inEnPin pin: ");
+    Serial.println(inEnPin);
+    Serial.print("inReadPin pin: ");
+    Serial.println(inReadPin);
+    delay(10);
+  }
   digitalWrite(loadPin, LOW); //On Low the parallel data is collected
   delayMicroseconds(5);
   digitalWrite(loadPin, HIGH); //On HIGH is read ready
@@ -258,6 +331,10 @@
   digitalWrite(inEnPin, LOW); //Active Low
   shiftIn(inReadPin, inClkPin);
   digitalWrite(inEnPin, HIGH); //Active Low
+  if(debug){
+    Serial.println("Scanning rows end");
+    delay(1);
+  }
 }

 /**
@@ -265,14 +342,22 @@
    @param pDatapin the pin to read.
    @param pClk the shift registers clock pin.
 */
-void shiftIn(int pDatapin, int pClk) {
-  for (int i = sizeof(rowsRead) / sizeof(byte) - 1; i >= 0 ; i--)
+void shiftIn(byte pDatapin, byte pClk) {
+  if(debug){
+    Serial.println("ShiftIn Start");
+    delay(1);
+  }
+  for (short i = sizeof(rowsRead) / sizeof(bool) - 1; i >= 0 ; i--)
   {
     digitalWrite(inClkPin, LOW);
     delayMicroseconds(5);
     rowsRead[i] = digitalRead(inReadPin);
     digitalWrite(inClkPin, HIGH);
   }
+  if(debug){
+    Serial.println("ShiftIn End");
+    delay(10);
+  }
 }


serial messages working

serial messages working

--- libraries/serial_using_structs/examples/demo_simple_messages/demo_simple_messages.ino
+++ libraries/serial_using_structs/examples/demo_simple_messages/demo_simple_messages.ino
@@ -53,8 +53,8 @@
     delay ( 1000 );
     pose.x += 1.;               		/// we are increasing the x for debugging reasons
     msg.update_time ( millis() ); 		/// update time stamp
-    msg.set_object ( text ).send;       /// send a object
-    msg.set_object ( pose ).send;       /// send a object
+    msg.set_object ( text ).send();       /// send a object
+    msg.set_object ( pose ).send();       /// send a object

     if ( msg.receive() ) {      		     /// check for messages
         tuw::ComHeader::Type type;


Alarm/relay IO stuff

Alarm/relay IO stuff

--- SmartAlarm.ino
+++ SmartAlarm.ino
@@ -38,6 +38,16 @@
                                          SPI_CLOCK_DIVIDER); // you can change this clock speed but DI
 // end cc3000 setup things
 // =====================================================
+// relay shield stuff
+#define RELAY1 7
+#define RELAY2 6
+#define RELAY3 5 // don't use; conflicts with CC3000 VBAT_SW_EN
+#define RELAY4 4
+// keys
+#define KEY_CANCEL 0
+#define KEY_DOWN 1
+#define KEY_UP 2
+#define KEY_OK 8

 DateTime now = DateTime(0);

@@ -156,6 +166,47 @@
   }

 }
+
+/**
+ * raises an alarm
+ */
+class Alarm {
+  unsigned long PrevMillis;
+  unsigned long DurationOn; // in millis
+  unsigned long DurationOff; // in millis
+  bool state;
+  uint8_t pin;
+
+public:
+  Alarm(unsigned long dOn, unsigned long dOff, uint8_t p) {
+    DurationOn = dOn;
+    DurationOff = dOff;
+    pin = p;
+    state = LOW;
+  }
+
+  Alarm() { // default
+    DurationOn = 1000; // 1 second
+    DurationOff = 1000; // 1 second
+    pin = RELAY1;
+    state = LOW;
+  }
+
+  void PoundTheAlarm() { // shameless Nicki Minaj reference
+    if (!state && (millis() - PrevMillis) > DurationOff) {
+    Serial.print("PTA!");
+      // turn it on
+      digitalWrite(pin, HIGH);
+      state = HIGH;
+      PrevMillis = millis();
+    } else if (state && (millis() - PrevMillis) > DurationOn) {
+      // turn it off
+      digitalWrite(pin, LOW);
+      state = LOW;
+      PrevMillis = millis();
+    }
+  }
+};

 /**
  * updates LCD
@@ -216,6 +267,10 @@
 void setup() {
   // serial debug connection
   Serial.begin(115200);
+  // I/O
+  pinMode(RELAY1, OUTPUT);
+  pinMode(RELAY2, OUTPUT);
+  pinMode(RELAY4, OUTPUT);
   // put your setup code here, to run once:
   Serial.println(F("\nInitialising the LCD ..."));
   lcd.begin(20,4);
@@ -275,5 +330,4 @@
   // put your main code here, to run repeatedly:
   now = rtc.now();
   DU.update(lcd, rtc, cc3000);
-
 }


remove reset, no reason for it

remove reset, no reason for it

--- examples/OnDemandConfigPortal/OnDemandConfigPortal.ino
+++ examples/OnDemandConfigPortal/OnDemandConfigPortal.ino
@@ -33,7 +33,7 @@
     //sets timeout until configuration portal gets turned off
     //useful to make it all retry or go to sleep
     //in seconds
-    //wifiManager.setConfigPortalTimeout(120);
+    wifiManager.setConfigPortalTimeout(120);

     //it starts an access point with the specified name
     //here  "AutoConnectAP"
@@ -48,16 +48,11 @@
     if (!wifiManager.startConfigPortal("OnDemandAP")) {
       Serial.println("failed to connect and hit timeout");
       delay(3000);
-      //reset and try again, or maybe put it to deep sleep
-      ESP.reset();
-      delay(5000);
-    }
-
-    //if you get here you have connected to the WiFi
-    Serial.println("connected...yeey :)");
+    } else {
+      //if you get here you have connected to the WiFi
+      Serial.println("connected...yeey :)");
+    }
   }

-
   // put your main code here, to run repeatedly:
-
 }


Update comments for Spark

Update comments for Spark

--- firmware/examples/button/button.ino
+++ firmware/examples/button/button.ino
@@ -8,8 +8,8 @@
 // Basic pin reading and pullup test for the MCP23017 I/O expander
 // public domain!

-// Connect pin #12 of the expander to Analog 5 (i2c clock)
-// Connect pin #13 of the expander to Analog 4 (i2c data)
+// Connect pin #12 of the expander to Analog 5 for Arduino and D1 for Spark Core (i2c clock)
+// Connect pin #13 of the expander to Analog 4 for Arduino and D0 for Spark Core (i2c data)
 // Connect pins #15, 16 and 17 of the expander to ground (address selection)
 // Connect pin #9 of the expander to 5V (power)
 // Connect pin #10 of the expander to ground (common ground)
@@ -33,4 +33,4 @@
 void loop() {
   // The LED will 'echo' the button
   digitalWrite(13, mcp.digitalRead(0));
-}+}


added checkColor method for calibration purposes

--- tictactoe/tictactoe.ino
+++ tictactoe/tictactoe.ino
@@ -189,4 +189,9 @@
   Serial.println();
 }

+void checkColor(int s){
+  int colorValue = squares[s]->getColorValue();
+  Serial.println(colorValue);
+}

+


handle last max_code digit

handle last max_code digit

--- tinkering/Lock/Lock.ino
+++ tinkering/Lock/Lock.ino
@@ -71,6 +71,9 @@
 		}
 		else {
 			change(INCORRECT);
+
+			if (code_idx == MAX_CODE)
+				change(LOCKED);
 		}
 	}
 }


main loop only writes once

main loop only writes once

--- Calibration/liveCode/overclockAccel/overclockAccel.ino
+++ Calibration/liveCode/overclockAccel/overclockAccel.ino
@@ -14,7 +14,7 @@
 /* Assign a unique ID to the sensors */
 Adafruit_10DOF                dof   = Adafruit_10DOF();
 URP_LSM303_Accel accel = URP_LSM303_Accel(30301);
-const char* FILENAME = "run2-26.txt";
+const char* FILENAME = "tlaunch.txt";
 sensors_event_t accel_event;
 sensors_vec_t   orientation;
 //data buffer for the accel and orientation readings


Added version return command to SerialSequencingUploader.ino sketch

--- Software/BasicController/ArduinoSketch/SerialSequenceUploader/SerialSequenceUploader.ino
+++ Software/BasicController/ArduinoSketch/SerialSequenceUploader/SerialSequenceUploader.ino
@@ -22,6 +22,7 @@
  *  S XX - Set sequence counter to XX
  *  T - Test main sequence programmed
  *  U - Echo only first array sequence as byte. Terse output version of 'E'.
+ *  V - Return version string.
  *  W BXXXXXX - Turn on array BXXXXXX directly.  No sequencing or triggering.
  *  X - All off and reset to trigger-enabled setting.
  *  ? X - Query state of device X.  Supported devices : S = shutter open (0 = closed, 1 = open)
@@ -32,6 +33,9 @@
  *
  *  Serial requires 9600 baud, newline characters only for line feed
 */
+
+// Version variables
+const String version = 1.2;

 // Serial variables
 String inputString = "";         // a string to hold incoming data
@@ -591,6 +595,13 @@
         }

         break;
+
+	  case ('V') :
+		// Return version via serial port
+		Serial.print("Version : ");
+		Serial.println(version);
+
+		break;

       case ('W') :


Update ESP8266iTachEmulatorGUI.ino

Update ESP8266iTachEmulatorGUI.ino

--- ESP8266iTachEmulatorGUI/ESP8266iTachEmulatorGUI.ino
+++ ESP8266iTachEmulatorGUI/ESP8266iTachEmulatorGUI.ino
@@ -7,7 +7,7 @@
   Tested with
   - IrScrutinizer 1.1.2 from https://github.com/bengtmartensson/harctoolboxbundle
   - iPhone iRule app with remote created with cloud codes online at http://iruleathome.com
-  TODO: Implement capture https://github.com/sebastienwarin/IRremoteESP8266
+  TODO: Implement capture from a modulated receiver, e.g., https://www.analysir.com/blog/2016/01/14/esp8266-nodemcu-infrared-decoding-added-to-analysir/
         Implement repeats
         Implement more commands, e.g., stopir
         Check with OpenRemote http://sourceforge.net/projects/openremote/