first pass at basic motor control via PWM

--- tankbot.ino
+++ tankbot.ino
@@ -3,6 +3,8 @@
 #include <FiniteStateMachine.h>
 #include <SPI.h>
 #include <aREST.h>
+#include <Wire.h>
+#include <Adafruit_PWMServoDriver.h>
 #include "LogHelpers.h"
 #include "TimingHelpers.h"

@@ -19,7 +21,24 @@

 aREST rest = aREST();

+// PWM driver board
+Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
+
+// define PWM channels that will tie to the motor driver board
+const byte MOTOR_A_PWM_CHANNEL = 0;
+const byte MOTOR_A_FORWARD_CHANNEL = 1;
+const byte MOTOR_A_REVERSE_CHANNEL = 2;
+
+const byte MOTOR_B_PWM_CHANNEL = 4;
+const byte MOTOR_B_FORWARD_CHANNEL = 5;
+const byte MOTOR_B_REVERSE_CHANNEL = 6;
+
+const byte MOTOR_STANDBY_CHANNEL = 7;
+
 void setup() {
+  pwm.begin();
+  pwm.setPWMFreq(1600);
+
   startLog(); // starts Serial, and prints a message if DEBUG is enabled
 }

@@ -103,15 +122,29 @@
 // disable the motors via the motor driver STANDBY
 void allStop() {
   warn(F("enabling STANDBY"));
+  pwm.setPWM(MOTOR_STANDBY_CHANNEL, 0, 0);
 }
 // disable the motors via the motor driver STANDBY
 void allStart() {
   warn(F("disabling STANDBY"));
+  pwm.setPWM(MOTOR_STANDBY_CHANNEL, 0, 4095);
 }
 void allSpeedAhead() {
   warn(F("moving forward"));
+  pwm.setPWM(MOTOR_A_PWM_CHANNEL, 0, 4095); // appromixmately 50% speed
+  pwm.setPWM(MOTOR_B_PWM_CHANNEL, 0, 4095); // appromixmately 50% speed
+  pwm.setPWM(MOTOR_A_FORWARD_CHANNEL, 0, 4095);
+  pwm.setPWM(MOTOR_A_REVERSE_CHANNEL, 0, 0);
+  pwm.setPWM(MOTOR_B_FORWARD_CHANNEL, 0, 4095);
+  pwm.setPWM(MOTOR_B_REVERSE_CHANNEL, 0, 0);
 }
 void allSpeedReverse() {
   warn(F("moving backward"));
+  pwm.setPWM(MOTOR_A_PWM_CHANNEL, 0, 4095); // appromixmately 50% speed
+  pwm.setPWM(MOTOR_B_PWM_CHANNEL, 0, 4095); // appromixmately 50% speed
+  pwm.setPWM(MOTOR_A_FORWARD_CHANNEL, 0, 0);
+  pwm.setPWM(MOTOR_A_REVERSE_CHANNEL, 0, 4095);
+  pwm.setPWM(MOTOR_B_FORWARD_CHANNEL, 0, 0);
+  pwm.setPWM(MOTOR_B_REVERSE_CHANNEL, 0, 4095);
 }


20150217.1145

--- cmdMULTIsens/src/sketch.ino
+++ cmdMULTIsens/src/sketch.ino
@@ -22,6 +22,9 @@
 DHT dht(Dht22Pin, DhtType);
 // Initialise TMP36 library
 TMP36 tmp36(Tmp36Pin, Tmp36Samples);
+
+float h;  // used for calculating dewpoint
+float t;  // used for calculating dewpoint

 void setup()
 {
@@ -87,10 +90,10 @@
       case 'R':
       case 'r':
         // All DHT22 data: Temperature, Humidity, DewPoint, DewPoint2
-        float t = dht.readTemperature();
+        t = dht.readTemperature();
         Serial.print(t);
         Serial.print(", ");
-        float h = dht.readHumidity();
+        h = dht.readHumidity();
         Serial.print(h);
         Serial.print(", ");
         Value = dht.computeDewPoint(t, h);


Refinement of menu

Refinement of menu

--- Arduino_HVAC_Controller/HVAC_Controller/HVAC_Controller.ino
+++ Arduino_HVAC_Controller/HVAC_Controller/HVAC_Controller.ino
@@ -32,7 +32,7 @@
 long oldTemp = 0;
 int timeout = 30;                 // Backlight timeout variable
 boolean editable = FALSE;         // Determines whether or not button presses will do anything, used to avoid accidental changes
-char menu[] = {"Cooling", "Heating"};  // Menu display for either setting the high point or the low point of the temp range
+char* menu[] = {"Cooling", "Heating"};  // Menu display for either setting the high point or the low point of the temp range
 int menuPosition = 1;             // Current position in the setting menu

 // -------------Library Interaction--------------
@@ -79,13 +79,13 @@

   if (timeout <= 0) {                   // Turn on backlight for 30 seconds, else turn it off
     lcd.setBacklight(OFF);
-    editable == FALSE
+    editable == FALSE;
   }else {
     lcd.setBacklight(ON);
   }
   // timeout = timout -                 TODO: When networking is implement, get system time and use it to change timeout

-  lcd.setCursor(0, 1);                  // Starting postion of character printing
+  lcd.setCursor(1, 1);                  // Starting postion of character printing

   uint8_t buttons = lcd.readButtons();  // Constantly check to see if something has been put on the bus

@@ -93,6 +93,7 @@
     lcd.clear();
     lcd.print("Current Temp: ");
     lcd.print(currentTemp);
+    Serial.println(currentTemp);
   }

   if (buttons) {                        // Handle button presses
@@ -102,7 +103,7 @@
       editable = TRUE;
     }
     if (editable) {                     // go to buttonHandler to handle menu switching and parameter manipulations
-      buttonHandler();
+      buttonHandler(buttons);
     }
   }

@@ -113,7 +114,7 @@
 // Parameters:    None
 // Returns:       Boolean, True if the temperature has changed, else False
 // Description:   This function polls the temp sensors, retrieves the values, and then returns
