Added UART with RPi. Added multiple songs via UART.

--- frankenbear.ino
+++ frankenbear.ino
@@ -1,6 +1,8 @@
 #include <Adafruit_PWMServoDriver.h>
 #include <Wire.h>
 #include "pitches.h"
+
+// Wiring information can be found in the project's README: https://github.com/cgoettel/frankenbear/blob/master/README.md

 #define DEBUG 0

@@ -42,8 +44,8 @@
 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

 // These are the minimum and maximum pulse length counts (out of 4096).
-#define BIG_SERVO_MIN 160
-#define BIG_SERVO_MAX 584
+#define BIG_SERVO_MIN   160
+#define BIG_SERVO_MAX   584
 #define MICRO_SERVO_MIN 160
 #define MICRO_SERVO_MAX 584

@@ -52,15 +54,15 @@
 #define RIGHT_ARM_CLOSED 478
 #define RIGHT_ARM_OPEN   372

-#define LEFT_EAR_BACK 475
-#define LEFT_EAR_FORWARD 265
-#define RIGHT_EAR_BACK 265
+#define LEFT_EAR_BACK     475
+#define LEFT_EAR_FORWARD  265
+#define RIGHT_EAR_BACK    265
 #define RIGHT_EAR_FORWARD 475
-#define MIDDLE_EAR 370
-
-const uint8_t left_arm = 0;
+#define MIDDLE_EAR        370
+
+const uint8_t left_arm  = 0;
 const uint8_t right_arm = 1;
-const uint8_t left_ear = 2;
+const uint8_t left_ear  = 2;
 const uint8_t right_ear = 3;

 // *******************
@@ -88,6 +90,13 @@
   4, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2
 };

+int twinkle_twinkle_notes[] = {
+  NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_G4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_C4
+};
+int twinkle_twinkle_lengths[] = {
+  4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2
+};
+
 void setup()
 {
   // Initialize serial port at 9600 baud.
@@ -137,10 +146,11 @@

 void loop()
 {
-  photocell_reading = analogRead(photocell_pin);
-
+  // PHOTOCELL
   // When it gets bright or dark, make a sound.
   // Don't play the sound again until it's normal lighting out.
+  photocell_reading = analogRead(photocell_pin);
+
   if ( photocell_reading >= 700 && photocell_reading <= 710 )
   {
     normal_light_flag = 1;
@@ -152,6 +162,7 @@
     normal_light_flag = 0;
   }

+  // BUTTON
   button_state = digitalRead(button_pin);

   if ( button_state == HIGH )
@@ -160,6 +171,7 @@
     reset_arms();
   }

+  // PROXIMITY SENSOR
   // read ambient light
   write8(VCNL4000_COMMAND, VCNL4000_MEASUREAMBIENT | VCNL4000_MEASUREPROXIMITY);

@@ -204,9 +216,27 @@
     normal_proximity_flag = 0;
   }

+  if ( Serial.available() > 0 )
+  {
+    // Read the incoming byte.
+    int incoming_byte = Serial.read();
+    incoming_byte -= 48;
+
+    play_song(incoming_byte);
+
+    // Echo it back to serial.
+#if DEGBUG
+    Serial.println(incoming_byte, DEC);
+#endif
+
+    incoming_byte = -1;
+  }
+
   // TODO: check if manually moved
   // is this as simple as just resetting the ears and arms after every loop?
   // This would work, I think, but could also draw a lot more power than otherwise.
+
+  // TODO: Change clock speed to save battery.
 }

 uint16_t readProximity() {
@@ -327,16 +357,35 @@

 void play_song(int song_number)
 {
+  if ( song_number < 0 )
+  {
+    return;
+  }
+
+  int song_length = 0;
+  if ( song_number == 0 )
+  {
+    song_length = sizeof(mary_had_a_little_lamb_lengths)/sizeof(mary_had_a_little_lamb_lengths[0]);
+  }
+  else if ( song_number == 1 )
+  {
+    song_length = sizeof(twinkle_twinkle_lengths)/sizeof(twinkle_twinkle_lengths[0]);
+  }
+
   int note_length = 0;

-  // 26 notes long
-  for ( int i = 0; i < 26; i++ )
-  {
-    if ( song_number == 0 || song_number > 0 )
+  for ( int i = 0; i < song_length; i++ )
+  {
+    if ( song_number == 0 || song_number > 1 )
     {
       note_length = 1000 / mary_had_a_little_lamb_lengths[i];
       tone(speakerPin, mary_had_a_little_lamb_notes[i], note_length);
     }
+    else if ( song_number == 1 )
+    {
+      note_length = 1000 / twinkle_twinkle_lengths[i];
+      tone(speakerPin, twinkle_twinkle_notes[i], note_length);
+    }

     int pause_between_notes = note_length * 1.30;
     delay(pause_between_notes);


Played around with reading numbers. Added flag so ears don't infinitely wiggle.

--- frankenbear.ino
+++ frankenbear.ino
@@ -30,6 +30,8 @@

 uint16_t ambient_reading = 0;
 uint16_t proximity_reading = 0;
+
+int normal_proximity_flag = 0;

 // **********************
 // **** SERVO SHIELD ****
@@ -140,7 +142,7 @@
     normal_light_flag = 1;
   }

-  if ( photocell_reading < 700 && normal_light_flag )
+  if ( photocell_reading < 650 && normal_light_flag )
   {
     play_song(0);
     normal_light_flag = 0;
@@ -177,7 +179,13 @@
     delay(10);
   }

-  if ( ambient_reading < 50 || proximity_reading > 10000 )
+  // Don't wiggle again until it's normal proximity again.
+  if ( ambient_reading > 75 )
+  {
+    normal_proximity_flag = 1;
+  }
+
+  if ( ambient_reading < 30 && normal_proximity_flag ) // proximity_reading doesn't work well through fabric.
   {
     for ( int i = 0; i < 4; i++ )
     {
@@ -185,6 +193,7 @@
     }

     reset_ears();
+    normal_proximity_flag = 0;
   }

   // TODO: check if manually moved


Added publisher to check for global velocity

--- OpenCR/turtlebot3_core_monster/turtlebot3_core_monster.ino
+++ OpenCR/turtlebot3_core_monster/turtlebot3_core_monster.ino
@@ -49,6 +49,10 @@
 sensor_msgs::JointState joint_states;
 ros::Publisher joint_states_pub("joint_states", &joint_states);

+// Global Velocity Msg Check
+geometry_msgs::Twist cmd_vel_check_msg;
+ros::Publisher cmd_vel_check_pub("cmd_vel_check", &cmd_vel_check_msg);
+
 /*******************************************************************************
 * Transform Broadcaster
 *******************************************************************************/
@@ -125,6 +129,10 @@
   nh.advertise(cmd_vel_rc100_pub);
   nh.advertise(odom_pub);
   nh.advertise(joint_states_pub);
+
+  // Added Publisher to publish command velocity
+  nh.advertise(cmd_vel_check_pub);
+
   tfbroadcaster.init(nh);

   nh.loginfo("Connected to OpenCR board!");
@@ -205,6 +213,11 @@
   // Show LED status
   showLedStatus();

+  // Publish Command Velocity Information as a check
+  cmd_vel_check_msg.linear.x = goal_linear_velocity;
+  cmd_vel_check_msg.linear.y = goal_angular_velocity;
+  cmd_vel_check_pub.publish(&cmd_vel_check_msg);
+
   // Call all the callbacks waiting to be called at that point in time
   nh.spinOnce();
 }


mode test

mode test

--- arduino_code/simple-test/edf-sender/edf-sender.ino
+++ arduino_code/simple-test/edf-sender/edf-sender.ino
@@ -18,9 +18,8 @@
 #define LINE_START    0x0A // 0x0A \n
 #define LINE_END      0x0D // 0x0D \r
 #define LINE_LENGTH   30   //      taille de ligne maximum
-#define VALUES_LENGTH 5   //      taille de tableau à enregitrer avant envoie
-
-char sep = ' ';
+#define VALUES_LENGTH 5    //      taille de tableau à enregitrer avant envoie
+#define MODE_TEST     1    //      désactivé pour la "release" (gagne de la mémoire)

 struct valuesWeCareAbout {
   long HC;
@@ -37,7 +36,7 @@
 /* CSW : Pin 8 */
 RF24 radio(7,8);

-// On crée une instance de SoftwareSerial
+/* On crée deux instances de SoftwareSerial */
 SoftwareSerial* cptSerial;
 SoftwareSerial* cptSerialFake;

@@ -51,7 +50,11 @@
 /* Variable intermédiaire */
 struct valuesWeCareAbout frame;

+/* Séparateur des lignes de la trame */
+char sep = ' ';
+
 /* FOR TEST */
+#if MODE_TEST
 int  __charIndex = 0;
 char __simulatedString[] = ":\nADCO 030622716812 =\r\nOPTARIF HC.. <\r\nISOUSC 30 9\r\nHCHC 035318160 !\r\nHCHP 039061379 9\r\nPTEC HP..  \r\nIINST 001 X\r\nIMAX 029 J\r\nPAPP 00180 *\r\nHHPHC C .\r\nMOTDETAT 000000 B\r?";
 char getCharSimulated(){
@@ -59,19 +62,22 @@
   __charIndex = (__charIndex + 1) % 170;
   return c;
 }
+#endif

 /* Retourne le prochain caractère en entrée */
 char getChar() {
-
-  //return getCharSimulated();
-  //while(!cptSerial->available()) {}
+  /*return getCharSimulated();*/
+  while(!cptSerial->available()) {}
   return cptSerial->read() & 0x7F;
 }
 /* Reset le tableau de relevé de valeurs */
 void resetTable()
 {
+#if MODE_TEST
   Serial.println("Reset table");
   Serial.flush();
+#endif
+
  for(int i = 0 ; i < VALUES_LENGTH ; i++)
  {
   b[i].HC = 0;
@@ -104,6 +110,7 @@
  * dans le tableau.
  */
 void saveFrame() {
+#if MODE_TEST
   Serial.print("Save frame : ");
   Serial.print(frame.HC);
   Serial.print("-");
@@ -113,7 +120,7 @@
   Serial.print("-");
   Serial.println(frame.timestamp);
   Serial.flush();
-
+#endif
   b[currentIndex] = frame;
   currentIndex++;
 }
@@ -122,9 +129,11 @@
  * est bien initialisée.
  */
 boolean checkFrame() {
+#if MODE_TEST
   Serial.println("Check frame");
   Serial.println(frame.HC);
   Serial.flush();
+#endif
   return frame.HC > 0 &&
          frame.HP > 0 &&
          frame.timestamp > 0;
@@ -134,36 +143,36 @@
  * la variable "frame".
  */
 void readFrame() {
+#if MODE_TEST
   Serial.println("Read frame");
   Serial.flush();
+#endif

   char currentChar = 0;

   /* Lecture des caractères jusqu'au début
      de la trame */
   while (currentChar != START_FRAME)
-   if(cptSerial->available())
-    currentChar = getChar();
-
+   currentChar = getChar();
+
+#if MODE_TEST
   Serial.println("Start frame found");
   Serial.flush();
-
+#endif
+
   /* Boucle principale */
   int index = 0;
-  //char line[LINE_LENGTH] = {0};
   String line;

   while (currentChar != END_FRAME)
   {
     /* Lecture d'un caractère */
-    while(!cptSerial->available()) {}
     currentChar = getChar();

     /* Soit c'est le début d'une ligne */
     if (currentChar == LINE_START)
     {
       line = "";
-      //memset(line, 0, sizeof(line));
       index = 0;
     }
     /* Soit c'est la fin d'une ligne */
@@ -198,15 +207,15 @@
         continue;
       }
       line += currentChar;
-      //line[index] = currentChar;
-      //index++;
     }
   }

   frame.timestamp = millis();

+#if MODE_TEST
   Serial.println("Frame has been read");
   Serial.flush();
+#endif
 }

 /* Permet de vider le buffer du serial
@@ -228,9 +237,10 @@
    for (int i = 0 ; i < 3 ; i++)
    {
       radio.stopListening();
+#if MODE_TEST
       Serial.println("Send table...");
       Serial.flush();
-
+#endif
       /* Envoie des données */
       radio.write(&b, sizeof(b));

@@ -257,12 +267,16 @@
        */
       if(!timeout)
       {
+#if MODE_TEST
         Serial.println("Send success !");
         Serial.flush();
+#endif
         break;
       }
+#if MODE_TEST
       Serial.println("Send failed");
       Serial.flush();
+#endif
    }
 }

@@ -316,12 +330,16 @@
   sendTable();
   resetTable();
  }
-
+
+#if MODE_TEST
  Serial.print("Bouh");
  Serial.flush();
+#endif
  cptSerialFake->listen();
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  cptSerial->listen();
+#if MODE_TEST
  Serial.println(" - hehe");
  Serial.flush();
-}
+#endif
+}


Uploading the right file replacing the placeholder

