Count jumping jacks too

Count jumping jacks too

--- StepCounter.ino
+++ StepCounter.ino
@@ -33,10 +33,18 @@
 #define STATE_SETUP    0x1
 #define STATE_READY    0x2
 #define STATE_RUNNING  0x3
-#define STATE_COMPLETE 0x4
-
+#define STATE_JUMPING  0x4
+#define STATE_COMPLETE 0x5
+
+#define LCD_PADDING_ZERO '0'
+#define LCD_PADDING_SPACE ' '
 #define LCD_POSITION_RUNG 14
 #define LCD_POSITION_SCR 8
+#define LCD_POSITION_RIGHT 15
+#define LCD_LINE_ZERO 0
+#define LCD_LINE_ONE 1
+
+#define MAX_JUMPS 7

 int programState;
 int displayState;
@@ -44,7 +52,9 @@
 uint8_t buttonState;

 int currentSteps;
+int currentJumps;
 int switchState;
+boolean justJumped;

 void setup() {
 	// Debugging output
@@ -57,7 +67,9 @@
 	displayState = 0;
 	buttonState = 0;
 	rung = 1;
-	currentSteps = -1;
+	currentSteps = 0;
+	currentJumps = 0;
+	justJumped = false;
 	switchState = HIGH;

 	lcd.setBacklight(WHITE);
@@ -72,14 +84,20 @@
 			break;
 		case STATE_READY:
 			processSwitch();
-			if(currentSteps == 0){
-				programState = STATE_RUNNING;
-			}
 			break;
 		case STATE_RUNNING:
 			processSwitch();
 			if(currentSteps == introLadder[rung]){
 				programState = STATE_COMPLETE;
+			}else if(currentSteps != 0 && currentSteps % 75 == 0 && !justJumped){
+				programState = STATE_JUMPING;
+			}
+		case STATE_JUMPING:
+			processSwitch();
+			if(currentJumps == MAX_JUMPS){
+				currentJumps = 0;
+				justJumped = true;
+				programState = STATE_RUNNING;
 			}
 		case STATE_COMPLETE:
 			break;
@@ -100,43 +118,25 @@
 		switchState = newSwitchState;

 		if(switchState == LOW){
-			currentSteps++;
-
-			if(programState == STATE_RUNNING || programState == STATE_COMPLETE){
-				displayCurrentSCR(1);
+			switch(programState){
+				case STATE_READY:
+					programState = STATE_RUNNING;
+					break;
+				case STATE_RUNNING:
+					justJumped = false;
+					currentSteps++;
+					displayCurrentSCR(LCD_LINE_ONE);
+					break;
+				case STATE_JUMPING:
+					currentJumps++;
+					displayJumps();
+					break;
+				default:
+					break;
 			}
 		}
 	}
-
-}
-
-// void checkSwitchState()
-// {
-	// newSwitchState = digitalRead(35);
-	// delay(10);
-	// state2 = digitalRead(35);
-
-	// if(newSwitchState == state2 && switchState != newSwitchState)
-	// {
-		// switchState = newSwitchState;
-		//// stateChanges++;
-
-		// lcd.clear();
-		// lcd.setCursor(0,0);
-
-		// if(switchState == HIGH)
-		// {
-			// lcd.print("HIGH");
-		// }
-		// else
-		// {
-			// lcd.print("LOW");
-		// }
-
-		// lcd.setCursor(0,1);
-		//// lcd.print(stateChanges);
-	// }
-// }
+}

 void processButtons(){
 	uint8_t buttons = lcd.readButtons();
@@ -179,17 +179,17 @@
 		}

 		displayRung();
-		displaySelectedSCR(1);
-	}
-}
-
-void displayNumber(int num, int width, int pos, int line){
+		displaySelectedSCR(LCD_LINE_ONE);
+	}
+}
+
+void displayNumber(int num, int width, int pos, int line, char padding){
 	lcd.setCursor(pos, line);

 	Serial.print("num: "); Serial.print(num); Serial.print(", width: "); Serial.print(width); Serial.print(", line: "); Serial.println(line);

 	while(width > 0 && num < pow(10, --width)){
-		lcd.print(0, 10);
+		lcd.print(padding);
 		lcd.setCursor(++pos, line);
 	}

@@ -197,39 +197,44 @@
 }

 void displayRung(){
-	displayNumber(rung, 2, LCD_POSITION_RUNG, 0);
+	displayNumber(rung, 2, LCD_POSITION_RUNG, LCD_LINE_ZERO, LCD_PADDING_ZERO);
 }

 void displaySelectedSCR(int line){
 	int steps = introLadder[rung];

 	// Steps
-	displayNumber(steps, 3, LCD_POSITION_SCR, line);
+	displayNumber(steps, 3, LCD_POSITION_SCR, line, LCD_PADDING_ZERO);
 	lcd.setCursor(LCD_POSITION_SCR + 3, line);
 	lcd.print(":");

 	// Count
-	displayNumber(steps / 75, 1, LCD_POSITION_SCR + 4, line);
+	displayNumber(steps / 75, 1, LCD_POSITION_SCR + 4, line, LCD_PADDING_ZERO);
 	lcd.setCursor(LCD_POSITION_SCR + 5, line);
 	lcd.print(":");

 	// Remainder
-	displayNumber(steps % 75, 2, LCD_POSITION_SCR + 6, line);
+	displayNumber(steps % 75, 2, LCD_POSITION_SCR + 6, line, LCD_PADDING_ZERO);
 }

 void displayCurrentSCR(int line){
 	// Steps
-	displayNumber(currentSteps, 3, LCD_POSITION_SCR, line);
+	displayNumber(currentSteps, 3, LCD_POSITION_SCR, line, LCD_PADDING_ZERO);
 	lcd.setCursor(LCD_POSITION_SCR + 3, line);
 	lcd.print(":");

 	// Count
-	displayNumber(currentSteps / 75, 1, LCD_POSITION_SCR + 4, line);
+	displayNumber(currentSteps / 75, 1, LCD_POSITION_SCR + 4, line, LCD_PADDING_ZERO);
 	lcd.setCursor(LCD_POSITION_SCR + 5, line);
 	lcd.print(":");

 	// Remainder
-	displayNumber(currentSteps % 75, 2, LCD_POSITION_SCR + 6, line);
+	displayNumber(currentSteps % 75, 2, LCD_POSITION_SCR + 6, line, LCD_PADDING_ZERO);
+}
+
+void displayJumps()
+{
+	displayNumber(currentJumps, LCD_POSITION_RIGHT - LCD_POSITION_SCR + 1, LCD_POSITION_SCR, LCD_LINE_ONE, LCD_PADDING_SPACE);
 }

 void updateDisplay(){
@@ -241,27 +246,34 @@
 			case STATE_SETUP:
 				lcd.print("Select rung:");
 				displayRung();
-				displaySelectedSCR(1);
+				displaySelectedSCR(LCD_LINE_ONE);
 				break;
 			case STATE_READY:
 				lcd.print("S:C:R -");
-				displaySelectedSCR(0);
-				lcd.setCursor(0, 1);
+				displaySelectedSCR(LCD_LINE_ZERO);
+				lcd.setCursor(0, LCD_LINE_ONE);
 				lcd.print("Step on to begin");
 				break;
 			case STATE_RUNNING:
 				lcd.print("S:C:R -");
-				displaySelectedSCR(0);
-				lcd.setCursor(0, 1);
+				displaySelectedSCR(LCD_LINE_ZERO);
+				lcd.setCursor(0, LCD_LINE_ONE);
 				lcd.print("Current:");
-				displayCurrentSCR(1);
+				displayCurrentSCR(LCD_LINE_ONE);
+				break;
+			case STATE_JUMPING:
+				lcd.print("S:C:R -");
+				displaySelectedSCR(LCD_LINE_ZERO);
+				lcd.setCursor(0, LCD_LINE_ONE);
+				lcd.print("JUMP!");
+				displayJumps();
 				break;
 			case STATE_COMPLETE:
 				lcd.print("DONE!");
-				displaySelectedSCR(0);
-				lcd.setCursor(0, 1);
+				displaySelectedSCR(LCD_LINE_ZERO);
+				lcd.setCursor(0, LCD_LINE_ONE);
 				lcd.print("Current:");
-				displayCurrentSCR(1);
+				displayCurrentSCR(LCD_LINE_ONE);
 				break;
 			}


tweeked batt voltage multiplier for 12v. Still needs fine tuneing

--- arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
+++ arduino/arduino_md03_v_5_0/arduino_md03_v_5_0.ino
@@ -3,7 +3,7 @@
 ****************************************************/

 //settings:
-const float referenceVolts = 4.94; //set the refrence multiplyer for the volt meter
+const float referenceVolts = 5.5; //set the refrence multiplyer for the volt meter
 unsigned long previousBattCheck = 10000;

 //#define DEBUG 1


Fixed up for issue #3 as found by @ijunglee

--- examples/MPU9250/MPU9250.ino
+++ examples/MPU9250/MPU9250.ino
@@ -16,7 +16,6 @@

 #define SPI_CLOCK 8000000  // 8MHz clock works.

-#define SCK_PIN  14
 #define SS_PIN   10
 #define INT_PIN  3
 #define LED      13
@@ -35,9 +34,8 @@

 	pinMode(INT_PIN, INPUT);
 	pinMode(LED, OUTPUT);
-	digitalWriteFast(LED, HIGH);
+	digitalWrite(LED, HIGH);

-	SPI.setSCK(SCK_PIN);
 	SPI.begin();

 	Serial.println("Press any key to continue");


Add files via upload

Add files via upload

Added notes about battery saving. Added an option to set unused pins as outpus to conserve battery. This option is not enabled by default as it is not safe if there happens to be something connected to that pin.

--- simu_buttonreader_teensy_wheel/simu_buttonreader_teensy_wheel.ino
+++ simu_buttonreader_teensy_wheel/simu_buttonreader_teensy_wheel.ino
@@ -1,25 +1,45 @@
-/* Base (connected with USB to a PC)
+/*
+ *  Code to put on the Wheel (connected with Bluetooth to a another system)
    for wireless bluetooth button/shifter system using
    two Teensy 3.2 microcontrollers and 2 HC-05 bluetooth modules.

-   Pinout for this unit on the wheel itself:
+   Authors: Mika Takala & Juha Koljonen 2016
+
+   PINOUT
+   -------------------------------------------------------------------------
    0 serial rx
    1 serial tx
-   2 bluetooth status
-
+   2 bluetooth stat
+   3-12 button inputs
    13  Teensy's own led
-   14
-   15
-   16
-   17
-   18
-   19
-   20
+   14-20 unused
    21/A7 Battery_low_led
    22 Connection_led
    23 Battery voltage adc
+   24-33 unused
+   -------------------------------------------------------------------------
+
+   NOTES ABOUT POWER SAVING MEASURES:
+   -------------------------------------------------------------------------
+   (1)
+   As the system is intended to be battery powered, the recommendation
+   is to program Teensy as USB TYPE = NO USB and use for example 24MHz
+   clock. These are set from Tools menu in Arduino/Teensyduino IDE:
+   Setting NO USB will require you to press the manual program button on
+   Teensy to upload the code, but it will save a lot of power.
+
+   (2)
+   Additionally you can set all unused inputs as outputs, which
+   makes them not floating and they will consume less power that way.
+   This has been implemented with a macro, and it has NOT been enabled
+   as default.
+   PLEASE BE SURE TO NOT HAVE ANYTHING CONNECTED TO THE UNUSED PINS
+   LISTED IN InitialiseIO() FUNCTION. THE AUTHOR(S) TAKE NOT RESPONSIBILITY
+   IF YOU MANAGE TO FRY/SHORT OUT A PIN OR YOUR TEENSY MICROCONTROLLER.
+   -------------------------------------------------------------------------
 */

+// used pin definitions, other than buttons
 #define btStatus 2
 #define teensyLed 13
 #define batteryLed 21
@@ -27,19 +47,29 @@
 #define batteryADC 23

+// Uncomment this to save a bit of battery power.
+// DANGER: Please make double sure that all your unconnected pins
+// are correctly set in InitialiseIO() -function.
+// Errors here will permanently damage your Teensy microcontroller.
+
+// #define POWERSAVING_WITH_PINS_AS_OUTPUTS
+
+
+
 // Included the Bounce2 library found here :
 // https://github.com/thomasfredericks/Bounce2
-
-// The library has been modified to use digitalReadFast()
-
+// The library has been modified to use digitalReadFast().
 // Fast reactions are needed in the buttons. Therefore in the library,
 // this is defined:
-// By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h"
-// you can activate the alternative debouncing method. This method is
-// a lot more responsive, but does not cancel noise.
+//  By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h"
+//  you can activate the alternative debouncing method. This method is
+//  a lot more responsive, but does not cancel noise.
 #include "Bounce2.h"

+// Bouncer instances connected to buttons.
+// If you have more or less buttons,
+// adjust this to your liking.
 Bounce debouncer3 = Bounce();
 Bounce debouncer4 = Bounce();
 Bounce debouncer5 = Bounce();
@@ -53,7 +83,7 @@

 // Two bytes to store button status
 volatile int buttons_0_6 = 0b00000000;
-volatile int buttons_7_13 = 0b10000000;
+volatile int buttons_7_13 = 0b10000000; // MSB indicates which is it.
 volatile short int ledStatus = 0;

 // periodic status intervals in milliseconds
@@ -89,7 +119,8 @@
   digitalWriteFast(batteryLed, LOW);

   // Define/set debounce intervalls here to suit your buttons
-
+  // Remember to adjust the amount of these if you have
+  // more or less buttons.
   debouncer3.attach(3);  debouncer3.interval(5);
   debouncer4.attach(4);  debouncer4.interval(5);
   debouncer5.attach(5);  debouncer5.interval(5);
@@ -180,6 +211,104 @@
     }
   }
 }