-boolean buttonHandler(){
+boolean buttonHandler(uint8_t buttons){

   // --------------PARAMETERS---------------------
   int highModifier = 0;
@@ -164,11 +165,10 @@
   high = high + highModifier;
   low = low + lowModifier;

+  lcd.setCursor(0, 0);
+  lcd.print(menu[menuPosition]);
   lcd.setCursor(0, 1);
-  lcd.print(menu[menuPosition]);
-  lcd.setCursor(1, 1);
   lcd.print("Setpoint: ");
-  lcd.setCursor(1,11);

   if (menuPosition == 0) {
     lcd.print(low);


Clean up

Clean up

--- frontdesk/frontdesk.ino
+++ frontdesk/frontdesk.ino
@@ -39,8 +39,6 @@

 		// LEDs stay off
 		digitalWrite(ledPin, LOW);
-		// redBeat(8, 64);
-		// rainbow();
 		rainbowCycle();

 		// If a tag is detected, go to the next state
@@ -60,7 +58,6 @@

 			// LEDs on
       		green();
-			// colorWipe(LED.Color(0, 0, 127));
 			digitalWrite(ledPin, HIGH);
 			playCoinSound();

@@ -75,7 +72,6 @@
 		// If data read fails, go back to scan state
 		else {
       		red();
-      		//colorWipe(LED.Color(127, 0, 0));
 			playDeath();
 			state = 0;
 		}


Delete Delta5-Race-Timer.ino

Delete Delta5-Race-Timer.ino

--- arduino/Delta5-Race-Timer.ino
+++ arduino/Delta5-Race-Timer.ino
@@ -1,524 +0,0 @@
-//Delta 5 Race Timer
-
-//MIT License
-//
-//Copyright (c) 2017 Scott G Chin
-//
-//Permission is hereby granted, free of charge, to any person obtaining a copy
-//of this software and associated documentation files (the "Software"), to deal
-//in the Software without restriction, including without limitation the rights
-//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-//copies of the Software, and to permit persons to whom the Software is
-//furnished to do so, subject to the following conditions:
-//
-//The above copyright notice and this permission notice shall be included in all
-//copies or substantial portions of the Software.
-//
-//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-//SOFTWARE.
-
-
-#include <Wire.h>
-
-#define rxFault 0x80
-#define txFault 0x40
-#define txRequest 0x20
-
-
-// *****UPDATE THE SETTINGS BELOW TO CHANGE THE SLAVE ADDRESS AND THE RECEIVER FREQUENCY
-#define slaveAddress 14 //i2c address to Raspberry Pi. 8-1, 10-2, 12-3, 14-4
-int count = 21; //channel 5685-17, 5760-25, 5800-27, 5860-30, 5905-21
-// *****************************************************************************
-
-
-const int slaveSelectPin = 10;
-const int spiDataPin = 11;
-const int spiClockPin = 13;
-const int buttonPin = 3;
-int buttonState = 0;
-int downcount=0;
-int rssi = 0;
-int highValue=0;
-int highChannel=0;
-unsigned long start, finished, elapsed, lapcheck;
-int flag = 0;
-int lapTrigger = 0; //Initial RSSI. 0 is off.
-int minLap = 5000; // Minimum lap time in milliseconds
-
-uint16_t rssiArr[6];
-int thresholdReduction = 2;
-
-
-struct {
-  byte volatile command;
-  byte volatile control; // rxFault:txFault:0:0:0:0:0:0
-  byte volatile rssiTrig;
-  byte volatile channel;
-  byte volatile lap;
-  byte volatile minutes;
-  byte volatile seconds;
-  byte volatile milliseconds;
-} commsTable;
-
-byte volatile txTable[32];   // prepare data for sending over I2C
-bool volatile dataReady = false; // flag to trigger a Serial printout after an I2C event
-
-//PROGMEM prog_uint16_t channelTable[] = {
-uint16_t channelTable[] = {
-  0x2A05, 0x299B, 0x2991, 0x2987, 0x291D, 0x2913, 0x2909, 0x289F,    //Band A
-  0x2903, 0x290C, 0x2916, 0x291F, 0x2989, 0x2992, 0x299C, 0x2A05,    //Band B
-  0x2895, 0x288B, 0x2881, 0x2817, 0x2A0F, 0x2A19, 0x2A83, 0x2A8D,    //Band E
-  0x2906, 0x2910, 0x291A, 0x2984, 0x298E, 0x2998, 0x2A02, 0x2A0C,    //Band F
-  0x281D, 0x288F, 0x2902, 0x2914, 0x2987, 0x2999, 0x2A0C, 0x2A1E     // Band C / Immersion Raceband
-};
-
-void SERIAL_SENDBIT1()
-{
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(300);
-
-digitalWrite(spiDataPin, HIGH);
-  delayMicroseconds(300);
-  digitalWrite(spiClockPin, HIGH);
-  delayMicroseconds(300);
-
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(300);
-}
-
-void SERIAL_SENDBIT0()
-{
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(300);
-
-digitalWrite(spiDataPin, LOW);
-  delayMicroseconds(300);
-  digitalWrite(spiClockPin, HIGH);
-  delayMicroseconds(300);
-
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(300);
-}
-
-void SERIAL_ENABLE_LOW()
-{
-  delayMicroseconds(100);
- digitalWrite(slaveSelectPin,LOW);
-  delayMicroseconds(100);
-}
-
-void SERIAL_ENABLE_HIGH()
-{
-  delayMicroseconds(100);
- digitalWrite(slaveSelectPin,HIGH);
-  delayMicroseconds(100);
-}
-
-void setup() {
-  Serial.begin(9600); // for the serial monitor
-  pinMode(buttonPin, INPUT);  // button
-  pinMode (slaveSelectPin, OUTPUT); //rx5808
-  pinMode (spiDataPin, OUTPUT); //rx5808
-  pinMode (spiClockPin, OUTPUT); //rx5808
-  digitalWrite(slaveSelectPin, HIGH); //rx5808
-  digitalWrite(buttonPin, HIGH); //button
-  while (!Serial) {};  // Wait for the Serial port to initialise properly
-  Serial.println("Ready");
-
-  Wire.begin(slaveAddress);  // I2C slave address 8 setup.
-  Wire.onReceive(i2cReceive);  // register our handler function with the Wire library
-  Wire.onRequest(i2cTransmit);  // register data return handler
-
-  commsTable.rssiTrig = lapTrigger; // simulate rssiTrig
-  commsTable.channel = 0;  // simulate channel
-  printCommsTable();
-  setChannelModule(count); //set to channel defined by count
-}
-
-void setChannelModule(uint8_t channel)
-{
-  uint8_t i;
-  uint16_t channelData;
-
-  //channelData = pgm_read_word(&channelTable[channel]);
-  channelData = channelTable[channel];
-
-  // bit bash out 25 bits of data
-  // Order: A0-3, !R/W, D0-D19
-  // A0=0, A1=0, A2=0, A3=1, RW=0, D0-19=0
-  SERIAL_ENABLE_HIGH();
-  delay(2);
-  SERIAL_ENABLE_LOW();
-
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT1();
-
-  SERIAL_SENDBIT0();
-
-  // remaining zeros
-  for (i=20;i>0;i--)
-    SERIAL_SENDBIT0();
-
-  // Clock the data in
-  SERIAL_ENABLE_HIGH();
-  delay(2);
-  SERIAL_ENABLE_LOW();
-
-  // Second is the channel data from the lookup table
-  // 20 bytes of register data are sent, but the MSB 4 bits are zeros
-  // register address = 0x1, write, data0-15=channelData data15-19=0x0
-  SERIAL_ENABLE_HIGH();
-  SERIAL_ENABLE_LOW();
-
-  // Register 0x1
-  SERIAL_SENDBIT1();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-
-  // Write to register
-  SERIAL_SENDBIT1();
-
-  // D0-D15
-  //   note: loop runs backwards as more efficent on AVR
-  for (i=16;i>0;i--)
-  {
-    // Is bit high or low?
-    if (channelData & 0x1)
-    {
-      SERIAL_SENDBIT1();
-    }
-    else
-    {
-      SERIAL_SENDBIT0();
-    }
-
-    // Shift bits along to check the next one
-    channelData >>= 1;
-  }
-
-  // Remaining D16-D19
-  for (i=4;i>0;i--)
-    SERIAL_SENDBIT0();
-
-  // Finished clocking data in
-  SERIAL_ENABLE_HIGH();
-  delay(2);
-
-  digitalWrite(slaveSelectPin,LOW);
- digitalWrite(spiClockPin, LOW);
- digitalWrite(spiDataPin, LOW);
-}
-
-
-void setThreshold() {
-  if(lapTrigger == 0){
-    lapTrigger = RSSIread() - thresholdReduction;
-  }
-  else {
-    lapTrigger = 0;
-  }
-}
-
-// Read the RSSI value for the current channel
-int RSSIread(){
-  int rssi = 0;
-  int rssiA = 0;
-  for (uint8_t i=0; i<50; i++){
-    rssiA += analogRead(0); //Pin A0
-  }
-  rssiA = rssiA/50; //average of 50 RSSI readings
-
-  rssiArr[0]=rssiA;
-  for(uint8_t i=1; i<=5; i++) {
-    rssiArr[i] = (rssiArr[i-1] + rssiArr[i]) >> 1;
-  }
-
-  rssi = rssiArr[5];
-
-  Serial.print("Channel: ");
-  Serial.print(count);
-  Serial.print("  RSSI: ");
-  Serial.println(rssi);
-
-  return rssi;
-}
-
-void displayResult()
-{
-  float h, m, s, ms;
-  unsigned long over;
-//  String timeString;
-
-  elapsed = finished - start;
-
-  h = int(elapsed / 3600000);
-  over = elapsed % 3600000;
-  m = int(over / 60000);
-  over = over % 60000;
-  s = int(over / 1000);
-  ms = over % 1000;
-
-  commsTable.lap = commsTable.lap + 1;
-
-  Serial.print("Lap: ");
-  Serial.print(commsTable.lap);
-  Serial.print(" Time: ");
-//  Serial.print(h, 0);
-//  Serial.print("h ");
-  Serial.print(m, 0);
-  Serial.print("m ");
-  Serial.print(s, 0);
-  Serial.print("s ");
-  Serial.print(ms, 0);
-  Serial.println("ms");
-  Serial.println();
-
-  commsTable.minutes = m;
-  commsTable.seconds = s;
-  commsTable.milliseconds = int(ms);
-
-}
-
-void loop()
-{
-  rssi = RSSIread();
-
-  if (lapTrigger != 0){
-    if(rssi>lapTrigger) {
-        if(flag==0)
-        {
-          start=millis();
-          flag=1;
-
-          Serial.println("START");
-          commsTable.minutes = 0;
-          commsTable.seconds = 0;
-          commsTable.milliseconds = 0;
-         }
-         else {
-          finished=millis();
-          lapcheck = finished-start;
-          if(lapcheck>=minLap){
-            displayResult();
-            start=millis();
-            Serial.println(rssi);
-          }
-         }
-    }
-  }
-
-  buttonState = digitalRead(buttonPin);
-  if (buttonState == LOW)
-  {
-      setThreshold();
-      Serial.print("Lap trigger set at: ");
-      Serial.println(lapTrigger);
-
-  }
-  downcount=0;
-  while(digitalRead(buttonPin)== LOW)
-  {
-    downcount++;
-    delay(100);
-
-  }
-
-  if (dataReady) {
-    printCommsTable();
-    dataReady = false;
-  }
-
-  if (commsTable.control > 0) {
-//    printTxTable();
-    commsTable.control = 0;
-  }
-
-}
-
-void i2cReceive(int byteCount) {
-  if (byteCount == 0) return;
-
-  byte command = Wire.read();
-  commsTable.command = command;
-  if (command < 0x80) {
-    i2cHandleRx(command);
-  } else {
-    i2cHandleTx(command);
-  }
-  dataReady = true;
-}
-
-
-void i2cTransmit() {
-  // byte *txIndex = (byte*)&txTable[0];
-  byte numBytes = 0;
-  int t = 0; // temporary variable used in switch occasionally below
-
-  if ((commsTable.control & txRequest) == 0) {
-    // this request did not come with a command, it is read_byte()
-    commsTable.command = 0; // clear previous command
-  }
-  // clear the rxRequest bit; reset it for the next request
-  commsTable.control &= ~txRequest;
-
-  // If an invalid command is sent, we write nothing back. Master must
-  // react to the crickets.
-  switch (commsTable.command) {
-    case 0x00: // send slaveAddress.
-      txTable[0] = slaveAddress;
-      numBytes = 1;
-      break;
-    case 0x81:  // send rssiTrig
-      setThreshold();
-      commsTable.rssiTrig = lapTrigger;
-      txTable[0] = commsTable.rssiTrig;
-      numBytes = 1;
-      break;
-    case 0x82:  // send channel
-//      t = int(round(commsTable.light * 100));
-//      txTable[1] = (byte)(t >> 8);
-//      txTable[0] = (byte)(t & 0xFF);
-//      numBytes = 2;
-      txTable[0] = commsTable.channel;
-      numBytes = 1;
-      break;
-    case 0x90: // send minutes, seconds, and milliseconds as an array
-      txTable[0] = commsTable.lap;
-      txTable[1] = commsTable.minutes;
-      txTable[2] = commsTable.seconds;
-      txTable[3] = commsTable.milliseconds;
-      numBytes = 4;
-      break;
-    case 0x91: // send minutes channel
-      txTable[0] = commsTable.minutes;
-      numBytes = 1;
-      break;
-    case 0x92: // send seconds channel
-      txTable[0] = commsTable.seconds;
-      numBytes = 1;
-      break;
-    case 0x93: // send milliseconds channel
-      txTable[0] = commsTable.milliseconds;
-      numBytes = 1;
-      break;
-    default:
-      // If an invalid command is sent, we write nothing back. Master must
-      // react to the sound of crickets.
-      commsTable.control |= txFault;
-  }
-  if (numBytes > 0) {
-    Wire.write((byte *)&txTable, numBytes);
-  }
-}
-
-byte i2cHandleRx(byte command) {
-  byte result = 0;
-  // returns the number of bytes read, or FF if unrecognised
-  // command or mismatch between data expected and received
-
-  switch (command) {
-    case 0x0A:  // read three bytes in a block to set brightness and color
-      if (Wire.available() == 3) { // good write from Master
-        commsTable.minutes = Wire.read();
-        commsTable.seconds = Wire.read();
-        commsTable.milliseconds = Wire.read();
-        result = 3;
-      } else {
-        result = 0xFF;
-      }
-      break;
-
-    case 0x0B: // read the byte and reset the lap counter and flag
-      if (Wire.available() == 1) { // good write from Master
-        commsTable.lap = Wire.read();
-        flag =0;
-        result = 1;
-      } else {
-        result = 0xFF;
-      }
-      break;
-
-    case 0x0C:
-      if (Wire.available() == 1) { // good write from Master
-        commsTable.seconds = Wire.read();
-        result = 1;
-      } else {
-        result = 0xFF;
-      }
-      break;
-
-    case 0x0D:
-      if (Wire.available() == 1) { // good write from Master
-        commsTable.milliseconds = Wire.read();
-        result = 1;
-      } else {
-        result = 0xFF;
-      }
-      break;
-
-    default:
-      result = 0xFF;
-  }
-
-  if (result == 0xFF) commsTable.control |= rxFault;
-  return result;
-
-}
-
-byte i2cHandleTx(byte command) {
-  // signal to i2cTransmit() that a pending command is ready
-  commsTable.control |= txRequest;
-  return 0;
-
-}
-
-void printCommsTable() {
-  String builder = "";
-  builder = "commsTable contents:";
-  Serial.println(builder);
-  builder = "  command: ";
-  builder += String(commsTable.command, HEX);
-  Serial.println(builder);
-  builder = "  control: ";
-  builder += String(commsTable.control, HEX);
-  Serial.println(builder);
-  builder = "  RSSI Triger: ";
-  builder += commsTable.rssiTrig;
-//  builder += (char)186;  // the "º" symbol
-  builder += " dB";
-  Serial.println(builder);
-  builder = "  Channel: ";
-  builder += commsTable.channel;
-//  builder += " lux";
-  Serial.println(builder);
-  builder = "  Minutes: ";
-  builder += commsTable.minutes;
-  Serial.println(builder);
-  builder = "  Seconds: ";
-  builder += commsTable.seconds;
-  Serial.println(builder);
-  builder = "  Milliseconds: ";
-  builder += commsTable.milliseconds;
-  Serial.println(builder);
-  Serial.println();
-}
-
-void printTxTable() {
-  Serial.println("Transmit Table");
-  for (byte i = 0; i < 32; i++) {
-    Serial.print("  ");
-    Serial.print(i);
-    Serial.print(": ");
-    Serial.println(txTable[i]);
-  }
-  Serial.println();
-}
-


change command 'l' to 'p'

change command 'l' to 'p'

--- arduino-neopixel.ino
+++ arduino-neopixel.ino
@@ -93,11 +93,11 @@
         Serial.println(argument);
       }
     }
-    else if(command=="l") { // set slit position
+    else if(command=="p") { // set position
       // TODO argument check
       // argument is float
       slit_position = argument.toFloat();
-      Serial.print("set slit position: ");
+      Serial.print("set position: ");
       Serial.println(slit_position);
       updateLED();
     }


removing code and sme of the redundant safeties we placed in order to increase write speed.

--- Calibration/liveCode/overclockAccel/overclockAccel.ino
+++ Calibration/liveCode/overclockAccel/overclockAccel.ino
@@ -87,73 +87,9 @@
   }
 }