--- pic32/libraries/DTWI/examples/DTWIscanner/DTWIscanner.ino
+++ pic32/libraries/DTWI/examples/DTWIscanner/DTWIscanner.ino
@@ -1 +1,178 @@
-//placeholder to create that directory (what a stupid method)
+// --------------------------------------
+// DTWIscanner v2.0
+// Author: Dr. Mathias Wilhelm
+// Copyright 2016 - CC BY-NC-SA
+// Creative Commons Attribution 4.0 International license.
+//
+// 17.03.2016 v1.0 initial release
+// 18.03.2016 v1.1 extending to scan multiple I2C buses is present
+//
+#include <DTWI.h>
+
+DTWI0 dtwi0;
+#ifdef _DTWI1_BASE
+DTWI1 dtwi1;
+#endif
+#ifdef _DTWI2_BASE
+DTWI2 dtwi2;
+#endif
+#ifdef _DTWI3_BASE
+DTWI3 dtwi3;
+#endif
+#ifdef _DTWI4_BASE
+DTWI4 dtwi4;
+#endif
+uint8_t numbus = 1; // assuming that this script is started on a system with at least one I2C bus
+
+void setup()
+{
+#ifdef _DTWI1_BASE
+	numbus++;
+#endif
+#ifdef _DTWI2_BASE
+	numbus++;
+#endif
+#ifdef _DTWI3_BASE
+	numbus++;
+#endif
+#ifdef _DTWI4_BASE
+	numbus++;
+#endif
+	Serial.begin(9600);
+  delay(5000); // allow the user to start serial monitor
+	Serial.println("I2C Scanner v1.0");
+	Serial.println("based on DTWI library");
+	Serial.print("number of I2C buses found on this board: ");
+	Serial.println(numbus);
+	SerialDelay(5);
+}
+
+void loop()
+{
+	byte error, address;
+	int nDevices;
+
+	// ========================================================== I2C BUS 0
+	Serial.println("starting master mode on I2C bus -= 0 =-");
+	dtwi0.beginMaster();
+	nDevices = 0;
+	for(address = 8; address < 127; address++ )
+	{
+		// The DTWIscanner uses the return value of
+		// the DTWI0.stopMaster() to see if
+		// a device did acknowledge to the address.
+		dtwi0.startMasterWrite(address);
+		delay(10);
+		if(!dtwi0.stopMaster())
+		{
+			Serial.print("I2C device found at address 0x");
+			if (address<16) Serial.print("0");
+			Serial.print(address,HEX);
+			Serial.println("  !");
+			nDevices++;
+		}
+	}
+	if (nDevices == 0) Serial.println("No I2C devices found\n");
+	dtwi0.endMaster();
+
+	// ========================================================== I2C BUS 1
+#ifdef _DTWI1_BASE
+	Serial.println("starting master mode on I2C bus -= 1 =-");
+	dtwi1.beginMaster();
+	nDevices = 0;
+	for(address = 8; address < 127; address++ )
+	{
+		dtwi1.startMasterWrite(address);
+		delay(10);
+		if(!dtwi1.stopMaster())
+		{
+			Serial.print("I2C device found at address 0x");
+			if (address<16) Serial.print("0");
+			Serial.print(address,HEX);
+			Serial.println("  !");
+			nDevices++;
+		}
+	}
+	if (nDevices == 0) Serial.println("No I2C devices found\n");
+	dtwi1.endMaster();
+#endif
+
+	// ========================================================== I2C BUS 2
+#ifdef _DTWI2_BASE
+	Serial.println("starting master mode on I2C bus -= 2 =-");
+	dtwi2.beginMaster();
+	nDevices = 0;
+	for(address = 8; address < 127; address++ )
+	{
+		dtwi2.startMasterWrite(address);
+		delay(10);
+		if(!dtwi2.stopMaster())
+		{
+			Serial.print("I2C device found at address 0x");
+			if (address<16) Serial.print("0");
+			Serial.print(address,HEX);
+			Serial.println("  !");
+			nDevices++;
+		}
+	}
+	if (nDevices == 0) Serial.println("No I2C devices found\n");
+	dtwi2.endMaster();
+#endif
+
+	// ========================================================== I2C BUS 3
+#ifdef _DTWI3_BASE
+	Serial.println("starting master mode on I2C bus -= 3 =-");
+	dtwi3.beginMaster();
+	nDevices = 0;
+	for(address = 8; address < 127; address++ )
+	{
+		dtwi3.startMasterWrite(address);
+		delay(10);
+		if(!dtwi3.stopMaster())
+		{
+			Serial.print("I2C device found at address 0x");
+			if (address<16) Serial.print("0");
+			Serial.print(address,HEX);
+			Serial.println("  !");
+			nDevices++;
+		}
+	}
+	if (nDevices == 0) Serial.println("No I2C devices found\n");
+	dtwi3.endMaster();
+#endif
+
+	// ========================================================== I2C BUS 4
+#ifdef _DTWI4_BASE
+	Serial.println("starting master mode on I2C bus -= 4 =-");
+	dtwi4.beginMaster();
+	nDevices = 0;
+	for(address = 8; address < 127; address++ )
+	{
+		dtwi4.startMasterWrite(address);
+		delay(10);
+		if(!dtwi4.stopMaster())
+		{
+			Serial.print("I2C device found at address 0x");
+			if (address<16) Serial.print("0");
+			Serial.print(address,HEX);
+			Serial.println("  !");
+			nDevices++;
+		}
+	}
+	if (nDevices == 0) Serial.println("No I2C devices found\n");
+	dtwi4.endMaster();
+#endif
+	SerialDelay(5);           // wait 5 seconds for next scan
+}
+
+void SerialDelay(int s){
+	Serial.print("Wait for ");
+	Serial.print(s);
+	Serial.print(" seconds  ");
+	for (int i=s; i>0; i--){
+		Serial.print("\b");
+		Serial.print(i);
+		delay(1000);
+	}
+	Serial.println("\bdone");
+}


added more diagnostic output

added more diagnostic output

--- sketch_lg_heartbeat/sketch_lg_heartbeat.ino
+++ sketch_lg_heartbeat/sketch_lg_heartbeat.ino
@@ -54,7 +54,10 @@

 void loop() {
   static int counter = 0;
-
+
+  SerialUSB.print("loops (minutes) since restart: ");
+  SerialUSB.println(loopcnt);
+
   counter++;
   if ((counter % 5) == 0) lg_heartbeat(); // every 5 loops


hello: multiple baud

hello: multiple baud

--- hello/hello.ino
+++ hello/hello.ino
@@ -2,7 +2,13 @@
 void setup() {
  //Initialize serial and wait for port to open:
   Serial.begin(9600);
-  Serial.println("hello!");
+  Serial.println(F("hello! (9600)"));
+  Serial.end();
+
+  Serial.begin(115200);
+  Serial.println(F("hello! (115200)"));
+  Serial.end();
+
 }
 void loop() {
 }


new comment

new comment

--- SketchBook/OpenSeaMap/OpenSeaMap.ino
+++ SketchBook/OpenSeaMap/OpenSeaMap.ino
@@ -71,13 +71,13 @@

  To Load firmware to OSM Lodder rename hex file to OSMFIRMW.HEX and put it on a FAT16 formatted SD card.
  */
-// WKLA 20131101
-// - Bug in Config DAtei lesen behoben.
-// WKLA 20131029
+// WKLA 20131101 V0.1.4
+// - Bug in Config Datei lesen behoben.
+// WKLA 20131029 V0.1.3
 // - Testen auf freien Platz
-// WKLA 20131028
+// WKLA 20131028 V0.1.2
 // - EEPROM für Konfiguration
-// WKLA 20131027
+// WKLA 20131027 V0.0.3
 // - Umstellung auf AltSoftSerial
 // WKLA 20131026
 // - diverse Änderungen wegen Speichervervrauch


en rotation er 11520 steps og højden er omkring 115200

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -7,7 +7,6 @@

 unsigned long nextUpdate = 0;

-int timer1_counter;

 boolean enabled = false;
 boolean homeing = false;
@@ -16,18 +15,18 @@
 {
   Serial.begin(57600);
   Serial.setTimeout(25);
-  stepperX.setMaxSpeed(2000);
-  stepperX.setAcceleration(5000);
+  stepperX.setMaxSpeed(3000);
+  stepperX.setAcceleration(4000);

-  stepperY.setMaxSpeed(2000);
-  stepperY.setAcceleration(5000);
+  stepperY.setMaxSpeed(1000);
+  stepperY.setAcceleration(4000);

-  Timer1.initialize(50); // microseconds
-  Timer1.attachInterrupt( timerIsr ); // attach the service routine here
-  pinMode(2, INPUT_PULLUP);
-  attachInterrupt(0, setY, FALLING);
+  Timer1.initialize(86);              // Microseconds
+  Timer1.attachInterrupt( timerIsr );  // Attach stepper update function
+  pinMode(2, INPUT_PULLUP);            // Enable pullup resistors for the homing switch
+  attachInterrupt(0, homeXIsr, FALLING);   // Attach homing function
   pinMode(6, OUTPUT);
   pinMode(9, OUTPUT);

@@ -38,9 +37,9 @@
   stepperY.run();
   stepperX.run();
 }
-void setY() {
-  stepperX.stop();
+void homeXIsr() {
   stepperX.setCurrentPosition(0);
+  stepperX.move(0);
   homeing = false;
 }
 void loop()
@@ -53,13 +52,13 @@

   if (homeing) {
     enable();
-    if (digitalRead(2)) {
-
-      stepperX.move(-10000);
-
+    if (!digitalRead(2)) { // Allready at home position
+      stepperX.move(1000); // Move away from home
+      }
+    if (digitalRead(2)) {  // If not homed
+      stepperX.move(-1000);// Move towards home
     }
   }
-
 }

 void enable() {
@@ -82,21 +81,22 @@
     Serial.print(stepperX.currentPosition());
     Serial.print(" ");
     Serial.print(stepperY.currentPosition());
-    Serial.print(" ");
-    Serial.print(stepperX.targetPosition());
-    Serial.print(" ");
-    Serial.print(stepperY.targetPosition());
-    Serial.print(" ");
-    Serial.print(stepperX.distanceToGo());
-    Serial.print(" ");
-    Serial.print(stepperY.distanceToGo());
+//    Serial.print(" ");
+//    Serial.print(stepperX.targetPosition());
+//    Serial.print(" ");
+//    Serial.print(stepperY.targetPosition());
+//    Serial.print(" ");
+//    Serial.print(stepperX.distanceToGo());
+//    Serial.print(" ");
+//    Serial.print(stepperY.distanceToGo());
     Serial.print(" ");
     Serial.print((homeing ? 'y' : 'n'));
     Serial.print(" ");
     Serial.print((enabled ? 'y' : 'n'));
+    Serial.print(" ");
+    Serial.print(millis()-nextUpdate);
     Serial.print("\r");
-
-    nextUpdate = millis() + 250;
+    nextUpdate = millis() + 1000;
   }
 }
 void handleInput() {


Add option to easily turn auto-calibration on and off.

--- Arduino/LaserHarpMultiplex/LaserHarpMultiplex.ino
+++ Arduino/LaserHarpMultiplex/LaserHarpMultiplex.ino
@@ -16,6 +16,14 @@
     "@" is received, all input should be ignored until a "~" is received.
  */

+// Set this to true to enable automatic calibration of the laser at startup.
+// Requires that the lasers are powered by the circuit board so they can be turned
+// on and off.
+const boolean autoCalibration = false;
+
+// Default threshold if autocalibration is off.
+const int defaultThreshold = 100;
+
 // These constants won't change.  They're used to give names
 // to the pins used:
 const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
@@ -34,7 +42,7 @@
 const int inputCount = 8;  // Number of inputs we are reading. Can be up to 16.

 // Thresholds for input on each pin. >= this value is ON, < this value is OFF.
-// These are set in the power-on calibration routine.
+// These are set in the power-on calibration routine, or set to defaultThreshold.
 int thresholds[inputCount];

 // Values during calibration.
@@ -229,6 +237,13 @@
   Serial.println("~");  // Transition back to output data.
 }

+void setManualThresholds()
+{
+  for (int i = 0; i < inputCount; ++i) {
+    thresholds[i] = defaultThreshold;
+  }
+}
+
 void setup() {
   // initialize serial communications at 57600 bps:
   Serial.begin(57600);
@@ -242,7 +257,12 @@
   pinMode(laserPin, OUTPUT);

   setLedMode(LED_ON, 0);
-  calibrate();
+
+  if (autoCalibration)
+      calibrate();
+  else
+      setManualThresholds();
+
   setLasers(true);
 }


persist brightness

persist brightness

--- firmware/http-neopixel/spark-neopixel-control.ino
+++ firmware/http-neopixel/spark-neopixel-control.ino
@@ -46,6 +46,7 @@
 };

 uint8_t brightness = 255;
+int _brightness = 255;

 Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(PIXEL_COUNT_0, PIXEL_PIN_0, PIXEL_TYPE);
 LEDObject stripObj0 = {{'I', 'N', 'I', 'T'}};
@@ -77,12 +78,8 @@
 #define SETALL "setAll"
 #define LOOPALTERNATE "loopAlternate"
 #define LOOPBLOCKS "loopBlocks"
-#define LATCHPIXEL "latchPixel"
-#define SETPIXEL "setPixel"
-#define LATCH "latch"
 #define ENDRUN "endrun"
 #define SNOW "snow"
-#define WEBSOCKET "websocket" //<- finish this
 #define SETBRIGHTNESS "setBrightness"
 #define USA "usa"
 #define LIGHTNING "lightning"
@@ -96,21 +93,24 @@

 void setup()
 {
+    //retrieve persisted state
     EEPROM.get(EEPROM_ADDR_STRIP_0, stripObj0);
     EEPROM.get(EEPROM_ADDR_STRIP_1, stripObj1);
     EEPROM.get(EEPROM_ADDR_STRIP_2, stripObj2);
     EEPROM.get(EEPROM_ADDR_PINS, pinObj);
     EEPROM.get(EEPROM_BRIGHTNESS, brightness);
+    _brightness = (int)brightness;

     Serial.begin(9600);
+
     strip2.begin();
-    strip2.show(); // Initialize all pixels to 'off'
-    //register the run command as an API endpoint
+    strip2.show();
+
+    //regiser cloud variables and the run function
     Particle.function("run", run);
-    //register the action variable as a GET parameter
     Particle.variable("action", action, STRING);
-    //register the parameters variable as a GET parameter
     Particle.variable("parameters", parameters, STRING);
+    Particle.variable("brightness", &_brightness, INT);

     pinMode(PIN_0, OUTPUT);
     pinMode(PIN_1, OUTPUT);
@@ -123,6 +123,7 @@
     {
         Serial.println("Reseting state");
         brightness = 255;
+        _brightness = 255;
         EEPROM.put(EEPROM_BRIGHTNESS, 255);
     }
     else
@@ -380,6 +381,7 @@
     else if(command.equals(SETBRIGHTNESS))
     {
         brightness = stringToInt(args[1]);
+        _brightness = (int)brightness;
         EEPROM.put(EEPROM_BRIGHTNESS, brightness);
         strip2.setBrightness(brightness);
         strip2.show();


when both eyes detect movement, perform big back & forth swing

--- direct-servo-turns/direct-servo-turns.ino
+++ direct-servo-turns/direct-servo-turns.ino
@@ -55,7 +55,7 @@
     myservo.write(angle);

     Serial.print("\t");
-    rndDelay();
+    rndDelay(4000, 6000);

     Serial.print("\t");
     int rightValue = readDetector(DETECTOR_RIGHT, "right");
@@ -70,6 +70,12 @@
       // right side movement
       angle = random(angle, angle + variation);
     }
+    else if (HIGH == leftValue && HIGH == rightValue) {
+      // both eyes busy - big swings left & right
+      rndTurn(LOW_LIMIT, LOW_LIMIT + VARIATION);
+      rndTurn(HIGH_LIMIT - VARIATION, HIGH_LIMIT);
+      break;
+    }
     else {
       break;
     }
@@ -78,9 +84,9 @@
   Serial.print("\t");
 }