+
+
+void updateButtons() {
+  // updates each button status and sees if it changed.
+  // add more or less code according to suit your buttons.
+  //
+  debouncer3.update();
+  if(debouncer3.fell()) {
+    buttons_0_6 |= 0b00000001;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer3.rose()) {
+    buttons_0_6 &= ~(0b00000001);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer4.update();
+  if(debouncer4.fell()) {
+    buttons_0_6 |= 0b00000010;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer4.rose()) {
+    buttons_0_6 &= ~(0b00000010);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer5.update();
+  if(debouncer5.fell()) {
+    buttons_0_6 |= 0b00000100;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer5.rose()) {
+    buttons_0_6 &= ~(0b00000100);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer6.update();
+  if(debouncer6.fell()) {
+    buttons_0_6 |= 0b00001000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer6.rose()) {
+    buttons_0_6 &= ~(0b00001000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer7.update();
+  if(debouncer7.fell()) {
+    buttons_0_6 |= 0b00010000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer7.rose()) {
+    buttons_0_6 &= ~(0b00010000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer8.update();
+  if(debouncer8.fell()) {
+    buttons_0_6 |= 0b00100000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer8.rose()) {
+    buttons_0_6 &= ~(0b00100000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer9.update();
+  if(debouncer9.fell()) {
+    buttons_0_6 |= 0b01000000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer9.rose()) {
+    buttons_0_6 &= ~(0b01000000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer10.update();
+  if(debouncer10.fell()) {
+    buttons_7_13 |= 0b00000001;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer10.rose()) {
+    buttons_7_13 &= ~(0b00000001);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer11.update();
+  if(debouncer11.fell()) {
+    buttons_7_13 |= 0b00000010;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer11.rose()) {
+    buttons_7_13 &= ~(0b00000010);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer12.update();
+  if(debouncer12.fell()) {
+    buttons_7_13 |= 0b00000100;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer12.rose()) {
+    buttons_7_13 &= ~(0b00000100);
+    Serial1.write(buttons_7_13);
+  }
+}
+
+

 void InitialiseIO(){
   pinMode(btStatus, INPUT);
@@ -204,97 +333,33 @@
   analogReadRes(12);
   analogReadAveraging(5);
   analogReference(INTERNAL);
-}
-
-void updateButtons() {
-  debouncer3.update();
-  if(debouncer3.fell()) {
-    buttons_0_6 |= 0b00000001;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer3.rose()) {
-    buttons_0_6 &= ~(0b00000001);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer4.update();
-  if(debouncer4.fell()) {
-    buttons_0_6 |= 0b00000010;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer4.rose()) {
-    buttons_0_6 &= ~(0b00000010);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer5.update();
-  if(debouncer5.fell()) {
-    buttons_0_6 |= 0b00000100;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer5.rose()) {
-    buttons_0_6 &= ~(0b00000100);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer6.update();
-  if(debouncer6.fell()) {
-    buttons_0_6 |= 0b00001000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer6.rose()) {
-    buttons_0_6 &= ~(0b00001000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer7.update();
-  if(debouncer7.fell()) {
-    buttons_0_6 |= 0b00010000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer7.rose()) {
-    buttons_0_6 &= ~(0b00010000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer8.update();
-  if(debouncer8.fell()) {
-    buttons_0_6 |= 0b00100000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer8.rose()) {
-    buttons_0_6 &= ~(0b00100000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer9.update();
-  if(debouncer9.fell()) {
-    buttons_0_6 |= 0b01000000;
-    Serial1.write(buttons_0_6);
-  } else if(debouncer9.rose()) {
-    buttons_0_6 &= ~(0b01000000);
-    Serial1.write(buttons_0_6);
-  }
-
-  debouncer10.update();
-  if(debouncer10.fell()) {
-    buttons_7_13 |= 0b00000001;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer10.rose()) {
-    buttons_7_13 &= ~(0b00000001);
-    Serial1.write(buttons_7_13);
-  }
-
-  debouncer11.update();
-  if(debouncer11.fell()) {
-    buttons_7_13 |= 0b00000010;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer11.rose()) {
-    buttons_7_13 &= ~(0b00000010);
-    Serial1.write(buttons_7_13);
-  }
-
-  debouncer12.update();
-  if(debouncer12.fell()) {
-    buttons_7_13 |= 0b00000100;
-    Serial1.write(buttons_7_13);
-  } else if(debouncer12.rose()) {
-    buttons_7_13 &= ~(0b00000100);
-    Serial1.write(buttons_7_13);
-  }
+
+  // By default, all pins are inputs.
+  // Unused inputs in an electrically noisy environment will consume many
+  // mA of power. This is because their voltage floats to a value which makes the input state
+  // switch, and all switching of digital circuitry consumes power.
+  // Please be double sure that you have not connected anything to these pins,
+  // as errors here might fry you Teensy.
+
+  #ifdef POWERSAVING_WITH_PINS_AS_OUTPUTS
+  // list your unused digital pins here
+  pinMode(14, OUTPUT);
+  pinMode(15, OUTPUT);
+  pinMode(16, OUTPUT);
+  pinMode(17, OUTPUT);
+  pinMode(18, OUTPUT);
+  pinMode(19, OUTPUT);
+  pinMode(20, OUTPUT);
+  pinMode(24, OUTPUT);
+  pinMode(25, OUTPUT);
+  pinMode(26, OUTPUT);
+  pinMode(27, OUTPUT);
+  pinMode(28, OUTPUT);
+  pinMode(29, OUTPUT);
+  pinMode(30, OUTPUT);
+  pinMode(31, OUTPUT);
+  pinMode(32, OUTPUT);
+  pinMode(33, OUTPUT);
+  #endif
 }


tweaks

tweaks

--- examples/Ports/compass_demo/compass_demo.ino
+++ examples/Ports/compass_demo/compass_demo.ino
@@ -6,12 +6,12 @@
 PortI2C myBus (1);
 CompassBoard compass (myBus);

-void setup(){
+void setup() {
     Serial.begin(57600);
     Serial.println("\n[compass_demo]");
 }

-void loop(){
+void loop() {
     Serial.println(compass.heading());
     delay(500);
 }


- use key code constant

- use key code constant

--- examples/GATT_HID/GATT_HID.ino
+++ examples/GATT_HID/GATT_HID.ino
@@ -33,7 +33,7 @@
       if (Serial.available() > 0) {
         Serial.read();

-        bleHID.write(0x1E); // 'a'
+        bleHID.write(KEYCODE_A);
       }
     }


Wifi power reduced from 82 to 10, to be tested.

--- FH_Tbot.ino
+++ FH_Tbot.ino
@@ -122,6 +122,7 @@
 void setup()
 {
   system_update_cpu_freq(160);           // set cpu to 80MHZ or 160MHZ !
+  system_phy_set_max_tpw(10);
   initHardware();
   setupWiFi();
   setupWebsocket();
@@ -395,6 +396,18 @@
   char AP_NameChar[AP_Name.length() + 1];
   AP_Name.toCharArray(AP_NameChar,AP_Name.length() + 1);

+  /*
+   * struct softap_config {
+      uint8 ssid[32];
+      uint8 password[64];
+      uint8 ssid_len;
+      uint8 channel; // support 1 ~ 13
+      uint8 authmode; // Don’t support AUTH_WEP in SoftAP mode
+      uint8 ssid_hidden; // default 0
+      uint8 max_connection; // default 4, max 4
+      uint16 beacon_interval; // 100 ~ 60000 ms, default 100
+    };
+   */
   // setup AP, start DNS server, start Web server

   int channel = random(1,13 + 1);               // have to add 1 or will be 1 - 12


update time

update time

--- IAQ/IAQ.ino
+++ IAQ/IAQ.ino
@@ -282,7 +282,7 @@
   {
     TimeOfsample = 0;
     TimesOfInt = 0;
-
+    time++;
     //read VOC
     noInterrupts();
     for( i=0; i<5; i++ )


Wand is kinda working.  Need another transceiver to be sure.

--- extern/Wand/Wand.ino
+++ extern/Wand/Wand.ino
@@ -5,19 +5,20 @@
 // include the library code:
 #include <Streaming.h> // <<-style printing
 #include <Metro.h> // timers
-#include <EEPROM.h> // saving and loading radio and menu settings
+
+// the glue
+#include <Simon_Common.h> // sizes, indexing and comms common to Towers and Console
+
+// radio
+#include <SPI.h> // radio board is a SPI device
 #include <avr/eeprom.h> // eeprom block r/w
-#include <SPI.h> // radio board is a SPI device
 #include <RFM69.h> // RFM12b radio transmitter module
-
-#include <Simon_Common.h> // sizes, indexing and comms common to Towers and Console

 // LCD
 #include <Wire.h>
 #include <Adafruit_MCP23017.h>
 #include <Adafruit_RGBLCDShield.h>
-//#include <LiquidCrystal_I2C.h>
-//#include <buttons.h>
+#include <EEPROM.h> // saving and loading radio and menu settings
 #include <MENWIZ.h>

 // this is where the lights and fire instructions from Console are placed
@@ -45,16 +46,21 @@

 // add global variables to bind to menu
 boolean buttonPressed = false;
-int towerLightIndex, towerFireIndex, towerFireMin, towerFireMax, controlIndex;
+int towerLightIndex, towerFireIndex, towerFireMin, towerFireMax;
+int testLightLevel, testFireLevel;

 #define FIRE_MIN 10
 #define FIRE_MAX 1000
 #define FIRE_STEP 10

+#define LEVEL_MIN 0
+#define LEVEL_MAX 10
+#define LEVEL_STEP 1
+
 #define INTERACTIVE_TIMEOUT 3000

 // force overwrite of EEPROM.  useful for bootstrapping new Moteinos.
-#define WRITE_EEPROM_NOW true
+#define WRITE_EEPROM_NOW false

 // radio pins
 #define D_CS_PIN 10 // default SS pin for RFM module
@@ -67,7 +73,6 @@
 #define BLUE 0x4
 #define VIOLET 0x5
 #define WHITE 0x7
-

 void menuSetup() {

@@ -87,43 +92,43 @@

   Serial << F("Setting up menu...") << endl;

-  _menu *r, *s1, *s11, *s12, *s13, *s14, *s15, *s2, *s21, *s22, *s3;
+  _menu *r, *s1, *s11, *s12, *s13, *s14, *s15, *s2, *s21, *s22, *s23, *s24, *s25, *s3;

   menu.begin(&lcd, 16, 2); //declare lcd object and screen size to menwiz lib

   r = menu.addMenu(MW_ROOT, NULL, F("Main Menu"));
+
   s1 = menu.addMenu(MW_SUBMENU, r, F("Config"));
-    s11 = menu.addMenu(MW_VAR, s1, F("Light Index"));
+    s11 = menu.addMenu(MW_VAR, s1, F("TowerLights"));
       s11->addVar(MW_LIST, &towerLightIndex);
-      s11->addItem(MW_LIST, F("Individual"));
-      s11->addItem(MW_LIST, F("All"));
-      s11->setBehaviour(MW_SCROLL_HORIZONTAL, true);
-
-    s12 = menu.addMenu(MW_VAR, s1, F("Fire Index"));
+      s11->addItem(MW_LIST, F("Each2Own"));
+      s11->addItem(MW_LIST, F("AllIn"));
+    s12 = menu.addMenu(MW_VAR, s1, F("TowerFire"));
       s12->addVar(MW_LIST, &towerFireIndex);
-      s12->addItem(MW_LIST, F("Individual"));
-      s12->addItem(MW_LIST, F("All"));
-      s12->setBehaviour(MW_SCROLL_HORIZONTAL, true);
-    s13 = menu.addMenu(MW_VAR, s1, F("Fire Time Min"));
+      s12->addItem(MW_LIST, F("Each2Own"));
+      s12->addItem(MW_LIST, F("AllIn"));
+    s13 = menu.addMenu(MW_VAR, s1, F("FireTimeMax"));
       s13->addVar(MW_AUTO_INT, &towerFireMin, FIRE_MIN, FIRE_MAX, FIRE_STEP);
-    s14 = menu.addMenu(MW_VAR, s1, F("Fire Time Min"));
-      s14->addVar(MW_AUTO_INT, &towerFireMax, FIRE_MIN, FIRE_MAX, FIRE_STEP);
-    s15 = menu.addMenu(MW_VAR, s1, F("Send Configuration"));
+    s14 = menu.addMenu(MW_VAR, s1, F("FireTimeMin"));
+      s14->addVar(MW_AUTO_INT, &towerFireMax, FIRE_MIN, FIRE_MAX, FIRE_STEP*10);
+    s15 = menu.addMenu(MW_VAR, s1, F("!!!Send!!!"));
       s15->addVar(MW_ACTION, configSend);

   s2 = menu.addMenu(MW_SUBMENU, r, F("Control"));
-    s21 = menu.addMenu(MW_VAR, s2, F("Control Index"));
-      s21->addVar(MW_LIST, &controlIndex);
-      s21->addItem(MW_LIST, F("Red"));
-      s21->addItem(MW_LIST, F("Green"));
-      s21->addItem(MW_LIST, F("Blue"));
-      s21->addItem(MW_LIST, F("Yellow"));
-      s21->addItem(MW_LIST, F("All"));
-      s21->setBehaviour(MW_SCROLL_HORIZONTAL, true);
-
-    s22 = menu.addMenu(MW_VAR, s2, F("Send Control"));
-      s22->addVar(MW_ACTION, controlSend);
-
+    s24 = menu.addMenu(MW_VAR, s2, F("LightSet"));
+      s24->addVar(MW_AUTO_INT, &testLightLevel, LEVEL_MIN, LEVEL_MAX, LEVEL_STEP);
+    s25 = menu.addMenu(MW_VAR, s2, F("FireSet"));
+      s25->addVar(MW_AUTO_INT, &testFireLevel, LEVEL_MIN, LEVEL_MAX, LEVEL_STEP);
+    s21 = menu.addMenu(MW_VAR, s2, F("Light Test"));
+      s21->addVar(MW_ACTION, lightTest);
+      s21->setBehaviour(MW_ACTION_CONFIRM, false); // just do it.
+    s22 = menu.addMenu(MW_VAR, s2, F("Sound Test"));
+      s22->addVar(MW_ACTION, soundTest);
+      s22->setBehaviour(MW_ACTION_CONFIRM, false); // just do it.
+    s23 = menu.addMenu(MW_VAR, s2, F("Fire Test"));
+      s23->addVar(MW_ACTION, fireTest);
+      s23->setBehaviour(MW_ACTION_CONFIRM, true);  // yeah.
+
   s3 = menu.addMenu(MW_VAR, r, F("Save Settings"));
     s3->addVar(MW_ACTION, saveSettings);

@@ -131,11 +136,11 @@
   menu.addUsrNav(readButtons, 4);

   // show a splash screen
-  char splash[] = "Simon v2 Wand\n(by Mike)";
+  char splash[] = " Simon v2 Wand\n      -Magister";
   menu.addSplash(splash, 1000);

   // After a inactivity, show custom screen with real-time information
-  menu.addUsrScreen(printInstruction, INTERACTIVE_TIMEOUT);
+//  menu.addUsrScreen(printInstruction, INTERACTIVE_TIMEOUT);

   // load settings
   menu.readEeprom();
@@ -156,8 +161,8 @@
   // Print a message to the LCD.
   lcd.setCursor(0, 0);
   lcd.print(F("LCD: startup"));
-  delay(100);
-
+  delay(500);
+
   // set up menus
   menuSetup();

@@ -189,24 +194,72 @@
 void printInstruction() {
   static char buf[3];

-  menu.sbuf = ""; // 1st row
-  strcat(menu.sbuf, "R");
+  strcpy(menu.sbuf, "G");
+  strcat(menu.sbuf, itoa(tInst.lightLevel[I_GRN], buf, 10));
+  strcat(menu.sbuf, itoa(tInst.fireLevel[I_GRN], buf, 10));
+  strcat(menu.sbuf, " R");  // 1st row
   strcat(menu.sbuf, itoa(tInst.lightLevel[I_RED], buf, 10));
   strcat(menu.sbuf, itoa(tInst.fireLevel[I_RED], buf, 10));
-  strcat(menu.sbuf, " G");
-  strcat(menu.sbuf, itoa(tInst.lightLevel[I_GRN], buf, 10));
-  strcat(menu.sbuf, itoa(tInst.fireLevel[I_GRN], buf, 10));

   strcat(menu.sbuf, "\n"); // 2nd row

-  strcat(menu.sbuf, "B");
+  strcat(menu.sbuf, "Y");
+  strcat(menu.sbuf, itoa(tInst.lightLevel[I_YEL], buf, 10));
+  strcat(menu.sbuf, itoa(tInst.fireLevel[I_YEL], buf, 10));
+  strcat(menu.sbuf, " B");
   strcat(menu.sbuf, itoa(tInst.lightLevel[I_BLU], buf, 10));
   strcat(menu.sbuf, itoa(tInst.fireLevel[I_BLU], buf, 10));
-  strcat(menu.sbuf, " Y");
-  strcat(menu.sbuf, itoa(tInst.lightLevel[I_YEL], buf, 10));
-  strcat(menu.sbuf, itoa(tInst.fireLevel[I_YEL], buf, 10));

   menu.drawUsrScreen(menu.sbuf);
+}
+
+void lightTest() {
+  Serial << F("Light Test!") << endl;
+  byte lightLevel = map(testLightLevel, 0, 10, 0, 255);
+
+  static char buf[3];
+  strcpy(menu.sbuf, "Light:"); // 1st row
+  strcat(menu.sbuf, itoa(lightLevel, buf, 10));
+  strcat(menu.sbuf, "\n"); // 2nd row
+  strcat(menu.sbuf, "|!! |esc");
+  menu.drawUsrScreen(menu.sbuf);
+
+  // always a good idea.
+  instClear(tInst);
+
+  // wait for escape to be pressed.
+  uint8_t buttons = lcd.readButtons();
+  while( ! ( buttons & BUTTON_SELECT ) ) {
+      buttons = lcd.readButtons();
+
+      tInst.lightLevel[I_RED] = (buttons & BUTTON_RIGHT) ? lightLevel : 0;
+      tInst.lightLevel[I_BLU] = (buttons & BUTTON_DOWN) ? lightLevel : 0;
+      tInst.lightLevel[I_YEL] = (buttons & BUTTON_LEFT) ? lightLevel : 0;
+      tInst.lightLevel[I_GRN] = (buttons & BUTTON_UP) ? lightLevel : 0;
+
+      sendTowerInst(3);
+  }
+
+  Serial << lightLevel << endl;
+}
+void soundTest() {
+  Serial << F("Sound Test!") << endl;
+}
+void fireTest() {
+  Serial << F("Fire Test!") << endl;
+}
+void sendTowerInst(int sendCount) {
+  static towerInstruction lastInst=tInst;
+
+  // careful.  Just send deltas.
+  if( memcmp((void*)(&tInst), (void*)(&lastInst), sizeof(tInst)) != 0 ) {
+    Serial << F("Sending iInst!") << endl;
+    for( int i=0; i<sendCount; i++ ) {
+      radio.send(0, (const void*)(&tInst), sizeof(tInst));
+      delay(5);
+    }
+    lastInst = tInst; // save it.
+  }
 }

 void configSend() {
@@ -227,7 +280,7 @@
   }

   // toggle light and fire
-  switch(controlIndex) {
+  switch(1) {
     case 0: // red
       tInst.lightLevel[I_RED] = val;
       tInst.fireLevel[I_RED] = val;
@@ -279,7 +332,9 @@
     else if (buttons & BUTTON_RIGHT) {
       return MW_BTC;
     }
-    else {
+    else if (buttons & BUTTON_SELECT) {
+      return MW_BTL; // escape
+    } else {
       return MW_BTNULL;
     }
   }


Changed header

Changed header

--- ballbot.ino
+++ ballbot.ino
@@ -1,6 +1,5 @@
 /* Program for my ballbot, found at http://onewaytobalance.blogspot.com
  *
- * Program pretty much runs on an interrupt.
  * Configurations, settings and global variables/objects found in ballbot.h
  *
  * Only runs on Teensy 3.x and requires a decent clock (I use 96MHz)


Fixed bug in state change logic

Fixed bug in state change logic

--- ReadSensors/ReadSensors.ino
+++ ReadSensors/ReadSensors.ino
@@ -21,7 +21,7 @@
 //#define CFGEN_SEND_STATE_REPORTS

 //Turn this on to send row data reports every detected row
-//#define CFGEN_SEND_ROW_REPORTS
+#define CFGEN_SEND_ROW_REPORTS

 #define NUM_CHANNELS 9
@@ -225,7 +225,7 @@

   if (state != prev)
   {
-    state = prev;
+    prev = state;
 #if defined(CFGEN_SEND_STATE_REPORTS)
     {
       byte report = (byte) (state & 0xFF);


Delete AutoConnect.ino

Delete AutoConnect.ino

--- AutoConnect/AutoConnect.ino
+++ AutoConnect/AutoConnect.ino
@@ -1,42 +0,0 @@
-#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
-
-//needed for library
-#include <DNSServer.h>
-#include <ESP8266WebServer.h>
-#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
-
-
-void setup() {
-    // put your setup code here, to run once:
-    Serial.begin(115200);
-
-    //WiFiManager
-    //Local intialization. Once its business is done, there is no need to keep it around
-    WiFiManager wifiManager;
-    //reset saved settings
-    //wifiManager.resetSettings();
-    wifiManager.setCustomHeadElement("<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;color:#fff;link=#fff;color=#fff} input{width:95%;} body{text-align: center;font-family:verdana; background-color:#444;color:#fff;link=#fff} button{border:0;border-radius:0.3rem;background-color:#A31621;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==\") no-repeat left center;background-size: 1em;}</style>");
-
-
-    //set custom ip for portal
-    //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
-
-    //fetches ssid and pass from eeprom and tries to connect
-    //if it does not connect it starts an access point with the specified name
-    //here  "AutoConnectAP"
-    //and goes into a blocking loop awaiting configuration
-    wifiManager.autoConnect("OwledtronicsAutoConnect");
-    //or use this for auto generated name ESP + ChipID
-    //wifiManager.autoConnect();
-
-
-
-
-    //if you get here you have connected to the WiFi
-    Serial.println("connected...yeey :)");
-}
-
-void loop() {
-    // put your main code here, to run repeatedly:
-
-}


added delay check inside ISR

added delay check inside ISR

--- code/arduino/sample/sketch_pushbutton/sketch_pushbutton.ino
+++ code/arduino/sample/sketch_pushbutton/sketch_pushbutton.ino
@@ -14,25 +14,37 @@
 volatile int state = LOW;
 volatile int counter = 0 ;

+volatile unsigned long irq_time ;
+volatile unsigned long last_irq_time ;
+
 void setup()
 {
     pinMode(ledPin, OUTPUT);
     // watch pin2
     attachInterrupt(0,isr_pin2,RISING);
+    last_irq_time = 0 ;
+    Serial.begin(9600);
+
 }

 void loop()
 {
     digitalWrite(ledPin, state);
-    delay(1000);
+    delay(5000);
+    Serial.print("counter=");
+    Serial.println(counter);

 }

 void isr_pin2()
 {
-    state = !state ;
-    counter++ ;
-    Serial.print("pin2 interrupted: ");
-    Serial.print("counter: ");
-    Serial.println(counter);
+
+    // @imp donot use millis() for comparison
+    // millis() donot advance inside an ISR
+    irq_time = millis();
+    if((irq_time - last_irq_time) > 250) {
+        state = !state ;
+        counter = counter +1 ;
+        last_irq_time = irq_time ;
+    }
 }


removed set CLK code from sample

removed set CLK code from sample

--- code/arduino/sample/DS1307RTC_sample/DS1307RTC_sample.ino
+++ code/arduino/sample/DS1307RTC_sample/DS1307RTC_sample.ino
@@ -1,93 +1,52 @@
 #include <Wire.h>
 #include <Time.h>
 #include <DS1307RTC.h>
-#include <AWS.h>
+
+// sample to ensure that we can use time library
+// with DS1307 RTC chip. You should have run the
+// DS1307 SetTime example before running this sketch.

 // DS1307RTC instance created in DS1307 lib
 // DS1307RTC RTC = DS1307RTC();
 // DS1307RTC constructor calls Wire.begin()

-const char *month_names[12] = {
-  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
 tmElements_t tm;
-aws_error_t aws_code ;

 void setup() {
-  Serial.begin(9600);
+    Serial.begin(9600);
+    // set DS1307 RTC as provider for time library
+    // sync interval is default 5 minutes
+    setSyncProvider(RTC.get);
+    micro_delay(20);
+    if(timeStatus()!= timeSet) {
+        micro_delay(100);
+    }

-  aws_code = init_rtc(__TIME__,__DATE__);
-  for(int i = 0 ; i < 200 ; i++) {
-      delayMicroseconds(1000);
-  }
+    // try again
+    if(timeStatus()!= timeSet) {
+        Serial.println("clock is not set, bailing out...");
+        for(;;);
+    }

-  // set DS1307 RTC as time provider
-  // sync interval is default 5 minutes
-  if(aws_code == AWS_RTC_ERROR_NONE) {
-      setSyncProvider(RTC.get);
-      if(timeStatus()!= timeSet) {
-          // wait a bit
-          for(int i = 0 ; i < 4000 ; i++) {
-              delayMicroseconds(1000);
-          }
-      }
+}

-      // try again
-      if(timeStatus()!= timeSet) {
-          aws_code = AWS_RTC_SYNC_ERROR ;
-      }
-  }
-
+void micro_delay(int n) {
+    for(int i = 0 ; i < n ; i++)
+        delayMicroseconds(10000);
 }

 void loop() {

-    if(aws_code == AWS_RTC_ERROR_NONE ) {
-        Serial.print(hour());
-        Serial.print(" ");
-        Serial.print(minute());
-        Serial.print(" ");
-        Serial.println(second());
-    } else {
-        Serial.print("error in RTC setup");
-        Serial.println(aws_code);
-
-    }
-
-    delay(1000);
+    int hh = hour();
+    int mm = minute();
+    int ss = second();
+    Serial.print(hh);
+    Serial.print(":");
+    Serial.print(mm);
+    Serial.print(":");
+    Serial.println(ss);
+    Serial.println();
+
+    micro_delay(100);
 }
-
-aws_error_t init_rtc(const char* str_time, const char* str_date) {
-
-  int hour, min, sec;
-  char month[12]; int day, year;
-  uint8_t month_index;
-
-  if (sscanf(str_time, "%d:%d:%d", &hour, &min, &sec) != 3) return AWS_RTC_COMPILER_ERROR;
-  if (sscanf(str_date, "%s %d %d", month, &day, &year) != 3) return AWS_RTC_COMPILER_ERROR;
-
-  tm.Hour = hour;
-  tm.Minute = min;
-  tm.Second = sec;
-
-
-  for (month_index = 0; month_index < 12; month_index++) {
-    if (strcmp(month, month_names[month_index]) == 0) break;
-  }
-
-  if (month_index >= 12) return AWS_RTC_COMPILER_ERROR;
-
-  tm.Day = day;
-  tm.Month = month_index + 1;
-  tm.Year = CalendarYrToTm(year);
-
-  // set this date time to DS1307 chip
-  bool flag = RTC.write(tm);
-  if(!flag) return AWS_RTC_WRITE_ERROR ;
-
-  return AWS_RTC_ERROR_NONE;
-
-}


Minor code corrections.

Minor code corrections.

--- arduino/skypointer/skypointer.ino
+++ arduino/skypointer/skypointer.ino
@@ -43,7 +43,7 @@
 // Motor 2 on port 2, 200 steps/rev
 SkyPointer_MicroStepper *motor2 = MS.getMicroStepper(STEPS, 2);

-int home = false;
+uint8_t home = false;

 // *** Interruption Routines ***
 // Timing routine
@@ -186,13 +186,9 @@

 // Enable/disable the laser module
 void ProcessLaser() {
-  uint8_t enable;
-
-  enable = atoi(sCmd.next()) != 0;
-
-
-  digitalWrite(LASER_PIN_H, enable);
-  digitalWrite(LASER_PIN_L, !enable);
+  uint8_t enable = atoi(sCmd.next()) != 0;
+
+  MS.laser(enable);
   Serial.print("OK\r");
 }

@@ -254,8 +250,7 @@
   // Configure laser pin and set to LOW
   pinMode(LASER_PIN_H, OUTPUT);
   pinMode(LASER_PIN_L, OUTPUT);
-  digitalWrite(LASER_PIN_H, LOW);
-  digitalWrite(LASER_PIN_L, HIGH);
+  MS.laser(0);

   // Start the serial port
   Serial.begin(115200);


modifying button controller

modifying button controller

--- Arduino_HVAC_Controller/HVAC_Controller/HVAC_Controller.ino
+++ Arduino_HVAC_Controller/HVAC_Controller/HVAC_Controller.ino
@@ -32,8 +32,9 @@
 String cool = "Cool";
 String currentMode = heat;
 int tempSetpoint = 75;            // Default temperature setpoint on a reboot
-boolean val;                // Variable for user input
+boolean val;                      // Variable for user input
 long oldTemp = 0;
+int timeout = 30                  // Backlight timeout variable

 // -------------Library Interaction--------------
 // Data wire is plugged into busPin on the Arduino
@@ -51,6 +52,8 @@

 // Create our LCD Shield instance
 Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
+#define ON 0x7            // For single color LCD, set on to white
+#define OFF 0x0           // For single color LCD, set off to black

 // ----------------------------------------------------------------------------------------
 // Function Name: setup()
@@ -59,15 +62,12 @@
 // Description:   This function executes housekeeping duties and staging for the loop() function; executed once
 void setup(){

-  pinMode(busPin,INPUT);
+  pinMode(busPin,INPUT);  // Designate temperature bus pin data direction
   Serial.begin(serialSpeed);

-  // Start up the library
-  sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay
-
-  // set up the LCD's number of columns and rows:
-  lcd.begin(16, 2);
-  lcd.setBacklight(ON);
+  sensors.begin();        // Start up the library. IC Default is 9 bit. If you have troubles consider upping it 12. Ups the delay
+  lcd.begin(16, 2);       // set up the LCD's number of columns and rows
+  lcd.setBacklight(ON);   // Start off with backlight on until time-out

 }

@@ -78,20 +78,40 @@
 // Description:   This is the main executing block of the program, calling all ancillary functions to operate the Arduino
 void loop(){

-  lcd.setCursor(0, 1);
+  if (timeout == 0) {                   // Turn on backlight for 30 seconds, else turn it off
+    lcd.setBacklight(OFF);
+  }else {
+    lcd.setBacklight(ON);
+  }
+
+  lcd.setCursor(0, 1);                  // Starting postion of character printing

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

-
-  uint8_t buttons = lcd.readButtons();
-
-  if (getTemp()) {
+  if (getTemp()) {                      // Constantly check to see if the temperature has changed, and update appropriately
     lcd.clear();
     lcd.print("Current Temp: ");
     lcd.print(currentTemp);
   }

   if (buttons) {
-    lcd.clear();
+    lcd.setBacklight(ON)
+    if (buttons & BUTTON_SELECT) {
+      lcd.print("SELECT ");
+      lcd.setBacklight(VIOLET);
+    }
+    buttonHandler();
+  }
+
+}
+
+// ----------------------------------------------------------------------------------------
+// Function Name: buttonHandler()
+// Parameters:    None
+// Returns:       Boolean, True if the temperature has changed, else False
+// Description:   This function polls the temp sensors, retrieves the values, and then returns
+boolean buttonHandler(){
+  lcd.clear();

     // If the UP Button is pushed, increasing the setpoint
     if (buttons & BUTTON_UP) {
@@ -106,8 +126,20 @@
       lcd.print("Setpoint: ");
       lcd.print(high);
     }
-  }
-
+
+    if (buttons & BUTTON_LEFT) {
+      lcd.print("LEFT ");
+      lcd.setBacklight(GREEN);
+    }
+    if (buttons & BUTTON_RIGHT) {
+      lcd.print("RIGHT ");
+      lcd.setBacklight(TEAL);
+    }
+    if (buttons & BUTTON_SELECT) {
+      lcd.print("SELECT ");
+      lcd.setBacklight(VIOLET);
+    }
+
 }

 // ----------------------------------------------------------------------------------------


Send hello message as a log

Send hello message as a log

--- Wild_Thumper_Controller/Wild_Thumper_Controller.ino
+++ Wild_Thumper_Controller/Wild_Thumper_Controller.ino
@@ -64,7 +64,7 @@
   Serial.flush();

   // Say hi
-  Serial.println("{\"type\":\"hello\"}");
+  Serial.println("{\"type\":\"log\",\"message\":\"Hello from dilBot!\"}");
 }


Massive comment refactoring

Massive comment refactoring

--- Wild_Thumper_Controller.ino
+++ Wild_Thumper_Controller.ino
@@ -2,9 +2,9 @@
 #include "IOpins.h"
 #include "Constants.h"

-
-//-------------------------------------------------------------- define global variables --------------------------------------------
-
+//
+// define global variables
+//
 unsigned int Volts;
 unsigned int LeftAmps;
 unsigned int RightAmps;
@@ -19,61 +19,77 @@
 int Rightspeed=0;
 int Speed;
 int Steer;
-byte Charged=1;                                               // 0=Flat battery  1=Charged battery
-int Leftmode=1;                                               // 0=reverse, 1=brake, 2=forward
-int Rightmode=1;                                              // 0=reverse, 1=brake, 2=forward
-int LeftPWM;                                                  // PWM value for left  motor speed / brake
-int RightPWM;                                                 // PWM value for right motor speed / brake
+// 0=Flat battery  1=Charged battery
+byte Charged=1;
+// 0=reverse, 1=brake, 2=forward
+int Leftmode=1;
+// 0=reverse, 1=brake, 2=forward
+int Rightmode=1;
+// PWM value for left  motor speed / brake
+int LeftPWM;
+// PWM value for right motor speed / brake
+int RightPWM;
 int data;
 int servo[7];

-//-------------------------------------------------------------- define servos ------------------------------------------------------
-
-Servo Servo0;                                                 // define servos
-Servo Servo1;                                                 // define servos
-Servo Servo2;                                                 // define servos
-Servo Servo3;                                                 // define servos
-Servo Servo4;                                                 // define servos
-Servo Servo5;                                                 // define servos
-Servo Servo6;                                                 // define servos
+//
+// define servos
+//
+Servo Servo0;
+Servo Servo1;
+Servo Servo2;
+Servo Servo3;
+Servo Servo4;
+Servo Servo5;
+Servo Servo6;

 void setup()
 {
-  //------------------------------------------------------------ Initialize Servos ----------------------------------------------------
-
-  Servo0.attach(S0);                                          // attach servo to I/O pin
-  Servo1.attach(S1);                                          // attach servo to I/O pin
-  Servo2.attach(S2);                                          // attach servo to I/O pin
-  Servo3.attach(S3);                                          // attach servo to I/O pin
-  Servo4.attach(S4);                                          // attach servo to I/O pin
-  Servo5.attach(S5);                                          // attach servo to I/O pin
-  Servo6.attach(S6);                                          // attach servo to I/O pin
-
-  //------------------------------------------------------------ Set servos to default position ---------------------------------------
-
-  Servo0.writeMicroseconds(DServo0);                          // set servo to default position
-  Servo1.writeMicroseconds(DServo1);                          // set servo to default position
-  Servo2.writeMicroseconds(DServo2);                          // set servo to default position
-  Servo3.writeMicroseconds(DServo3);                          // set servo to default position
-  Servo4.writeMicroseconds(DServo4);                          // set servo to default position
-  Servo5.writeMicroseconds(DServo5);                          // set servo to default position
-  Servo6.writeMicroseconds(DServo6);                          // set servo to default position
-
-  //------------------------------------------------------------ Initialize I/O pins --------------------------------------------------
-
-  pinMode (Charger,OUTPUT);                                   // change Charger pin to output
-  digitalWrite(Charger,1);                                   // disable current regulator to charge battery
-
-  if (Cmode==1)
-  {
-    Serial.begin(Brate);                                      // enable serial communications if Cmode=1
-    Serial.flush();                                           // flush buffer
+  //
+  // Attach servos to I/O pins
+  //
+  Servo0.attach(S0);
+  Servo1.attach(S1);
+  Servo2.attach(S2);
+  Servo3.attach(S3);
+  Servo4.attach(S4);
+  Servo5.attach(S5);
+  Servo6.attach(S6);
+
+  //
+  // Set servos to default position
+  //
+  Servo0.writeMicroseconds(DServo0);
+  Servo1.writeMicroseconds(DServo1);
+  Servo2.writeMicroseconds(DServo2);
+  Servo3.writeMicroseconds(DServo3);
+  Servo4.writeMicroseconds(DServo4);
+  Servo5.writeMicroseconds(DServo5);
+  Servo6.writeMicroseconds(DServo6);
+
+  //
+  // Initialize I/O pins
+  //
+
+  // Change charger pin to output
+  pinMode(Charger, OUTPUT);
+
+  // Disable current regulator to charge battery
+  digitalWrite(Charger, 1);
+
+  if (Cmode==1)
+  {
+    // enable serial communications if Cmode=1
+    Serial.begin(Brate);
+
+    // flush buffer
+    Serial.flush();
   }
   else {
     // Enable regardless for logging
     Serial.begin(Brate);
   }
-
+
   Serial.print("Wild Thumper started in ");
   switch(Cmode) {
     case 0:
@@ -93,11 +109,18 @@

 void loop()
 {
-  //------------------------------------------------------------ Check battery voltage and current draw of motors ---------------------
-
-  Volts=analogRead(Battery);                                  // read the battery voltage
-  LeftAmps=analogRead(LmotorC);                               // read left motor current draw
-  RightAmps=analogRead(RmotorC);                              // read right motor current draw
+  //
+  // Check battery voltage and current draw of motors
+  //
+
+  // read the battery voltage
+  Volts=analogRead(Battery);
+
+  // read left motor current draw
+  LeftAmps=analogRead(LmotorC);
+
+  // read right motor current draw
+  RightAmps=analogRead(RmotorC);

   //Serial.print(LeftAmps);
   //Serial.print("    ");
@@ -105,48 +128,70 @@

   if (LeftAmps>Leftmaxamps)                                   // is motor current draw exceeding safe limit
   {
-    analogWrite (LmotorA,0);                                  // turn off motors
-    analogWrite (LmotorB,0);                                  // turn off motors
-    leftoverload=millis();                                    // record time of overload
+    // Turn off motors
+    analogWrite (LmotorA,0);
+    analogWrite (LmotorB,0);
+
+    // Record time of overload
+    leftoverload=millis();
   }

   if (RightAmps>Rightmaxamps)                                 // is motor current draw exceeding safe limit
   {
-    analogWrite (RmotorA,0);                                  // turn off motors
-    analogWrite (RmotorB,0);                                  // turn off motors
-    rightoverload=millis();                                   // record time of overload
+    // Turn off motors
+    analogWrite (RmotorA,0);
+    analogWrite (RmotorB,0);
+
+    // Record time of overload
+    rightoverload=millis();
   }

   if ((Volts<lowvolt) && (Charged==1))                        // check condition of the battery
   {                                                           // change battery status from charged to flat

-    //---------------------------------------------------------- FLAT BATTERY speed controller shuts down until battery is recharged ----
-    //---------------------------------------------------------- This is a safety feature to prevent malfunction at low voltages!! ------
-
-    Charged=0;                                                // battery is flat
-    highVolts=Volts;                                          // record the voltage
+    //
+    // FLAT BATTERY speed controller shuts down until battery is recharged
+    //
+    //
+    // This is a safety feature to prevent malfunction at low voltages!!
+    //
+
+    // Battery is flat
+    Charged=0;
+
+    // Record the voltage
+    highVolts=Volts;
     startVolts=Volts;
-    chargeTimer=millis();                                     // record the time
-
-    chargeStart=millis();                                     // record start time
+
+    // Record the time
+    chargeTimer=millis();
+
+    // Record start time
+    chargeStart=millis();

     Serial.print("Battery dead at ");
     Serial.print(Volts, DEC);
     Serial.println(", enabling charger...");

-    digitalWrite(Charger,0);                                  // enable current regulator to charge battery
-  }
-
-  //------------------------------------------------------------ CHARGE BATTERY -------------------------------------------------------
+    // Enable current regulator to charge battery
+    digitalWrite(Charger,0);
+  }
+
+  //
+  // CHARGE BATTERY
+  //

   if ((Charged==0) && (Volts-startVolts>67))                  // if battery is flat and charger has been connected (voltage has increased by at least 1V)
   {
     if (Volts>highVolts)                                      // has battery voltage increased?
     {
-      highVolts=Volts;                                        // record the highest voltage. Used to detect peak charging.
-      chargeTimer=millis();                                   // when voltage increases record the time
-    }
-
+      // record the highest voltage. Used to detect peak charging.
+      highVolts=Volts;
+
+      // when voltage increases record the time
+      chargeTimer=millis();
+    }
+
     if ((millis()-reportTimer) > reportInterval) {
       logBatteryVoltage();
       reportTimer=millis();
@@ -156,44 +201,53 @@
     {
       if ((highVolts-Volts)>5 || (millis()-chargeTimer)>chargetimeout) // has voltage begun to drop or levelled out?
       {
-        Charged=1;                                            // battery voltage has peaked
-        digitalWrite(Charger,1);                             // turn off current regulator
-
+        // battery voltage has peaked
+        Charged=1;
+
+        // turn off current regulator
+        digitalWrite(Charger,1);
+
         Serial.print("Charge complete after ");
         Serial.print((millis()-chargeStart)*1000 / 60);
         Serial.print(":");
         Serial.print((millis()-chargeStart)*1000 % 60);
         Serial.println("!");
-
+
         logBatteryVoltage();
       }
-    }
-  }
-
-  else
-
-  {//----------------------------------------------------------- GOOD BATTERY speed controller opperates normally ----------------------
+    }
+  }
+
+  else {
+    //
+    // GOOD BATTERY speed controller opperates normally
+    //

     switch(Cmode)
     {
-    case 0:                                                   // RC mode via D0 and D1
-      RCmode();
-      break;
-
-    case 1:                                                   // Serial mode via D0(RX) and D1(TX)
-      SCmode();
-      break;
-
-    case 2:                                                   // I2C mode via A4(SDA) and A5(SCL)
-      I2Cmode();
-      break;
-    }
-
-    // --------------------------------------------------------- Code to drive dual "H" bridges --------------------------------------
+      // RC mode via D0 and D1
+      case 0:
+        RCmode();
+        break;
+
+      // Serial mode via D0(RX) and D1(TX)
+      case 1:
+        SCmode();
+        break;
+
+      // I2C mode via A4(SDA) and A5(SCL)
+      case 2:
+        I2Cmode();
+        break;
+    }
+
+    //
+    // Code to drive dual "H" bridges
+    //

     if (Charged==1)                                           // Only power motors if battery voltage is good
     {
-      if ((millis()-leftoverload)>overloadtime)
+      if ((millis()-leftoverload)>overloadtime)
       {
         switch (Leftmode)                                     // if left motor has not overloaded recently
         {
@@ -232,14 +286,15 @@
           analogWrite(RmotorB,0);
           break;
         }
-      }
-    }
-    else                                                      // Battery is flat
-    {
-      analogWrite(LmotorA,0);                                // turn off motors
-      analogWrite(LmotorB,0);                                // turn off motors
-      analogWrite(RmotorA,0);                                // turn off motors
-      analogWrite(RmotorB,0);                                // turn off motors
+      }
+    }
+    else {
+      // Battery is flat
+      // Turn off motors
+      analogWrite(LmotorA,0);
+      analogWrite(LmotorB,0);
+      analogWrite(RmotorA,0);
+      analogWrite(RmotorB,0);
     }
   }
 }
@@ -247,64 +302,84 @@

 void RCmode()
 {
-  //------------------------------------------------------------ Code for RC inputs ---------------------------------------------------------
-  Speed=pulseIn(RCleft,HIGH,25000);                           // read throttle/left stick
-  Steer=pulseIn(RCright,HIGH,25000);                          // read steering/right stick
-
-  if (Speed==0) Speed=1500;                                   // if pulseIn times out (25mS) then set speed to stop
-  if (Steer==0) Steer=1500;                                   // if pulseIn times out (25mS) then set steer to centre
-
-  if (abs(Speed-1500)<RCdeadband) Speed=1500;                 // if Speed input is within deadband set to 1500 (1500uS=center position for most servos)
-  if (abs(Steer-1500)<RCdeadband) Steer=1500;                 // if Steer input is within deadband set to 1500 (1500uS=center position for most servos)
-
-  if (Mix==1)                                                 // Mixes speed and steering signals
-  {
+  //
+  // Code for RC inputs
+  //
+
+  // read throttle/left stick
+  Speed=pulseIn(RCleft,HIGH,25000);
+
+  // read steering/right stick
+  Steer=pulseIn(RCright,HIGH,25000);
+
+  // if pulseIn times out (25mS) then set speed to stop
+  if (Speed==0) Speed=1500;
+
+  // if pulseIn times out (25mS) then set steer to centre
+  if (Steer==0) Steer=1500;
+
+  // if Speed input is within deadband set to 1500 (1500uS=center position for most servos)
+  if (abs(Speed-1500)<RCdeadband) Speed=1500;
+
+  // if Steer input is within deadband set to 1500 (1500uS=center position for most servos)
+  if (abs(Steer-1500)<RCdeadband) Steer=1500;
+
+  if (Mix==1)
+  {
+    // Mixes speed and steering signals
     Steer=Steer-1500;
     Leftspeed=Speed-Steer;
     Rightspeed=Speed+Steer;
   }
-  else                                                        // Individual stick control
-  {
+  else
+  {
+    // Individual stick control
     Leftspeed=Speed;
     Rightspeed=Steer;
   }
-
+
   /*
   Serial.print("Left:");
   Serial.println(Leftspeed);
   Serial.print("Right:");
   Serial.println(Rightspeed);
   */
-
+
   Leftmode=2;
   Rightmode=2;
-  if (Leftspeed>(Leftcenter+RCdeadband)) Leftmode=0;          // if left input is forward then set left mode to forward
-  if (Rightspeed>(Rightcenter+RCdeadband)) Rightmode=0;       // if right input is forward then set right mode to forward
-
-  LeftPWM=abs(Leftspeed-Leftcenter)*10/scale;                 // scale 1000-2000uS to 0-255
-  LeftPWM=min(LeftPWM,255);                                   // set maximum limit 255
-
-  RightPWM=abs(Rightspeed-Rightcenter)*10/scale;              // scale 1000-2000uS to 0-255
-  RightPWM=min(RightPWM,255);                                 // set maximum limit 255
-}
-
-
-void SCmode()
-{// ------------------------------------------------------------ Code for Serial Communications --------------------------------------
-
-                                                              // FL = flush serial buffer

-                                                              // AN = report Analog inputs 1-5
-
-                                                              // SV = next 7 integers will be position information for servos 0-6
+  // if left input is forward then set left mode to forward
+  if (Leftspeed>(Leftcenter+RCdeadband)) Leftmode=0;

-                                                              // HB = "H" bridge data - next 4 bytes will be:
-                                                              //      left  motor mode 0-2
-                                                              //      left  motor PWM  0-255
-                                                              //      right motor mode 0-2
-                                                              //      right motor PWM  0-255
+  // if right input is forward then set right mode to forward
+  if (Rightspeed>(Rightcenter+RCdeadband)) Rightmode=0;
+
+  // scale 1000-2000uS to 0-255
+  LeftPWM=abs(Leftspeed-Leftcenter)*10/scale;

-  if (Serial.available()>1)                                   // command available
+  // set maximum limit 255
+  LeftPWM=min(LeftPWM,255);
+
+  // scale 1000-2000uS to 0-255
+  RightPWM=abs(Rightspeed-Rightcenter)*10/scale;
+
+  // set maximum limit 255
+  RightPWM=min(RightPWM,255);
+}
+
+//
+// Code for Serial Communications
+//
+// FL = flush serial buffer
+// AN = report Analog inputs 1-5
+// SV = next 7 integers will be position information for servos 0-6
+// HB = "H" bridge data - next 4 bytes will be:
+//      left  motor mode 0-2
+//      left  motor PWM  0-255
+//      right motor mode 0-2
+//      right motor PWM  0-255
+void SCmode() {
+  if (Serial.available()>1)
   {
     int A=Serial.read();
     int B=Serial.read();
@@ -323,35 +398,45 @@
         break;

       case FL:                                                // FL
-        Serial.flush();                                       // flush buffer
-        break;
-
+        // flush buffer
+        Serial.flush();
+        break;
+
       case AN:                                                // AN - return values of analog inputs 1-5
         Serial.println('Reporting analog input values');
         for (int i=1;i<6;i++)                                 // index analog inputs 1-5
         {
-          data=analogRead(i);                                 // read 10bit analog input
-          Serial.write(highByte(data));                       // transmit high byte
-          Serial.write(lowByte(data));                        // transmit low byte
+          // read 10bit analog input
+          data=analogRead(i);
+
+          // transmit high byte
+          Serial.write(highByte(data));
+
+          // transmit low byte
+          Serial.write(lowByte(data));
         }
         break;
-
-       case SV:                                               // SV - receive postion information for servos 0-6
-         for (int i=0;i<15;i++)                               // read 14 bytes of data
+
+        // SV - receive postion information for servos 0-6
+       case SV:
+         // read 14 bytes of data
+         for (int i=0;i<15;i++)
          {
-           Serialread();
+           Serialread();
            servo[i]=data;
          }
-         Servo0.writeMicroseconds(servo[0]*256+servo[1]);     // set servo position
-         Servo1.writeMicroseconds(servo[2]*256+servo[3]);     // set servo position
-         Servo2.writeMicroseconds(servo[4]*256+servo[5]);     // set servo position
-         Servo3.writeMicroseconds(servo[6]*256+servo[7]);     // set servo position
-         Servo4.writeMicroseconds(servo[8]*256+servo[9]);     // set servo position
-         Servo5.writeMicroseconds(servo[10]*256+servo[11]);   // set servo position
-         Servo6.writeMicroseconds(servo[12]*256+servo[13]);   // set servo position
+         // set servo positions
+         Servo0.writeMicroseconds(servo[0]*256+servo[1]);
+         Servo1.writeMicroseconds(servo[2]*256+servo[3]);
+         Servo2.writeMicroseconds(servo[4]*256+servo[5]);
+         Servo3.writeMicroseconds(servo[6]*256+servo[7]);
+         Servo4.writeMicroseconds(servo[8]*256+servo[9]);
+         Servo5.writeMicroseconds(servo[10]*256+servo[11]);
+         Servo6.writeMicroseconds(servo[12]*256+servo[13]);
          break;
-
-       case HB:                                               // HB - mode and PWM data for left and right motors
+
+       // HB - mode and PWM data for left and right motors
+       case HB:
          Serialread();
          Leftmode=data;
          Serialread();
@@ -360,7 +445,7 @@
          Rightmode=data;
          Serialread();
          RightPWM=data;
-
+
          Serial.print("Leftmode = ");
          Serial.print(Leftmode);
          Serial.print(" at ");
@@ -371,26 +456,31 @@
          Serial.println(RightPWM);

          break;
-
-       default:                                                // invalid command
-         Serial.flush();                                       // flush buffer
-    }
-  }
-}
-
-
-void Serialread()
-{//---------------------------------------------------------- Read serial port until data has been received -----------------------------------
-  do
+
+       // invalid command
+       default:
+         Serial.flush();
+    }
+  }
+}
+
+//
+// Read serial port until data has been received
+//
+void Serialread()
+{
+  do
   {
     data=Serial.read();
   } while (data<0);
 }
-
+

 void I2Cmode()
-{//----------------------------------------------------------- Your code goes here ------------------------------------------------------------
-
+{
+//
+// Your code goes here
+//
 }

@@ -403,3 +493,4 @@
   Serial.print(units);
   Serial.println(" units)");
 }
+


Deleted forgotten file

Deleted forgotten file

--- test/Arduino/MicroView/MicroView.ino
+++ test/Arduino/MicroView/MicroView.ino
@@ -1,53 +0,0 @@
-// MicroView OLED
-#include <MicroView.h>
-
-// Adafruit BNO055
-#include <Wire.h>
-#include <Adafruit_Sensor.h>
-#include <Adafruit_BNO055.h>
-#include <utility/imumaths.h>
-
-
-void setup()
-{
-        // begin of MicroView
-	uView.begin();
-	uView.clear(ALL);	// erase hardware memory inside the OLED controller
-	uView.display();	// display the content in the buffer memory, by default it is the MicroView logo
-	delay(700);
-	uView.clear(PAGE);	// erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
-
-}
-
-
-void loop()
-{
-        // MicroView
-        // TEXT Font 0
-	uView.clear(PAGE);
-	uView.setCursor(0,40);
-	uView.print("  Font 0  ");
-	uView.display();
-
-	uView.setFontType(0);
-	uView.setCursor(0,0);
-	uView.print("01234567890ABCDabcd01234567890ABCDabcd");
-	uView.display();
-	delay(1500);
-
-
-        // TEXT Font 1
-	uView.clear(PAGE);
-	uView.setCursor(0,40);
-	uView.print("  Font 1  ");
-	uView.display();
-
-	uView.setFontType(1);
-	uView.setCursor(0,0);
-	uView.print("0123ABCDabcd");
-	uView.display();
-	delay(1500);
-	uView.clear(PAGE);
-}
-
-


remove degF reporting = not needed.

remove degF reporting = not needed.

--- sensRH/src/sketch.ino
+++ sensRH/src/sketch.ino
@@ -49,7 +49,7 @@
   // Read temperature as Celsius
   float t = dht.readTemperature();
   // Read temperature as Fahrenheit
-  float f = dht.readTemperature(true);
+  // float f = dht.readTemperature(true);

   // Check if any reads failed and exit early (to try again).
   //if (isnan(h) || isnan(t) || isnan(f)) {
@@ -66,10 +66,9 @@
   Serial.print(" %\t");
   Serial.print("Temperature: ");
   Serial.print(t);
-  Serial.print(" *C / ");
-  Serial.print(f);
-  Serial.print(" *F\t");
+  Serial.print(" *C");
+  Serial.print(" %\t");
   Serial.print("Dewpoint: ");
   Serial.print(dpc);
-  Serial.println(" *C / ");
+  Serial.println(" *C");
 }


Adds some serial debug for looptime checkend; and tweaked paramters WORKS

--- Haardvuur/Haardvuur.ino
+++ Haardvuur/Haardvuur.ino
@@ -1,5 +1,9 @@
 // TODO: changing/other palette?
 #include <FastLED.h>
+// #define SERIAL_DEBUG
+#ifdef SERIAL_DEBUG
+#include <Streaming.h>
+#endif

 #define ROWS 10
 #define COLS 10
@@ -7,14 +11,16 @@

 // Fire settings
 #define BRIGHTNESS 180
-#define LOOP_TIME 500
-#define COOLING 55
-#define SPARKING 120
+#define LOOP_TIME 45
+#define FIRE_EVERY 6 //update fire every n loops only; interpolate in-between
+#define COOLING 40
+#define SPARKING 90

 // direct output buffer
 CRGB leds[NUM_LEDS];
 // Heatmap, with the 'temperature' of the fire
 uint8_t heat[NUM_LEDS];
+uint8_t heat_old[NUM_LEDS];
 // Current colour palette
 CRGBPalette16 gPal;

@@ -23,7 +29,6 @@
   // (0,0) is bottom-left corner; x is right; y is up
   // LED string snake starts at (0,0) and goes up first
   //so x always increases, but y alternates between + and -
-
   if(x%2 == 0){
     // In the 'even' rows (first row is x=0), y increases
     return ROWS*x + y;
@@ -34,9 +39,13 @@
 }

 void setup(){
+#ifdef SERIAL_DEBUG
+  Serial.begin(57600);
+  Serial << "Haardvuur.ino" << endl;
+#endif
   FastLED.delay(1000);

-  FastLED.addLeds<WS2812, RGB>(leds, NUM_LEDS);
+  FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
   FastLED.setBrightness(BRIGHTNESS);
   //test to see if everything is working
   fill_rainbow(leds, NUM_LEDS, 0, 255/NUM_LEDS);
@@ -55,17 +64,28 @@
 // 2. Heat drifts up (a lot) and sideways (a bit)
 // 3. New 'sparks'

+uint8_t loopCounter = 1;
+#ifdef SERIAL_DEBUG
+unsigned long prev_looptime;
+#endif
 void loop(){
   // Random is used a lot, so 'add entropy' here
   random16_add_entropy(random());

   // Execute the fire simulation function
-  FireAway();
+  if(loopCounter++ == FIRE_EVERY){
+    loopCounter = 0;
+    FireAway();
+  }

   // Calculate the proper LED colours
-  ColourLeds();
+  ColourLeds(loopCounter);

   FastLED.show();
+#ifdef SERIAL_DEBUG
+  Serial << (millis()-prev_looptime) << endl;
+  prev_looptime = millis();
+#endif
   FastLED.delay(LOOP_TIME);
 }

@@ -75,14 +95,19 @@

   // 1. each cell cools down a bit
   for( i=0; i != NUM_LEDS; ++i){
+    // copy heatmap to old heatmap for interpolation
+    heat_old[i] = heat[i];
     heat[i] = qsub8(heat[i], random8(0, COOLING));
   }

   // 2. now heat drifts up (a lot) and sideways (a bit)
-  for( uint8_t y=COLS-1; y != 2; --y){
+  for( uint8_t y=COLS-1; y != 0; --y){
     for( uint8_t x=0; x != ROWS; ++x){
       i = xy2i(x,y);
-      heat_sum = 2*(uint16_t)heat[xy2i(x,y-1)] + 4*(uint16_t)heat[xy2i(x,y-2)];
+      heat_sum = 4*(uint16_t)heat[xy2i(x,y-1)];
+      if(y != 1){
+        heat_sum += 2*(uint16_t)heat[xy2i(x,y-2)];
+      }
       if(x != 0){
         heat_sum += heat[xy2i(x-1,y-1)];
       }
@@ -108,11 +133,14 @@
   }
 }

-void ColourLeds(){
+void ColourLeds(uint8_t count){
   // Calculate the proper LED colours
+  uint8_t frac = count * (255/FIRE_EVERY);
+  uint8_t current_heat;
   for(uint8_t i=0; i!=NUM_LEDS; ++i){
     // apparently palette works best if max is 240
-    leds[i] = ColorFromPalette( gPal, scale8(heat[i],240));
+    current_heat = lerp8by8(heat_old[i],heat[i],frac);
+    leds[i] = ColorFromPalette( gPal, scale8(current_heat,240));
   }
 }


Store the config in the eeprom.

Store the config in the eeprom.

--- JnGeneral/JnGeneral.ino
+++ JnGeneral/JnGeneral.ino
@@ -33,6 +33,8 @@

 #include "JnGRF12.h"
 #include "JnPlugs.h"
+
+#define JG_EEPROM_ADDR ((uint8_t*) 0x80)

 // Lame floating point format, only powers of ten = mant*10^exp
 // 4 bits mantissa (0..15), 4 bits exponent (-8..7)
@@ -213,6 +215,7 @@
                      numPlugs++;
                      Serial.println("Device added.");
                  }
+                 saveConfig();
             }
             break;

@@ -228,6 +231,7 @@
                         break;
                     }
                 }
+                saveConfig();
             }
             break;

@@ -242,6 +246,7 @@
                         Serial.println("Device removed.");
                     }
                 }
+                saveConfig();
             }
             break;

@@ -370,6 +375,96 @@
         Serial.print("\r\n");
     }
     Serial.println(rf12config.msg);
+    saveConfig();
+}
+
+static int saveConfig()
+{
+    byte buffer[128];
+    byte *ptr = buffer;
+
+    *ptr++ = 'J';
+    *ptr++ = 'G';
+    ptr++;  // space for total length
+
+    for(int i=0; i<numPlugs; i++) {
+        Device *dev = getDevice(plugs[i].device_id);
+        if(!dev) {
+            continue;
+        }
+        byte *start = ptr++;   // space for length for this plug
+        *ptr++ = plugs[i].port;
+        *ptr++ = plugs[i].device_id;
+        *ptr++ = plugs[i].period;
+        for(int j=0; j<dev->num_measurements; j++)
+            *ptr++ = plugs[i].scale[j];
+
+        *start = ptr-start;
+    }
+    buffer[2] = ptr-buffer+2;  // Add two for CRC
+
+    word crc = ~0;
+    for (byte i = 0; i < ptr-buffer; ++i)
+        crc = _crc16_update(crc, buffer[i]);
+
+    *ptr++ = crc & 0xFF;
+    *ptr++ = crc >> 8;
+
+    // save to EEPROM
+    for (byte i = 0; i < ptr-buffer; ++i) {
+        byte b = buffer[i];
+        eeprom_write_byte(JG_EEPROM_ADDR + i, b);
+    }
+
+    if (!loadConfig())
+        Serial.println("config save failed");
+}
+
+static int loadConfig()
+{
+    if(eeprom_read_byte(JG_EEPROM_ADDR) != 'J' || eeprom_read_byte(JG_EEPROM_ADDR + 1) != 'G')
+        return 0;
+    int len = eeprom_read_byte(JG_EEPROM_ADDR + 2);
+    if(len>=128)
+        return 0;
+    byte buffer[128];
+    /// check CRC
+    uint16_t crc = ~0;
+    for (uint8_t i = 0; i < len; ++i) {
+        buffer[i] = eeprom_read_byte(JG_EEPROM_ADDR + i);
+        crc = _crc16_update(crc, buffer[i]);
+    }
+    if (crc != 0)
+        return 0;
+
+    byte *ptr = buffer;
+
+    int nodes = 0;
+    ptr = buffer+3;
+    while(ptr < buffer+len-2) {
+        int nodelen = *ptr;
+        if(nodelen < 4 || nodelen > 8) {
+            Serial.println("nodelen fail");
+            return 0;
+        }
+
+        memset(&plugs[nodes], 0, sizeof(plugs[nodes]));
+        plugs[nodes].port = ptr[1];
+        plugs[nodes].device_id = ptr[2];
+        plugs[nodes].period = ptr[3];
+
+        Device *dev = getDevice(plugs[nodes].device_id);
+        if(!dev) {
+            // Ignore unknown devices
+            continue;
+        }
+        for(int j=0; j<dev->num_measurements; j++)
+            plugs[nodes].scale[j] = ptr[4+j];
+        ptr += nodelen;
+        nodes++;
+    }
+    numPlugs = nodes;
+    return 1;
 }

 static int doMeasure(int count)
@@ -418,6 +513,7 @@
     Serial.begin(57600);
     Serial.print("\r\n[JeeNode General]\r\n");
     loadRF12Config();
+    loadConfig();
     showHelp();
     showConfig();
     showDevices();


poursuite proprete machine etat

poursuite proprete machine etat

--- calibrateur.ino
+++ calibrateur.ino
@@ -7,6 +7,7 @@
 # Program principal:

 // A FAIRE : gérer les vitesse : les mettre à fond quand test usb les mettre plus bas pour les autres modes.
+// A FAIRE : au démarage de l'arduino initialiser les valeurs potence loin de disque optique.

 #*******************************************************************************
  J.Soranzo
@@ -134,7 +135,7 @@
 			{
 				case USB :
 					Serial.println(F("Double Clic pour procéder à l'etlonnage"));
-					etatCalibrateur=10;
+					etatCalibrateur=ETALORSWEEP;
 					break;

 				case ETALORSWEEP :
@@ -151,7 +152,7 @@
 						boutonP.acquit();
 						leServo.setVitesse(4000);
 						Serial.println(F("tourner potar à fond à gauche"));
-						etatCalibrateur=11;
+						etatCalibrateur=REGPOTENCINVIT;
 					}
 					break;

@@ -162,7 +163,7 @@
 					//ou potar par ex
 					if (lePotar.getValue()>1000)
 					{
-						etatCalibrateur=12;
+						etatCalibrateur=REGLPOTENC;
 						Serial.println(F("quand potence reglé (sur le disque optique) faire 1 clic"));
 					}
 					break;
@@ -180,7 +181,7 @@
 						{
 							bonnePositionPotence=map(lePotar.getValue(),0,1023,potence.getMin(),potence.getMax());
 							boutonP.acquit();
-							etatCalibrateur=13;
+							etatCalibrateur=MESREFPULSE;
 						}
 					break;

@@ -188,11 +189,24 @@
 					Serial.println("ICI");
 					compteur=0;
 					compteurRef=0;
+                                        Serial.print("En Cours=");
+                                        Serial.print(leServo.getEnCours());
+                                        Serial.print(" Objectif =");
+                                        Serial.println(leServo.getObjectif());
 					objTest=leServo.getMilieu()+DELTA;
 					leServo.setObjectif(objTest);
-
+                                        Serial.println("Envoi incrément Servo");
+                                        Serial.println("En Cours=");
+                                        Serial.print(leServo.getEnCours());
+                                        Serial.print(" Objectif =");
+                                        Serial.println(leServo.getObjectif());
 					sleep(TEMPOSLEEP);
-					etatCalibrateur=14;
+                                        Serial.println("Fin attente");
+                                        Serial.println("En Cours=");
+                                        Serial.print(leServo.getEnCours());
+                                        Serial.print(" Objectif =");
+                                        Serial.println(leServo.getObjectif());
+					etatCalibrateur=FINDMINMAX;
 					Serial.println("la");
 					compteurRef=compteur;
 					if (compteurRef==0)


Now only dumps card data at end of read cycle This improves performance slightly, as no serial writes in main loop

--- ReadSensors/ReadSensors.ino
+++ ReadSensors/ReadSensors.ino
@@ -2,18 +2,12 @@
 //
 // (c) 2015 D.J.Whale

-//TODO
-//read just reg channel
-//card absent/card present state machine based on hole/card on reg
-//while card present
-//read analogs
-//filter into binary
-//turn into a byte, present value
-//or with sticky value
-//as soon as present value goes to zero
-  //clock a byte into memory
-//if see reg go active then inactive without data
-  //clock a zero into memory
+//punching
+//punch data in the 8 columns
+//if you want an empty row, punch the REG hole
+//don't punch all 8+reg else it will see a card removal
+
+//TODO error correcting mode
 //when seen 8, we have the IN phase
 //repeat for another 8, this is the OUT phase
 //now have 16 bytes in memory
@@ -22,6 +16,7 @@
 //e.g. if IN saw a hole and OUT did not, might assume we missed a hole
 //might just be able to do this by ORing each line together

+//TODO response protocol
 // return data is in hexascii
 // 00 - power up status/version etc
 // 01 - valid card, 8 bytes follow
@@ -29,12 +24,6 @@
 // 81 - card length error (not 16 clocks)
 // 82 - card data error (significantly different IN and OUT
 //bits numbered from left, so D7 is on left next to REG hole
-
-//punching
-//punch data in the 8 columns
-//if you want an empty row, punch the REG hole
-//you can punch all reg holes, but not needed unless empty row
-

 #define REGISTRATION A0
@@ -57,6 +46,8 @@
 #define LED_D2       16
 #define LED_D1       14
 #define LED_D0       15
+
+#define CARD_ROWS 8

 void setup()
@@ -77,6 +68,7 @@
 byte sticky = 0;
 boolean seenReg = false;
 byte row = 0;
+byte card[CARD_ROWS];

 typedef enum
 {
@@ -91,9 +83,7 @@
 STATE state = STATE_REMOVED;

 void loop()
-{
-  //delay(250);
-
+{
   // Read all 9 inputs (roughly) at same time
   unsigned int reg = analogRead(A0);

@@ -195,15 +185,17 @@
     break;

     case STATE_GAP:
-      //TODO store row
-      Serial.print("row:");
-      Serial.print(row);
-      Serial.print("=");
-      Serial.println(sticky);
+      //Serial.print("row:");
+      //Serial.print(row);
+      //Serial.print("=");
+      //Serial.println(sticky);
+
+      //store row data in card buffer
+      card[row] = sticky;
       // advance row
       row += 1;
       // more rows?
-      if (row == 8)
+      if (row == CARD_ROWS)
       {
         state = STATE_END;
         //Serial.println(state);
@@ -220,6 +212,7 @@
       //Note, later version will read on way out again, and complare in and out readings
       if ((freg == 1) && (now == 0xFF))
       {
+        sendCard(card, CARD_ROWS);
         state = STATE_REMOVED;
         //Serial.println(state);
       }
@@ -247,3 +240,16 @@
   digitalWrite(LED_D1,  data&(1<<1));
   digitalWrite(LED_D0,  data&(1<<0));
 }
+
+void sendCard(byte* pData, byte len)
+{
+  for (byte i=0; i<len; i++)
+  {
+    Serial.print(pData[i]);
+    Serial.print(" ");
+  }
+  Serial.println();
+}
+
+
+


adapted KMQTT ESP8266 demo

adapted KMQTT ESP8266 demo


Update signB_3d.ino

Update signB_3d.ino


Tweaked the values in Arm_test.

Tweaked the values in Arm_test.

--- Tests/Arm_test/Arm_test.ino
+++ Tests/Arm_test/Arm_test.ino
@@ -1,6 +1,8 @@
 #include <Servo.h>

-int ARM_SERVO_PIN = 11;
+const int ARM_SERVO_PIN = 11;
+int offset = 30;
+

 Servo armServo;

@@ -10,9 +12,9 @@
 }

 void loop() {
-  armServo.write(180);   // Rotate servo counter clockwise
+  armServo.write(180-offset*2);   // Rotate servo counter clockwise
   delay(2000);          // Wait 2 seconds
-  armServo.write(0);     // Rotate servo clockwise
+  armServo.write(0+offset);     // Rotate servo clockwise
   delay(2000);
   armServo.write(90);    // Rotate servo to center
   delay(2000);


updated parallel out test

updated parallel out test

--- proj/parallel_out_test/parallel_out_test.ino
+++ proj/parallel_out_test/parallel_out_test.ino
@@ -15,9 +15,9 @@
 //

 const CRGBPalette16 test(CRGB::Red, CRGB::Blue, CRGB::Orange, CRGB::Purple, CRGB::Yellow,
-                            CRGB::Green, CRGB::White, CRGB::Pink, CRGB::Black, CRGB::Black,
-                            CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black
-                           );
+                         CRGB::Green, CRGB::White, CRGB::Pink, CRGB::Black, CRGB::Black,
+                         CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Black
+                        );

 void setup() {
   // LEDS.addLeds<WS2811_PORTA,NUM_STRIPS>(leds, NUM_LEDS_PER_STRIP);
@@ -30,10 +30,10 @@
 void loop() {

   for (uint8_t ss = 0; ss < NUM_STRIPS; ss++) {
-    if(ss == 0) {
-      fill_solid(leds, NUM_LED, test[ss]);
+    if (ss == 0) {
+      fill_solid(leds, NUM_LED, ColorFromPalette(test, ss * 16, 32, LINEARBLEND));
     }
-    fill_solid(leds + ss * NUM_LED, NUM_LED, test[ss]);
+    fill_solid(leds + ss * NUM_LED, NUM_LED, ColorFromPalette(test, ss * 16, 32, LINEARBLEND));
   }


Comment out the 15 second startup delay

Comment out the 15 second startup delay

--- scatdat_v2/scatdat_v2.ino
+++ scatdat_v2/scatdat_v2.ino
@@ -127,14 +127,14 @@
   pinMode(LED_PIN, OUTPUT);
   digitalWrite(LED_PIN, LOW);

-  for (int i = 0; i < 25; ++i)
-  {
-    Serial.println("in loop");
-    Serial.println(i);
-    digitalWrite(LED_PIN, led_status);
-    led_status ^= 0x01;
-    delay(500);
-  }
+  // for (int i = 0; i < 25; ++i)
+  // {
+  //   Serial.println("in loop");
+  //   Serial.println(i);
+  //   digitalWrite(LED_PIN, led_status);
+  //   led_status ^= 0x01;
+  //   delay(500);
+  // }
   // setup pins/serial comms
   initHardware();
   Serial.println("Done with init hardware!");


Optimizing clear region in count down clock example.

--- examples/Canvas/CosaCanvasClock/CosaCanvasClock.ino
+++ examples/Canvas/CosaCanvasClock/CosaCanvasClock.ino
@@ -42,7 +42,6 @@
   tft.set_orientation(Canvas::LANDSCAPE);
   tft.set_text_font(&segment32x50);
   tft.set_text_color(tft.shade(Canvas::RED, 75));
-  tft.set_pen_color(tft.shade(Canvas::RED, 75));
   tft.fill_screen();
 }

@@ -52,7 +51,7 @@
   static uint8_t min = 30;
   static uint8_t sec = 00;

-  tft.fill_screen();
+  tft.fill_rect(0, 30, tft.WIDTH, segment32x50.HEIGHT);
   tft.set_cursor(8, 30);
   tft.draw_char('0' + min/10);
   tft.draw_char('0' + min%10);


getting v working

getting v working

--- ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
+++ ImageAnalysis/PrinterMechanics_Scanner/PrinterMechanics_Scanner.ino
@@ -7,30 +7,25 @@
 #include <Servo.h>

 // Horizontal axis
-#define StepPinY                2
-#define DirectionPinY           3
-#define StepPinX                4
-#define DirectionPinX           5
-#define JoyH_Y                 A1
-#define JoyH_X                 A0
-																																																												#define JoySwitch 2 // Joystick switch connected to interrupt Pin 2 on UNO
-/*
-#define RPMS                104.0
-#define STEPS_PER_REV         200
-#define MICROSTEPS_PER_STEP     8
-#define MICROSECONDS_PER_MICROSTEP   (1000000/(STEPS_PER_REV * MICROSTEPS_PER_STEP)/(RPMS / 60))
-*/
+#define StepPinH_Y                2
+#define DirectionPinH_Y           3
+#define StepPinH_X                4
+#define DirectionPinH_X           5
+#define JoyH_Y                    A1
+#define JoyH_X                    A0
+
+// Vertical axis
+#define StepPinV_Y                6
+#define DirectionPinV_Y           7
+#define JoyV_Y                    A2
+#define JoyV_X                    A3
+#define ServoV                    10
+

 Servo dvd_down;
-// Define a stepper and the pins it will use
-
-//int joyY = A1;
-//int y;
-
-//int angle = 0;

-//int pos = 12600;
+
 /*
 void setup()
 {
@@ -52,21 +47,29 @@

 void setup() {
 	// Big
-	pinMode(DirectionPinY, OUTPUT);
-	pinMode(StepPinY, OUTPUT);
-	digitalWrite(StepPinY, LOW);
-	digitalWrite(DirectionPinY, LOW);
+	pinMode(DirectionPinH_Y, OUTPUT);
+	pinMode(StepPinH_Y, OUTPUT);
+	digitalWrite(StepPinH_Y, LOW);
+	digitalWrite(DirectionPinH_Y, LOW);

 	// Scanner
-	pinMode(DirectionPinX, OUTPUT);
-	pinMode(StepPinX, OUTPUT);
-	digitalWrite(StepPinX, LOW);
-	digitalWrite(DirectionPinX, LOW);
+	pinMode(DirectionPinH_X, OUTPUT);
+	pinMode(StepPinH_X, OUTPUT);
+	digitalWrite(StepPinH_X, LOW);
+	digitalWrite(DirectionPinH_X, LOW);
+
+	// DVD
+	pinMode(DirectionPinV_Y, OUTPUT);
+	pinMode(StepPinV_Y, OUTPUT);
+	digitalWrite(StepPinV_Y, LOW);
+	digitalWrite(DirectionPinV_Y, LOW);
+
+	dvd_down.attach(ServoV);

 	Serial.begin(9600);
 	Serial.print("Ready");

-	//dvd_down.attach(10);
+
 }

@@ -74,74 +77,98 @@

 	//Serial.println(analogRead(JoyH_X));
 	//Serial.println(analogRead(JoyH_Y));
-
+	Serial.println(analogRead(JoyV_Y));
+	Serial.println(analogRead(JoyV_X));
+
+	// Big
 	if (analogRead(JoyH_Y)<400)
 	{
 		move_big();
-		digitalWrite(DirectionPinY, LOW);
+		digitalWrite(DirectionPinH_Y, LOW);
 	}

 	if (analogRead(JoyH_Y)>600)
 	{
 		move_big();
-		digitalWrite(DirectionPinY, HIGH);
+		digitalWrite(DirectionPinH_Y, HIGH);
 	}

+	// Scanner
 	if (analogRead(JoyH_X)<400)
 	{
 		move_scanner();
-		digitalWrite(DirectionPinX, LOW);
+		digitalWrite(DirectionPinH_X, HIGH);
 	}

 	if (analogRead(JoyH_X)>600)
 	{
 		move_scanner();
-		digitalWrite(DirectionPinX, HIGH);
+		digitalWrite(DirectionPinH_X, LOW);
 	}

-	/*
-	if (poy<400)
+	// DVD
+	if (analogRead(JoyV_Y)<400)
 	{
-		y = joyY;
-		y = map(analogRead(joyY), 0, 1023, 900, 2100);
-		dvd_down.write(y);
-		delay(15);
+		move_dvd();
+		digitalWrite(DirectionPinV_Y, HIGH);
 	}

-	if (poy>600)
+	if (analogRead(JoyV_Y)>600)
 	{
-		y = joyY;
-		y = map(analogRead(joyY), 0, 1023, 900, 2100);
+		move_dvd();
+		digitalWrite(DirectionPinV_Y, LOW);
+	}
+
+	// Servo
+
+	if (analogRead(JoyV_X)<400)
+	{
+		int y = map(analogRead(JoyV_X), 0, 1023, 900, 2100);
 		dvd_down.write(y);
-		delay(15);
+		delay(1000);
 	}
-*/
+
+	if (analogRead(JoyV_X)>600)
+	{
+		int y = map(analogRead(JoyV_X), 0, 1023, 900, 2100);
+		dvd_down.write(y);
+		delay(1000);
+	}
+
 }

 void move_big() // big motor
 {
-	digitalWrite(StepPinY, HIGH);
+	digitalWrite(StepPinH_Y, HIGH);
 	delayMicroseconds(100); //big motor

-	digitalWrite(StepPinY, LOW);
+	digitalWrite(StepPinH_Y, LOW);
 	delayMicroseconds(100); //big motor
 }

 void move_scanner()
 {
-	digitalWrite(StepPinX, HIGH);
-	delayMicroseconds(1); //scanner
+	digitalWrite(StepPinH_X, HIGH);
+	delayMicroseconds(.01); //scanner

-	digitalWrite(StepPinX, LOW);
-	delayMicroseconds(1); //scanner
+	digitalWrite(StepPinH_X, LOW);
+	delayMicroseconds(.01); //scanner
 }
-/*
+
 void move_dvd()
 {
-	digitalWrite(STEP_PIN, HIGH);
+	digitalWrite(StepPinV_Y, HIGH);
 	delayMicroseconds(700); //DVD

-	digitalWrite(STEP_PIN, LOW);
+	digitalWrite(StepPinV_Y, LOW);
 	delayMicroseconds(700); //DVD
 }
-*/+
+void move_servo()
+{
+	digitalWrite(StepPinV_Y, HIGH);
+	delayMicroseconds(700); //DVD
+
+	digitalWrite(StepPinV_Y, LOW);
+	delayMicroseconds(700); //DVD
+}


added Pitch output

added Pitch output

--- Sequencer/Sequencer.ino
+++ Sequencer/Sequencer.ino
@@ -130,21 +130,27 @@
     switch(curStep){
       case 0:
          PORTE &= ~_BV(PE4); // pin2 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[0]);
       break;
       case 1:
          PORTE &= ~_BV(PE5); // pin3 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[1]);
       break;
       case 2:
          PORTG &= ~_BV(PG5); // pin4 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[2]);
       break;
       case 3:
          PORTE &= ~_BV(PE3); // pin5 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[3]);
       break;
       case 4:
          PORTH &= ~_BV(PH3); // pin6 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[4]);
       break;
       case 5:
          PORTH &= ~_BV(PH4); // pin7 LOW (common anode, so it's a ON)
+         analogWrite(PITCHPIN, pitch[5]);
       break;
       default:
       break;


ble_my_project_template done

ble_my_project_template done

--- libraries/BLE/examples/ble_my_project_template/ble_my_project_template.ino
+++ libraries/BLE/examples/ble_my_project_template/ble_my_project_template.ino
@@ -40,10 +40,6 @@

  */
 #include <SPI.h>
-#include <avr/pgmspace.h>
-#undef PROGMEM
-#define PROGMEM __attribute__(( section(".progmem.data") ))
-
 #include <ble_system.h>
 #include <lib_aci.h>
 #include <aci_setup.h>
@@ -136,14 +132,15 @@

   /* We initialize the data structures required to setup the nRF8001
   */
-  lib_aci_init(&aci_state);
-
-  lib_aci_debug_print(true);
+  //The second parameter is for turning debug printing on for the ACI Commands and Events so they be printed on the Serial
+  lib_aci_init(&aci_state, true);
 }

 void loop()
 {
+  static bool setup_required = false;
+
   // We enter the if statement only when there is a ACI event available to be processed
   if (lib_aci_event_get(&aci_state, &aci_data))
   {
@@ -165,10 +162,7 @@
             When the device is in the setup mode
             */
             Serial.println(F("Evt Device Started: Setup"));
-            if (ACI_STATUS_TRANSACTION_COMPLETE != do_aci_setup(&aci_state))
-            {
-              Serial.println(F("Error in ACI Setup"));
-            }
+            setup_required = true;
             break;

             case ACI_DEVICE_STANDBY:
@@ -261,5 +255,17 @@
     // Arduino can go to sleep now
     // Wakeup from sleep from the RDYN line
   }
+
+  /* setup_required is set to true when the device starts up and enters setup mode.
+   * It indicates that do_aci_setup() should be called. The flag should be cleared if
+   * do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
+   */
+  if(setup_required)
+  {
+    if (SETUP_SUCCESS == do_aci_setup(&aci_state))
+    {
+      setup_required = false;
+    }
+  }
 }


Got the buffers translated into the correct types to use with CAN

--- src/md5_test/md5_test.ino
+++ src/md5_test/md5_test.ino
@@ -1,33 +1,35 @@
 #include <MD5.h>

-
-char *key = "sharedkey";
-int keyLen;
-int32_t id = 0xa0;
-int8_t dlc = 2;
-char *data = "a1f2";
-int dataLen;
+char *correct_key = "sharedkey";

 void setup()
 {
     Serial.begin(115200);
-    uint8_t *newKey = CStringToUInt8(key, keyLen);
-    uint8_t *newMessage = HexToUInt8(data, dataLen);
-
-    SendAuthMessages();
 }

 void loop()
 {
-
+    if (Serial.available() >= 3)
+    {
+        // Get user message
+        uint32_t id = (uint32_t)Serial.parseInt();
+        uint8_t dlc = (uint8_t)Serial.parseInt();
+        uint8_t *msg = new uint8_t[dlc+1];
+        for(int i = 0; i < dlc; i++)
+            msg[i] = (uint8_t)Serial.parseInt();
+        char *key = (char *)(Serial.readString().c_str());
+        uint8_t msgLen, keyLen;
+        SendAuthMessages(correct_key, keyLen, msg, msgLen);
+        Serial.flush();
+    }
 }

-void SendAuthMessages()
+void SendAuthMessages(char *key, uint8_t &keyLen, uint8_t *data, uint8_t &dataLen)
 {
     // Convert to uint8_t
     uint8_t *theKey = CStringToUInt8(key, keyLen);
-    uint8_t *theMessage = HexToUInt8(data, dataLen);
+    uint8_t *theMessage = data;

     // Concatenate into one full message
     uint8_t *fullMessage = new uint8_t[keyLen + dataLen + 1];
@@ -48,7 +50,7 @@
 }

-uint8_t *HexToUInt8(char *hexStr, int &len)
+uint8_t *HexToUInt8(char *hexStr, uint8_t &len)
 {
     len = strlen(hexStr);
     uint8_t *buf = new uint8_t[len];
@@ -67,7 +69,7 @@
 }

-uint8_t *CStringToUInt8(char *str, int &len)
+uint8_t *CStringToUInt8(char *str, uint8_t &len)
 {
     len = strlen(str);
     uint8_t *buf = new uint8_t[len];


Changed 'ToString( lightStatus_t status )' to static inline function.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -192,7 +192,7 @@
   LIGHTS_OFF, LIGHTS_ON, LIGHTS_AUTO
 };

-inline const char* ToString( lightStatus_t status )
+static inline __attribute__((always_inline)) const char *ToString( const lightStatus_t status )
 {
   switch ( status )
   {