-bool sdWrite(String data) {
+void sdWrite(String data) {
   File dataFile = SD.open(FILENAME, FILE_WRITE);
   // if the file is available, write to it:
-  if (dataFile) {
-    dataFile.print(data);
-    dataFile.print(", ");
-    dataFile.close();
-    // print to the serial port too:
-  }
-  // if the file isn't open, pop up an error:
-  else {
-    dataFile.close();
-  }
+  dataFile.print(data + ", ");
+  dataFile.close();
 }
-char * floatToString(char * outstr, double val, byte precision, byte widthp){
- char temp[16]; //increase this if you need more digits than 15
- byte i;
-
- temp[0]='\0';
- outstr[0]='\0';
-
- if(val < 0.0){
-   strcpy(outstr,"-\0");  //print "-" sign
-   val *= -1;
- }
-
- if( precision == 0) {
-   strcat(outstr, ltoa(round(val),temp,10));  //prints the int part
- }
- else {
-   unsigned long frac, mult = 1;
-   byte padding = precision-1;
-
-   while (precision--)
-     mult *= 10;
-
-   val += 0.5/(float)mult;      // compute rounding factor
-
-   strcat(outstr, ltoa(floor(val),temp,10));  //prints the integer part without rounding
-   strcat(outstr, ".\0"); // print the decimal point
-
-   frac = (val - floor(val)) * mult;
-
-   unsigned long frac1 = frac;
-
-   while(frac1 /= 10)
-     padding--;
-
-   while(padding--)
-     strcat(outstr,"0\0");    // print padding zeros
-
-   strcat(outstr,ltoa(frac,temp,10));  // print fraction part
- }
-
- // generate width space padding
- if ((widthp != 0)&&(widthp >= strlen(outstr))){
-   byte J=0;
-   J = widthp - strlen(outstr);
-
-   for (i=0; i< J; i++) {
-     temp[i] = ' ';
-   }
-
-   temp[i++] = '\0';
-   strcat(temp,outstr);
-   strcpy(outstr,temp);
- }
-
- return outstr;
-}


Basic pixel moving program & hex

Basic pixel moving program & hex


Added functionality for one wire

Added functionality for one wire

--- Temperature/Temperature.ino
+++ Temperature/Temperature.ino
@@ -12,24 +12,35 @@
 #include <Wire.h>
 #include <ros.h>
 #include <std_msgs/String.h>
+#include <OneWire.h>
+#include <DallasTemperature.h>

 #define SENSOR_COUNT 1
 #define TYPE_ANALOG 0
 #define ANALOG_PIN 0

+#define TYPE_ONE_WIRE 1
+#define ONE_WIRE_PIN 1
+
 #define MAX_SAMPLE_RATE 10
 #define MAX_SAMPLE_COUNT 10
 #define MAX_DELTA 0.5
+
+typedef struct one_wire_data {
+  OneWire one_wire;
+  DallasTemperature dt_sensor;
+} OneWireData;

 typedef struct temperature_sensor {
   unsigned int id;
   float prev_temp;
   float curr_temp;
   unsigned int type;
-  unsigned int address;
+  unsigned int pin;
   unsigned int sample_rate;
   unsigned int sample_count;
   unsigned long publisher_timer;
+  OneWireData* one_wire_data;
 } TemperatureSensor;

 const TemperatureSensor default_sensor {
@@ -89,17 +100,28 @@
 }

 static void handle_analog(TemperatureSensor* sensor) {
-  unsigned int raw_voltage = analogRead(sensor->address);
+  unsigned int raw_voltage = analogRead(sensor->pin);
   float volts = raw_voltage / 205.0f;
   float celsius = 100.0 * volts - 50;
   sensor->curr_temp = celsius;
 }

-static void create_sensor(unsigned int id, unsigned int address, unsigned int type, TemperatureSensor* sensor) {
+static void handle_one_wire(TemperatureSensor* sensor) {
+  sensor->one_wire_data->dt_sensor.requestTemperatures();
+  sensor->curr_temp = sensor->one_wire_data->dt_sensor.getTempCByIndex(0);
+}
+
+static void create_sensor(unsigned int id, unsigned int pin, unsigned int type, TemperatureSensor* sensor) {
   *sensor = default_sensor;
   sensor->id = id;
-  sensor->address = address;
+  sensor->pin = pin;
   sensor->type = type;
+  if(type == TYPE_ONE_WIRE) {
+    sensor->one_wire_data = (OneWireData*)malloc(sizeof(OneWireData));
+    sensor->one_wire_data->one_wire = OneWire(sensor->pin);
+    sensor->one_wire_data->dt_sensor = DallasTemperature(&sensor->one_wire_data->one_wire);
+    sensor->one_wire_data->dt_sensor.begin();
+  }
 }

 void setup()
@@ -112,6 +134,10 @@
   TemperatureSensor analog_sensor;
   create_sensor(sensor_count, ANALOG_PIN, TYPE_ANALOG, &analog_sensor);
   sensors[sensor_count++] = analog_sensor;
+
+  TemperatureSensor one_wire_sensor;
+  create_sensor(sensor_count, ONE_WIRE_PIN, TYPE_ONE_WIRE, &one_wire_sensor);
+  sensors[sensor_count++] = one_wire_sensor;
 }

 void loop()


style fix

style fix

--- WiFi_CONNECTION/WiFi_CONNECTION.ino/WiFi_CONNECTION.ino.ino
+++ WiFi_CONNECTION/WiFi_CONNECTION.ino/WiFi_CONNECTION.ino.ino
@@ -1,4 +1,3 @@
-
 #include "esp_wpa2.h"
 #include <WiFi.h>


mpu: rename var

mpu: rename var

--- MPU6050/MPU6050_temperature/MPU6050_temperature.ino
+++ MPU6050/MPU6050_temperature/MPU6050_temperature.ino
@@ -7,7 +7,7 @@
 #include "Wire.h"
 #endif

-MPU6050 accelgyro;
+MPU6050 mpu;

 void setup()
 {
@@ -21,21 +21,21 @@

     // initialize device
     Serial.println("Initializing I2C devices...");
-    accelgyro.initialize();
+    mpu.initialize();

     // verify connection
     Serial.println("Testing device connections...");
     Serial.println(
-            accelgyro.testConnection() ?
+            mpu.testConnection() ?
                     "MPU6050 connection successful" :
                     "MPU6050 connection failed");

-    accelgyro.setTempSensorEnabled(1);
+    mpu.setTempSensorEnabled(1);
 }

 void loop()
 {
-    int16_t t = accelgyro.getTemperature();
+    int16_t t = mpu.getTemperature();
     Serial.print("temperature: ");
 //    Serial.print(t);
 //    Serial.print("  ");


Delete Inputs.ino

Delete Inputs.ino

--- Inputs.ino
+++ Inputs.ino
@@ -1,75 +0,0 @@
-// These functions are used to interpret input from the rotary encoder and the integrated button
-
-void EncoderTranslate (int x) {
-  pulseMod = (pulses/pulseAdjust) % x;
-}
-
-
-
-// ** BUTTON **//
-void Button(){
-  // read the pushbutton input pin:
-  buttonState = digitalRead(buttonPin);
-  if (buttonState != lastButtonState) {
-    if (buttonState == HIGH) {
-      buttontime = millis();
-      buttonstate = true;
-    }
-    else {
-      buttontime = millis() - buttontime;
-      buttonstate = false;
-      delay(10);
-    }
-  }
-  lastButtonState = buttonState;
-}
-
-// ** INTERRUPT ** //
-
-void A_RISE(){
- detachInterrupt(0);
- A_SIG=1;
-
- if(B_SIG==0)
- pulses++;//moving forward
- if(B_SIG==1)
- pulses--;//moving reverse
- //Serial.println(pulses);
- attachInterrupt(0, A_FALL, FALLING);
-}
-
-void A_FALL(){
-  detachInterrupt(0);
- A_SIG=0;
-
- if(B_SIG==1)
- pulses++;//moving forward
- if(B_SIG==0)
- pulses--;//moving reverse
- //Serial.println(pulses);
- attachInterrupt(0, A_RISE, RISING);
-}
-
-void B_RISE(){
- detachInterrupt(1);
- B_SIG=1;
-
- if(A_SIG==1)
- pulses++;//moving forward
- if(A_SIG==0)
- pulses--;//moving reverse
- //Serial.println(pulses);
- attachInterrupt(1, B_FALL, FALLING);
-}
-
-void B_FALL(){
- detachInterrupt(1);
- B_SIG=0;
-
- if(A_SIG==0)
- pulses++;//moving forward
- if(A_SIG==1)
- pulses--;//moving reverse
- //Serial.println(pulses);
- attachInterrupt(1, B_RISE, RISING);
-}


Update

Update

--- Master.ino
+++ Master.ino
@@ -456,7 +456,13 @@
   th_Val[0].r_t = ((float) r * thErrOFF);
   th_Val[0].g_t = ((float) g * thErrOFF);
   th_Val[0].b_t = ((float) b * thErrOFF);
+<<<<<<< Updated upstream
   Serial.print("\nWaiting for threshold sequence");
+=======
+  Serial.print("\nWaiting for threshold sequence or type ");
+  Serial.print(sync);
+  Serial.println(" to send threshold sequence");
+>>>>>>> Stashed changes
   uint16_t r_h, g_h, b_h;
   setupMain: //come back here untill sync seq start
   if (Serial.available() > 0) //if there is an input data
@@ -814,7 +820,10 @@
       flashDotOrDash(redLED, false);
       flashDotOrDash(blueLED, false);
       flashDotOrDash(greenLED, false);
+<<<<<<< Updated upstream
       Serial.print(" ");
+=======
+>>>>>>> Stashed changes
     delay(trnsDELAY);
   }
   Serial.println(); //for testing **************************************
@@ -876,3 +885,58 @@
     else
         digitalWrite(color, LOW);
 }
+
+void ledControl(int led)
+{
+  if(led == 0)
+  {
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, LOW);
+  }
+  else if(led == 1)
+  {
+    digitalWrite(redLED, HIGH);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, LOW);
+  }
+  else if(led == 2)
+  {
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, HIGH);
+    digitalWrite(blueLED, LOW);
+  }
+  else if(led == 3)
+  {
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, HIGH);
+  }
+  else if(led == 4)
+  {
+    digitalWrite(redLED, HIGH);
+    digitalWrite(greenLED, HIGH);
+    digitalWrite(blueLED, LOW);
+  }
+  else if(led == 5)
+  {
+    digitalWrite(redLED, HIGH);
+    digitalWrite(greenLED, LOW);
+    digitalWrite(blueLED, HIGH);
+  }
+  else if(led == 6)
+  {
+    digitalWrite(redLED, LOW);
+    digitalWrite(greenLED, HIGH);
+    digitalWrite(blueLED, HIGH);
+  }
+  else if(led == 7)
+  {
+    digitalWrite(redLED, HIGH);
+    digitalWrite(greenLED, HIGH);
+    digitalWrite(blueLED, HIGH);
+  }
+  else
+    Serial.println("Please enter a number between 0 and 7!!");
+}
+


Cleaned up setup and loop functions by splitting some functions out to *hopefully* make it more readable.

--- boxbeatsspectrum.ino
+++ boxbeatsspectrum.ino
@@ -22,69 +22,67 @@
 TCPClient client;
 byte server[] = { 192, 168, 1, 103 };
 int port = 54555;
+int hueValue = 100;

 void setup() {
-    Particle.function("nextMode", nextMode);
-    Particle.function("previousMode", previousMode);
     // Serial.begin(9600);

-    Particle.subscribe("NEXT_MODE", handleNextMode);
-    Particle.subscribe("PREVIOUS_MODE", handlePreviousMode);
-
-    if (client.connect(server, port)) {
-        Serial.println("Connected");
-        Particle.publish("Connected");
-    } else {
-        Serial.println("Connection failed");
-    }
+    setupModeFunctions()
+    connectToRemote();

     spectrum = new SpectrumEqualizer();
     animations = new LEDAnimations(spectrum);
+
     FastLED.addLeds<LED_TYPE, BORDER_LED_PIN, COLOR_ORDER>(animations->borderLeds, NUM_BORDER_LEDS).setCorrection(TypicalLEDStrip);
     FastLED.addLeds<LED_TYPE, SHELF_LED_PIN, COLOR_ORDER>(animations->allShelves, NUM_SHELF_LEDS).setCorrection(TypicalLEDStrip);
-
-    //  for(int i=0;i<LEDS_PER_SHELF;i++) {
-    //     animations->bottomShelfLeds[i] = animations->allShelves[i];
-    // }
-    for(int j=0;j<NUM_BORDER_LEDS;j++) {
-      animations->borderLeds[j] = 0;
-    }
-    for(int j=0;j<NUM_SHELF_LEDS;j++) {
-      animations->allShelves[j] = 0;
-    }
-    FastLED.show();

     animations->currentPattern = 0;
 }

-int hueValue = 100;
 void loop() {
     if(client.connected()) {
-        client.println("s");
-        if(client.available()) {
-            char hueFromController[3];
-            int readCount = 0;
-            while(client.available()) {
-                char c = client.read();
-                hueFromController[readCount] = c;
-                readCount++;
-            }
-            hueValue = atoi(hueFromController);
-        }
-        animations->hueCounter = hueValue;
+        readColorFromRemote();
     } else {
-        if (client.connect(server, port)) {
-            Serial.println("Reconnected");
-            Particle.publish("Reconnected");
-        } else {
-            Serial.println("Reconnection failed");
-        }
+      connectToRemote();
     }
     animations->runCurrentAnimation();
     FastLED.show();
     // FastLED.delay(1000 / FRAMES_PER_SECOND);

     // EVERY_N_MILLISECONDS(20) { animations->hueCounter++; } // slowly cycle the "base color" through the rainbow
+}
+
+void readColorFromRemote() {
+  client.println("s");
+  if(client.available()) {
+      char hueFromController[3];
+      int readCount = 0;
+      while(client.available()) {
+          char c = client.read();
+          hueFromController[readCount] = c;
+          readCount++;
+      }
+      hueValue = atoi(hueFromController);
+  }
+  animations->hueCounter = hueValue;
+}
+
+void connectToRemote() {
+  if (client.connect(server, port)) {
+      Serial.println("Connected");
+      Particle.publish("Connected");
+  } else {
+      Serial.println("Connection failed");
+      Particle.publish("Connection failed");
+  }
+}
+
+void setupModeFunctions() {
+  Particle.function("nextMode", nextMode);
+  Particle.function("previousMode", previousMode);
+
+  Particle.subscribe("NEXT_MODE", handleNextMode);
+  Particle.subscribe("PREVIOUS_MODE", handlePreviousMode);
 }

 int nextMode(String mode) {
@@ -96,7 +94,7 @@
 }

 void handleNextMode(const char *eventName, const char *data) {
-    nextMode("fuckoff");
+    nextMode("notSureWhyIHaveToDoItLikeThis");
 }

 int previousMode(String mode) {


Update example.ino

Update example.ino

--- firmware/examples/example.ino
+++ firmware/examples/example.ino
@@ -1,36 +1,107 @@
 /***************************************************
-  Library code written by Limor Fried/Ladyada for Adafruit Industries.
-  Example code written by Mauricio Sanchez Duque/sheva29
-
+  This is a library for the CAP1188 I2C/SPI 8-chan Capacitive Sensor
+
+  Designed specifically to work with the CAP1188 sensor from Adafruit
+  ----> https://www.adafruit.com/products/1602
+
+  These sensors use I2C/SPI to communicate, 2+ pins are required to
+  interface
+  Adafruit invests time and resources providing this open source code,
+  please support Adafruit and open-source hardware by purchasing
+  products from Adafruit!
+
+  Written by Limor Fried/Ladyada for Adafruit Industries.
+  BSD license, all text above must be included in any redistribution
  ****************************************************/
+
+//#include <Wire.h>
+//#include <SPI.h>
+#include <TreeLamp/Adafruit_CAP1188.h>

+// Reset Pin is used for I2C or SPI
+#define CAP1188_RESET  4

-// This #include statement was automatically added by the Particle IDE.
-#include "Adafruit_CAP1188.h"
+// CS pin is used for software or hardware SPI
+#define CAP1188_CS  10

-//For SDA in Photon use pin D0
-//For SCK in Photon use pin D1
-// VIN works with both 3.3V and 5V
+// These are defined for software SPI, for hardware SPI, check your
+// board's SPI pins in the Arduino documentation
+//#define CAP1188_MOSI  11
+//#define CAP1188_MISO  12
+//#define CAP1188_CLK  13

-Adafruit_CAP1188 cap = Adafruit_CAP1188();
+volatile byte interrupt = 0;
+
+// Publish debugging info to Dashboard TBA.
+int debug = 0;
+
+// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
+// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
+// On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
+// On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21
+
+// Use I2C, no reset pin!
+ Adafruit_CAP1188 cap = Adafruit_CAP1188();
+
+// Or...Use I2C, with reset pin
+//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_RESET);
+
+// Or... Hardware SPI, CS pin & reset pin
+//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CS, CAP1188_RESET);
+
+// Or.. Software SPI: clock, miso, mosi, cs, reset
+//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CLK, CAP1188_MISO, CAP1188_MOSI, CAP1188_CS, CAP1188_RESET);

 void setup() {
+  Serial.begin(9600);
+  Serial.println("CAP1188 test!");
+  pinMode(3,INPUT);
+  // Raise SPI slave select (SS) pins
+  // Communication begins when you drop the individual select signals to LOW
+  digitalWrite(10,HIGH);
+

-  Serial.begin(19200);
-  cap.begin();
-
-  //we set our level of sensitivity
-  //we pass values from 1 to 7
-  cap.setSensitivity(6);
-
+  // Initialize the sensor, if using i2c you can pass in the i2c address
+  // if (!cap.begin(0x28)) {
+  if (!cap.begin()) {
+    Serial.println("CAP1188 not found");
+    Particle.publish("CAP1188 not found");
+    while (1);
+  }
+  Serial.println("CAP1188 found!");
+  Particle.publish("CAP1188 found!");
+  pinMode(3, INPUT);
+  // Turn off multitouch so only one button pressed at a time
+  cap.writeRegister(0x2A, 0x80);  // 0x2A default 0x80 use 0x41  — Set multiple touches back to off
+  cap.writeRegister(0x41, 0x39);  // 0x41 default 0x39 use 0x41  — Set "speed up" setting back to off
+  cap.writeRegister(0x72, 0x00);  // 0x72 default 0x00  — Sets LED links back to off (default)
+  cap.writeRegister(0x44, 0x41);  // 0x44 default 0x40 use 0x41  — Set interrupt on press but not release
+  cap.writeRegister(0x28, 0x00);  // 0x28 default 0xFF use 0x00  — Turn off interrupt repeat on button hold
+  //EIFR = 1; // clear flag for interrupt 1
+  attachInterrupt(1, routine_Interrupt_CAP1188, FALLING);
 }

 void loop() {
+
+  // Serial.println(digitalRead(3));
+  uint8_t touched = cap.touched();

-  //cap.touchedAnalog(1) will call second electrode analog values
-  for (byte i = 0; i < 8; i++){
-    int8_t analogValues = cap.touchedAnalog(i);
-    Serial.print(i);Serial.print(" : ");Serial.print(analogValues);Serial.print("\t");
+  if (touched == 0) {
+    // No touch detected
+    // return;
+  }
+
+  for (uint8_t i=0; i<8; i++) {
+    if (touched & (1 << i)) {
+      Serial.print("C"); Serial.print(i+1); Serial.print("\t");
+    }
   }
   Serial.println();
+  delay(50);
+  Serial.print("Interrupt: ");  Serial.println(interrupt);
+  Particle.publish("Interrupt: ",Serial.println(interrupt);)
 }
+
+void routine_Interrupt_CAP1188()  {
+  ++interrupt;
+}


better arduino code + reading incoming data

--- sounddetector/sounddetector.ino
+++ sounddetector/sounddetector.ino
@@ -3,9 +3,11 @@
 void checkSoundState(int pin, int level);
 void sendSoundState(int pin, int state);
 void sendSoundLevel(int pin, int level);
+void turnOffMonitoring();

 /* Variables -----------------------------------------------------------------*/
-#define NodeSerial Serial1 // makes it a little easier to read the code :-) NodeSerial is the serial port that communicates with Node.js, accesible as /dev/ttyATH0 in Linux
+// #define NodeSerial Serial1 // makes it a little easier to read the code :-) NodeSerial is the serial port that communicates with Node.js, accesible as /dev/ttyATH0 in Linux
+#define NodeSerial Serial // connect directly with laptop (for debugging purposes)

 int incomingByte = 0;

@@ -16,22 +18,26 @@
 const int soundPins[] = {A0, A1, A2, A3, A4, A5};

 const int pinCount = 6;
-int soundValues[pinCount] = {0};
-
-unsigned int signalMax[pinCount] = {0};
-unsigned int signalMin[pinCount] = {1024};
+int soundValues[] = {0, 0, 0, 0, 0, 0};
+
+unsigned int signalMax[] = {0, 0, 0, 0, 0, 0};
+unsigned int signalMin[] = {1024, 1024, 1024, 1024, 1024, 1024};
 unsigned long startMillis = millis();

-int silenceThreshold[pinCount] = {200};
-int soundThreshold[pinCount] = {300};
-int nrOfConsecutiveSilenceSamplesBeforeFlippingToSilence[pinCount] = {12};
-int nrOfConsecutiveSoundSamplesBeforeFlippingToSound[pinCount] = {5};
-
-int silenceSampleCounter[pinCount] = {0};
-int soundSampleCounter[pinCount] = {0};
-
-int currentState[pinCount] = {0};
-int currentSoundState[pinCount] = {0};
+
+int silenceSampleCounter[] = {0, 0, 0, 0, 0, 0};
+int soundSampleCounter[] = {0, 0, 0, 0, 0, 0};
+
+int currentState[] = {0, 0, 0, 0, 0, 0};
+int currentSoundState[] = {0, 0, 0, 0, 0, 0};
+
+// settings:
+int silenceThreshold[] = {200, 200, 200, 200, 200, 200};
+int soundThreshold[] = {300, 300, 300, 300, 300, 300};
+int nrOfConsecutiveSilenceSamplesBeforeFlippingToSilence[] = {12, 12, 12, 12, 12, 12};
+int nrOfConsecutiveSoundSamplesBeforeFlippingToSound[] = {5, 5, 5, 5, 5, 5};
+
+

 bool debug = false;

@@ -45,9 +51,6 @@

     // register every led pin as output:
     pinMode(ledPins[pin], OUTPUT);
-
-    while (!Serial);
-    Serial.println(nrOfConsecutiveSilenceSamplesBeforeFlippingToSilence[pin]);
   }

   while (!NodeSerial); //hang till NodeSerial is up
@@ -89,7 +92,8 @@
       checkSoundState(pin, soundValues[pin]);

       // send sound level (if required):
-      sendSoundLevel(pin, soundValues[pin]);
+      if(pin == 0)
+        sendSoundLevel(pin, soundValues[pin]);
     }
   }