-void rndDelay()
+void rndDelay(int loBound, int hiBound)
 {
-  int ms = random(4000, 7000);
+  int ms = random(loBound, hiBound);

   Serial.print("delay:");
   Serial.print(ms);
@@ -98,7 +104,7 @@

   myservo.write(angle);

-  rndDelay();
+  rndDelay(2000, 4000);
   Serial.println("");
 }


removed queue from program

removed queue from program

--- beanWheelwriterControl/beanWheelwriterControl.ino
+++ beanWheelwriterControl/beanWheelwriterControl.ino
@@ -6,7 +6,6 @@
          sending data
  */

-#include<QueueArray.h>
 #include<PinChangeInt.h>

 static int d0 = 0;
@@ -16,8 +15,6 @@
 #define LETTER_DELAY 170
 #define CARRIAGE_WAIT_BASE 300
 #define CARRIAGE_WAIT_MULTIPLIER 15
-
-QueueArray<int> q; // holds the bytes we will send to the bus

 byte asciiTrans[128] =
 //col: 0     1     2     3     4     5     6     7     8     9     a     b     c     d     e     f     row:
@@ -325,13 +322,13 @@
 }

 void send_letter(int letter) {
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000011);
-    q.enqueue(letter);
-    q.enqueue(0b000001010);
-    sendBytes();
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000000011);
+    sendByte(letter);
+    sendByte(0b000001010);
+

     delay(LETTER_DELAY); // before next character
 }
@@ -341,37 +338,37 @@
   // 1 == down
   // 4 == micro-down
   // 21 == micro-up
-  q.enqueue(0b100100001);
-  q.enqueue(0b000001011);
-  q.enqueue(0b100100001);
-  q.enqueue(0b000000101);
+  sendByte(0b100100001);
+  sendByte(0b000001011);
+  sendByte(0b100100001);
+  sendByte(0b000000101);
   if (direction == 0) { // cursor-up (paper-down)
-      q.enqueue(0b000001000);
+      sendByte(0b000001000);
   } else if (direction == 1) {
-      q.enqueue(0b010001000); // cursor-down (paper-up)
+      sendByte(0b010001000); // cursor-down (paper-up)
   } else if (direction == 4) {
-      q.enqueue(0b010000010); // cursor-micro-down (paper-micro-up)
+      sendByte(0b010000010); // cursor-micro-down (paper-micro-up)
   } else if (direction == 21) {
-      q.enqueue(0b000000010); // cursor-micro-up (paper-micro-down)
+      sendByte(0b000000010); // cursor-micro-up (paper-micro-down)
   }
-  q.enqueue(0b100100001);
-  q.enqueue(0b000001011);
-  sendBytes();
+  sendByte(0b100100001);
+  sendByte(0b000001011);
+
   delay(LETTER_DELAY * 2); // give it a bit more time
 }

 void backspace_no_correct() {
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000100);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b000000000);
-    q.enqueue(0b000001010);
-    q.enqueue(0b100100001);
-    sendBytes();
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000100);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b000000000);
+    sendByte(0b000001010);
+    sendByte(0b100100001);
+

     // send one more byte but don't wait explicitly for the response
     // of 0b000000100
@@ -384,15 +381,15 @@
     int byte1 = (numChars * 5) >> 7;
     int byte2 = ((numChars * 5) & 0x7f) << 1;

-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000111);
-    q.enqueue(0b100100001);
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000111);
+    sendByte(0b100100001);

     if (numChars <= 23 || numChars >= 26) {
-        q.enqueue(0b000000110);
+        sendByte(0b000000110);

         // We will send two bytes from a 10-bit number
         // which is numChars * 5. The top three bits
@@ -401,27 +398,27 @@
         // byte, although the byte needs to be shifted
         // left by one (not sure why)
         // the numbers are calculated above for timing reasons
-        q.enqueue(byte1);
-        q.enqueue(byte2); // each char is worth 10
-        q.enqueue(0b100100001);
+        sendByte(byte1);
+        sendByte(byte2); // each char is worth 10
+        sendByte(0b100100001);
         // right now, the platten is moving, maybe?

     } else if (numChars <= 25) {
         // not sure why this is so different
-        q.enqueue(0b000001101);
-        q.enqueue(0b000000111);
-        q.enqueue(0b100100001);
-        q.enqueue(0b000000110);
-        q.enqueue(0b000000000);
-        q.enqueue(numChars * 10);
-        q.enqueue(0b100100001);
+        sendByte(0b000001101);
+        sendByte(0b000000111);
+        sendByte(0b100100001);
+        sendByte(0b000000110);
+        sendByte(0b000000000);
+        sendByte(numChars * 10);
+        sendByte(0b100100001);
         // right now, the platten is moving, maybe?
     }

-    q.enqueue(0b000000101);
-    q.enqueue(0b010010000); //
-    q.enqueue(0b100100001);
-    sendBytes();
+    sendByte(0b000000101);
+    sendByte(0b010010000); //
+    sendByte(0b100100001);
+

     // send one more byte but don't wait explicitly for the response
     // of 0b001010000
@@ -432,53 +429,48 @@
 }

 void correct_letter(int letter) {
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000101);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b000000000);
-    q.enqueue(0b000001010);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000100);
-    q.enqueue(letter);
-    q.enqueue(0b000001010);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001100);
-    q.enqueue(0b010010000);
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000101);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b000000000);
+    sendByte(0b000001010);
+    sendByte(0b100100001);
+    sendByte(0b000000100);
+    sendByte(letter);
+    sendByte(0b000001010);
+    sendByte(0b100100001);
+    sendByte(0b000001100);
+    sendByte(0b010010000);
 }

 void micro_backspace() {
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001110);
-    q.enqueue(0b011010000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000100);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b000000000);
-    q.enqueue(0b000000010);
-    q.enqueue(0b100100001);
-    sendBytes();
+    sendByte(0b100100001);
+    sendByte(0b000001110);
+    sendByte(0b011010000);
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000100);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b000000000);
+    sendByte(0b000000010);
+    sendByte(0b100100001);
+

     // send one more byte but don't wait explicitly for the response
     // of 0b000000100
     sendByteOnPin(0b000001011);
 }

-void sendBytes() {
-    while (!q.isEmpty()) {
-        //Serial.println("sending bytes!");
-        sendByteOnPin(q.dequeue());
-        // wait for low then high (for a zero)
-        //PORTD |= 0b01000000;
-        //int pinStatus = ((PIND & 0b01000000) >> 6);
-        //Serial.println(pinStatus);
+void sendByte(int b) {
+        //Serial.println("sending byte!");
+        sendByteOnPin(b);
         while (((PIND & 0b01000000) >> 6) == 1) {
           // busy
         }
@@ -486,71 +478,70 @@
           // busy
         }
         delayMicroseconds(5); // wait a bit before sending next char
-    }
 }
 void fastText(char *s) {
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001011);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001001);
-    q.enqueue(0b000000000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001010);
-    q.enqueue(0b000000000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000110);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b010000000);
-    q.enqueue(0b000000000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000101);
-    q.enqueue(0b010000000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000010010);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b010000000);
+    sendByte(0b100100001);
+    sendByte(0b000001011);
+    sendByte(0b100100001);
+    sendByte(0b000001001);
+    sendByte(0b000000000);
+    sendByte(0b100100001);
+    sendByte(0b000001010);
+    sendByte(0b000000000);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000110);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b010000000);
+    sendByte(0b000000000);
+    sendByte(0b100100001);
+    sendByte(0b000000101);
+    sendByte(0b010000000);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000010010);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b010000000);
     //Serial.print("queue size: ");
     //Serial.println(q.count());
     // if odd, send 0:
     if (strlen(s) % 2 == 1 or strlen(s) < 26) {
-        q.enqueue(0b000000000);
+        sendByte(0b000000000);
     } else {
-        q.enqueue(0b000000101);
+        sendByte(0b000000101);
     }

     // letters start here
     while (*s != '\0') {
-        q.enqueue(0b100100001);
-        q.enqueue(0b000000011);
-
-        q.enqueue(asciiTrans[*s++]);
+        sendByte(0b100100001);
+        sendByte(0b000000011);
+
+        sendByte(asciiTrans[*s++]);

-        q.enqueue(0b000001010);
-    }
-
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001001);
-    q.enqueue(0b000000000);
+        sendByte(0b000001010);
+    }
+
+    sendByte(0b100100001);
+    sendByte(0b000001001);
+    sendByte(0b000000000);
     /*
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001100);
-    q.enqueue(0b001000000);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000001101);
-    q.enqueue(0b000000111);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000110);
-    q.enqueue(0b000000001);
-    q.enqueue(0b011110100);
-    q.enqueue(0b100100001);
-    q.enqueue(0b000000101);
-    q.enqueue(0b010010000);*/
+    sendByte(0b100100001);
+    sendByte(0b000001100);
+    sendByte(0b001000000);
+    sendByte(0b100100001);
+    sendByte(0b000001101);
+    sendByte(0b000000111);
+    sendByte(0b100100001);
+    sendByte(0b000000110);
+    sendByte(0b000000001);
+    sendByte(0b011110100);
+    sendByte(0b100100001);
+    sendByte(0b000000101);
+    sendByte(0b010010000);*/
     //Serial.println("About to send bytes.");
-    sendBytes();
+
     delay(LETTER_DELAY * 2); // a bit more time
 }


use proper degrees symbol

use proper degrees symbol

--- ardesp/waterelf/waterelf.ino
+++ ardesp/waterelf/waterelf.ino
@@ -709,12 +709,12 @@
   if(GOT_TEMP_SENSOR){
     buf->concat("^ ~waterTemp~+ ");
     buf->concat(m->waterCelsius);
-    if(! JSON) buf->concat("\tC");
+    if(! JSON) buf->concat("\t\u00B0C");
   }
   if(GOT_HUMID_SENSOR){
     buf->concat("^ ~airTemp~+ ");
     buf->concat(m->airCelsius);
-    if(! JSON) buf->concat("\tC");
+    if(! JSON) buf->concat("\t\u00B0C");
     buf->concat("^ ~humidity~+ ");
     buf->concat(m->airHumid);
     if(! JSON) buf->concat("\t%RH");


Update Wrench-Mask-BLE_Unicorn-Hat-HD.ino

Eliminated if/else chain for switching faces.
Changing the face color is now done with a function.

--- NRF52832/Unicorn_Hat_HD/Wrench-Mask-BLE_Unicorn-Hat-HD.ino
+++ NRF52832/Unicorn_Hat_HD/Wrench-Mask-BLE_Unicorn-Hat-HD.ino
@@ -991,9 +991,6 @@
 Unicorn_Hat_HD lefteye = Unicorn_Hat_HD(slaveSelectPinA);
 Unicorn_Hat_HD righteye = Unicorn_Hat_HD(slaveSelectPinB);

-// Define initial facial expression
-char FaceMode = 1;
-
 // Define color parameters
 uint32_t colorRed = 0xFF0000;
 uint32_t colorGreen = 0x00FF00;
@@ -1011,7 +1008,10 @@
 long OffTime = 70; // milliseconds of off-time
 byte EyeBrightness = 50;

-// Initial boolean variables for face status checks when switching faces
+// Initialize boolean variables for face status checks when switching faces
+
+//Startup
+bool startupCheck = false;
 // Face001
 bool Face001RunningCheck = false;
 bool Face001BlinkCheck = false;
@@ -1162,6 +1162,11 @@

 void loop()
 {
+  if(startupCheck == false)
+  {
+    Face001();
+    startupCheck = true;
+  }
   // Respond to command and forward from BLEUART to HW Serial for Debugging
   while ( bleuart.available() )
   {
@@ -1170,126 +1175,40 @@
     Serial.print("Received Command: ");
     Serial.write(ch);
     Serial.println("");
-    if(ch == 0x57){
-      setFaceColor(colorRed);
-    }
-    else if(ch == 0x58){
-      setFaceColor(colorGreen);
-    }
-    else if(ch == 0x59){
-      setFaceColor(colorBlue);
-    }
-    else if(ch == 0x5A){
-      setFaceColor(colorWhite);
-    }
-    else if(ch == 0x31){
-      FaceMode=1;
-    }
-    else if(ch == 0x32){
-      FaceMode=2;
-    }
-    else if(ch == 0x33){
-      FaceMode=3;
-    }
-    else if(ch == 0x34){
-      FaceMode=4;
-    }
-    else if(ch == 0x35){
-      FaceMode=5;
-    }
-    else if(ch == 0x36){
-      FaceMode=6;
-    }
-    else if(ch == 0x37){
-      FaceMode=7;
-    }
-    else if(ch == 0x38){
-      FaceMode=8;
-    }
-    else if(ch == 0x39){
-      FaceMode=9;
-    }
-    else if(ch == 0x30){
-      FaceMode=0;
-    }
-    else if(ch == 0x41){
-      FaceMode='A';
-    }
-    else if(ch == 0x42){
-      FaceMode='B';
-    }
-    else if(ch == 0x43){
-      FaceMode='C';
-    }
-    else if(ch == 0x44){
-      FaceMode='D';
-    }
-    else if(ch == 0x45){
-      FaceMode='E';
-    }
-    else if(ch == 0x46){
-      FaceMode='F';
-    }
-    else if(ch == 0x47){
-      FaceMode='G';
-    }
-    else if(ch == 0x48){
-      FaceMode='H';
-    }
-    else if(ch == 0x49){
-      FaceMode='I';
-    }
-    else if(ch == 0x4A){
-      FaceMode='J';
-    }
-    else if(ch == 0x4B){
-      FaceMode='K';
-    }
-    else if(ch == 0x4C){
-      FaceMode='L';
-    }
-    else if(ch == 0x4D){
-      FaceMode='M';
-    }
-    else if(ch == 0x4E){
-      FaceMode='N';
-      Serial.println("Umbrella LEDs ON");
-    }
-    else if(ch == 0x2B){
-      IncrementBrightness();
-    }
-    else if(ch == 0x2D){
-      DecrementBrightness();
-    }
-  }
-
-  switch (FaceMode)
+    switch (ch)
    {
-    case 1: Face001(); break; // Draw Face001
-    case 2: Face002(); break; // Draw Face002
-    case 3: Face003(); break; // Draw Face003
-    case 4: Face004(); break; // Draw Face004
-    case 5: Face005(); break; // Draw Face005
-    case 6: Face006(); break; // Draw Face006
-    case 7: Face007(); break; // Draw Face007
-    case 8: Face008(); break; // Draw Face008
-    case 9: Face009(); break; // Draw Face009
-    case 0: Face010(); break; // Draw Face010
-    case 'A': Face011(); break; // Draw Face011
-    case 'B': Face012(); break; // Draw Face012
-    case 'C': Face013(); break; // Draw Face013
-    case 'D': Face014(); break; // Draw Face014
-    case 'E': Face015(); break; // Draw Face015
-    case 'F': Face016(); break; // Draw Face016
-    case 'G': Face017(); break; // Draw Face017
-    case 'H': Face018(); break; // Draw Face018
-    case 'I': Face019(); break; // Draw Face019
-    case 'J': Face020(); break; // Draw Face020
-    case 'K': Face021(); break; // Draw Face021
-    case 'L': Face022(); break; // Draw Face022
-    case 'M': Face023(); break; // Draw Face023
-    case 'N': Umbrella(); break; // Draw Umbrella Corp logo
+    case 0x2B: IncrementBrightness(); break;
+    case 0x2D: DecrementBrightness(); break;
+    case 0x30: Face010(); break; // Draw Face010
+    case 0x31: Face001(); break; // Draw Face001
+    case 0x32: Face002(); break; // Draw Face002
+    case 0x33: Face003(); break; // Draw Face003
+    case 0x34: Face004(); break; // Draw Face004
+    case 0x35: Face005(); break; // Draw Face005
+    case 0x36: Face006(); break; // Draw Face006
+    case 0x37: Face007(); break; // Draw Face007
+    case 0x38: Face008(); break; // Draw Face008
+    case 0x39: Face009(); break; // Draw Face009
+    case 0x41: Face011(); break; // Draw Face011
+    case 0x42: Face012(); break; // Draw Face012
+    case 0x43: Face013(); break; // Draw Face013
+    case 0x44: Face014(); break; // Draw Face014
+    case 0x45: Face015(); break; // Draw Face015
+    case 0x46: Face016(); break; // Draw Face016
+    case 0x47: Face017(); break; // Draw Face017
+    case 0x48: Face018(); break; // Draw Face018
+    case 0x49: Face019(); break; // Draw Face019
+    case 0x4A: Face020(); break; // Draw Face020
+    case 0x4B: Face021(); break; // Draw Face021
+    case 0x4C: Face022(); break; // Draw Face022
+    case 0x4D: Face023(); break; // Draw Face023
+    case 0x4E: Umbrella(); break; // Draw Umbrella Corp logo
+    case 0x57: setFaceColor(colorRed); break;
+    case 0x58: setFaceColor(colorGreen); break;
+    case 0x59: setFaceColor(colorBlue); break;
+    case 0x5A: setFaceColor(colorWhite); break;
    }
+  }
 }

 void connect_callback(uint16_t conn_handle)


add comment

add comment

--- examples/RF12/rf12compat/rf12compat.ino
+++ examples/RF12/rf12compat/rf12compat.ino
@@ -1,6 +1,8 @@
 /// @dir rf12compat
 /// Test for making the RFM12 modules compatible with RFM69 in native mode.
 // 2015-05-19 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
+//
+// Note: you need to set RF12_COMPAT to 1 in "rf12.h" to compile the sketch.

 #include <JeeLib.h>


Log when we're in Recovery.

Log when we're in Recovery.

--- linefollow/linefollow.ino
+++ linefollow/linefollow.ino
@@ -35,6 +35,7 @@

 void loop()
 {
+  bool inRecovery = false;
   int leftReading = left.read();
   int centerReading = center.read();
   int rightReading = right.read();
@@ -73,6 +74,7 @@
   // recovery
   if(!onTape(leftReading) && !onTape(centerReading) && !onTape(rightReading))
   {
+    inRecovery = true;
     if(driftingLeft) {
       leftSpeed = SPEED;
       rightSpeed = MIN_SPEED;
@@ -102,6 +104,7 @@
   Serial.print(leftSpeed);
   Serial.print("\t");
   Serial.print(rightSpeed);
+  if(inRecovery) { Serial.print("\tRECOVERY"); }
   Serial.println();
 }


Add the display loop

Add the display loop

Added three frames that are displayed. The current frames are: total
power consumption (KWh), current consumption (W), and consumption today
(KWh). Of course, data is static.

--- code/oakpowerboard/oakpowerboard.ino
+++ code/oakpowerboard/oakpowerboard.ino
@@ -1,14 +1,119 @@
+#include <Wire.h>
+
+//https://github.com/squix78/esp8266-oled-ssd1306
+#include "SSD1306.h"
+#include "SSD1306Ui.h"
+
+//Resources included with the sketch
 #include "roboto_10.h"
 #include "roboto_12.h"
 #include "roboto_thin_20.h"
 #include "images.h"

-void setup() {
-  // put your setup code here, to run once:

+// Initialize the oled display for address 0x3c
+SSD1306   display(0x3c, 0, 2);
+SSD1306Ui ui     ( &display );
+
+bool draw_totalcount_frame(SSD1306 *display, SSD1306UiState* state, int x, int y) {
+  display->setTextAlignment(TEXT_ALIGN_LEFT);
+  display->setFont(Roboto_Plain_10);
+  display->drawString(0 + x, 20, "Total:");
+  display->setFont(Roboto_Thin_Plain_20);
+  display->drawString(0 + x, 32, " 56712.12 KWh");
+  return false;
 }

+bool draw_currentconsumption_frame(SSD1306 *display, SSD1306UiState* state, int x, int y) {
+  display->setTextAlignment(TEXT_ALIGN_LEFT);
+  display->setFont(Roboto_Plain_10);
+  display->drawString(0 + x, 20, "Current:");
+  display->setFont(Roboto_Thin_Plain_20);
+  display->drawString(0 + x, 34, "  6.82 KWh");
+  return false;
+}
+
+bool draw_consumptiontoday_frame(SSD1306 *display, SSD1306UiState* state, int x, int y) {
+  display->setTextAlignment(TEXT_ALIGN_LEFT);
+  display->setFont(Roboto_Plain_10);
+  display->drawString(0 + x, 20, "Today:");
+  display->setFont(Roboto_Thin_Plain_20);
+  display->drawString(0 + x, 34, "  6.82 KWh");
+  return false;
+}
+
+bool msOverlay(SSD1306 *display, SSD1306UiState* state) {
+  display->drawXbm(32, 0, 8, 8, wifiActive);
+  display->setTextAlignment(TEXT_ALIGN_LEFT);
+  display->setFont(ArialMT_Plain_10);
+  display->drawString(0, 0, String("20:41")); //This should be the current time
+  display->setTextAlignment(TEXT_ALIGN_RIGHT);
+  display->drawString(128, 0, String(millis()));
+  return true;
+}
+
+// this array keeps function pointers to all frames
+// frames are the single views that slide from right to left
+bool (*frames[])(SSD1306 *display, SSD1306UiState* state, int x, int y) = {
+  draw_totalcount_frame,
+  draw_currentconsumption_frame,
+  draw_consumptiontoday_frame
+};
+
+// how many frames are there?
+int frameCount = 3;
+
+bool (*overlays[])(SSD1306 *display, SSD1306UiState* state)             = { msOverlay };
+int overlaysCount = 1;
+
+bool isConnected = false;
+
+void setup() {
+  ui.setTargetFPS(30);
+  ui.setActiveSymbole(activeSymbole);
+  ui.setInactiveSymbole(inactiveSymbole);
+  ui.setIndicatorPosition(TOP);
+
+  // Defines where the first frame is located in the bar.
+  ui.setIndicatorDirection(LEFT_RIGHT);
+
+  // You can change the transition that is used
+  // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
+  ui.setFrameAnimation(SLIDE_LEFT);
+
+  // Add frames
+  ui.setFrames(frames, frameCount);
+
+  // Add overlays
+  ui.setOverlays(overlays, overlaysCount);
+
+  // Inital UI takes care of initalising the display too.
+  ui.init();
+
+  display.flipScreenVertically();
+
+  // put your setup code here, to run once:
+  // initialize the digital pin as an output.
+  pinMode(1, OUTPUT); //LED on Model A
+  pinMode(6, INPUT);//Button pin
+}
+
+bool btn_state = false;
+
 void loop() {
-  // put your main code here, to run repeatedly:
+  int remainingTimeBudget = ui.update();
+  if (remainingTimeBudget > 0) {
+    // You can do some work here
+    // Don't do stuff if you are below your
+    // time budget.
+    bool curr_btn_state = (digitalRead(6) == HIGH) ? true : false;
+    if(curr_btn_state != btn_state) {
+      digitalWrite(1, curr_btn_state ? LOW : HIGH);
+      btn_state = curr_btn_state;
+    }
+    delay(remainingTimeBudget);
+  }
+}

-}
+
+


[feat] more dynamism to counters. Only eeprom config is missing for them.

--- heater_control.ino
+++ heater_control.ino
@@ -22,7 +22,8 @@

 // interrupt counter is not bound very elegantly to
 // cntArr, I think about this later.
-volatile unsigned int _kwCounter = 0;   // counter for the number of interrupts
+int volatile *_counters;
+

 IPAddress ip(192,168,1,177);
 IPAddress gateway(192,168,1, 1);
@@ -50,12 +51,13 @@

 struct cnt {
-  unsigned int counter;
+  unsigned int irqno;
   char *name;
   int flags;
   time_t last_send;
   long avg_counter;
   int avg_samples;
+  void (* irqh)(void);
   struct dig2a prev;
   struct dig2a prevsnd;
   struct dig2a diff;
@@ -76,8 +78,9 @@

 // counters are kept in array, this for preparing to have more of them.

-struct cnt cntArr[] = {         //prev prevsnd    diff   factor  scale  measured
-  {0,"electricity",  0,0,0,0,     0,0.0, 0,0.0,   0,0.1, 0,0.55, 50,1.0,  0,0.0}
+struct cnt cntArr[] = {                //prev prevsnd    diff   factor  scale  measured
+  { 1,"electricity", 0,0,0,0,irqh0,     0,0.0, 0,0.0,   0,0.1, 0,0.55, 50,1.0,  0,0.0},
+  {-1,"water",       0,0,0,0,irqh1,     0,0.0, 0,0.0,   0,0.1, 0,0.55, 50,1.0,  0,0.0}
 };

 Timer sched;
@@ -128,8 +131,13 @@
   setSyncProvider(getNtpTime);
   sched.every(1000,processSensors);
   sched.every(200,checkEthernet);
-  cntArr[0].last_send=now();
-  attachInterrupt(1, elmeter, CHANGE);
+  _counters=(int *) malloc(sizeof(int) * sizeof(cntArr) / sizeof(struct cnt));
+  for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
+    if (cntArr[i].irqno!=-1) {
+      cntArr[i].last_send=now();
+      attachInterrupt(cntArr[i].irqno,cntArr[i].irqh, CHANGE);
+    }
+  }
 }

 void loop()
@@ -138,9 +146,14 @@
   refreshEvents();
 }

-void elmeter()
-{
-  _kwCounter++;
+void irqh0()
+{
+  _counters[0]++;
+}
+
+void irqh1()
+{
+  _counters[1]++;
 }

 void processSensors()
@@ -171,28 +184,32 @@
       chkAdTimeouts(adArr,chcnt, ts, true);
     }
     calcAdChannels(adArr,chcnt);
-    calcKw();
+    calcCnt();
     sendM2X(adArr,chcnt);
     resetAdChannels(adArr,chcnt);
   }
 }

-void calcKw()
+void calcCnt()
 {
   unsigned int tmpCnt;

-  noInterrupts();
-  tmpCnt=_kwCounter;
-  interrupts();
-  cntArr[0].prev.analog=cntArr[0].measured.analog;
-  cntArr[0].measured.analog = (tmpCnt-cntArr[0].prev.digital) / (cntArr[0].scale.digital * cntArr[0].scale.analog);
-  if (cntArr[0].measured.analog > 20.0) {  // debug code. Sometimes during development a very big kw is sent to iot host.
-    cntArr[0].measured.analog = 20.0;
-  }
-  cntArr[0].avg_counter+=tmpCnt-cntArr[0].prev.digital;
-  cntArr[0].avg_samples++;
-  cntArr[0].prev.digital=tmpCnt;
+  for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
+    if (cntArr[i].irqno!=-1) {
+      noInterrupts();
+      tmpCnt=_counters[i];
+      interrupts();
+      cntArr[i].prev.analog=cntArr[i].measured.analog;
+      cntArr[i].measured.analog = (tmpCnt-cntArr[i].prev.digital) / (cntArr[i].scale.digital * cntArr[i].scale.analog);
+      if (cntArr[i].measured.analog > 20.0) {  // debug code. Sometimes during development a very big kw is sent to iot host.
+	cntArr[i].measured.analog = 20.0;
+      }
+      cntArr[i].avg_counter+=tmpCnt-cntArr[i].prev.digital;
+      cntArr[i].avg_samples++;
+      cntArr[i].prev.digital=tmpCnt;
+    }
+  }
 }

 void checkEthernet()