@@ -97,7 +101,8 @@
 }

 void checkSoundState(int pin, int level){
-  if(pin != 0 && pin != 5) return; //only check pin 0 for now
+  // if(pin != 0) return; //only check pin 0 for now
+

   if( currentState[pin] == 0 ) {
     // IF SILENCE
@@ -144,38 +149,31 @@
   if(debug) Serial.println(state);

   // always start with 3 bytes of 255 so that Node.js knows were this 'packet' starts:
-  NodeSerial.write(255);
-  NodeSerial.write(255);
-  NodeSerial.write(255);
-  NodeSerial.write(02); // 02 = soundstate
-  NodeSerial.write(pin); // channel
-  NodeSerial.write(state); // volumeon
-  NodeSerial.write(0); // empty byte, because we always expect 4 bytes ;-)
-}
-
-
-
-void sendSoundLevel(int pin, int level){
-  return;
-
-
-  if(pin != 0) return; //debug
-
-
-
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)02); // 02 = soundstate
+  NodeSerial.write((byte)pin); // channel
+  NodeSerial.write((byte)state); // volumeon
+  NodeSerial.write((byte)0); // empty byte, because we always expect 4 bytes ;-)
+}
+
+
+
+void sendSoundLevel(int pin, int level){
   uint16_t number = level;
   uint16_t mask   = B11111111;
   uint8_t first_half   = number >> 8;
   uint8_t sencond_half = number & mask;

   // always start with 3 bytes of 255 so that Node.js knows were this 'packet' starts:
-  NodeSerial.write(255);
-  NodeSerial.write(255);
-  NodeSerial.write(255);
-  NodeSerial.write(03); // 03 = soundlevel
-  NodeSerial.write(pin);  // channel
-  NodeSerial.write(first_half);   // value, first byte (Big Endian)
-  NodeSerial.write(sencond_half); // value, last byte  (Big Endian)
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)255);
+  NodeSerial.write((byte)03); // 03 = soundlevel
+  NodeSerial.write((byte)pin);  // channel
+  NodeSerial.write((byte)first_half);   // value, first byte (Big Endian)
+  NodeSerial.write((byte)sencond_half); // value, last byte  (Big Endian)
 }

@@ -186,32 +184,34 @@
 void readIncommingNodeData() {
   // READ RESPONSE
   if( NodeSerial.available() ) {
-    // 1. empty incomingByte:
+    // empty incomingByte:
     incomingByte = 0x00;

-    // 2. read first byte:
+    // read first byte:
     incomingByte = NodeSerial.read();
-
-    // 3. read the rest of the buffer so that it's empty
+
+    if(incomingByte == 255) {
+      turnOffMonitoring();
+      if(debug) Serial.print("turn off monitoring");
+    }else{
+      // do something with the channel:
+      int channel = incomingByte;
+      if(debug) Serial.print("do something with channel ");
+      if(debug) Serial.println(channel, DEC);
+    }
+
+    // read the rest of the buffer so that it's empty
     while(NodeSerial.available())
     {
       NodeSerial.read();
     }
-
-    if(incomingByte != 0x00)
-    {
-      if(debug) Serial.print("> incomingByte:");
-      if(debug) Serial.println(incomingByte);
-
-      if (incomingByte == 97){ //97='a' in ASCII
-        digitalWrite(ledPins[0], HIGH);
-      }else{
-        digitalWrite(ledPins[0], LOW);
-      }
-    }
-  }
-}
-
-
-
-
+  }
+}
+
+void turnOffMonitoring() {
+
+}
+
+
+
+


Manage luminance only on 7Segment, fixes #1

--- Timerino.ino
+++ Timerino.ino
@@ -846,17 +846,17 @@
     timer_mode = (selstatus == HIGH) ? MODFSTFREE : MODLINFREE;
     say_timermode();
   }
-
+
+#if 0 == MYMODEL
   lum = analogRead(lumpin);

-
-  if (lum < lastlum-10 || lum > lastlum+10) {
-
+  if (lum < lastlum-10 || lum > lastlum+10) {
     brightness = 100*lum/1024;
     Serial7Segment.write(0x7A);  // Brightness control command
     Serial7Segment.write((byte) brightness);
     lastlum = lum;
   }
+#endif

   if (running && btnhigh) {
     // shut down the relay and pause the timer


Changed the UI to be independent of the ranges of the motor. All calls now return -1 to 1 and the middleware maps that to the motor ranges in the ArduinoPhysics.js file.

--- arduino/OpenROV/OpenROV.ino
+++ arduino/OpenROV/OpenROV.ino
@@ -40,6 +40,8 @@
 int v = MIDPOINT;
 int s = MIDPOINT;
 int smoothingIncriment = 5; //How aggressive the throttle changes
+int deadZone_min = MIDPOINT;
+int deadZone_max = MIDPOINT;
 void setup(){

   Serial.begin(115200);
@@ -73,7 +75,14 @@
   // the way to the target this time.
   double x = target - current;
   int sign = (x>0) - (x<0);
-  return(current + sign * (min(abs(target - current), smoothingIncriment)));
+  int adjustedVal = current + sign * (min(abs(target - current), smoothingIncriment));
+  // skip the deadzone
+  if (sign<0) {
+    return (min(adjustedVal,deadZone_min));
+  } else if(sign>0){
+    return (max(adjustedVal,deadZone_max));
+  } else
+    return (adjustedVal);
 }

 void loop(){
@@ -110,6 +119,14 @@
       Serial.print("*settings:");
       Serial.print("smoothingIncriment|");
       Serial.print(String(smoothingIncriment) + ";");
+      Serial.print("deadZone_min|" + String(deadZone_min) + ";");
+      Serial.print("deadZone_max|" + String(deadZone_max) + ";");
+    }
+    else if (cmd.cmp("updateSetting")) {
+      cmd.parse(array);
+      smoothingIncriment = array[1];
+      deadZone_min = array[2];
+      deadZone_max = array[3];
     }
     else {
       motors.stop();


major code base refactoring operation (int red,green,blue -> crgb

--- wip/wip.ino
+++ wip/wip.ino
@@ -53,26 +53,36 @@
 //    sparkleAt(i, leds, NUM_LEDS, 0, 0, 25, 350);
 //  }

-  flashyShit(leds, NUM_LEDS, 2000);
+//  flashyShit(leds, NUM_LEDS, 2000);
 //  int randred = random8(50);
 //  int randgreen = random8(50);
 //  int randblue = random8(50);
-  randomIndexFill(leds, NUM_LEDS, 0, 30, 10, 2600);
+//  randomIndexFill(leds, NUM_LEDS, 0, 30, 10, 2600);

 //  void sparkleAt(int index, CRGB *leds, int numOfLeds, int red, int green, int blue, int ms){

-  for (int i = 0; i < NUM_LEDS; i++){
-    sparkleAt(i, leds, NUM_LEDS, 0, 0, 25, 350);
-  }
-
-  for (int i = (NUM_LEDS - 1); i >=0; i--){
-  sparkleAt(i, leds, NUM_LEDS, 0, 0, 25, 350);
-  }
-
-}
-
-void runner(CRGB *leds, int numOfLeds, int red, int green, int blue, int duration) {
+//  for (int i = 0; i < NUM_LEDS; i++){
+//    sparkleAt(i, leds, NUM_LEDS, 0, 0, 25, 350);
+//  }
+//
+//  for (int i = (NUM_LEDS - 1); i >=0; i--){
+//  sparkleAt(i, leds, NUM_LEDS, 0, 0, 25, 350);
+//  }
+
+//  CRGB test = CRGB(10,10,10);
+//
+//  for (int i = 0; i < NUM_LEDS; i++){
+//    leds[i] = test;
+//    FastLED.show();
+//    delay(500);
+//  }
+//
+//  clearAll(leds, NUM_LEDS);
+  runner(leds, NUM_LEDS, CRGB(10,0,20), 3000);
+}
+
+void runner(CRGB *leds, int numOfLeds, CRGB color, int duration) {

   int i, wait;

@@ -80,24 +90,24 @@

   for (i = 0; i < numOfLeds; i++) {

-    leds[i].setRGB(red, green, blue);
-    FastLED.show();
-    delay(wait);
-    leds[i].setRGB(0, 0, 0);
+    leds[i] = color;
+    FastLED.show();
+    delay(wait);
+    leds[i] = CRGB::Black;
     FastLED.show();
   }

   for (i = (numOfLeds - 1); i > 0; i--) {

-    leds[i].setRGB(red, green, blue);
-    FastLED.show();
-    delay(wait);
-    leds[i].setRGB(0, 0, 0);
-    FastLED.show();
-  }
-}
-
-void progressbar(CRGB *leds, int numOfLeds, int red, int green, int blue, int duration) {
+    leds[i] = color;
+    FastLED.show();
+    delay(wait);
+    leds[i] = CRGB::Black;
+    FastLED.show();
+  }
+}
+
+void progressbar(CRGB *leds, int numOfLeds, CRGB color, int duration) {

   int i, wait;

@@ -105,34 +115,34 @@

   for (i = 0; i < numOfLeds; i++) {

-    leds[i].setRGB(red, green, blue);
-    FastLED.show();
-    delay(wait);
-  }
-
-  for (i = 0; i < numOfLeds; i++) {
-
-    leds[i].setRGB(0, 0, 0);
+    leds[i] = color;
+    FastLED.show();
+    delay(wait);
+  }
+
+  for (i = 0; i < numOfLeds; i++) {
+
+    leds[i] = CRGB::Black;
     FastLED.show();
     delay(wait);
   }

   for (i = numOfLeds; i >= 0; i--) {

-    leds[i].setRGB(red, green, blue);
+    leds[i] = color;
     FastLED.show();
     delay(wait);
   }

   for (i = numOfLeds; i >= 0; i--) {

-    leds[i].setRGB(0, 0, 0);
-    FastLED.show();
-    delay(wait);
-  }
-}
-
-void progressbarCentered(CRGB *leds, int numOfLeds, int red, int green, int blue, int duration) {
+    leds[i] = CRGB::Black;
+    FastLED.show();
+    delay(wait);
+  }
+}
+
+void progressbarCentered(CRGB *leds, int numOfLeds, CRGB color, int duration) {

   int i, center, inv, wait;

@@ -142,8 +152,8 @@
   for (i = center; i < numOfLeds; i++) {

     inv = (numOfLeds - i) - 1;
-    leds[i].setRGB(red, green, blue);
-    leds[inv].setRGB(red, green, blue);
+    leds[i] = color;
+    leds[inv] = color;
     FastLED.show();
     delay(wait);
   }
@@ -151,14 +161,14 @@
   for (i = (numOfLeds - 1); i >= center; i--) {

     inv = (numOfLeds - i) - 1;
-    leds[i].setRGB(0, 0, 0);
-    leds[inv].setRGB(0, 0, 0);
-    FastLED.show();
-    delay(wait);
-  }
-}
-
-void blinking(CRGB *leds, int numOfLeds, int red, int green, int blue, int duration) {
+    leds[i] = CRGB::Black;
+    leds[inv] = CRGB::Black;
+    FastLED.show();
+    delay(wait);
+  }
+}
+
+void blinking(CRGB *leds, int numOfLeds, CRGB color, int duration) {

   int i, wait;

@@ -166,7 +176,7 @@

   for (i = 0; i < numOfLeds; i++) {

-    leds[i].setRGB(red, green, blue);
+    leds[i] = color;
   }

   FastLED.show();
@@ -174,14 +184,14 @@

   for (i = 0; i < numOfLeds; i++) {

-    leds[i].setRGB(0, 0, 0);
+    leds[i] = CRGB::Black;
   }

   FastLED.show();
   delay(wait);
 }

-void blinkingParts(CRGB *leds, int numOfLeds, int parts, int red, int green, int blue, int duration) {
+void blinkingParts(CRGB *leds, int numOfLeds, int parts, CRGB color, int duration) {

   int i, steps, wait;

@@ -190,7 +200,7 @@

   for (i = 0; i < numOfLeds; i += steps) {

-    leds[i].setRGB(red, green, blue);
+    leds[i] = color;
   }

   FastLED.show();
@@ -198,7 +208,7 @@

   for (i = 0; i < numOfLeds; i += steps) {

-    leds[i].setRGB(0, 0, 0);
+    leds[i] = CRGB::Black;
   }

   FastLED.show();
@@ -206,17 +216,21 @@
 }

 //ms = time of pulse
-void pulse(CRGB *leds, int numOfLeds, int red, int green, int blue, int ms) {
+void pulse(CRGB *leds, int numOfLeds, CRGB color, int ms) {
   int numOfSteps = 20;

   for (int step = 0; step < numOfSteps; step++) {
+
+    int red = color.r;
+    int green = color.g;
+    int blue = color.b;

     int tempRed = red - (step * (red / numOfSteps));
     int tempGreen = green - (step * (green / numOfSteps));
     int tempBlue = blue - (step * (blue / numOfSteps));

     for (int i = 0; i < numOfLeds; i++) {
-      leds[i].setRGB(tempRed, tempGreen, tempBlue);
+      leds[i] = CRGB(tempRed, tempGreen, tempBlue);
     }

     FastLED.show();
@@ -225,40 +239,40 @@
 }

-void sparkleAt(int index, CRGB *leds, int numOfLeds, int red, int green, int blue, int ms){
+void sparkleAt(int index, CRGB *leds, int numOfLeds, CRGB color, int ms){
   if (index >= numOfLeds){
     //out of bounds
   }else{
     int spread = 2;
     int spreadIndex = 0;

-    leds[index].setRGB(red, green, blue);
+    leds[index] = color;
     FastLED.show();

     int i;
     for (i =  1; i <= spread; i++){
       delay(ms/(spread+1));
       if (index - (i-1)>=0){
-        leds[index - (i-1)].setRGB(0,0,0);
+        leds[index - (i-1)] = CRGB::Black;
       }

       if (index + (i-1)<numOfLeds){
-        leds[index + (i-1)].setRGB(0,0,0);
+        leds[index + (i-1)] = CRGB::Black;
       }

-      leds[index + i].setRGB(red, green, blue);
-      leds[index - i].setRGB(red, green, blue);
+      leds[index + i] = color;
+      leds[index - i] = color;

       FastLED.show();
     }

      delay(ms/(spread+1));
       if (index - (i-1)>=0){
-        leds[index - (i-1)].setRGB(0,0,0);
+        leds[index - (i-1)] = CRGB::Black;
       }

       if (index + (i-1)<numOfLeds){
-        leds[index + (i-1)].setRGB(0,0,0);
+        leds[index + (i-1)] = CRGB::Black;
       }

       FastLED.show();
@@ -266,48 +280,48 @@
   }
 }

-void sparkleAtRandomIndex(CRGB *leds, int numOfLeds, int red, int green, int blue, int ms){
+void sparkleAtRandomIndex(CRGB *leds, int numOfLeds, CRGB color, int ms){
   int randomIndex = random8(numOfLeds);
-  sparkleAt(randomIndex, leds, numOfLeds, red, green, blue, ms);
-}
-
-void flashyShit(CRGB *leds, int numOfLeds, int ms){
+  sparkleAt(randomIndex, leds, numOfLeds, color, ms);
+}
+
+void flashyShit(CRGB *leds, int numOfLeds, int ms, int maxIntensity){
   int middle = numOfLeds / 2;
   int randred,randgreen,randblue;

   for (int i = 0; i < numOfLeds / 2; i ++){
-    randred = random8(7);
-    randgreen = random8(7);
-    randblue = random8(7);
+    randred = random8(maxIntensity);
+    randgreen = random8(maxIntensity);
+    randblue = random8(maxIntensity);

-    leds[middle + i].setRGB(randred,randgreen,randblue);
-    leds[middle - i].setRGB(randred,randgreen,randblue);
+    leds[middle + i] = CRGB(randred,randgreen,randblue);
+    leds[middle - i] = CRGB(randred,randgreen,randblue);
     FastLED.show();
     delay(ms / (numOfLeds / 2));

-    leds[middle + i].setRGB(0,0,0);
-    leds[middle - i].setRGB(0,0,0);
+    leds[middle + i] = CRGB::Black;
+    leds[middle - i] = CRGB::Black;
     FastLED.show();
   }

   for (int i = numOfLeds / 2; i >= 0; i --){
-    randred = random8(7);
-    randgreen = random8(7);
-    randblue = random8(7);
+    randred = random8(maxIntensity);
+    randgreen = random8(maxIntensity);
+    randblue = random8(maxIntensity);

-    leds[middle + i].setRGB(randred,randgreen,randblue);
-    leds[middle - i].setRGB(randred,randgreen,randblue);
+    leds[middle + i] = CRGB(randred,randgreen,randblue);
+    leds[middle - i] = CRGB(randred,randgreen,randblue);
     FastLED.show();
     delay(ms / (numOfLeds / 2));

-    leds[middle + i].setRGB(0,0,0);
-    leds[middle - i].setRGB(0,0,0);
-    FastLED.show();
-
-  }
-}
-
-void randomIndexFill(CRGB *leds, int numOfLeds, int red, int green, int blue, int ms){
+    leds[middle + i] = CRGB::Black;
+    leds[middle - i] = CRGB::Black;
+    FastLED.show();
+
+  }
+}
+
+void randomIndexFill(CRGB *leds, int numOfLeds, CRGB color, int ms){
   int ledsOn[numOfLeds];
   memset(ledsOn, 0, sizeof(ledsOn));
   int onCounter = 0;
@@ -315,7 +329,7 @@
   while (onCounter < numOfLeds){
     int randomIndex = random8(numOfLeds);
     if (ledsOn[randomIndex] == 0){
-      leds[randomIndex].setRGB(red, green, blue);
+      leds[randomIndex] = color;
       FastLED.show();

       ledsOn[randomIndex] = 1;
@@ -333,7 +347,7 @@

 void clearAll(CRGB *leds, int numOfLeds){
   for (int i = 0; i < numOfLeds; i++){
-    leds[i].setRGB(0,0,0);
-  }
-  FastLED.show();
-}
+    leds[i] = CRGB::Black;
+  }
+  FastLED.show();
+}


AD7173-8.ino added channel enable/disable function

--- AD7173-8.ino
+++ AD7173-8.ino
@@ -132,8 +132,9 @@
 ==================================================
 */
 void resync_adc() {
+    /* toggle the chip select */
     digitalWrite(SS, HIGH);
-    delay(100);
+    delay(1);
     digitalWrite(SS, LOW);
 }

@@ -207,6 +208,36 @@
     }
     /* return error code */
     return 0;
+}
+
+/*
+=================================
+enables or disables ADC channels
+@param byte - channel
+@param bool - status
+@return int - error code
+=================================
+*/
+int set_channel(byte channel, bool status) {
+    /* when channel out of range */
+    if (channel < 0x10 || channel > 0x1F) {
+        if (DEBUG_ENABLED) {
+            Serial.println("channel out of range");
+        }
+        return 1;
+    }
+    byte value[2];
+    /* read specified channel configuration */
+    read_adc_register(channel, value, 2);
+    /* clear the enable bit */
+    value[0] &= ~(1 << 7);
+    /* enable or disable this channel */
+    value[0] |= (status << 7);
+    /* set the correct analog inputs */
+    byte ain = (channel & 0x0F);
+    value[1] = (ain << 5) | (ain + 1);
+    /* update specified channel configuration */
+    write_adc_register(channel, value, 2);
 }

 /*
@@ -235,32 +266,34 @@
 */
 int set_adc_data_mode(int mode) {
     byte value[2];
+    /* diable continuous read mode */
+    read_adc_register(IFMODE_REG, value, 2);
+    value[1] &= 0xF7;
+    write_adc_register(IFMODE_REG, value, 2);
+
+    /* when continuous read mode */
     if (mode == CONTINUOUS_READ_MODE) {
         /* set the adc to continuous read mode, the data register can be read directly when DATA_READY */
         set_adc_data_mode(CONTINUOUS_CONVERSION_MODE);
         read_adc_register(IFMODE_REG, value, 2);
         value[1] |= 0x08;
         write_adc_register(IFMODE_REG, value, 2);
+    /* when single conversion mode */
     } else if (mode == SINGLE_CONVERSION_MODE) {
-        /* set the adc to single conversion mode, the conversion has to be triggered manually */
-        read_adc_register(IFMODE_REG, value, 2);
-        value[1] &= 0xF7;
-        write_adc_register(IFMODE_REG, value, 2);
+        /* set the adc to single conversion mode, the ADC conversion has to be triggered manually */
         read_adc_register(ADCMODE_REG, value, 2);
         value[1] &= 0x8F;
         value[1] |= 0x10;
         write_adc_register(ADCMODE_REG, value, 2);
+    /* when continuous conversion mode */
     } else if (mode == CONTINUOUS_CONVERSION_MODE) {
-        /* set the adc to continuous conversion mode, the communication register has to be notified for a read */
-        read_adc_register(IFMODE_REG, value, 2);
-        value[1] &= 0xF7;
-        write_adc_register(IFMODE_REG, value, 2);
+        /* set the adc to continuous conversion mode, the communication register has to be notified for a ADC read */
         read_adc_register(ADCMODE_REG, value, 2);
         value[1] &= 0x8F;
         value[1] |= 0x00;
         write_adc_register(ADCMODE_REG, value, 2);
+    /* unknown data read mode */
     } else {
-        /* unknown data read mode */
         return 1;
     }
     return 0;


removing magic numbers inlace of already established DEFINE values.

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -121,15 +121,15 @@
 uint8_t first_tune=1;
 boolean force_menu_redraw=0;
 uint16_t rssi_best=0; // used for band scaner
-uint16_t rssi_min_a=0;
-uint16_t rssi_max_a=0;
-uint16_t rssi_setup_min_a=0;
-uint16_t rssi_setup_max_a=0;
-#ifdef USE_DIVERSITY
-    uint16_t rssi_min_b=0;
-    uint16_t rssi_max_b=0;
-    uint16_t rssi_setup_min_b=0;
-    uint16_t rssi_setup_max_b=0;
+uint16_t rssi_min_a=RSSI_MIN_VAL;
+uint16_t rssi_max_a=RSSI_MAX_VAL;
+uint16_t rssi_setup_min_a=RSSI_MIN_VAL;
+uint16_t rssi_setup_max_a=RSSI_MAX_VAL;
+#ifdef USE_DIVERSITY
+    uint16_t rssi_min_b=RSSI_MIN_VAL;
+    uint16_t rssi_max_b=RSSI_MAX_VAL;
+    uint16_t rssi_setup_min_b=RSSI_MIN_VAL;
+    uint16_t rssi_setup_max_b=RSSI_MAX_VAL;
 #endif
 uint8_t rssi_setup_run=0;

@@ -427,15 +427,15 @@
                 if(state==STATE_RSSI_SETUP)
                 {
                     // prepare new setup
-                    rssi_min_a=0;
-                    rssi_max_a=400; // set to max range
-                    rssi_setup_min_a=400;
-                    rssi_setup_max_a=0;
-#ifdef USE_DIVERSITY
-                    rssi_min_b=0;
-                    rssi_max_b=400; // set to max range
-                    rssi_setup_min_b=400;
-                    rssi_setup_max_b=0;
+                    rssi_min_a=50;
+                    rssi_max_a=300; // set to max range
+                    rssi_setup_min_a=RSSI_MAX_VAL;
+                    rssi_setup_max_a=RSSI_MIN_VAL;
+#ifdef USE_DIVERSITY
+                    rssi_min_b=50;
+                    rssi_max_b=300; // set to max range
+                    rssi_setup_min_b=RSSI_MAX_VAL;
+                    rssi_setup_max_b=RSSI_MIN_VAL;
 #endif
                     rssi_setup_run=RSSI_SETUP_RUN;
                 }


was missing a variable in my last update. Added it

--- AutoREQ2.ino
+++ AutoREQ2.ino
@@ -200,7 +200,7 @@
     {

       Serial.println("Connected!");
-
+      char c; //char variable for buffer value
       //converts decimals in buffer to chars and sends across to server
       for (byte i=0; i < bufferSize; i++)
       {


Update ESP8266_library_test.ino

Update ESP8266_library_test.ino

--- examples/ESP8266_library_test/ESP8266_library_test.ino
+++ examples/ESP8266_library_test/ESP8266_library_test.ino
@@ -2,7 +2,7 @@
 #include <ESP8266wifi.h>

 #define sw_serial_rx_pin 4 //  Connect this pin to TX on the esp8266
-#define sw_serial_tx_pin 6 //  Connect this pin to TX on the esp8266
+#define sw_serial_tx_pin 6 //  Connect this pin to RX on the esp8266
 #define esp8266_reset_pin 5 // Connect this pin to CH_PD on the esp8266, not reset. (let reset be unconnected)

 SoftwareSerial swSerial(sw_serial_rx_pin, sw_serial_tx_pin);


Update HelloOLED.ino

Update HelloOLED.ino

I deleted the unnecessary "src" subfolder from the path to "ACROBOTIC_SSD1306.h".

--- examples/HelloOLED/HelloOLED.ino
+++ examples/HelloOLED/HelloOLED.ino
@@ -18,7 +18,7 @@
   information.  All text above must be included in any redistribution.
 */
 #include <Wire.h>
-#include "src/ACROBOTIC_SSD1306.h"
+#include "ACROBOTIC_SSD1306.h"

 void setup()
 {


Added door sensor

Added door sensor

--- closet_mote_v0_1/closet_mote_v0_1.ino
+++ closet_mote_v0_1/closet_mote_v0_1.ino
@@ -12,16 +12,24 @@
 #define TMP36_PIN  A0
 #define temperature_topic "sensor/temperature"

+#define DOOR_PIN 5
+#define door_topic "sensor/door"
+
 WiFiClient espClient;
 PubSubClient client(espClient);

 unsigned long previousMillis = 0;  // will store last temp was read
 const long interval = 10000;        // interval at which to read sensor

+bool oldDoorState;
+
 void setup() {
   Serial.begin(115200);
   setup_wifi();
   client.setServer(mqtt_server, 1883);
+
+  pinMode(DOOR_PIN, INPUT_PULLUP);
+  oldDoorState = !digitalRead(DOOR_PIN);
 }

 void setup_wifi() {
@@ -69,10 +77,19 @@
   }
   client.loop();

-  gettemperature();
+  getDoorState();
+  getTemperature();
 }

-void gettemperature() {
+void getDoorState() {
+  int doorState = digitalRead(DOOR_PIN);
+  if (doorState != oldDoorState) {
+    client.publish(door_topic, doorState ? "CLOSED" : "OPEN", true);
+    oldDoorState = doorState;
+  }
+}
+
+void getTemperature() {
   // Wait at least 2 seconds seconds between measurements.
   // if the difference between the current time and last time you read
   // the sensor is bigger than the interval you set, read the sensor


working fona example without progmem

working fona example without progmem

--- examples/mqtt_fona/mqtt_fona.ino
+++ examples/mqtt_fona/mqtt_fona.ino
@@ -25,8 +25,9 @@

 /*************************** FONA Pins ***********************************/

-#define FONA_RX 2
-#define FONA_TX 3
+// Default pins for Feather 32u4 FONA
+#define FONA_RX  9
+#define FONA_TX  8
 #define FONA_RST 4
 SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

@@ -52,14 +53,8 @@

 /************ Global State (you don't need to change this!) ******************/

-// Store the MQTT server, username, and password in flash memory.
-// This is required for using the Adafruit MQTT library.
-const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
-const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
-const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;
-
 // Setup the FONA MQTT class by passing in the FONA class and MQTT server and login details.
-Adafruit_MQTT_FONA mqtt(&fona, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
+Adafruit_MQTT_FONA mqtt(&fona, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

 // You don't need to change anything below this line!
 #define halt(s) { Serial.println(F( s )); while(1);  }
@@ -72,11 +67,11 @@

 // Setup a feed called 'photocell' for publishing.
 // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
-const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
+const char PHOTOCELL_FEED[]     = AIO_USERNAME "/feeds/photocell";
 Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);

 // Setup a feed called 'onoff' for subscribing to changes.
-const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
+const char ONOFF_FEED[]            = AIO_USERNAME "/feeds/onoff";
 Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);

 /*************************** Sketch Code ************************************/
@@ -125,17 +120,6 @@
   MQTT_connect();

   Watchdog.reset();
-
-  // this is our 'wait for incoming subscription packets' busy subloop
-  Adafruit_MQTT_Subscribe *subscription;
-  while ((subscription = mqtt.readSubscription(5000))) {
-    if (subscription == &onoffbutton) {
-      Serial.print(F("Got: "));
-      Serial.println((char *)onoffbutton.lastread);
-    }
-  }
-
-  Watchdog.reset();
   // Now we can publish stuff!
   Serial.print(F("\nSending photocell val "));
   Serial.print(x);
@@ -146,6 +130,16 @@
   } else {
     Serial.println(F("OK!"));
     txfailures = 0;
+  }
+
+  Watchdog.reset();
+  // this is our 'wait for incoming subscription packets' busy subloop
+  Adafruit_MQTT_Subscribe *subscription;
+  while ((subscription = mqtt.readSubscription(5000))) {
+    if (subscription == &onoffbutton) {
+      Serial.print(F("Got: "));
+      Serial.println((char *)onoffbutton.lastread);
+    }
   }

   // ping the server to keep the mqtt connection alive, only needed if we're not publishing


Update Docking.ino

Update Docking.ino

--- 10Docking/Docking.ino
+++ 10Docking/Docking.ino
@@ -1,6 +1,7 @@
 #include <Servo.h>

 Servo magnetServo;
+int val = 2;

 void setup(){
   Serial.begin(9600);
@@ -12,17 +13,20 @@
 }

 void loop(){
-  int val = 789789;
-  if (val == 789789 || val != digitalRead(3)){
+  if (val == 2){
+    val = digitalRead(3);
+  }
+
+  else if (val != digitalRead(3)){
     val = digitalRead(3);

     if (val == HIGH){
-      Serial.write("ON");
+      Serial.println("ON");
       Serial.println("000"); //healthy
     }

     else if (val == LOW){
-      Serial.write("OFF");
+      Serial.println("OFF");
       Serial.println("000"); //healthy
     }

@@ -33,7 +37,7 @@

   else{}

-  /*if (Serial.available()){
+  if (Serial.available()){
     char i = Serial.read();

     if (i == '0'){
@@ -63,6 +67,6 @@
     else{
       Serial.println("002"); //Something is wrong with the RPi Communication
     }
-  }*/
+  }
   delay(50);
 }


Update Adafruit_Bluefruit_LE.ino

Update Adafruit_Bluefruit_LE.ino

--- examples/Boards_BLE/Adafruit_Bluefruit_LE/Adafruit_Bluefruit_LE.ino
+++ examples/Boards_BLE/Adafruit_Bluefruit_LE/Adafruit_Bluefruit_LE.ino
@@ -29,9 +29,10 @@

 #define BLYNK_USE_DIRECT_CONNECT

-#include <BlynkSimpleSerialBLE.h>
+#include <SPI.h>
 #include <BLEPeripheral.h>
 #include "BLESerial.h"
+#include <BlynkSimpleSerialBLE.h>

 // You should get Auth Token in the Blynk App.
 // Go to the Project Settings (nut icon).


OLED contrast set to 10

OLED contrast set to 10

Another OLED lifetime saving feature. With set to 10 is bright enough to see all labels, even more readable on cheap OLEDs.

--- usermods/ssd1306_i2c_oled_u8g2/wled06_usermod.ino
+++ usermods/ssd1306_i2c_oled_u8g2/wled06_usermod.ino
@@ -19,6 +19,7 @@
 void userSetup() {
   u8x8.begin();
   u8x8.setPowerSave(0);
+    u8x8.setContrast(10); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
   u8x8.setFont(u8x8_font_chroma48medium8_r);
   u8x8.drawString(0, 0, "Loading...");
 }


Update weather168_list2_57600.ino

Update weather168_list2_57600.ino

--- weather168_list2_57600/weather168_list2_57600.ino
+++ weather168_list2_57600/weather168_list2_57600.ino
@@ -66,21 +66,20 @@
 lcd.setCursor(6,0);
 lcd.print((char)223);
 lcd.print("C");
-lcd.setCursor(11,0);
+
+lcd.setCursor(10,0);
 lcd.print(int(humidity_SHT20));
-lcd.print("%");
+lcd.print(" %");
 lcd.print("RH");

 lcd.setCursor(0,1);
 lcd.print(pressure_BMP);
 lcd.setCursor(6,1);
 lcd.print("kPa");
-lcd.setCursor(14,1);
-lcd.rightToLeft();
+
+lcd.setCursor(10,1);
 lcd.print(lux_BH1750);
-lcd.setCursor(15,1);
-lcd.leftToRight();
-lcd.print("L");
+lcd.print(" L");
  delay(1000);

  }


change speed

change speed

--- hook___dail/hook___dail.ino
+++ hook___dail/hook___dail.ino
@@ -89,7 +89,7 @@
   //Serial.begin(9600);
   // initiate the BT serial at 38400 which is the default
   // speed at which the BT AT mode operates at
-  BT.begin(38400);
+  BT.begin(9600);
   Serial.println("BT started at 38400");

   // self explanatory


Updates batlog.ino to use new SSD1306 API

--- batlog.ino
+++ batlog.ino
@@ -23,8 +23,11 @@
   BatLog.min_count = 0;
   BatLog.interval = interval;

+  oled.setBufferRegion(SSD1306_REGION_TOP);
+
   if (EEPROM[0] != cookie) {
     oled.drawString("Making new batlog", 0, 0, FONT_SIZE, COLOR_RED);
+
     EEPROM[0] = cookie;
     // filled the log with 0xFF so we know later when the log stops.
     for (uint16_t addr = 1; addr < 1024; ++addr) {
@@ -52,9 +55,10 @@
         printlog = 0;
         break;
       } else {
-        oled.drawString("\x80", 0, ypos, FONT_SIZE, COLOR_BLACK);
+        oled.b_drawString("\x80", 0, ypos, FONT_SIZE, COLOR_BLACK);
         sprintf(_sbuf, "%d", 3-diff/1000);
-        oled.drawString(_sbuf, 0, ypos, FONT_SIZE, COLOR_RED);
+        oled.b_drawString(_sbuf, 0, ypos, FONT_SIZE, COLOR_RED);
+        oled.uploadBuffer();
         delay(250);
       }
     }


Add simple error message

Add simple error message

--- EmotionalClothing.ino
+++ EmotionalClothing.ino
@@ -53,7 +53,7 @@
   FatReader file;

   file.open(root, "MACNTOSH.WAV");
-  wave.create(file);
+  if (!wave.create(file)) Serial.println("Can't open the file");
   wave.play();
   while(wave.isplaying) delay(100);
 }


Cleaning up code

Cleaning up code

--- source/monkeyDAB/monkeyDAB_display.ino
+++ source/monkeyDAB/monkeyDAB_display.ino
@@ -4,7 +4,7 @@
 //           display-related routines
 // author  : Thomas Euler
 // history : 2016-10-09, created
-//           2016-12-24, changed to use OLED 128x32 I2C display
+//           2016-12-24, changed to use OLED 128x64 I2C display
 //
 //--------------------------------------------------------------------------------
 #define LOGO16_GLCD_HEIGHT 16


Updated Arduino driver.

Updated Arduino driver.

Removed magic numbers and did some thinking as to the type of control I want to have for pitch, yaw, roll, etc.

--- KSPboard.ino
+++ KSPboard.ino
@@ -1,43 +1,56 @@
 /// Justin Lee <justin at kitten dot pink>
 //
 // Arduino driver for the KSPboard game
-// controller.  See LICENSE and README.
+// controller.  See LICENSE and README
+// for more information.

-byte pinLED = 6, pinSwitch = 2;
-int delayTime = 10;

-byte pitch, yaw, roll, throttle;
+#define ENABLE 1
+#define DISABLE 0
+
+#define SERIAL_SPEED 115200
+
+#define PIN_LED 13
+
+#define LOOP_DELAY 1
+#define START_DELAY 5
+
+
+byte pinSwitch = 2;
+
+volatile byte pitch, yaw, roll, throttle;

 byte state = 1;

 void setupSerial()
 {
-  Serial.begin(115200);
+  Serial.begin(SERIAL_SPEED);
   Serial.println();
   Serial.flush();

+  Serial.print(1); // enable code, super secure
   Serial.print(1);
   Serial.print(1);
-  Serial.print(1);
-
-  delay(5);
 }

 void updateState()
 {
+  // tells the python client when to close
   state = digitalRead(pinSwitch);
-  digitalWrite(pinLED, state);
+  digitalWrite(PIN_LED, state);

   if (state)
-    Serial.print(1);
+    Serial.print(ENABLE);
   else
-    Serial.print(0);
+    Serial.print(DISABLE);
 }

 void updateHelm()
 {
+  // helm are always sent without enable code
+
   Serial.print(pitch);
   Serial.print(yaw);
   Serial.print(roll);
@@ -46,23 +59,30 @@

 void updateOps()
 {
-  Serial.print(0);
+  Serial.print(DISABLE);
 }

 void setup()
 {
-  pinMode(pinLED, OUTPUT); // debug led
+  pinMode(PIN_LED, OUTPUT); // debug led
+  digitalWrite(PIN_LED, HIGH);
+
   pinMode(pinSwitch, INPUT_PULLUP); // active-low switch

   setupSerial();
+
+  delay(START_DELAY);
 }

 void loop()
 {
- updateState();
- updateHelm();
- updateOps();
+  if (state)
+  {
+    updateState();
+    updateHelm();
+    updateOps();
+  }

- delay(1);
+  delay(LOOP_DELAY);
 }


Fixed button mechanics

Fixed button mechanics

--- ManeAvis.ino
+++ ManeAvis.ino
@@ -70,10 +70,11 @@

 AlarmToneLanguage *parser;

-int rssi = 0;
+int32_t rssi = 0;
 uint32_t freeMemory = 0;
 uint32_t frameTime = 0;
-uint32_t loopTime = 0;
+
+uint32_t clicks = 0;

 uint8_t previousMinute;

@@ -97,7 +98,6 @@
   Display.display();
   #endif

-  Particle.variable("loopTime", loopTime);
   Particle.variable("frameTime", frameTime);
   Particle.variable("freeMemory", freeMemory);
   Particle.variable("rssi", rssi);
@@ -106,19 +106,14 @@
 }

 void loop() {
-  uint32_t start = millis();
-
   if(!Particle.connected()) {
     Particle.connect();
   }

-  if(stateMachine.isInState(Alarm) || stateMachine.isInState(Snuze)) {
-    button.Update();
-  }
+  button.Update();
+  clicks = button.clicks;

   stateMachine.update();
-
-  loopTime = millis() - start;
 }

 void enterStart() {
@@ -158,8 +153,6 @@
 void enterAlarm() {
   Particle.publish("alarm:start", Time.format(Time.now(), TIME_FORMAT_ISO8601_FULL));

-  /*alarmRuntime.start();*/
-
   RGB.color(0, 0, 255);

   parser = new AlarmToneLanguage(song);
@@ -169,9 +162,7 @@
 void updateAlarm() {
   RGB.brightness(map(abs((millis() % 2000) - 1000), 0, 1000, 0, 255));

-  uint8_t clicks = button.clicks;
-
-  switch(button.clicks) {
+  switch(clicks) {
     case -1:
       stateMachine.transitionTo(Clock);
       return;
@@ -179,11 +170,6 @@
       stateMachine.transitionTo(Snuze);
       return;
   }
-
-  // TODO: Remove when snooze/dismiss functionality is implemented
-  /*if(alarmRuntime.check(ALARM_LENGTH)) {
-    stateMachine.transitionTo(Clock);
-  }*/
 }

 void exitAlarm() {
@@ -204,7 +190,7 @@
 }

 void updateSnuze() {
-  if(button.clicks == -1) {
+  if(clicks == -1) {
     stateMachine.transitionTo(Clock);
     return;
   }


Code for reciever part

Code for reciever part

--- Reciever.ino
+++ Reciever.ino
@@ -13,8 +13,8 @@
 #define thErrON 0.9
 #define thErrOFF 1.3
 #define setupWaitTime 10 //(ms)
-#define fbTime 1000
-#define cycTime 1000
+#define fbTime 1000 // feedback led high time
+#define cycTime 1000 // feedback led low time
 Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_4X);


Brightness fix

Brightness fix

--- Sattrack.ino
+++ Sattrack.ino
@@ -181,7 +181,7 @@
                 Serial.println("Can't get data");
                 Serial.println();
               #endif
-              LedStrip.SetAnimColor(0x9f,0x0,0x0);
+              LedStrip.SetAnimColor(0x0,0x0,0x0,0x9f,0x0,0x0);
               LedStrip.AnimStart(ANIM_WAIT);
               dataError = true;
               updatejdtime = jd + 0.000694;   // retry update in 1 min
@@ -239,6 +239,8 @@
     }else{
       brightness = (passPredictions[0].jdstop-jd)/(passPredictions[0].jdstop-passPredictions[0].jdmax);
     }
+    if (brightness < 0.0){brightness = 0.0;}
+    if (brightness > 1.0){brightness = 1.0;}
     Color = RgbColor::LinearBlend(RgbColor(0,0,0), Color, brightness);
   }


Switch RFDuino to use BLEPeripheral

Switch RFDuino to use BLEPeripheral

--- examples/Boards_Bluetooth/RFDuino_BLE/RFDuino_BLE.ino
+++ examples/Boards_Bluetooth/RFDuino_BLE/RFDuino_BLE.ino
@@ -18,37 +18,49 @@
   This example shows how to use RFduino BLE
   to connect your project to Blynk.

+  Note: This requires RFduino support package:
+    https://github.com/RFduino/RFduino
+
+  And BLEPeripheral library
+    from http://librarymanager/all#BLEPeripheral
+    or https://github.com/sandeepmistry/arduino-BLEPeripheral
+
   NOTE: BLE support is in beta!

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

-//#define BLYNK_USE_DIRECT_CONNECT
+#define BLYNK_USE_DIRECT_CONNECT

 #define BLYNK_PRINT Serial

-#include <BlynkSimpleRFduinoBLE.h>
-#include <RFduinoBLE.h>
+#include <BlynkSimpleBLEPeripheral.h>
+#include <BLEPeripheral.h>

+// You should get Auth Token in the Blynk App.
+// Go to the Project Settings (nut icon).
 char auth[] = "YourAuthToken";

-void setup()
-{
+// Create ble serial instance, parameters are ignored for MicroBit
+BLESerial SerialBLE(0, 0, 0);
+
+void setup() {
   Serial.begin(9600);

-  RFduinoBLE.deviceName = "RFDuino";
-  RFduinoBLE.advertisementInterval = MILLISECONDS(300);
-  RFduinoBLE.txPowerLevel = -20;  // (-20dbM to +4 dBm)
-
-  // start the BLE stack
-  RFduinoBLE.begin();
+  SerialBLE.setLocalName("Blynk");
+  SerialBLE.setDeviceName("Blynk");
+  SerialBLE.setAppearance(0x0080);
+  SerialBLE.begin();

   Serial.println("Waiting for connections...");

-  Blynk.begin(auth);
+  Blynk.begin(SerialBLE, auth);
 }

-void loop()
-{
-  Blynk.run();
+void loop() {
+  SerialBLE.poll();
+
+  if (SerialBLE) {    // If BLE is connected...
+    Blynk.run();
+  }
 }


fix bug

fix bug

--- WiFiScan/WiFiScan.ino
+++ WiFiScan/WiFiScan.ino
@@ -110,13 +110,17 @@
     tft.setTextColor(green, bg);
     tft.print(WiFi.SSID(j));

+    int16_t x = tft.getCursorX();
+    if(x < X_SIG)
+      tft.fillRect(x, y, X_SIG - x, LH, bg);
+
     tft.setCursor(X_SIG, y);
-    tft.setTextColor(cyan, bg);
+    tft.setTextColor(cyan,bg);
     tft.printf("%3d", WiFi.RSSI(j));

     tft.setTextSize(1);
     tft.setCursor(tft.getCursorX()+1, y + 8);
-    tft.setTextColor(blue, bg);
+    tft.setTextColor(blue,bg);
     tft.print("dBm");

     y += LH;


Delete tftbmp.ino

Delete tftbmp.ino

--- examples/tftbmp/tftbmp.ino
+++ examples/tftbmp/tftbmp.ino
@@ -1,201 +0,0 @@
-// Tft Touch Shield V1.0 demo - Display BMP file
-
-#include <SD.h>
-#include <TFT.h>
-
-// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!)
-// the file itself
-File bmpFile;
-
-// information we extract about the bitmap file
-int bmpWidth, bmpHeight;
-uint8_t bmpDepth, bmpImageoffset;
-
-void setup()
-{
-    Serial.begin(9600);
-
-    Tft.init();
-
-    Serial.print("Initializing SD card...");
-    pinMode(53, OUTPUT); //53 is used as chip select pin
-
-    if (!SD.begin(53)) { //53 is used as chip select pin
-        Serial.println("failed!");
-        return;
-    }
-    Serial.println("SD OK!");
-
-}
-
-void loop()
-{
-    Tft.setOrientation(0);
-
-    //Image 1
-    bmpFile = SD.open("flower.bmp");
-    if (! bmpFile) {
-        Serial.println("didnt find image");
-        while (1);
-    }
-
-    if (! bmpReadHeader(bmpFile)) {
-        Serial.println("bad bmp");
-        return;
-    }
-
-    Serial.print("image size ");
-    Serial.print(bmpWidth, DEC);
-    Serial.print(", ");
-    Serial.println(bmpHeight, DEC);
-    bmpdraw(bmpFile, 0, 0);
-    delay(3000);
-    bmpFile.close();
-
-    //Image 2
-    bmpFile = SD.open("hibiscus.bmp");
-    if (! bmpFile) {
-        Serial.println("didnt find image");
-        while (1);
-    }
-
-    if (! bmpReadHeader(bmpFile)) {
-        Serial.println("bad bmp");
-        return;
-    }
-
-    Serial.print("image size ");
-    Serial.print(bmpWidth, DEC);
-    Serial.print(", ");
-    Serial.println(bmpHeight, DEC);
-    bmpdraw(bmpFile, 0, 0);
-    delay(3000);
-}
-
-
-/*********************************************/
-// This procedure reads a bitmap and draws it to the screen
-// its sped up by reading many pixels worth of data at a time
-// instead of just one pixel at a time. increading the buffer takes
-// more RAM but makes the drawing a little faster. 20 pixels' worth
-// is probably a good place
-
-#define BUFFPIXEL 20
-
-void bmpdraw(File f, int x, int y) {
-    bmpFile.seek(bmpImageoffset);
-
-    uint32_t time = millis();
-    uint16_t p;
-    uint8_t g, b;
-    int i, j;
-
-    uint8_t sdbuffer[3 * BUFFPIXEL];  // 3 * pixels to buffer
-    uint8_t buffidx = 3*BUFFPIXEL;
-
-
-    for (i=0; i< bmpHeight; i++) {
-
-        Tft.setXY(x, y+bmpHeight-i);
-
-
-        for (j=0; j<bmpWidth; j++) {
-            // read more pixels
-            if (buffidx >= 3*BUFFPIXEL) {
-                bmpFile.read(sdbuffer, 3*BUFFPIXEL);
-                buffidx = 0;
-            }
-
-            // convert pixel from 888 to 565
-            b = sdbuffer[buffidx++];     // blue
-            g = sdbuffer[buffidx++];     // green
-            p = sdbuffer[buffidx++];     // red
-
-            p >>= 3;
-            p <<= 6;
-
-            g >>= 2;
-            p |= g;
-            p <<= 5;
-
-            b >>= 3;
-            p |= b;
-
-            // write out the 16 bits of color
-            Tft.sendData(p);
-        }
-    }
-    Serial.print(millis() - time, DEC);
-    Serial.println(" ms");
-}
-
-boolean bmpReadHeader(File f) {
-    // read header
-    uint32_t tmp;
-
-    if (read16(f) != 0x4D42) {
-        // magic bytes missing
-        return false;
-    }
-
-    // read file size
-    tmp = read32(f);
-    Serial.print("size 0x"); Serial.println(tmp, HEX);
-
-    // read and ignore creator bytes
-    read32(f);
-
-    bmpImageoffset = read32(f);
-    Serial.print("offset "); Serial.println(bmpImageoffset, DEC);
-
-    // read DIB header
-    tmp = read32(f);
-    Serial.print("header size "); Serial.println(tmp, DEC);
-    bmpWidth = read32(f);
-    bmpHeight = read32(f);
-
-
-    if (read16(f) != 1)
-    return false;
-
-    bmpDepth = read16(f);
-    Serial.print("bitdepth "); Serial.println(bmpDepth, DEC);
-
-    if (read32(f) != 0) {
-        // compression not supported!
-        return false;
-    }
-
-    Serial.print("compression "); Serial.println(tmp, DEC);
-
-    return true;
-}
-
-/*********************************************/
-// These read data from the SD card file and convert them to big endian
-// (the data is stored in little endian format!)
-
-// LITTLE ENDIAN!
-uint16_t read16(File f) {
-    uint16_t d;
-    uint8_t b;
-    b = f.read();
-    d = f.read();
-    d <<= 8;
-    d |= b;
-    return d;
-}
-
-// LITTLE ENDIAN!
-uint32_t read32(File f) {
-    uint32_t d;
-    uint16_t b;
-
-    b = read16(f);
-    d = read16(f);
-    d <<= 16;
-    d |= b;
-    return d;
-}
-
-


Perfboard prototype. Manualmode, outputpin, powergood.

--- kast.ino
+++ kast.ino
@@ -2,42 +2,97 @@
 // Herman Kopinga herman@kopinga.nl for 212 Fahrenheit 212f.nl

 #include <TimerOne.h>
+#include <Bounce.h>

 // Pin definitions.
-#define LEDOUT 14
+#define LEDOUT 4
 #define STATUSLED 11
 #define LIGHTSENSOR A1
 #define MULTIPLIER A2
+#define SENSITIVITY A3
+#define SOUND A0
+#define SOUNDLED 17
+#define MANUALMODE 0
+#define OVERRIDE 16

 // Globals
 unsigned long nextBlink;
+bool manualMode = 0;
+bool powerGood = 0;
+bool powerOverride = 0;
+Bounce overrideButton = Bounce(OVERRIDE, 20);

 void setup() {
   // Speed is ignored by Teensy.
   Serial.begin(115200);
-
-  pinMode(A0, INPUT);
+
+  pinMode(SOUND, INPUT);
   pinMode(LIGHTSENSOR, INPUT);
   pinMode(MULTIPLIER, INPUT);
   pinMode(A3, INPUT);
+  pinMode(A8, INPUT);
   pinMode(STATUSLED, OUTPUT);
   pinMode(LEDOUT, OUTPUT);
-
-  Timer1.initialize(128);
+  pinMode(SOUNDLED, OUTPUT);
+  pinMode(MANUALMODE, INPUT_PULLUP);
+  pinMode(OVERRIDE, INPUT_PULLUP);
+
+  // Timer1 library, 10 BIT PWM! (http://www.pjrc.com/teensy/td_libs_TimerOne.html)
+  Timer1.initialize(512);
   Timer1.pwm(LEDOUT, 0);
 }

 void loop() {
   // Blink internal LED: working.
+  // Also: do power check.
   if (millis() > nextBlink) {
     digitalWrite(STATUSLED, !digitalRead(STATUSLED));
     nextBlink = millis() + 1000;
+
+    // Auto shut off if supply voltage is below ~11.8v.
+    // Measured using 4.7k/10k voltage divider on A8.
+    if (analogRead(A8) > 770 || powerOverride) {
+      powerGood = 1;
+    }
+    else {
+      nextBlink = millis() + 50;
+      powerGood = 0;
+    }
+
+    // Handle the two buttons:
+    manualMode = digitalRead(MANUALMODE);
+    overrideButton.update();
+    if (overrideButton.fallingEdge()) {
+      powerOverride = !powerOverride;
+    }
   }
-  // If sound detected, restart countdown and fade in.
-
-  // Measure light intensity, map to output power (through adjustment pot).
-  int light = analogRead(LIGHTSENSOR);
-  Serial.println(light);
-  Timer1.setPwmDuty(LEDOUT, map(light, 0, 1024, 255, 0)*analogRead(MULTIPLIER)/1024);
+
+  if (powerGood) {
+    if (manualMode) {
+      Timer1.setPwmDuty(LEDOUT, map(analogRead(MULTIPLIER), 0, 1024, 255, 0));
+    }
+    else {
+      // If sound detected, restart countdown and fade in.
+      int soundLevel = analogRead(SOUND);
+      int sensitivityLevel = analogRead(SENSITIVITY);
+      //    Serial.print(sensitivityLevel);
+      //    Serial.print(" ");
+      //    Serial.println(soundLevel);
+      if (soundLevel > sensitivityLevel) {
+        digitalWrite(SOUNDLED, 1);
+        delay(1);
+        digitalWrite(SOUNDLED, 0);
+      }
+
+      // Measure light intensity, map to output power (through adjustment pot).
+      int lightLevel = analogRead(LIGHTSENSOR);
+      Timer1.setPwmDuty(LEDOUT, map(lightLevel, 0, 1024, 255, 0) * analogRead(MULTIPLIER)/1024);
+    }
+  }
+  else {
+    digitalWrite(LEDOUT, 0);
+  }
 }

+
+


readtag now just outputs payload.. will tidy up because printhexchar isnt what i need

--- firmware/examples/readTag/readtag.ino
+++ firmware/examples/readTag/readtag.ino
@@ -1,3 +1,4 @@
+#include "application.h"
 #include "pn532_i2c_particle/pn532_i2c_particle.h"
 #include "pn532_i2c_particle/PN532.h"
 #include "pn532_i2c_particle/NfcAdapter.h"
@@ -9,7 +10,8 @@
     Serial.begin(9600);
     Serial.println("NDEF Reader");
     nfc.begin();
-}
+    }
+

 void loop(void) {
     Serial.println("\nScan a NFC tag\n");
@@ -20,16 +22,23 @@
                 NdefMessage tagMessage = tag.getNdefMessage();
                 int i;
                 for (i = 0; i < tagMessage.getRecordCount()   ; i++)  {
-                         //
-                         NdefRecord tagRecord = tagMessage.getRecord(i);
-                         tagRecord.print();
-                         int payloadLength = tagRecord.getPayloadLength();
-                         byte payload[payloadLength];
-                         tagRecord.getPayload(payload);
-
+                    NdefRecord tagRecord = tagMessage.getRecord(i);
+                    int payloadLength = tagRecord.getPayloadLength();
+                    byte payload[payloadLength];
+                    tagRecord.getPayload(payload);
+                    for (uint8_t i = 0; i < payloadLength; i++) {
+                        char c = payload[i];
+                        if (c <= 0x1f || c > 0x7f) {
+                            Serial.print('.');
+                            } else {
+                            Serial.print(c);
+                        }
+                    }
+                    Serial.println("");
                 }
         }
     }
     delay(5000);
     Particle.process();
 }
+


Reduced code size

Reduced code size

--- examples/direct_draw/draw_bitmap/draw_bitmap.ino
+++ examples/direct_draw/draw_bitmap/draw_bitmap.ino
@@ -136,10 +136,10 @@

 void loop()
 {
-    ssd1306_fillScreen(0x00);
+    ssd1306_clearScreen( );
     ssd1306_drawBitmap(0, 0, 128, 64, Owl);
     delay(3000);
-    ssd1306_fillScreen(0x00);
+    ssd1306_clearScreen( );
     ssd1306_drawXBitmap(0, 0, 40, 32, Soba);
     delay(3000);
 }


Added Atom's calibration

Added Atom's calibration

--- gps_arduino/gps_arduino.ino
+++ gps_arduino/gps_arduino.ino
@@ -159,8 +159,11 @@
     lead to an assumed magnetometer bias of 0. Use the Calibrate example
     program to determine appropriate values for your particular unit.
     */
-    compass.m_min = (LSM303::vector<int16_t>){-767, -642, -379};
-    compass.m_max = (LSM303::vector<int16_t>){+322, +647, +616};
+    //min: {  -525,   -547,   -614}    max: {  +689,   +562,   +438}
+    //compass.m_min = (LSM303::vector<int16_t>){-767, -642, -379};  /Josh
+    //compass.m_max = (LSM303::vector<int16_t>){+322, +647, +616};
+    compass.m_min = (LSM303::vector<int16_t>){-525, -547, -624}; //Atom
+    compass.m_max = (LSM303::vector<int16_t>){+689, +562, +438};

     //Setup test waypoint. Start 38.631514, -90.271908
     mLat[0] = 38.631158;


Updated main_sketch with wheels code

Updated main_sketch with wheels code

--- main_sketch/main_sketch.ino
+++ main_sketch/main_sketch.ino
@@ -15,7 +15,7 @@
                  red  - 5v
                  white- ir(A5)

-Motor setup:    ask AC
+Motor setup:    motor

 Photores setup:  power- 5v
                  gnd  - gnd
@@ -47,9 +47,18 @@
 const int disMin = 10;  //min value of obj to be determined "in way"

 //WHEELS
+//left motor
+const int speedLPin = 7;    //speed pin for left motor
+const int enableLForPin = 6;   //enable left forward pin
+  const int enableLRevPin = 5;   //enable left forward pin
+//right motor
+const int speedR = 4;    //speed pin for right motor
+const int enRFor = 3;   //controller pin 1 for right motor
+const int enRRev = 2;   //controller pin 2 for right motor
+
 int wheelTurn = 0; //Magnitude of turn, I guess could be difference of wheels
                    //(- is left and + is right and 0 is straight)
-int wheelSpeed = 0;    //speed of actual robots, dependent on wheel
+int wheelSpeed = 0;    //speed of actual robots, dependent on wheel (0-255)

 //PHOTORES
 const int prLPin = 10;  //pin to hook up left photoresistor to
@@ -60,10 +69,25 @@

 void setup()
 {
+  //Servo
   myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
+
+  //SharpIR
   pinMode(ir, INPUT);
+
+  //PhotoRes
   pinMode(prLPin, INPUT);
   pinMode(prRPin, INPUT);
+
+  //Wheels
+  pinMode(enL, OUTPUT);
+  pinMode(inL1, OUTPUT);
+  pinMode(inL2, OUTPUT);
+  pinMode(enR, OUTPUT);
+  pinMode(inR1, OUTPUT);
+  pinMode(inR2, OUTPUT);
+
+  //Serial
   Serial.begin(9600);
 }


Boat will never try to go higher into the wind than 45 degrees when on automatic control

--- Arduino/Sailbot/Sailbot.ino
+++ Arduino/Sailbot/Sailbot.ino
@@ -36,6 +36,7 @@
 #define MAX_RUDDER 10.0

 unsigned long lastDataPacketSent;
+unsigned long timeOnCurrentTack;

 char state;
 char remoteState;
@@ -46,7 +47,8 @@
 float automaticHeading;
 float rudder;
 float sheet;
-float compassOffset;
+float tackAngle;
+float tackTime;

 Servo tillerServo;
 Servo sheetServo;
@@ -56,7 +58,7 @@
   Wire.begin();
   remoteState = SBTSailbotModelStateManualControl;
   windDirection = -1.0;
-  compassOffset = M_PI;
+  tackAngle = 90.0 * M_PI / 180.0;
   calibratedWind = false;
   imu = RTIMU::createIMU(&settings);                        // create the imu object

@@ -114,8 +116,17 @@

     // Update rudder and sheet
     if (state == SBTSailbotModelStateAutomaticControl) {
-      float angle = atan2(sin(heading - automaticHeading), cos(heading - automaticHeading));
-      setRudder(40.0 * angle / M_PI);
+      float rudderAngle;
+      float angleToWind = angleSubtractf(windDirection, automaticHeading);
+      if (abs(angleToWind) < tackAngle / 2.0) {
+        float tack = angleToWind > 0 ? tackAngle / 2.0 : -tackAngle / 2.0;
+        rudderAngle = angleSubtractf(angleSubtractf(windDirection, tack), heading);
+        Serial.print("Angle towards wind: "); Serial.println(angleToWind * 180.0 / M_PI);
+      } else {
+        rudderAngle = angleSubtractf(automaticHeading, heading);
+      }
+      setRudder(40.0 * rudderAngle / M_PI);
+
     } else if (state == SBTSailbotModelStateRecoveryMode) {

     }
@@ -200,7 +211,7 @@
         if (newWindDirection < 0) {
           windDirection = heading;
         } else {
-          windDirection = ((float)newWindDirection) * M_PI / 180.0;
+          windDirection = ((float)newWindDirection)  * M_PI / 180.0;
         }
         calibratedWind = true;
         state = SBTSailbotModelStateManualControl;
@@ -211,3 +222,7 @@
   }
 }

+float angleSubtractf(float angleOne, float angleTwo) {
+    return atan2f(sinf(angleOne - angleTwo), cosf(angleOne - angleTwo));
+}
+


Update ADXL362_SimpleRead.ino

Update ADXL362_SimpleRead.ino

--- firmware/examples/ADXL362_SimpleRead/ADXL362_SimpleRead.ino
+++ firmware/examples/ADXL362_SimpleRead/ADXL362_SimpleRead.ino
@@ -20,8 +20,7 @@

 */

-#include <SPI.h>
-#include <ADXL362.h>
+#include "adxl362/spark_internet_button__adxl362.h"

 ADXL362 xl;


Fixed issue when factory defaults were loaded all the time.

--- src/main.ino
+++ src/main.ino
@@ -69,10 +69,10 @@
  */
 void setup() {
   EEPROM.begin(SPI_FLASH_SEC_SIZE);
+  EEPROM_read(cfg);
   if (cfg.ic != INIT_HASH) {
     loadFactoryDefaults();
   }
-  EEPROM_read(cfg);

 // Serial Port Initialization
 #ifdef DEBUG


main: put SDS011 to sleep on OTA mode

main: put SDS011 to sleep on OTA mode

--- src/main.ino
+++ src/main.ino
@@ -175,6 +175,10 @@
         display.println(banner);
     }

+    sensor.set_sleep(false);
+    sensor.set_mode(sds011::QUERY);
+    sensor.set_sleep(true);
+
 #ifdef ESP8266
     WiFi.mode(WIFI_AP_STA);

@@ -215,11 +219,6 @@
     delay(100);
     WiFi.forceSleepBegin(); // Use WiFi.forceSleepWake() to enable wifi
 #endif
-
-
-    sensor.set_sleep(false);
-    sensor.set_mode(sds011::QUERY);
-
 }

 #ifdef ESP8266


minification with F()ing strings

minification with F()ing strings

--- src/nest.ino
+++ src/nest.ino
@@ -21,7 +21,6 @@
 #include <avr/pgmspace.h>
 #include <UIPEthernet.h>

-#define ENC28J60DEBUG 1
 #define RF_SERVER_ADDRESS 0

 RF22ReliableDatagram manager(RF_SERVER_ADDRESS, 8, 0);
@@ -29,13 +28,12 @@
 EthernetUDP udp;

 void setup() {
-
   Serial.begin(9600);
   if (manager.init()) {
-    //Serial.println(F("init success"));
+      Serial.println(F("init success"));
   }
   else {
-    /*Serial.println(F("init failed"));*/
+      Serial.println(F("init failed"));
   }
   uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};

@@ -62,16 +60,19 @@

 void sendMessage(const char *nestId, char *message) {
   int success = udp.beginPacket(skydome, skydome_port);
-  /*Serial.print("beginPacket: ");
-  Serial.println(success ? "success" : "failed");*/
+
+  Serial.print(F("beginPacket: "));
+  Serial.println(success ? F("success") : F("failed"));

   success = udp.write(nestId);
   success = udp.write(message);
-  /*Serial.print("bytes written: ");
-  Serial.println(success);*/
+
+  Serial.print(F("bytes written: "));
+  Serial.println(success);
+

   success = udp.endPacket();
-  /*Serial.print("endPacket: ");
-  Serial.println(success ? "success" : "failed");*/
+  Serial.print(F("endPacket: "));
+  Serial.println(success ? F("success") : F("failed"));
   udp.stop();
 }


Checkout behaviour should be no debug flags.

--- device.ino
+++ device.ino
@@ -123,14 +123,14 @@
 //#define GPS_DEBUG_ON
 //#define PUMP_DEBUG_ON
 //#define EXECUTION_PATH_DEBUG_ON
-#define NMEA_DEBUG_ON
+//#define NMEA_DEBUG_ON
 //#define DEBUG_MEMORY_ON
 //#define STRESS_MEMORY_ON
 //#define BYPASS_AES_ON
 //#define BARO_DEBUG_ON
 //#define ACTIVE_DEBUG_ON
 //#define SERIAL_DEBUG_ON
-#define SOFTSERIAL_DEBUG_ON
+//#define SOFTSERIAL_DEBUG_ON