@@ -267,9 +284,11 @@
     timeout-=300;

   for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt)); i++) {
-    if (ts-cntArr[i].last_send > timeout) {
-      cntArr[i].flags |= FLAGS_TIMEOUT;
-      ret=true;
+    if (cntArr[i].irqno!=-1) {
+      if (ts-cntArr[i].last_send > timeout) {
+	cntArr[i].flags |= FLAGS_TIMEOUT;
+	ret=true;
+      }
     }
   }
   return ret;
@@ -283,11 +302,13 @@
   boolean ret=false;

   for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
-    diff = abs(cntArr[i].measured.analog-cntArr[i].prevsnd.analog);
-    limit = cntArr[i].diff.analog * (1.0 + cntArr[i].measured.analog * cntArr[i].diff_factor.analog);
-    if (diff > limit) {
-      cntArr[i].flags |= FLAGS_DATACHANGE;
-      ret=true;
+    if (cntArr[i].irqno!=-1) {
+      diff = abs(cntArr[i].measured.analog-cntArr[i].prevsnd.analog);
+      limit = cntArr[i].diff.analog * (1.0 + cntArr[i].measured.analog * cntArr[i].diff_factor.analog);
+      if (diff > limit) {
+	cntArr[i].flags |= FLAGS_DATACHANGE;
+	ret=true;
+      }
     }
   }
   return ret;
@@ -323,22 +344,24 @@

   // counter build part
   for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
-    if (cntArr[i].flags & FLAGS_DATACHANGE) {
-      if (ts-cntArr[i].last_send > 30) {                   // value changed and there is more than 30 seconds after prev,
-	iot.addValue(cntAvg(i),buildTime(ts-10,prevtime)); // so this time we'll send two samples.
-      }
-      currval=cntArr[i].measured.analog;
-      added=true;
-    }
-    else if (cntArr[i].flags & FLAGS_TIMEOUT) { // no big changes, only timeout
-      currval=cntAvg(i);
-      added=true;
-    }
-    if (added) {
-      iot.name(cntArr[i].name);
-      iot.addValue(currval,chbuf);
-      iot.next();
-      cntPrepareForNext(i,ts);
+    if (cntArr[i].irqno!=-1) {
+      if (cntArr[i].flags & FLAGS_DATACHANGE) {
+	if (ts-cntArr[i].last_send > 30) {                   // value changed and there is more than 30 seconds after prev,
+	  iot.addValue(cntAvg(i),buildTime(ts-10,prevtime)); // so this time we'll send two samples.
+	}
+	currval=cntArr[i].measured.analog;
+	added=true;
+      }
+      else if (cntArr[i].flags & FLAGS_TIMEOUT) { // no big changes, only timeout
+	currval=cntAvg(i);
+	added=true;
+      }
+      if (added) {
+	iot.name(cntArr[i].name);
+	iot.addValue(currval,chbuf);
+	iot.next();
+	cntPrepareForNext(i,ts);
+      }
     }
   }


Update LoRaWAN_Send.ino

Update LoRaWAN_Send.ino

--- examples/Modules/COM_LoRaWAN/LoRaWAN_Send/LoRaWAN_Send.ino
+++ examples/Modules/COM_LoRaWAN/LoRaWAN_Send/LoRaWAN_Send.ino
@@ -48,7 +48,6 @@
 void setup()
 {
   M5.begin();
-  Serial.begin(115200);
   Serial2.begin(115200, SERIAL_8N1, 15, 13);

   TerminalBuff.createSprite(250,220);


Potentially weeded out nextTime corruption (no promises!). Added sanity checks for multiple points of failure. Current status also includes several unmemorable changes and modification by other parties.

--- Elcano_C2_LowLevel/Elcano_C2_LowLevel.ino
+++ Elcano_C2_LowLevel/Elcano_C2_LowLevel.ino
@@ -80,7 +80,7 @@
 int min_rc = MIN_RC;
 #define LED_PIN_OUT 16
 //==========================================================================================
-void ISR_TURN_rise() {
+void ISR_TURN_rise(){
   noInterrupts();
   ProcessRiseOfINT(RC_TURN);
   attachInterrupt(digitalPinToInterrupt(IRPT_TURN), ISR_TURN_fall, FALLING);
@@ -259,7 +259,7 @@
 }
 /*---------------------------------------------------------------------------------------*/
 void loop() {
-  Serial.println("Start of loop");
+  //Serial.println("Start of loop");
   SerialData Results;

   // Save start time for performance report.
@@ -267,30 +267,37 @@
   // Get the next loop start time.
   unsigned long nextTime = startTime + LOOP_TIME_MS;

+  digitalWrite(27, LOW);
+  digitalWrite(33, LOW);
   startCapturingRCState();

   unsigned long local_results[7];
   //  PrintDone();

   while (millis() < nextTime &&
-         ~((RC_Done[RC_ESTP] == 1) && (RC_Done[RC_GO] == 1) && (RC_Done[RC_TURN] == 1) && (RC_Done[RC_RDR])))
+         ~((RC_Done[RC_ESTP] == 1) && (RC_Done[RC_GO] == 1) && (RC_Done[RC_TURN] == 1) && (RC_Done[RC_RDR] == 1)))
+  {
     ;  //wait
-
+  }
   // got data;
   for (int i = 0; i < 8; i++)
     local_results[i] = RC_elapsed[i];
   //Print7(false, local_results);
-  Serial.println("Processing RC data...");
+  //Serial.println("Processing RC data...");
   byte automate = processRC(local_results);
   if (automate == 0x01) //remember to tell Pat to fix this, was = instead of ==
   {
-    Serial.println("Processing high-level data");
+    //Serial.println("Processing high-level data");
     processHighLevel(&Results);
   }
   //    Print7( true, local_results);

-  Serial.println(nextTime);
-  Serial.println("Clearing Results");
+  digitalWrite(27, HIGH);
+  if(nextTime < startTime || nextTime > startTime + LOOP_TIME_MS) {
+    digitalWrite(33, HIGH);
+  }
+  //Serial.println(nextTime); //Old sanity check line; testing new pin output sanity check.
+  //Serial.println("Clearing Results");
   Results.Clear();
   Results.kind = MSG_SENSOR;
   Results.angle_deg = TurnAngle_degx10() / 10;
@@ -298,7 +305,7 @@

   // Report how long the loop took.
   unsigned long endTime = millis();
-  unsigned long elapsedTime = endTime - startTime;
+ // unsigned long elapsedTime = endTime - startTime;
 //  Serial.print("loop elapsed time = ");
 //  Serial.println(elapsedTime);

@@ -318,17 +325,22 @@

   // Did we spend long enough in the loop that we should immediately
   // start the next pass?
-  Serial.print("Time: "); Serial.print(endTime); Serial.print(", Next: "); Serial.println(nextTime);
+  //Serial.print("Time: "); Serial.print(endTime); Serial.print(", Next: "); Serial.println(nextTime);
   if (nextTime > endTime) {
     // No, pause til the next loop start time.
+    Serial.print("Start Sanity: "); Serial.println(startTime);
+    Serial.print("Const Sanity: "); Serial.println(LOOP_TIME_MS);
+    Serial.print("Next Sanity: "); Serial.println(nextTime);
+    Serial.print("End Sanity: "); Serial.println(endTime);
     Serial.print("Delaying: "); Serial.println(nextTime - endTime);
     delay(nextTime - endTime);
-  } else {
-    // Yes, we overran the expected loop interval. Extend the time.
-    nextTime = endTime + LOOP_TIME_MS;
-  }
+  }
+//  else {
+//    // Yes, we overran the expected loop interval. Extend the time.
+//    nextTime = endTime + LOOP_TIME_MS;
+//  }

-  Serial.println("End of loop");
+  //Serial.println("End of loop");
 }
 /*---------------------------------------------------------------------------------------*/
 void PrintDone()
@@ -443,7 +455,7 @@
   Serial.println("Starting square routine...");
   results = HIGH;
   long straightSpeed = 128;        //mmPs
-  long turnSpeed = 64;            //mmPs
+  long turnSpeed = 96;            //mmPs
   sides = sides * 1000;             //convert side length to mm
   unsigned long sideSec = sides / straightSpeed;  //calculate seconds per side at set speed
   sideSec = sideSec * 1000;         //convert to ms
@@ -533,10 +545,10 @@

   /* 4th pulse is gear (position 2 on receiver; controlled by gear/mode toggle on transmitter)
     will be used for emergency stop. D38 */
+  Serial.println(results[RC_ESTP]);
   results[RC_ESTP] = (results[RC_ESTP] > MIDDLE ? HIGH : LOW);

-  if (results[RC_ESTP] == HIGH)
-  {
+  if (results[RC_ESTP] == HIGH){
     E_Stop();  // already done at interrupt level
     if ((results[RC_AUTO] == LOW)  && (NUMBER_CHANNELS > 5)) // under RC control
       ;//steer(results[RC_TURN]);
@@ -572,7 +584,7 @@
   Serial.println(results[RC_GO]);
   if (liveBrake(results[RC_GO])){
     Serial.print("Braking: "); Serial.println(results[RC_GO]);
-    convertBrake ((results[RC_GO]));
+    brake(convertBrake(results[RC_GO]));
   }

   //Accelerating
@@ -716,7 +728,7 @@
 boolean liveBrake(int b)
 {
   if (b < 500) return false;
-  return (b < (MIDDLE - DEAD_ZONE));
+  return (b > (MIDDLE + DEAD_ZONE));
 }
 /*---------------------------------------------------------------------------------------*/
 // Emergency stop
@@ -736,13 +748,23 @@
   steer_control = pos;
 }
 /*---------------------------------------------------------------------------------------*/
-void convertBrake(unsigned long amount)
-{
-  if(amount < (MIDDLE + MIN_RC) / 2)
-    amount = MAX_BRAKE_OUT;
-  else if (amount > (MAX_RC - DEAD_ZONE))
-    amount = MIN_BRAKE_OUT;
-  brake (amount);
+int convertBrake(unsigned long amount){
+  const int brakeRange = MAX_BRAKE_OUT - MIN_BRAKE_OUT;
+  const int rcRange = MAX_RC - (MIDDLE + DEAD_ZONE);
+  amount -= (MIDDLE + DEAD_ZONE);
+  float operand = (float)amount / (float)rcRange;
+  operand *= brakeRange;
+  operand += MIN_BRAKE_OUT;
+  int result = (int)operand;
+  if(result > MAX_BRAKE_OUT)
+  {
+    result = MAX_BRAKE_OUT;
+  }
+//  if(amount > (MIDDLE + MIN_RC)
+//    amount = MAX_BRAKE_OUT;
+//  else if (amount > (MAX_RC - DEAD_ZONE))
+//    amount = MIN_BRAKE_OUT;
+  return result;
 }
 /*---------------------------------------------------------------------------------------*/
 void brake (int amount)


Adjusted interval bug in TwitterClient

Adjusted interval bug in TwitterClient

--- libraries/Ethernet/examples/TwitterClient/TwitterClient.ino
+++ libraries/Ethernet/examples/TwitterClient/TwitterClient.ino
@@ -14,10 +14,9 @@
  version 0019.

  Circuit:
-  * Ethernet shield attached to pins 10, 11, 12, 13
+ * Ethernet shield attached to pins 10, 11, 12, 13

  created 21 May 2011
- updates 2 Mar 2012
  by Tom Igoe

  This code is in the public domain.
@@ -30,7 +29,7 @@
 // Enter a MAC address and IP address for your controller below.
 // The IP address will be dependent on your local network:
 byte mac[] = {
-  0xDE,0xAD,0xBE,0xEF,0xFE,0xED };
+  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
 IPAddress ip(192,168,1,20);

 // initialize the library instance:
@@ -52,17 +51,17 @@
   currentLine.reserve(256);
   tweet.reserve(150);

-// initialize serial:
+  // initialize serial:
   Serial.begin(9600);
   // attempt a DHCP connection:
   Serial.println("Attempting to get an IP address using DHCP:");
   if (!Ethernet.begin(mac)) {
+    // if DHCP fails, start with a hard-coded address:
     Serial.println("failed to get an IP address using DHCP, trying manually");
-    // if DHCP fails, start with a hard-coded address:
     Ethernet.begin(mac, ip);
   }
-  Serial.print("My IP address:");
-  Serial.println(ip);
+  Serial.print("My address:");
+  Serial.println(Ethernet.localIP());
   // connect to Twitter:
   connectToServer();
 }
@@ -119,7 +118,7 @@
   Serial.println("connecting to server...");
   if (client.connect(serverName, 80)) {
     Serial.println("making HTTP request...");
-  // make HTTP GET request to twitter:
+    // make HTTP GET request to twitter:
     client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1");
     client.println("HOST: api.twitter.com");
     client.println();
@@ -127,3 +126,4 @@
   // note the time of this connect attempt:
   lastAttemptTime = millis();
 }
+


OLL solution added

OLL solution added

Sketch uses 20324 bytes (63%) of program storage space.
Global variables use 689 bytes (33%) of dynamic memory,


時刻補正の不具合修正

時刻補正の不具合修正


Now yes the last modification

Now yes the last modification

For now...

--- ArduinoVoltmeter/ArduinoVoltmeter.ino
+++ ArduinoVoltmeter/ArduinoVoltmeter.ino
@@ -1,5 +1,16 @@
+#include <D7S.h>
+
+int tiempoEspera=4;
+
+D7S dig1(5,tiempoEspera);
+D7S dig2(4,tiempoEspera);
+D7S dig3(1,tiempoEspera);
+D7S dig4(0,tiempoEspera);
+
 int entrada=2;
-int salida=13;
+
+int voltaje;
+long voltajeMap;

 int lastButtonState=HIGH;
 int buttonState;
@@ -8,22 +19,22 @@
 long inicioPresion=0;
 long finPresion=0;
 int calibrar=0;
-int canal=0;
-float calibracion=1.0;
+int canal=-1;
+float calibracion[]={
+  1.0,1.0,1.0,1.0,1.0,1.0};
+float voltajeCalibrado;

 void setup(){
-  Serial.begin(9600);
-  while(!Serial);
-
   pinMode(entrada, INPUT_PULLUP);
-  pinMode(salida, OUTPUT);

   inicioPresion=millis();
 }

 void loop(){
   leerBoton();
+  checarCanal();
   leerVoltaje();
+  mostrarVoltaje();
 }

 void leerBoton(){
@@ -38,28 +49,18 @@
       buttonState=reading;

       if(buttonState==HIGH){
-        //Serial.println("ALTO");
         finPresion=millis();
         float presion=(float)(finPresion-inicioPresion)/1000.0;
         if(presion>3.0){
           calibrar=!calibrar;
-          if(calibrar==0){
-            Serial.println("No calibrando");
-          }
-          else if(calibrar==1){
-            Serial.println("Calibrando");
-          }
         }
         else{
-          Serial.print("Canal ");
-          Serial.println(canal);
           if(canal++>=5){
             canal=0;
           }
         }
       }
       else if(buttonState==LOW){
-        //Serial.println("BAJO");
         inicioPresion=millis();
       }
     }
@@ -68,14 +69,103 @@
   lastButtonState=reading;
 }

+void checarCanal(){
+  switch(canal){
+  case 0:
+    dig4.display(0x77);
+    break;
+  case 1:
+    dig4.display(0x7c);
+    break;
+  case 2:
+    dig4.display(0x39);
+    break;
+  case 3:
+    dig4.display(0x5e);
+    break;
+  case 4:
+    dig4.display(0x79);
+    break;
+  case 5:
+    dig4.display(0x71);
+    break;
+  }
+}
+
 void leerVoltaje(){
+  voltaje=analogRead(canal);
+  voltajeMap=map(voltaje,0,1023,0,200);
+  voltajeCalibrado=(float)voltajeMap*calibracion[canal];
   if(!calibrar){
-    int voltaje=analogRead(canal);
-    long voltajeMap=map(voltaje,0,1023,0,200);
-    Serial.println(voltajeMap*calibracion);
   }
   else{
-    calibracion=(1023.0*5.0)/((float)analogRead(canal)*200.0);
-    Serial.println(calibracion);
+    calibracion[canal]=(200.0*90.0)/((float)voltajeMap*200.0);
   }
 }
+
+void mostrarVoltaje(){
+  if(!calibrar){
+    dig1.display(ponerNumero(obtenerDecenas()));
+    dig2.display(ponerNumero(obtenerUnidades())|0x80);
+    dig3.display(ponerNumero(obtenerDecimales()));
+  }
+  else{
+    dig1.display(ponerNumero(obtenerUnidadCal())|0x80);
+    dig2.display(ponerNumero(obtenerDecimasCal()));
+    dig3.display(ponerNumero(obtenerCentesimasCal())|0x80);
+  }
+}
+
+byte ponerNumero(int numero){
+  switch(numero){
+  case 0:
+    return 0x3f;
+  case 1:
+    return 0x06;
+  case 2:
+    return 0x5b;
+  case 3:
+    return 0x4f;
+  case 4:
+    return 0x66;
+  case 5:
+    return 0x6d;
+  case 6:
+    return 0x7d;
+  case 7:
+    return 0x07;
+  case 8:
+    return 0x7f;
+  case 9:
+    return 0x67;
+  default:
+    return 0x79;
+  }
+}
+
+int obtenerDecenas(){
+  int temp = ((int)voltajeCalibrado/100)%100;
+  return temp;
+}
+
+int obtenerUnidades(){
+  int temp = (((int)voltajeCalibrado%100)/10)%10;
+  return temp;
+}
+
+int obtenerDecimales(){
+  int temp = (int)voltajeCalibrado%10;
+  return temp;
+}
+
+int obtenerUnidadCal(){
+  return (int)calibracion[canal]%10;
+}
+
+int obtenerDecimasCal(){
+  return (int)(calibracion[canal]*10.0)%10;
+}
+
+int obtenerCentesimasCal(){
+  return (int)(calibracion[canal]*100.0)%10;
+}


Change pan servo "home" value to 90 degrees

--- Arduino/Thingamabot/Thingamabot.ino
+++ Arduino/Thingamabot/Thingamabot.ino
@@ -164,7 +164,7 @@
 {
   pan_servo.attach(PAN_SERVO_PIN);
   tilt_servo.attach(TILT_SERVO_PIN);
-  pan_servo.write(0);
+  pan_servo.write(90);
   tilt_servo.write(90);
 }

@@ -176,7 +176,7 @@
 {

     if (angle == 999) {
-        pan_servo.write(0);
+        pan_servo.write(90);
         tilt_servo.write(90);
     }
     else if (servoID == PAN_SERVO) {


Fix seperator for serial communication.

Fix seperator for serial communication.

--- brotherKH930_arduino.ino
+++ brotherKH930_arduino.ino
@@ -37,7 +37,7 @@
     else if (brother.carriageType() == G_CARRIAGE) Serial.print("G");
     else if (brother.carriageType() == L_CARRIAGE) Serial.print("L");
     else Serial.print("?");
-    Serial.print(" ");
+    Serial.print("\t");

     if (brother.carriagePosition() == LEFT_OUTSIDE) Serial.print("<");
     else if (brother.carriagePosition() == RIGHT_OUTSIDE) Serial.print(">");


Update comment in IRRemoteControlDemo.ino

--- examples/IRRemoteControlDemo/IRRemoteControlDemo.ino
+++ examples/IRRemoteControlDemo/IRRemoteControlDemo.ino
@@ -1,5 +1,5 @@
 /*
- * IRsend: IRRemoteControlDemo - demonstrates receiving/sending IR codes.
+ * IRRemoteControle: IRRemoteControlDemo - demonstrates receiving/sending IR codes.
  * Created by Cristiano Borges - STI - Fatesg
  * August, 2017
  */


Switch to serial com

Switch to serial com

--- sw-machine-control/module-robot-arm/src/main.ino
+++ sw-machine-control/module-robot-arm/src/main.ino
@@ -3,6 +3,7 @@
 #include <Wire.h>
 #include <Adafruit_PWMServoDriver.h>

+//#define BLUETOOTH
 //Servo Ports
 #define SERVO_TURN 0    //Turn Servo
 #define SERVO_LIFT 1    //Lift Servo
@@ -88,7 +89,7 @@
       posGrab = moveServo(SERVO_GRAB, posGrab, GRAB_OPEN);
       posLift = moveServo(SERVO_LIFT, posLift, LIFT_UP);
       posTurn = moveServo(SERVO_TURN, posTurn, TURN_MIDDLE);
-      releaseServos;
+      releaseServos();
       moduleJob = JOB_IDLE;
       sendBT("success(1)");
     }
@@ -103,7 +104,7 @@
       posGrab = moveServo(SERVO_GRAB, posGrab, GRAB_CLOSE);
       posLift = moveServo(SERVO_LIFT, posLift, LIFT_UP);
       posTurn = moveServo(SERVO_TURN, posTurn, TURN_MIDDLE);
-      releaseServos;
+      releaseServos();
       moduleJob = JOB_IDLE;
       sendBT("success(1)");
     }


Modified the firmware for the new dynamixel control code.

--- Firmware/Source/jetduino/jetduino.ino
+++ Firmware/Source/jetduino/jetduino.ino
@@ -231,9 +231,12 @@
 {
   byte servo = cmd[1];
   byte side = cmd[2];
-  byte speed = cmd[3];
-
-  Serial.print("Dynamixel Set Endless");
+  byte speed0 = cmd[3];
+  byte speed1 = cmd[4];
+
+  int speed = dynamixel.makeWord(speed0, speed1);
+
+  Serial.print("Dynamixel Set turn speed");
   Serial.print(", servo: "); Serial.print(servo);
   Serial.print(", side: "); Serial.print(side);
   Serial.print(", speed: "); Serial.println(speed);
@@ -298,7 +301,7 @@
 void loop()
 {
   long dur,RangeCm;
-  if(idx==4)
+  if(idx==6)
   {
     flag=1;
     //IR reciever pin set command
@@ -1033,9 +1036,12 @@

 void receiveData(int byteCount)
 {
+    //Serial.print("Avail: ");
+    //Serial.println(Wire.available());
+
     while(Wire.available())
     {
-      if(Wire.available()==5)
+      if(Wire.available()==6)
       {
         flag=0;
         idx=0;


Display 38400 baud properly.  Hayes: Allow DEL in PETSCII mode.

--- MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
+++ MicroView/WiFiModem-Menu/WiFiModem-Menu.ino
@@ -821,7 +821,7 @@
         Display(temp);
         delay(1000);

-        sprintf_P(temp, PSTR("Baud Rate\n\n%d"), BAUD_RATE);
+        sprintf_P(temp, PSTR("Baud Rate\n\n%u"), BAUD_RATE);
         Display(temp);
         delay(1000);

@@ -2027,7 +2027,7 @@
 void Modem_Connected()
 {
     char temp[20];
-    sprintf_P(temp, PSTR("CONNECT %d"), BAUD_RATE);
+    sprintf_P(temp, PSTR("CONNECT %u"), BAUD_RATE);

     DisplayBothP(temp);

@@ -2106,7 +2106,7 @@

             // Block non-ASCII/PETSCII characters
             unsignedInbound = (unsigned char)inbound;
-            if (unsignedInbound == 0x08 || unsignedInbound == 0x0a || unsignedInbound == 0x0d) {}  // backspace, LF, CR
+            if (unsignedInbound == 0x08 || unsignedInbound == 0x0a || unsignedInbound == 0x0d || unsignedInbound == 0x14) {}  // backspace, LF, CR, C= Delete
             else if (unsignedInbound <= 0x1f)
                 isValid = false;
             else if (unsignedInbound >= 0x80 && unsignedInbound <= 0xc0)
@@ -2114,8 +2114,8 @@
             else if (unsignedInbound >= 0xdb)
                 isValid = false;

-            /*
-            if (!isValid) {
+            // Do not delete this.  Used for troubleshooting...
+            /*if (!isValid) {
                 sprintf(temp, "-%d-",unsignedInbound);
                 C64Serial.write(temp);
             }*/


Fix indexing bug for microstep pins.

Fix indexing bug for microstep pins.

--- OpenStage/openStage_HelperFunctions.ino
+++ OpenStage/openStage_HelperFunctions.ino
@@ -185,9 +185,9 @@
       if (!axisPresent[ii]){
         continue;
       }
+      digitalWrite(MS[ii][0],LOW);
       digitalWrite(MS[ii][1],LOW);
       digitalWrite(MS[ii][2],LOW);
-      digitalWrite(MS[ii][3],LOW);
     }
   }

@@ -197,45 +197,45 @@
       if (!axisPresent[ii]){
         continue;
       }
+      digitalWrite(MS[ii][0],HIGH);
+      digitalWrite(MS[ii][1],LOW);
+      digitalWrite(MS[ii][2],LOW);
+    }
+  }
+
+  if (stepMode==(1.0/4.0))
+  {
+    for (byte ii=0; ii<4; ii++){
+      if (!axisPresent[ii]){
+        continue;
+      }
+      digitalWrite(MS[ii][0],LOW);
       digitalWrite(MS[ii][1],HIGH);
       digitalWrite(MS[ii][2],LOW);
-      digitalWrite(MS[ii][3],LOW);
+    }
+  }
+
+  if (stepMode==(1.0/8.0))
+  {
+    for (byte ii=0; ii<4; ii++){
+      if (!axisPresent[ii]){
+        continue;
+      }
+      digitalWrite(MS[ii][0],HIGH);
+      digitalWrite(MS[ii][1],HIGH);
+      digitalWrite(MS[ii][2],LOW);
     }
   }

-  if (stepMode==(1.0/4.0))
-  {
-    for (byte ii=0; ii<4; ii++){
-      if (!axisPresent[ii]){
-        continue;
-      }
-      digitalWrite(MS[ii][1],LOW);
-      digitalWrite(MS[ii][2],HIGH);
-      digitalWrite(MS[ii][3],LOW);
-    }
-  }
-
-  if (stepMode==(1.0/8.0))
-  {
-    for (byte ii=0; ii<4; ii++){
-      if (!axisPresent[ii]){
-        continue;
-      }
+  if (stepMode==(1.0/16.0))
+  {
+    for (byte ii=0; ii<4; ii++){
+      if (!axisPresent[ii]){
+        continue;
+      }
+      digitalWrite(MS[ii][0],HIGH);
       digitalWrite(MS[ii][1],HIGH);
       digitalWrite(MS[ii][2],HIGH);
-      digitalWrite(MS[ii][3],LOW);
-    }
-  }
-
-  if (stepMode==(1.0/16.0))
-  {
-    for (byte ii=0; ii<4; ii++){
-      if (!axisPresent[ii]){
-        continue;
-      }
-      digitalWrite(MS[ii][1],HIGH);
-      digitalWrite(MS[ii][2],HIGH);
-      digitalWrite(MS[ii][3],HIGH);
     }
   }


Fix UART benchmark for CDC (eg Arduino Leonardo/ATmega32U4).

--- examples/Benchmarks/CosaBenchmarkUART/CosaBenchmarkUART.ino
+++ examples/Benchmarks/CosaBenchmarkUART/CosaBenchmarkUART.ino
@@ -33,8 +33,10 @@
 static IOBuffer<128> ibuf;
 static IOBuffer<1024> obuf;

-// Create UART1 and bind to the cout IOStream
+// Create UART and bind to the cout IOStream
+#if !defined(USBCON)
 UART uart(0, &ibuf, &obuf);
+#endif

 void setup()
 {


refine led status activity

refine led status activity

--- TClab/TClab_Firmware/TClab_Firmware.ino
+++ TClab/TClab_Firmware/TClab_Firmware.ino
@@ -4,28 +4,30 @@
   This firmware is initially loaded into the Temperature Control Laboratory Arduino.
   The firmware scans the serial port looking for case-insensitive commands:

-  Q int     set Heater 1, range 0 to 255,  limit to 150 to prevent overheating
-            (note: Q turns off Heater 2 as safety precaution)
-  Q1 int    set Heater 1, range 0 to 255,  limit to 150 to prevent overheating
-  Q2 int    set Heater 2, range 0 to 255,  limit to 150 to prevent overheating
-  T         get Temperature T1, returns deg C as sring
+  Q int     set Heater 1 and 2, range 0 to 255, subject to limits
+  Q1 int    set Heater 1, range 0 to 255 subject to limit
+  Q2 int    set Heater 2, range 0 to 255 subject to limit
   T1        get Temperature T1, returns deg C as string
   T2        get Temperature T2, returns dec C as string
   VERSION   get firmware version string
-  X         shutdown, set Q1, Q2 to zero
+  X         shutdown, reset required

-  LED1 is on during normal operation.
+  LED1 on dim during normal operation.
+  LED1 on bright when if either is on
+  LED1 blinks if high temperature alarm is on

-  LED1 is on bright for high temperature alarm.
-
-  Receipt of any unrecognized commands cause the board to shutdown and report
-  status by blinking LED1. Reset is required.
+  Receipt of any unrecognized commands cause the board to shutdown and  Reset is required.
 */

 // global variables
 char Buffer[64];               // buffer for parsing serial input
 String cmd;                    // command
 int pv;                        // command pin value
+int ledStatus;                 // 0:off, 1:dim, 2:bright 3:dim blink 4:bright blink
+int brdStatus = 1;             // board status 0:reset required 1:ok
+int Q1 = 0;                    // last value written to Q1 pin
+int Q2 = 0;                    // last value written to Q2 poin
+int alarmStatus = 0;           // hi temperature alarm status

 // constants
 const String vers = "0.1";     // version of this firmware
@@ -41,12 +43,30 @@
 const int pinLED1 = 9;         // LED1

 // high limits expressed (units of pin values)
-const int limLED1 =  50;       // LED1 limit
 const int limQ1   = 150;       // Q1 limit
 const int limQ2   = 150;       // Q2 limit
 const int limT1   = 310;       // T1 high alarm (approx. 50 deg C)
 const int limT2   = 310;       // T2 high alarm (approx. 50 deg C)

+// LED1 levels
+const int hiLED   =  50;       // high limit of LED
+const int loLED   = hiLED/16;  // low LED
+
+void setHeater1(int pv) {
+  if (brdStatus > 0) {
+    Q1 = max(0, min(limQ1, pv));
+    analogWrite(pinQ1, Q1);
+    Serial.println(Q1);
+  }
+}
+
+void setHeater2(int pv) {
+  if (brdStatus > 0) {
+    Q2 = max(0, min(limQ2, pv));
+    analogWrite(pinQ2, Q2);
+    Serial.println(Q2);
+  }
+}

 // parse serial input
 void SerialParse(void) {
@@ -67,24 +87,18 @@
   pv = data.toInt();
 }

-
 // dispatch commands
 void CommandDispatch(void) {
   // process commands
   if (cmd == "Q") {
-    analogWrite(pinQ1, max(0,min(limQ1,pv)));
-    analogWrite(pinQ2, 0);
+    setHeater1(pv);
+    setHeater2(pv);
   }
   else if (cmd == "Q1") {
-    analogWrite(pinQ1, max(0,min(limQ1,pv)));
+    setHeater1(pv);
   }
   else if (cmd == "Q2") {
-    analogWrite(pinQ2, max(0,min(limQ2,pv)));
-  }
-  else if (cmd == "T") {
-    float mV = (float)analogRead(pinT1) * (3300.0/1024.0);
-    float degC = (mV - 500.0)/10.0;
-    Serial.println(degC);
+    setHeater2(pv);
   }
   else if (cmd == "T1") {
     float mV = (float)analogRead(pinT1) * (3300.0/1024.0);
@@ -97,39 +111,70 @@
     Serial.println(degC);
   }
   else if (cmd == "VERSION") {
-    Serial.println("TC Laboratory Firmware Version " + vers);
+    Serial.println("TClab Firmware Version " + vers);
   }
   // shutdown
-  else if (cmd == "X") {
-    analogWrite(pinQ1, 0);
-    analogWrite(pinQ2, 0);
+  else if ((cmd == "X") or (cmd.length() > 0)) {
+    Serial.println("Unrecognized command. Please reset.");
+    setHeater1(0);
+    setHeater2(0);
+    brdStatus = 0;
   }
-  // shut down on unrecognized command
-  else if (cmd.length() > 0) {
-    Serial.println("Unrecognized command. Please reset.");
-    analogWrite(pinQ1, 0);
-    analogWrite(pinQ2, 0);
-    while (true) {
-      analogWrite(pinLED1, limLED1);
-      delay(250);
+}
+
+// check alarms and update status on LED1
+void AlarmCheck(void) {
+  if (analogRead(pinT1) > limT1) {
+    alarmStatus = 1;
+  }
+  else if (analogRead(pinT2) > limT2) {
+    alarmStatus = 1;
+  }
+  else {
+    alarmStatus = 0;
+  }
+}
+
+// update LED
+void LEDUpdate(void) {
+  // find led status
+  ledStatus = brdStatus;
+  if ((Q1 > 0) or (Q2 > 0)) {
+    ledStatus = 2;
+  }
+  if (alarmStatus > 0) {
+    ledStatus = 3;
+    if ((Q1 > 0) or (Q2 > 0)) {
+      ledStatus = 4;
+    }
+  }
+  // update led depending on ledStatus
+  if (ledStatus == 0) {
+    analogWrite(pinLED1, 0);
+  }
+  else if (ledStatus == 1) {
+    analogWrite(pinLED1, loLED);
+  }
+  else if (ledStatus == 2) {
+    analogWrite(pinLED1, hiLED);
+  }
+  else if (ledStatus == 3) {
+    if ((millis() % 2000) > 1000) {
+      analogWrite(pinLED1, loLED);
+    } else {
       analogWrite(pinLED1, 0);
-      delay(250);
+    }
+  }
+  else if (ledStatus == 4) {
+    if ((millis() % 2000) > 1000) {
+      analogWrite(pinLED1, hiLED);
+    } else {
+      analogWrite(pinLED1, 0);
     }
   }
 }

-
-// check alarms and update status on LED1
-void AlarmsCheck(void) {
-  if ((analogRead(pinT1) > limT1) or (analogRead(pinT2) > limT2)) {
-    analogWrite(pinLED1,limLED1);
-  } else {
-    analogWrite(pinLED1,limLED1/16);
-  }
-}
-
-
-// setup on reboot
+// arduino setup procedure
 void setup() {
   analogReference(EXTERNAL);
   Serial.begin(baud);
@@ -137,14 +182,14 @@
     ; // wait for serial port to connect.
   }
   Serial.flush();
-  analogWrite(pinQ1,0);
-  analogWrite(pinQ2,0);
+  setHeater1(0);
+  setHeater2(0);
 }

-
-// main event loop
+// arduino main event loop
 void loop() {
   SerialParse();
   CommandDispatch();
-  AlarmsCheck();
+  AlarmCheck();
+  LEDUpdate();
 }


Add rainbow clock

Add rainbow clock

Add rainbow clock face.

--- firmware/examples/1_RGBPongClock.ino
+++ firmware/examples/1_RGBPongClock.ino
@@ -81,7 +81,7 @@
 /****************************************/

-#define MAX_CLOCK_MODE		8                 // Number of clock modes
+#define MAX_CLOCK_MODE		9                 // Number of clock modes

 /********** RGB565 Color definitions **********/
 #define Black           0x0000
@@ -286,6 +286,7 @@
 void randomFillWorld();
 int neighbours(int x, int y);
 void conwayLife();
+void rainbow();
 /*************************************/

@@ -422,6 +423,9 @@
 	case 7:
 		conwayLife();
 		break;
+	case 8:
+		rainbow();
+		break;
 	default:
 		normal_clock();
 		break;
@@ -507,6 +511,10 @@
 	else if(command == "life") {
 		mode_changed = 1;
 		clock_mode = 7;
+	}
+	else if(command == "rainbow") {
+		mode_changed = 1;
+		clock_mode = 8;
 	}
 	if (mode_changed == 1) {
 		modeSwitch = millis();
@@ -2515,3 +2523,73 @@
 	}
 }

+void rainbow() {
+	long hval = 0;
+	uint8_t x, y, r, g, b, a;
+	int16_t hue = 0;
+
+	cls();
+
+	int showTime = Time.now();
+
+	while((Time.now() - showTime) < showClock) {
+		if (mode_changed == 1)
+			return;
+		if(mode_quick){
+			mode_quick = false;
+			display_date();
+			quickWeather();
+			conwayLife();
+			return;
+		}
+
+		// Draw alternating rainbow
+		for(x=0; x<matrix.width(); x++) {
+			for(int h=hue, y=0; y<matrix.height(); y++, h += 48) {
+				a = h;
+				switch((h >> 8) % 6) {
+				case 0: r = 255; g =   a; b =   0; break;
+				case 1: r =  ~a; g = 255; b =   0; break;
+				case 2: r =   0; g = 255; b =   a; break;
+				case 3: r =   0; g =  ~a; b = 255; break;
+				case 4: r =   a; g =   0; b = 255; break;
+				case 5: r = 255; g =   0; b =  ~a; break;
+				}
+				matrix.drawPixel(x, y, matrix.Color888(r, g, b, true));
+			}
+		}
+		hue += 7;
+		if(hue >= 1536) hue -= 1536;
+
+		// Display the time
+		int mins = Time.minute();
+		int hours = Time.hour();
+		char buffer[3];
+
+		itoa(hours,buffer,10);
+		//fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
+		if (hours < 10) {
+			buffer[1] = buffer[0];
+			buffer[0] = '0';
+		}
+		vectorNumber(buffer[0]-'0',8,1,Black,1,1);
+		vectorNumber(buffer[1]-'0',12,1,Black,1,1);
+
+		itoa(mins,buffer,10);
+		//fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
+		if (mins < 10) {
+			buffer[1] = buffer[0];
+			buffer[0] = '0';
+		}
+		vectorNumber(buffer[0]-'0',18,1,Black,1,1);
+		vectorNumber(buffer[1]-'0',22,1,Black,1,1);
+
+		matrix.drawPixel(16,2,Black);
+		matrix.drawPixel(16,4,Black);
+
+		matrix.swapBuffers(false);
+		Particle.process();	//Give the background process some lovin'
+		delay(50);
+	}
+}
+


FW fix

FW fix

--- _firmware/tiny2313-3/tiny2313-3.ino
+++ _firmware/tiny2313-3/tiny2313-3.ino
@@ -50,7 +50,7 @@

 #define WAIT 2

-uint8_t display[4] = {0x79,0x5e,0x1c,0x6d}; //0x9e
+uint8_t display[4] = {128,128,128,128}; //0x9e

 // global buffer to store data sent from the master.


Added mode sensor.

Added mode sensor.

--- RelayTemperatureSensor/RelayTemperatureSensor.ino
+++ RelayTemperatureSensor/RelayTemperatureSensor.ino
@@ -16,6 +16,7 @@

 // ---- NODE
 #define NODE_ID 110
+#define CHILD_ID_MODE 3 // MODE true: AC, false: Heating
 #define CHILD_ID_RELAY_AC 2 // Relay for Air conditioner
 #define CHILD_ID_RELAY 1    // Relay for heating
 #define CHILD_ID_TEMP 0
@@ -46,6 +47,7 @@
 // ----- GLOBAL
 MySensor hw;
 static char outstr[15];
+static uint8_t MODE = 0;

 void setup()
 {
@@ -67,6 +69,10 @@
   // --- RELAY
   hw.present(CHILD_ID_RELAY, S_LIGHT);
   hw.present(CHILD_ID_RELAY_AC, S_LIGHT);
+  hw.present(CHILD_ID_MODE, S_LIGHT);
+
+  // Set last mode
+  MODE = hw.loadState(CHILD_ID_MODE);

   // Then set relay pins in output mode
   pinMode(RELAY_PIN, OUTPUT);
@@ -124,11 +130,12 @@
 void incomingMessage(const MyMessage &message) {
   processHeatingMessage(message);
   processACMessage(message);
+  processModeMessage(message);
 }

 void processHeatingMessage(const MyMessage &message) {
   // We only expect one type of message from controller. But we better check anyway.
-  if (message.sensor == CHILD_ID_RELAY && message.type == V_LIGHT) {
+  if (!MODE && message.sensor == CHILD_ID_RELAY && message.type == V_LIGHT) {
     // Change relay state
     digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
     // Store state in eeprom
@@ -139,7 +146,7 @@

 void processACMessage(const MyMessage &message) {
   // We only expect one type of message from controller. But we better check anyway.
-  if (message.sensor == CHILD_ID_RELAY_AC && message.type == V_LIGHT) {
+  if (MODE && message.sensor == CHILD_ID_RELAY_AC && message.type == V_LIGHT) {
     digitalWrite(RELAY_PIN, RELAY_ON);
     hw.wait(PUSH_TIMEOUT);
     digitalWrite(RELAY_PIN, RELAY_OFF);
@@ -147,3 +154,11 @@
   }
 }

+void processModeMessage(const MyMessage &message) {
+  if (message.sensor == CHILD_ID_MODE && message.type == V_LIGHT) {
+    MODE = message.getBool();
+    // Store state in eeprom
+    hw.saveState(CHILD_ID_MODE, MODE);
+  }
+}
+


Beefier servos update

Beefier servos update

--- ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
+++ ElevatorGUI/ElevatorController_arduino/ArielsMotorCode/ArielsMotorCode.ino
@@ -74,10 +74,12 @@

       // valid step modes: 1, 2, 4, 8, 16, 32, 64, 128
       stepper.setStepMode(input_mode);
-
+
       for (int x = 0; x < input_step; x++)
       {
+        //unsigned long t = micros();
         step(input_delay);
+        //Serial.println(micros()-t);
         //Serial.println(x);
       }
   }
@@ -91,9 +93,9 @@
   digitalWrite(amisStepPin, HIGH);
   // delay = time each step takes, or
   // delay = ((60,000 msecs)/(200 steps)) * (1/RPM)
-  delay(input_delay * 1000);
+  delayMicroseconds(input_delay * 1000);
   digitalWrite(amisStepPin, LOW);
-  delay(input_delay * 1000);
+  delayMicroseconds(input_delay * 1000);
 }

 // Writes a high or low value to the direction pin to specify


Added missing final "}"

Added missing final "}"

--- VernierThermistorStore/VernierThermistorStore.ino
+++ VernierThermistorStore/VernierThermistorStore.ino
@@ -244,3 +244,4 @@
   Temp = 1 / (0.00102119 + (0.000222468 * Temp) + (0.000000133342 * Temp * Temp * Temp));
   Temp = Temp - 273.15;  // Convert Kelvin to Celsius
   return Temp;                                      // Return the Temperature
+}


cleaned formatting

cleaned formatting

formatting

--- WordClock_NeoMatrix8x8/WordClock_NeoMatrix8x8.ino
+++ WordClock_NeoMatrix8x8/WordClock_NeoMatrix8x8.ino
@@ -60,26 +60,26 @@

 // define masks for each word. we add them with "bitwise or" to generate a mask for the entire "phrase".
 // have to use two different 32-bits numbers, luckily none of the words are spread across top and bottom halves of the NeoMatrix.
-#define MFIVE topMask |= 0xF000        // these are in hexadecimal
-#define MTEN topMask |= 0x58000000
-#define AQUARTER topMask |= 0x80FE0000
-#define TWENTY topMask |= 0x7E000000
-#define HALF topMask |= 0xF00
-#define PAST topMask |= 0x78
-#define TO topMask |= 0xC
-#define ONE bottomMask |= 0x43
-#define TWO bottomMask |= 0xC040
-#define THREE bottomMask |= 0x1F0000
-#define FOUR bottomMask |= 0xF0
-#define FIVE bottomMask |= 0xF0000000
-#define SIX bottomMask |= 0xE00000
-#define SEVEN bottomMask |= 0x800F00
-#define EIGHT bottomMask |= 0x1F000000
-#define NINE bottomMask |= 0xF
-#define TEN bottomMask |= 0x1010100
+#define MFIVE     topMask |= 0xF000        // these are in hexadecimal
+#define MTEN      topMask |= 0x58000000
+#define AQUARTER  topMask |= 0x80FE0000
+#define TWENTY    topMask |= 0x7E000000
+#define HALF      topMask |= 0xF00
+#define PAST      topMask |= 0x78
+#define TO        topMask |= 0xC
+#define ONE    bottomMask |= 0x43
+#define TWO    bottomMask |= 0xC040
+#define THREE  bottomMask |= 0x1F0000
+#define FOUR   bottomMask |= 0xF0
+#define FIVE   bottomMask |= 0xF0000000
+#define SIX    bottomMask |= 0xE00000
+#define SEVEN  bottomMask |= 0x800F00
+#define EIGHT  bottomMask |= 0x1F000000
+#define NINE   bottomMask |= 0xF
+#define TEN    bottomMask |= 0x1010100
 #define ELEVEN bottomMask |= 0x3F00
 #define TWELVE bottomMask |= 0xF600
-#define ANDYDORO topMask |= 0x89010087
+#define ANDYDORO  topMask |= 0x89010087

 // define pins
 #define NEOPIN 8  // connect to DIN on NeoMatrix 8x8


Enable pull-up resistors on RSSI pins

Enable pull-up resistors on RSSI pins

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -152,6 +152,13 @@
     pinMode(PIN_SPI_SLAVE_SELECT, OUTPUT);
     pinMode(PIN_SPI_DATA, OUTPUT);
 	pinMode(PIN_SPI_CLOCK, OUTPUT);
+
+    // Enabe pull-up resistors on RSSI pins to help keep the receivers a little
+    // cooler.
+    digitalWrite(PIN_RSSI_A, HIGH);
+    #ifdef USE_DIVERSITY
+        digitalWrite(PIN_RSSI_B, HIGH);
+    #endif
 }

 void setupSettings() {


removing dip mode and general cleanup of the code for readabuility.

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -5,6 +5,7 @@
  * Inital 2 Button version by Peter (pete1990)
  * Refactored and GUI reworked by Marko Hoepken
  * Universal version my Marko Hoepken
+ * Diversity Receiver Mode and GUI improvements by Shea Ivey

 The MIT License (MIT)

@@ -35,10 +36,7 @@
 #include <EEPROM.h>

 // Feature Togglels
-//define USE_DIP
-#define USE_DIVERSITY
 //#define DEBUG
-//#define RSSI_DEBUG

 #define spiDataPin 10
 #define slaveSelectPin 11
@@ -48,7 +46,6 @@
 #define receiverA_led A1
 #define rssiPinA A7

-#ifdef USE_DIVERSITY
 // Diversity
 #define receiverB_led A0
 #define rssiPinB A6
@@ -58,7 +55,6 @@
 // rssi strenth should be 2% greater than other receiver before switch.
 // this pervents flicker when rssi are close.
 #define DIVERSITY_CUTOVER 2
-#endif

 // this two are minimum required
 #define buttonSeek 2
@@ -68,17 +64,6 @@
 #define buttonSave 5
 // Buzzer
 #define buzzer 6
-
-// pins for DIP switch
-//#define USE_DIP
-#ifdef USE_DIP
-    #define dip_ch0 A0
-    #define dip_ch1 A1
-    #define dip_ch2 A2
-    #define dip_band0 A3
-    #define dip_band1 A4
-    #define dip_enable 0
-#endif

 // key debounce delay in ms
 // NOTE: good values are in the range of 100-200ms
@@ -107,9 +92,7 @@
 #define STATE_SWITCH 4
 #define STATE_SAVE 5
 #define STATE_RSSI_SETUP 6
-#ifdef USE_DIVERSITY
 #define STATE_DIVERSITY 7
-#endif

 #define START_STATE STATE_SEEK
 #define MAX_STATE STATE_MANUAL
@@ -137,14 +120,11 @@
 #define EEPROM_ADR_RSSI_MIN_A_H 3
 #define EEPROM_ADR_RSSI_MAX_A_L 4
 #define EEPROM_ADR_RSSI_MAX_A_H 5
-#ifdef USE_DIVERSITY
 #define EEPROM_ADR_DIVERSITY 6
 #define EEPROM_ADR_RSSI_MIN_B_L 7
 #define EEPROM_ADR_RSSI_MIN_B_H 8
 #define EEPROM_ADR_RSSI_MAX_B_L 9
 #define EEPROM_ADR_RSSI_MAX_B_H 10
-#endif
-//#define DEBUG

 // Channels to sent to the SPI registers
 const uint16_t channelTable[] PROGMEM = {
@@ -181,9 +161,7 @@
 uint8_t channelIndex = 0;
 uint8_t rssi = 0;
 uint8_t rssi_scaled = 0;
-#ifdef USE_DIVERSITY
 uint8_t diversity_mode = useReceiverAuto;
-#endif
 uint8_t hight = 0;
 uint8_t state = START_STATE;
 uint8_t state_last_used=START_STATE;
@@ -208,12 +186,10 @@
 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;
-#endif
 uint16_t rssi_seek_found=0;
 uint16_t rssi_setup_run=0;

@@ -241,25 +217,8 @@
     //Receiver Setup
     pinMode(receiverA_led,OUTPUT);
     digitalWrite(buzzer, HIGH);
-#ifdef USE_DIVERSITY
     pinMode(receiverB_led,OUTPUT);
     digitalWrite(receiverA_led, LOW);
-#endif
-    // dip switches
-#ifdef USE_DIP
-    pinMode(dip_ch0, INPUT);
-    digitalWrite(dip_ch0, INPUT_PULLUP);
-    pinMode(dip_ch1, INPUT);
-    digitalWrite(dip_ch1, INPUT_PULLUP);
-    pinMode(dip_ch2, INPUT);
-    digitalWrite(dip_ch2, INPUT_PULLUP);
-    pinMode(dip_band0, INPUT);
-    digitalWrite(dip_band0, INPUT_PULLUP);
-    pinMode(dip_band1, INPUT);
-    digitalWrite(dip_band1, INPUT_PULLUP);
-    pinMode(dip_enable, INPUT);
-    digitalWrite(dip_enable, INPUT_PULLUP);
-#endif
 #ifdef DEBUG
     Serial.begin(115200);
     Serial.println(F("START:"));
@@ -300,7 +259,6 @@
         // save 16 bit
         EEPROM.write(EEPROM_ADR_RSSI_MAX_A_L,lowByte(RSSI_MAX_VAL));
         EEPROM.write(EEPROM_ADR_RSSI_MAX_A_H,highByte(RSSI_MAX_VAL));
-#ifdef USE_DIVERSITY
         // diversity
         EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
         // save 16 bit
@@ -309,21 +267,16 @@
         // save 16 bit
         EEPROM.write(EEPROM_ADR_RSSI_MAX_B_L,lowByte(RSSI_MAX_VAL));
         EEPROM.write(EEPROM_ADR_RSSI_MAX_B_H,highByte(RSSI_MAX_VAL));
-#endif
-    }
-    // debug reset EEPROM
-    //EEPROM.write(EEPROM_ADR_STATE,255);
+    }

     // read last setting from eeprom
     state=EEPROM.read(EEPROM_ADR_STATE);
     channelIndex=EEPROM.read(EEPROM_ADR_TUNE);
     rssi_min_a=((EEPROM.read(EEPROM_ADR_RSSI_MIN_A_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MIN_A_L)));
     rssi_max_a=((EEPROM.read(EEPROM_ADR_RSSI_MAX_A_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MAX_A_L)));
-#ifdef USE_DIVERSITY
     diversity_mode = EEPROM.read(EEPROM_ADR_DIVERSITY);
     rssi_min_b=((EEPROM.read(EEPROM_ADR_RSSI_MIN_B_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MIN_B_L)));
     rssi_max_b=((EEPROM.read(EEPROM_ADR_RSSI_MAX_B_H)<<8) | (EEPROM.read(EEPROM_ADR_RSSI_MAX_B_L)));
-#endif
     force_menu_redraw=1;
 }

@@ -384,11 +337,7 @@
             TV.printPGM(10, 5+1*MENU_Y_SIZE, PSTR("Auto Search"));
             TV.printPGM(10, 5+2*MENU_Y_SIZE, PSTR("Band Scanner"));
             TV.printPGM(10, 5+3*MENU_Y_SIZE, PSTR("Manual Mode"));
-#ifdef USE_DIVERSITY
             TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Diversity"));
-#else
-            TV.printPGM(10, 5+4*MENU_Y_SIZE, PSTR("Switch Mode"));
-#endif
             TV.printPGM(10, 5+5*MENU_Y_SIZE, PSTR("Save Setup"));
             // selection by inverted box
             switch (menu_id)
@@ -410,12 +359,7 @@
                 break;
                 case 3: // DIP mode or diversity
                     TV.draw_rect(8,3+4*MENU_Y_SIZE,100,12,  WHITE, INVERT);
-#ifdef USE_DIVERSITY
                     state=STATE_DIVERSITY;
-#else
-                    state=STATE_SWITCH;
-                    last_dip_channel=255; // force update
-#endif
                 break;
                 case 4: // Save settings
                     TV.draw_rect(8,3+5*MENU_Y_SIZE,100,12,  WHITE, INVERT);
@@ -477,16 +421,6 @@
     { // reset debounce
         switch_count = 0;
     }
-#ifdef USE_DIP
-    /***********************/
-    /*   Static SWITCH MODE   */
-    /***********************/
-    // set to SWITCH mode if SWITCH_ENABLE is low (no interactive mode)
-    if(digitalRead(dip_enable) == LOW)
-    {
-        state=STATE_SWITCH;
-    }
-#endif
     /***********************/
     /*     Save buttom     */
     /***********************/
@@ -580,17 +514,13 @@
                 update_frequency_view=1;
                 force_seek=1;
             break;
-#ifdef USE_DIVERSITY
             case STATE_DIVERSITY:
                 // diversity menu is below this is just a place holder.
             break;
-#endif
             case STATE_SAVE:
                 EEPROM.write(EEPROM_ADR_TUNE,channelIndex);
                 EEPROM.write(EEPROM_ADR_STATE,state_last_used);
-#ifdef USE_DIVERSITY
                 EEPROM.write(EEPROM_ADR_DIVERSITY,diversity_mode);
-#endif
                 TV.select_font(font8x8);
                 TV.draw_rect(0,0,127,95,  WHITE);
                 TV.draw_line(0,14,127,14,WHITE);
@@ -679,7 +609,6 @@
     /*************************************/
     /*   Processing depending of state   */
     /*************************************/
-#ifdef USE_DIVERSITY
     if(state == STATE_DIVERSITY) {
         // simple menu
         char menu_id=diversity_mode;
@@ -766,7 +695,6 @@

         state=state_last_used;
     }
-#endif
     /*****************************************/
     /*   Processing MANUAL MODE / SEEK MODE  */
     /*****************************************/
@@ -798,24 +726,6 @@
                 update_frequency_view=1;
             }
         }
-#ifdef USE_DIP
-        if(state == STATE_SWITCH) // SWITCH MODE
-        {
-            // read band DIP switch (invert since switch pulls to gnd)
-            uint8_t dip_band= (((digitalRead(dip_band1)<<1) | digitalRead(dip_band0)) ^0x3);
-            // read channel DIP switch (invert since switch pulls to gnd)
-            uint8_t dip_channel = (((digitalRead(dip_ch2)<<2) | ((digitalRead(dip_ch1))<<1) | (digitalRead(dip_ch0))) ^0x7);
-            if((dip_band != last_dip_band) || (dip_channel != last_dip_channel)) // check for changes to avoid unrequred tuning
-            {
-                last_dip_band=dip_band;
-                last_dip_channel=dip_channel;
-                // caclulate index of channel in 4x8 array
-                channelIndex=CHANNEL_BAND_SIZE*last_dip_band + last_dip_channel;
-                update_frequency_view=1;
-            }
-
-        }
-#endif
         // display refresh handler
         if(update_frequency_view) // only updated on changes
         {
@@ -992,7 +902,6 @@
                     // save 16 bit
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_A_L,(rssi_max_a & 0xff));
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_A_H,(rssi_max_a >> 8));
-#ifdef USE_DIVERSITY
                     rssi_min_b=rssi_setup_min_b;
                     rssi_max_b=rssi_setup_max_b;
                     // save 16 bit
@@ -1001,7 +910,6 @@
                     // save 16 bit
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_B_L,(rssi_max_b & 0xff));
                     EEPROM.write(EEPROM_ADR_RSSI_MAX_B_H,(rssi_max_b >> 8));
-#endif

                     state=EEPROM.read(EEPROM_ADR_STATE);
                     beep(1000);
@@ -1091,32 +999,22 @@
     }
 }

-#ifdef USE_DIVERSITY
 uint16_t readRSSI()
 {
     return readRSSI(-1);
 }
 uint16_t readRSSI(uint8_t receiver)
 {
-#else
-uint16_t readRSSI()
-{
-#endif
     uint16_t rssi = 0;
     uint16_t rssiA = 0;
-#ifdef USE_DIVERSITY
     uint16_t rssiB = 0;
-#endif
     for (uint8_t i = 0; i < 10; i++)
     {
         rssiA += analogRead(rssiPinA);
-#ifdef USE_DIVERSITY
         rssiB += analogRead(rssiPinB);
-#endif
-    }
-    rssiA = rssiA/10;
-#ifdef USE_DIVERSITY
-    rssiB = rssiB/10;
+    }
+    rssiA = rssiA/10; // average of 10 readings
+    rssiB = rssiB/10; // average of 10 readings
     // choosing which receiver RSSI to use.. do not change LED
     if(receiver == useReceiverA)
     {
@@ -1165,12 +1063,8 @@
                 break;
         }
     }
-#else
-    digitalWrite(receiverA_led, HIGH);
-#endif
-
-
-    //rssi=rssi/10; // average
+
+
     // special case for RSSI setup
     if(state==STATE_RSSI_SETUP)
     { // RSSI setup
@@ -1186,7 +1080,6 @@
             TV.print(110, SCANNER_LIST_Y_POS, "   ");
             TV.print(110, SCANNER_LIST_Y_POS, rssi_setup_max_a , DEC);
         }
-#ifdef USE_DIVERSITY
         if(rssiB < rssi_setup_min_b)
         {
             rssi_setup_min_b=rssiB;
@@ -1195,10 +1088,8 @@
         {
             rssi_setup_max_b=rssiB;
         }
-#endif
-    }
-
-#ifdef USE_DIVERSITY
+    }
+
     if(receiver == useReceiverA || state==STATE_RSSI_SETUP)
     {
         rssi = constrain(rssiA, rssi_min_a, rssi_max_a);    //original 90---250
@@ -1210,15 +1101,9 @@
         rssi=rssi-rssi_min_b; // set zero point (value 0...160)
         rssi = map(rssi, 0, rssi_max_a-rssi_min_b , 1, 100);   // scale from 1..100%
     }
-#else
-    rssi = constrain(rssiA, rssi_min_a, rssi_max_a);    //original 90---250
-    rssi=rssi-rssi_min_a; // set zero point (value 0...160)
-    rssi = map(rssi, 0, rssi_max_a-rssi_min_a , 1, 100);   // scale from 1..100%
-#endif
     return (rssi);
 }

-#ifdef USE_DIVERSITY
 void setReceiver(uint8_t receiver) {
     if(receiver == useReceiverA)
     {
@@ -1231,7 +1116,6 @@
         digitalWrite(receiverA_led, LOW);
     }
 }
-#endif

 // Private function: from http://arduino.cc/playground/Code/AvailableMemory
 int freeRam () {