Rewrote by our test framework

Rewrote by our test framework

--- tests/TestStringRefs/TestStringRefs.ino
+++ tests/TestStringRefs/TestStringRefs.ino
@@ -1,23 +1,24 @@
 # 2 "TestStringRefs.ino"

 #include <Arduino.h>
-#include <ArduinoUnit.h>
 #include <Arduino_FreeRTOS.h>
 #include <StandardCplusplus.h>
 #include <RabirdToolkit.h>
 #include <RAbstractStringRef.h>
+#include <RTest.h>
 #include <string.h>

-class BasicStringRef: public RAbstractStringRef
+class BasicStringRef:
+public RAbstractStringRef
 {
 public:
-  BasicStringRef(const char * str);
+  BasicStringRef(const char *str);
   ~BasicStringRef();

   unsigned int
   length(void) const
   {
-    return static_cast<unsigned int>(mLength);
+    return static_cast < unsigned int > (mLength);
   }

   char
@@ -32,11 +33,12 @@
   }

 private:
-  const char * mStr;
-  rnumber_t    mLength;
+  const char *mStr;
+  rnumber_t   mLength;
 };

-BasicStringRef::BasicStringRef(const char * str): RAbstractStringRef(), mStr(str), mLength(0)
+BasicStringRef::BasicStringRef(const char *str) : RAbstractStringRef(),
+  mStr(str), mLength(0)
 {
   if(NULL != str)
   {
@@ -48,118 +50,143 @@
 {
 }

-test(TestAbstractStringRef)
+RTEST(TestAbstractStringRef)
 {
-  const char * normalString0 = "";
-  const char * normalString1 = "a";
-  const char * normalString2 = "ab";
-  const char * normalString3 = "abc";
-  const char * normalString4 = "AbC";
+  const char *normalString0 = "";
+  const char *normalString1 = "a";
+  const char *normalString2 = "ab";
+  const char *normalString3 = "abc";
+  const char *normalString4 = "AbC";

   // length
-  assertEqual(BasicStringRef(normalString0).length(), strlen(normalString0));
-  assertEqual(BasicStringRef(normalString1).length(), strlen(normalString1));
-  assertEqual(BasicStringRef(normalString2).length(), strlen(normalString2));
-  assertEqual(BasicStringRef(normalString3).length(), strlen(normalString3));
+  RASSERT_EQUAL(BasicStringRef(normalString0).length(), strlen(normalString0));
+  RASSERT_EQUAL(BasicStringRef(normalString1).length(), strlen(normalString1));
+  RASSERT_EQUAL(BasicStringRef(normalString2).length(), strlen(normalString2));
+  RASSERT_EQUAL(BasicStringRef(normalString3).length(), strlen(normalString3));

   // compareTo
-  assertEqual(BasicStringRef(normalString3).compareTo(BasicStringRef(normalString3)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo(BasicStringRef(normalString2)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo(BasicStringRef(normalString1)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo(BasicStringRef(normalString0)), 0);
+  RASSERT_EQUAL(BasicStringRef(normalString3).compareTo(BasicStringRef(
+                                                          normalString3)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo(BasicStringRef(
+                                                         normalString2)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo(BasicStringRef(
+                                                         normalString1)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo(BasicStringRef(
+                                                         normalString0)), 0);

-  assertLess(BasicStringRef(normalString0).compareTo(BasicStringRef(normalString3)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo(BasicStringRef(normalString2)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo(BasicStringRef(normalString1)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo(BasicStringRef(normalString0)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo(BasicStringRef(
+                                                         normalString3)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo(BasicStringRef(
+                                                         normalString2)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo(BasicStringRef(
+                                                         normalString1)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo(BasicStringRef(
+                                                         normalString0)), 0);

-  assertEqual(BasicStringRef(normalString3).compareTo((normalString3)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo((normalString2)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo((normalString1)), 0);
-  assertMore(BasicStringRef(normalString3).compareTo((normalString0)), 0);
+  RASSERT_EQUAL(BasicStringRef(normalString3).compareTo((normalString3)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo((normalString2)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo((normalString1)), 0);
+  RASSERT_MORE(BasicStringRef(normalString3).compareTo((normalString0)), 0);

-  assertLess(BasicStringRef(normalString0).compareTo((normalString3)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo((normalString2)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo((normalString1)), 0);
-  assertLess(BasicStringRef(normalString0).compareTo((normalString0)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo((normalString3)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo((normalString2)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo((normalString1)), 0);
+  RASSERT_LESS(BasicStringRef(normalString0).compareTo((normalString0)), 0);

   // equals
-  assertTrue(BasicStringRef(normalString3).equals(BasicStringRef(normalString3)));
-  assertTrue(BasicStringRef(normalString3).equals((normalString3)));
+  RASSERT_TRUE(BasicStringRef(normalString3).equals(BasicStringRef(
+                                                      normalString3)));
+  RASSERT_TRUE(BasicStringRef(normalString3).equals((normalString3)));

   // equalsIgnoreCase
-  assertTrue(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(normalString4)));
-  assertTrue(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(normalString3)));
-  assertFalse(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(normalString2)));
-  assertFalse(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(normalString0)));
+  RASSERT_TRUE(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(
+                                                                normalString4)));
+  RASSERT_TRUE(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(
+                                                                normalString3)));
+  RASSERT_FALSE(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(
+                                                                 normalString2)));
+  RASSERT_FALSE(BasicStringRef(normalString3).equalsIgnoreCase(BasicStringRef(
+                                                                 normalString0)));

   // startsWith
-  assertTrue(BasicStringRef(normalString3).startsWith(BasicStringRef(normalString3)));
-  assertTrue(BasicStringRef(normalString3).startsWith(BasicStringRef(normalString2)));
-  assertTrue(BasicStringRef(normalString3).startsWith(BasicStringRef(normalString1)));
-  assertFalse(BasicStringRef(normalString3).startsWith(BasicStringRef(normalString0)));
+  RASSERT_TRUE(BasicStringRef(normalString3).startsWith(BasicStringRef(
+                                                          normalString3)));
+  RASSERT_TRUE(BasicStringRef(normalString3).startsWith(BasicStringRef(
+                                                          normalString2)));
+  RASSERT_TRUE(BasicStringRef(normalString3).startsWith(BasicStringRef(
+                                                          normalString1)));
+  RASSERT_FALSE(BasicStringRef(normalString3).startsWith(BasicStringRef(
+                                                           normalString0)));

   // endsWith
-  assertTrue(BasicStringRef(normalString3).endsWith(BasicStringRef("c")));
-  assertTrue(BasicStringRef(normalString3).endsWith(BasicStringRef("bc")));
-  assertTrue(BasicStringRef(normalString3).endsWith(BasicStringRef("abc")));
-  assertFalse(BasicStringRef(normalString3).endsWith(BasicStringRef("")));
+  RASSERT_TRUE(BasicStringRef(normalString3).endsWith(BasicStringRef("c")));
+  RASSERT_TRUE(BasicStringRef(normalString3).endsWith(BasicStringRef("bc")));
+  RASSERT_TRUE(BasicStringRef(normalString3).endsWith(BasicStringRef("abc")));
+  RASSERT_FALSE(BasicStringRef(normalString3).endsWith(BasicStringRef("")));

   // charAt
-  assertTrue(BasicStringRef(normalString3).charAt(0) == 'a');
-  assertTrue(BasicStringRef(normalString3).charAt(1) == 'b');
-  assertTrue(BasicStringRef(normalString3).charAt(2) == 'c');
-  assertTrue(BasicStringRef(normalString3).charAt(3) == '\0');
+  RASSERT_TRUE(BasicStringRef(normalString3).charAt(0) == 'a');
+  RASSERT_TRUE(BasicStringRef(normalString3).charAt(1) == 'b');
+  RASSERT_TRUE(BasicStringRef(normalString3).charAt(2) == 'c');
+  RASSERT_TRUE(BasicStringRef(normalString3).charAt(3) == '\0');

   // indexOf
-  assertEqual(BasicStringRef(normalString3).indexOf('a'), 0);
-  assertEqual(BasicStringRef(normalString3).indexOf('b'), 1);
-  assertEqual(BasicStringRef(normalString3).indexOf('c'), 2);
-  assertEqual(BasicStringRef(normalString3).indexOf('d'), -1);
+  RASSERT_EQUAL(BasicStringRef(normalString3).indexOf('a'), 0);
+  RASSERT_EQUAL(BasicStringRef(normalString3).indexOf('b'), 1);
+  RASSERT_EQUAL(BasicStringRef(normalString3).indexOf('c'), 2);
+  RASSERT_EQUAL(BasicStringRef(normalString3).indexOf('d'), -1);

   // lastIndexOf
-  assertEqual(BasicStringRef(normalString3).lastIndexOf('a'), 0);
-  assertEqual(BasicStringRef(normalString3).lastIndexOf('b'), 1);
-  assertEqual(BasicStringRef(normalString3).lastIndexOf('c'), 2);
-  assertEqual(BasicStringRef(normalString3).lastIndexOf('d'), -1);
+  RASSERT_EQUAL(BasicStringRef(normalString3).lastIndexOf('a'), 0);
+  RASSERT_EQUAL(BasicStringRef(normalString3).lastIndexOf('b'), 1);
+  RASSERT_EQUAL(BasicStringRef(normalString3).lastIndexOf('c'), 2);
+  RASSERT_EQUAL(BasicStringRef(normalString3).lastIndexOf('d'), -1);

   // operator ==
-  assertTrue(BasicStringRef(normalString3) == BasicStringRef(normalString3));
-  assertTrue(BasicStringRef(normalString3) == normalString3);
+  RASSERT_TRUE(BasicStringRef(normalString3) == BasicStringRef(normalString3));
+  RASSERT_TRUE(BasicStringRef(normalString3) == normalString3);

   // operator !=
-  assertTrue(BasicStringRef(normalString3) != BasicStringRef(normalString3));
-  assertTrue(BasicStringRef(normalString3) != BasicStringRef(normalString0));
+  RASSERT_TRUE(BasicStringRef(normalString3) != BasicStringRef(normalString3));
+  RASSERT_TRUE(BasicStringRef(normalString3) != BasicStringRef(normalString0));

   // operator >
-  assertTrue(BasicStringRef(normalString3) > BasicStringRef(normalString2));
-  assertTrue(BasicStringRef(normalString3) > BasicStringRef(normalString0));
+  RASSERT_TRUE(BasicStringRef(normalString3) > BasicStringRef(normalString2));
+  RASSERT_TRUE(BasicStringRef(normalString3) > BasicStringRef(normalString0));

   // operator <
-  assertTrue(BasicStringRef(normalString1) < BasicStringRef(normalString3));
-  assertTrue(BasicStringRef(normalString1) < BasicStringRef(normalString2));
+  RASSERT_TRUE(BasicStringRef(normalString1) < BasicStringRef(normalString3));
+  RASSERT_TRUE(BasicStringRef(normalString1) < BasicStringRef(normalString2));

   // operator <=
-  assertTrue(BasicStringRef(normalString2) <= BasicStringRef(normalString3));
-  assertTrue(BasicStringRef(normalString2) <= BasicStringRef(normalString2));
-  assertTrue(BasicStringRef(normalString2) <= BasicStringRef(normalString1));
-  assertFalse(BasicStringRef(normalString2) <= BasicStringRef(normalString0));
+  RASSERT_TRUE(BasicStringRef(normalString2) <= BasicStringRef(normalString3));
+  RASSERT_TRUE(BasicStringRef(normalString2) <= BasicStringRef(normalString2));
+  RASSERT_TRUE(BasicStringRef(normalString2) <= BasicStringRef(normalString1));
+  RASSERT_FALSE(BasicStringRef(normalString2) <= BasicStringRef(normalString0));

   // operator >=
-  assertFalse(BasicStringRef(normalString2) >= BasicStringRef(normalString3));
-  assertTrue(BasicStringRef(normalString2) >= BasicStringRef(normalString2));
-  assertTrue(BasicStringRef(normalString2) >= BasicStringRef(normalString1));
-  assertTrue(BasicStringRef(normalString2) >= BasicStringRef(normalString0));
+  RASSERT_FALSE(BasicStringRef(normalString2) >= BasicStringRef(normalString3));
+  RASSERT_TRUE(BasicStringRef(normalString2) >= BasicStringRef(normalString2));
+  RASSERT_TRUE(BasicStringRef(normalString2) >= BasicStringRef(normalString1));
+  RASSERT_TRUE(BasicStringRef(normalString2) >= BasicStringRef(normalString0));
 }

-void setup()
+void
+setup()
 {
   Serial.begin(9600);
-  while(!Serial); // for the Arduino Leonardo/Micro only
+
+  while(!Serial)  // for the Arduino Leonardo/Micro only
+  {
+  }
+
+  RTestApplication testApp;
+
+  testApp.addTest(&RTEST_INSTANCE(TestAbstractStringRef));
+  testApp.run();
 }

-void loop()
+void
+loop()
 {
-  Test::run();
 }
-


moves once better

moves once better

--- XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
+++ XBee_rob_function_2.0/xBee_2.0/xBee_2.0.ino
@@ -66,7 +66,7 @@
             infoPk[i] = jelly;
           }

-  while(emg1==1023 && g==0){
+  while(emg1 > 500 && g==0){
     Dynamixel.performMovement(2148, 2048, 2048, CLOSE);   //"Initial" position
     delay(1000);
     Dynamixel.performMovement(2148, 1850, 3250, OPEN);     //Ready position
@@ -81,7 +81,7 @@
     g++;
     break;
     }
-  if(emg1!=1023){
+  if(emg1 < 100){
     g=0;
   }
   for(int a = 13; a < 24; a++) {


RobotFirmware: added "Floor control" sensor data update

--- platform_src/RobotFirmware/RobotFirmware.ino
+++ platform_src/RobotFirmware/RobotFirmware.ino
@@ -53,6 +53,7 @@
 void loop() {
   holdingRegs[TOTAL_ERRORS] = modbus_update(holdingRegs);
   IR_update();
+  Floor_update();
   delay(50);
 }

@@ -61,3 +62,12 @@
   data*=5;data/=1024;//transform readed data to volts
   holdingRegs[IR]=(unsigned int)round(-115+205*data-29*data*data-216*log(data));//transform to distance, using magic formula
 }
+void Floor_update(){
+  Robot.updateIR();
+  byte sum=0;
+  for(int i=0;i<=4;i++){
+    if(Robot.IRarray[i]>455)
+      sum+=1;
+  }
+  holdingRegs[FLOOR]=(sum>=3?0:1);
+}


Debug functions to see time passing

Debug functions to see time passing

--- soft/drOctopusArduino/drOctopusArduino.ino
+++ soft/drOctopusArduino/drOctopusArduino.ino
@@ -9,6 +9,7 @@
 #include "oled.h"
 #include "servos.h"
 #include "commandBuffer.h"
+#include "time.h"

 boolean wifiConnectedLast = true;

@@ -26,8 +27,9 @@
 }

 void loop() {
-	digitalWrite(A2, HIGH);
+	servosLoop();
 	wifiLoop();
+	static uint32_t tLast=0;
 	if (wifiConnected && !wifiConnectedLast) {
 		char str[23] = "WiFi:";
 		oledCls();
@@ -41,6 +43,15 @@
 		oledLoop();
 	}
 	wifiConnectedLast = wifiConnected;
-	digitalWrite(A2, LOW);
+	uint32_t t;
+	t=timeGet();
+	char temp[20];
+	if(t>=(tLast+1000))
+	{
+		tLast=t;
+		itoa(t/1000,temp,10);
+		oledPrintLine(temp,2);
+		oledLoop();
+	}
 }


pad 17 to 24

pad 17 to 24


frontend: ping

frontend: ping

--- frontend/frontend.ino
+++ frontend/frontend.ino
@@ -43,73 +43,31 @@
 long timeout_start = 0;
 long timeout = 10000;

+String serial_buffer = "";
+String serial_unfinished_line = "";
 String buffer = "";

 void updateDisplay() {
   lcd.clear();
   if (state == LOCKED) {
-    /*
-    Serial.println("+--------------------+");
-    Serial.println("|                    |");
-    Serial.println("| Hello Stranger!    |");
-    Serial.println("|   Door is locked.  |");
-    Serial.println("|                    |");
-    Serial.println("+--------------------+");
-    */
     lcd.print("Hello Stranger! ");
     lcd.setCursor(0, 1);
     lcd.print(" Door is locked.");
   } else if (state == PIN_ENTRY) {
-    /*Serial.println("+--------------------+");
-    Serial.println("|Entry token read.   |");
-    Serial.println("|Please enter PIN:   |");
-    Serial.print("| ");
-    for (int i = 0; i < buffer.length(); i++) {
-      Serial.print("*");
-    }
-    for (int i = 0; i < 18-buffer.length(); i++) {
-      Serial.print(" ");
-    }
-    Serial.println(" |");
-    Serial.println("|                    |");
-    Serial.println("+--------------------+");
-    */
     lcd.print("Please enter PIN");
     lcd.setCursor(0, 1);
     for (int i = 0; i < buffer.length(); i++) {
       lcd.print("*");
     }
   } else if (state == WAIT_FOR_UNLOCK) {
-    /*Serial.println("+--------------------+");
-    Serial.println("|                    |");
-    Serial.println("| Waiting for        |");
-    Serial.println("|       unlocking    |");
-    Serial.println("|                    |");
-    Serial.println("+--------------------+");*/
     lcd.print("Waiting for     ");
     lcd.setCursor(0, 1);
     lcd.print("   confirmation ");
   } else if (state == INVALID_PIN) {
-    /*
-    Serial.println("+--------------------+");
-    Serial.println("|                    |");
-    Serial.println("| Invalid PIN        |");
-    Serial.println("|   Pleas try again. |");
-    Serial.println("|                    |");
-    Serial.println("+--------------------+");
-    */
     lcd.print("Invalid PIN     ");
     lcd.setCursor(0, 1);
     lcd.print("Please try again");
   } else if (state == UNLOCKED) {
-    /*
-    Serial.println("+--------------------+");
-    Serial.println("|     Welcome!       |");
-    Serial.println("| The space is open. |");
-    Serial.println("|                    |");
-    Serial.println("| Press 0# to lock.  |");
-    Serial.println("+--------------------+");
-    */
     lcd.print("Space is open   ");
     lcd.setCursor(0, 1);
     lcd.print("Press 0# to lock");
@@ -144,6 +102,31 @@
 }

 void loop() {
+  if (Serial.available() > 0) {
+    byte incomingByte = Serial.read();
+    if (incomingByte == '\n') {
+      if (serial_unfinished_line == "PING;") {
+        Serial.println("PONG;");
+      } else if (serial_unfinished_line.startsWith("PONG,")) {
+        String tmp = serial_unfinished_line.substring(5,6);
+        if (tmp == "0") {
+          if (state == UNLOCKED) {
+            setState(LOCKED);
+          }
+        } else if (tmp == "1") {
+          if (state != UNLOCKED) {
+            setState(UNLOCKED);
+          }
+        }
+      } else {
+        serial_buffer = serial_unfinished_line;
+      }
+      serial_unfinished_line = "";
+    } else {
+      serial_unfinished_line += (char)incomingByte;
+    }
+  }
+
   if (state == LOCKED) {
     // Look for new cards
     if ( ! mfrc522.PICC_IsNewCardPresent()) {
@@ -183,19 +166,13 @@
       }
     }
   } else if (state == WAIT_FOR_UNLOCK) {
-    if (Serial.available() > 0) {
-      byte incomingByte = Serial.read();
-      if (incomingByte == '\n') {
-        Serial.println(buffer);
-        if (buffer == "ACK;") {
-          setState(UNLOCKED);
-        } else {
-          setState(INVALID_PIN);
-        }
-      } else {
-        buffer += (char)incomingByte;
-        resetTimeout();
-      }
+    if (serial_buffer != "") {
+      if (serial_buffer == "ACK;") {
+        setState(UNLOCKED);
+      } else {
+        setState(INVALID_PIN);
+      }
+      serial_buffer = "";
     } else if (timeoutExpired()) {
       setState(LOCKED);
     }
@@ -205,7 +182,7 @@
     if (key) {
       if (key == '#' || key == '*') {
         if (buffer == "0") {
-          Serial.print("LOCK;");
+          Serial.println("LOCK;");
           setState(LOCKED);
         }
       } else {
@@ -219,7 +196,7 @@
     char key = keypad.getKey();
     if (key) {
       setState(PIN_ENTRY);
-      buffer = key;
+      buffer += key;
       updateDisplay();
     } else if (timeoutExpired()) {
       setState(LOCKED);
@@ -228,12 +205,4 @@
     Serial.println("state not implemented");
     delay(1000);
   }
-      /*
-      // Dump debug info about the card; PICC_HaltA() is automatically called
-        for (byte i = 0; i<mfrc522.uid.size; i++) {
-          Serial.print(mfrc522.uid.uidByte[i],HEX);
-        }
-        mfrc522.PICC_HaltA();
-        Serial.println();
-        */
-}
+}


Changed stuff

Changed stuff

--- backend/Arduino/ping_client/ping_client.ino
+++ backend/Arduino/ping_client/ping_client.ino
@@ -93,9 +93,9 @@
       if (drum.drumID > 0 && drum.strength > 1) {
         if (receiver.detectPeak()) {
             // Use drum.drumID to get ID and drum.strength to get strength
-            data[0] = drum.drumID;
-            data[1] = drum.strength;
-            data[3] = 0;
+            data = drum.drumID;
+            data = data + drum.strength << 4;
+            data = data + 0 << 8;
         }
       }
     }


デバイス追加

デバイス追加

--- 2_example/example60_lcdkey/lcdBarGraph.ino
+++ 2_example/example60_lcdkey/lcdBarGraph.ino
@@ -21,7 +21,7 @@

 // デバイスリスト

-#define lcd_bar_DEV_ATTR_MAX 17
+#define lcd_bar_DEV_ATTR_MAX 20
 // #define DEBUG
 int lcd_bar_DEV_ATTR_MAX_var=0;

@@ -152,8 +152,28 @@
 	lcd_bar_devAttr[15].max[0]=   30;
 	lcd_bar_devAttr[15].min[1]=	0;
 	lcd_bar_devAttr[15].max[1]= 1026;
+	strncpy(lcd_bar_devAttr[16].dev,"onoff",6);
+	lcd_bar_devAttr[16].num_a=		2;
+	lcd_bar_devAttr[16].num[0]=		1;
+	lcd_bar_devAttr[16].num[1]=		2;
+	lcd_bar_devAttr[16].min[0]=		0;
+	lcd_bar_devAttr[16].max[0]=	    1;
+	lcd_bar_devAttr[16].min[1]=		0;
+	lcd_bar_devAttr[16].max[1]=	    1;
+	strncpy(lcd_bar_devAttr[17].dev,"ocean",6);
+	lcd_bar_devAttr[17].num_a=		1;
+	lcd_bar_devAttr[17].num[0]=		1;
+	lcd_bar_devAttr[17].num[1]=		0;
+	lcd_bar_devAttr[17].min[0]=		0;
+	lcd_bar_devAttr[17].max[0]=	   30;
+	strncpy(lcd_bar_devAttr[18].dev,"alarm",6);
+	lcd_bar_devAttr[18].num_a=		1;
+	lcd_bar_devAttr[18].num[0]=		1;
+	lcd_bar_devAttr[18].num[1]=		0;
+	lcd_bar_devAttr[18].min[0]=		0;
+	lcd_bar_devAttr[18].max[0]=	   10;
 	// 終端
-	strncpy(lcd_bar_devAttr[16].dev,"",6);
+	strncpy(lcd_bar_devAttr[19].dev,"",6);
 	lcd_bar_DEV_ATTR_MAX_var = sizeof(lcd_bar_devAttr) / sizeof(lcd_bar_devAttr[0]);
 	#ifdef DEBUG
 		Serial.print("lcd_bar_DEV_ATTR_MAX_var=");


floaty ball example should use frame management

--- examples/FloatyBall/FloatyBall.ino
+++ examples/FloatyBall/FloatyBall.ino
@@ -9,8 +9,6 @@
 #include "bitmaps.h"

 Arduboy arduboy;
-
-int gameFPS = 1000/30;

 // Things that make the game work the way it do
 const int pipeArraySize = 4;  // For the for loops, at current settings only 3 sets of pipes can be onscreen at once
@@ -40,7 +38,6 @@
 int gameHighScore = 0;
 int pipeGenCount = 0;  // Frame counter to generate new pipes
 int ballVY = 0;
-unsigned long lTime;

 // Sounds
@@ -76,7 +73,7 @@
   arduboy.drawCircle(ballX, ballY, ballRadius, WHITE);  // Draw outline
   arduboy.drawLine(ballX, ballY, ballX-(ballRadius+1), ballY - ballFlapper, WHITE);  // Draw wing
   arduboy.drawPixel(ballX-(ballRadius+1), ballY - ballFlapper + 1, WHITE);  // Dot the wing
-  arduboy.drawPixel(ballX+1, ballY-2, WHITE);  // Eye
+  arduboy.drawPixel(ballX+1, ballY-2, WHITE);  // Eye
 }
 void drawPipes() {
   for (int x = 0; x < pipeArraySize; x++){
@@ -109,27 +106,27 @@
   int AyA = ballY - (ballRadius-1);  // of the hitbox will go outside of floaty's
   int AyB = ballY + (ballRadius-1);  // drawing
   int BxA, BxB, ByA, ByB;
-
+
   // check top cylinder
   BxA = pipes[0][x];
   BxB = pipes[0][x] + pipeWidth;
   ByA = 0;
   ByB = pipes[1][x];
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with top pipe
-
+
   // check top cap
   BxA = pipes[0][x] - pipeCapWidth;
   BxB = BxA + pipeWidth + (pipeCapWidth*2);
   ByA = pipes[1][x] - pipeCapHeight;
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with top cap
-
+
   // check bottom cyllinder
   BxA = pipes[0][x];
   BxB = pipes[0][x] + pipeWidth;
   ByA = pipes[1][x] + pipeGapHeight;
   ByB = HEIGHT-1;
   if (AxA < BxB && AxB > BxA && AyA < ByB && AyB > ByA) { return true; } // Collided with bottom pipe
-
+
   // check bottom cap
   BxA = pipes[0][x] - pipeCapWidth;
   BxB = BxA + pipeWidth + (pipeCapWidth*2);
@@ -147,6 +144,7 @@
 }
 void setup() {
   arduboy.begin();
+  arduboy.setFrameRate(30);
   for(int i=-8; i<28; i=i+2) {
     arduboy.clear();
     arduboy.drawSlowXYBitmap(46,i, arduino, 32,8,1);
@@ -163,126 +161,125 @@
   arduboy.print("Press Any Button");
   arduboy.display();

-  while (!arduboy.getInput());
+  while (!arduboy.buttonsState());

   delay(500);
   for (int x = 0; x < pipeArraySize; x++) { pipes[0][x] = 255; }  // set all pipes offscreen
-  lTime = millis();
 }
 void loop() {
-  if (millis() > lTime + gameFPS) {
-    arduboy.clear();
-    lTime = millis();
-    if (gameState == 0) {       // If the game is paused
-      drawFloor();
-      drawFloaty();
-      if (arduboy.getInput()) { // Wait for a button press
-        gameState = 1;          // Then start the game
-        ballVY = jumpHeight;    // And make Floaty jump
+  if (!arduboy.nextFrame())
+    return;
+
+  arduboy.clear();
+  if (gameState == 0) {       // If the game is paused
+    drawFloor();
+    drawFloaty();
+    if (arduboy.buttonsState()) { // Wait for a button press
+      gameState = 1;          // Then start the game
+      ballVY = jumpHeight;    // And make Floaty jump
+      if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
+      arduboy.tunes.playScore (flap);
+    }
+  }
+  if (gameState == 1) {       // If the game is playing
+    pipeGenCount++;           // inc pipe generator counter 1 frame
+    if (ballVY > 0) {         // If the ball isn't already rising, check for jump
+      if (arduboy.pressed(B_BUTTON) || arduboy.pressed(A_BUTTON)) {
+        ballVY = jumpHeight;  // jump
         if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
         arduboy.tunes.playScore (flap);
       }
     }
-    if (gameState == 1) {       // If the game is playing
-      pipeGenCount++;           // inc pipe generator counter 1 frame
-      if (ballVY > 0) {         // If the ball isn't already rising, check for jump
-        if (arduboy.pressed(B_BUTTON) || arduboy.pressed(A_BUTTON)) {
-          ballVY = jumpHeight;  // jump
+    if (pipeGenCount > pipeGenTimer) {  // Every pipeGenTimer worth of frames
+      generatePipe();                   // Generate a pipe
+      pipeGenCount = 0;                 // Reset the generator counter
+    }
+    ballY = ballY + ballVY;             // Move the ball according to ballVY
+    if (ballY < ballRadius) { ballY = ballRadius; } // No clipping the top
+    ballVY++;                           // Decrement VY
+    for (int x = 0; x < pipeArraySize; x++) {  // For each pipe array element
+      if (pipes[0][x] != 255) {         // If the x value isn't 255
+        pipes[0][x] = pipes[0][x] - 2;  // Then move it left 2px
+        if (pipes[0][x] + pipeWidth < 0) {  // If the pipe's right edge is off screen
+        pipes[0][x] = 255;              // Then set its value to 255
+      }
+        if (pipes[0][x] + pipeWidth == (ballX-ballRadius)) {  // If the pipe passed Floaty
+          gameScore++;                  // And increment the score
+          gameScoreX = ballX;           // Load up the floating text with
+          gameScoreY = ballY - ballRadius; // Current ball x/y values
+          gameScoreRiser = 15;          // And set it for 15 frames
           if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
-          arduboy.tunes.playScore (flap);
+          arduboy.tunes.playScore (point);
         }
       }
-      if (pipeGenCount > pipeGenTimer) {  // Every pipeGenTimer worth of frames
-        generatePipe();                   // Generate a pipe
-        pipeGenCount = 0;                 // Reset the generator counter
-      }
-      ballY = ballY + ballVY;             // Move the ball according to ballVY
-      if (ballY < ballRadius) { ballY = ballRadius; } // No clipping the top
-      ballVY++;                           // Decrement VY
-      for (int x = 0; x < pipeArraySize; x++) {  // For each pipe array element
-        if (pipes[0][x] != 255) {         // If the x value isn't 255
-          pipes[0][x] = pipes[0][x] - 2;  // Then move it left 2px
-          if (pipes[0][x] + pipeWidth < 0) {  // If the pipe's right edge is off screen
-          pipes[0][x] = 255;              // Then set its value to 255
-        }
-          if (pipes[0][x] + pipeWidth == (ballX-ballRadius)) {  // If the pipe passed Floaty
-            gameScore++;                  // And increment the score
-            gameScoreX = ballX;           // Load up the floating text with
-            gameScoreY = ballY - ballRadius; // Current ball x/y values
-            gameScoreRiser = 15;          // And set it for 15 frames
-            if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
-            arduboy.tunes.playScore (point);
-          }
-        }
-      }
-
-      if (gameScoreRiser > 0) {  // If we have floating text
-        arduboy.setCursor(gameScoreX - 2,gameScoreY + gameScoreRiser - 24);
-        arduboy.print(gameScore);
-        gameScoreX = gameScoreX - 2;
-        gameScoreRiser--;
-      }
-
-      if (ballY + ballRadius > (HEIGHT-1)) {  // If the ball has fallen below the screen
-        ballY = (HEIGHT-1) - ballRadius;      // Don't let the ball go under :O
-        gameState = 2;                        // Game over. State is 2.
-      }
-      // Collision checking
-      for (int x = 0; x < pipeArraySize; x++) { // For each pipe array element
-        if (pipes[0][x] != 255) {               // If the pipe is active (not 255)
-          if (checkPipe(x)) { gameState = 2; }  // If the check is true, game over
-        }
-      }
-
+    }
+
+    if (gameScoreRiser > 0) {  // If we have floating text
+      arduboy.setCursor(gameScoreX - 2,gameScoreY + gameScoreRiser - 24);
+      arduboy.print(gameScore);
+      gameScoreX = gameScoreX - 2;
+      gameScoreRiser--;
+    }
+
+    if (ballY + ballRadius > (HEIGHT-1)) {  // If the ball has fallen below the screen
+      ballY = (HEIGHT-1) - ballRadius;      // Don't let the ball go under :O
+      gameState = 2;                        // Game over. State is 2.
+    }
+    // Collision checking
+    for (int x = 0; x < pipeArraySize; x++) { // For each pipe array element
+      if (pipes[0][x] != 255) {               // If the pipe is active (not 255)
+        if (checkPipe(x)) { gameState = 2; }  // If the check is true, game over
+      }
+    }
+
+    drawPipes();
+    drawFloor();
+    drawFloaty();
+
+  }
+  if (gameState == 2) {  // If the gameState is 2 then we draw a Game Over screen w/ score
+    if (gameScore > gameHighScore) { gameHighScore = gameScore; }
+    if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
+    arduboy.display();              // Make sure final frame is drawn
+    arduboy.tunes.playScore (hit);  // Hit sound
+    delay(100);                     // Pause for the sound
+    while (ballY + ballRadius < (HEIGHT-1)) {  // While floaty is still airborne
+    if (ballVY < 0) { ballVY = 0; } // Stop any upward momentum
+      ballY = ballY + ballVY;       // Fall
+      ballVY++;                     // Increase falling speed
+      if (ballY + ballRadius > (HEIGHT-1)) { ballY = HEIGHT - ballRadius; } // Don't fall through the floor plx
+      arduboy.clear();
       drawPipes();
       drawFloor();
       drawFloaty();
-
-    }
-    if (gameState == 2) {  // If the gameState is 2 then we draw a Game Over screen w/ score
-      if (gameScore > gameHighScore) { gameHighScore = gameScore; }
-      if (arduboy.tunes.playing()) { arduboy.tunes.stopScore(); }
-      arduboy.display();              // Make sure final frame is drawn
-      arduboy.tunes.playScore (hit);  // Hit sound
-      delay(100);                     // Pause for the sound
-      while (ballY + ballRadius < (HEIGHT-1)) {  // While floaty is still airborne
-      if (ballVY < 0) { ballVY = 0; } // Stop any upward momentum
-        ballY = ballY + ballVY;       // Fall
-        ballVY++;                     // Increase falling speed
-        if (ballY + ballRadius > (HEIGHT-1)) { ballY = HEIGHT - ballRadius; } // Don't fall through the floor plx
-        arduboy.clear();
-        drawPipes();
-        drawFloor();
-        drawFloaty();
-        arduboy.display();
-      }
-      arduboy.tunes.playScore (horns);     // SOUND THE LOSER'S HORN
-      arduboy.drawRect(16,8,96,48, WHITE); // Box border
-      arduboy.fillRect(17,9,94,46, BLACK); // Black out the inside
-      arduboy.drawSlowXYBitmap(30,12,gameover,72,14,1);
-      arduboy.setCursor(56 - getOffset(gameScore),30);
-      arduboy.print(gameScore);
-      arduboy.setCursor(69,30);
-      arduboy.print("Score");
-
-      arduboy.setCursor(56 - getOffset(gameHighScore),42);
-      arduboy.print(gameHighScore);
-      arduboy.setCursor(69,42);
-      arduboy.print("High");
-
       arduboy.display();
-
-      while (!arduboy.getInput());
-
-      gameState = 0;       // Then start the game paused
-      gameScore = 0;       // Reset score to 0
-      gameScoreRiser = 0;  // Clear the floating score
-      for (int x = 0; x < pipeArraySize; x++) { pipes[0][x] = 255; }	// set all pipes inactive
-      ballY = 32;          // Reset ball to center
-      ballVY = 0;          // With zero lift
-      delay(250);          // Slight delay so input doesn't break pause
-
-    }
-    arduboy.display();  // Finally draw this thang
-  }
-}
+    }
+    arduboy.tunes.playScore (horns);     // SOUND THE LOSER'S HORN
+    arduboy.drawRect(16,8,96,48, WHITE); // Box border
+    arduboy.fillRect(17,9,94,46, BLACK); // Black out the inside
+    arduboy.drawSlowXYBitmap(30,12,gameover,72,14,1);
+    arduboy.setCursor(56 - getOffset(gameScore),30);
+    arduboy.print(gameScore);
+    arduboy.setCursor(69,30);
+    arduboy.print("Score");
+
+    arduboy.setCursor(56 - getOffset(gameHighScore),42);
+    arduboy.print(gameHighScore);
+    arduboy.setCursor(69,42);
+    arduboy.print("High");
+
+    arduboy.display();
+
+    while (!arduboy.buttonsState());
+
+    gameState = 0;       // Then start the game paused
+    gameScore = 0;       // Reset score to 0
+    gameScoreRiser = 0;  // Clear the floating score
+    for (int x = 0; x < pipeArraySize; x++) { pipes[0][x] = 255; }  // set all pipes inactive
+    ballY = 32;          // Reset ball to center
+    ballVY = 0;          // With zero lift
+    delay(250);          // Slight delay so input doesn't break pause
+
+  }
+  arduboy.display();  // Finally draw this thang
+}


Update telemetry outputs

Update telemetry outputs

--- examples/quadcopter/quadcopter.ino
+++ examples/quadcopter/quadcopter.ino
@@ -176,9 +176,10 @@
         comms.sendTelem(HEADING    , toDeg(orientation.getYaw()));
         comms.sendTelem(PITCH      , toDeg(orientation.getPitch()));
         comms.sendTelem(ROLL       , toDeg(orientation.getRoll()));
-        comms.sendTelem(GROUNDSPEED, horizon.testPoint[0]);//profile[0]);
+        comms.sendTelem(GROUNDSPEED, profileTime(0));
         comms.sendTelem(VOLTAGE    , voltage);
-        comms.sendTelem(VOLTAGE+1  , altitude.get());
+        comms.sendTelem(AMPERAGE   , safe());
+        comms.sendTelem(ALTITUDE   , altitude.get());

         Serial.println();
         Serial.flush();


Fixed a bug IR function

Fixed a bug IR function

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -84,6 +84,9 @@

  setupSerialCommands();

+ pinMode(IR_LED_LEFT, OUTPUT);      // sets the digital pin as output
+ pinMode(IR_LED_RIGHT, OUTPUT);
+
  if ( IR_ON ) {
   digitalWrite(IR_LED_LEFT,HIGH);
   digitalWrite(IR_LED_RIGHT,HIGH);
@@ -102,13 +105,16 @@
   arg = sCmd.next();
   int status = atoi(arg);

+
   if( status == 1) {
     digitalWrite(IR_LED_LEFT,HIGH);
     digitalWrite(IR_LED_RIGHT,HIGH);
+    Serial.println("ON " + String(status));
   }
   else if ( status == 0) {
     digitalWrite(IR_LED_LEFT,LOW);
     digitalWrite(IR_LED_RIGHT,LOW);
+    Serial.println("OFF " + String(status));
   }
   listValues();
 }


Fixed a naming issue.

Fixed a naming issue.

--- firmware/firmware.ino
+++ firmware/firmware.ino
@@ -177,6 +177,7 @@
   size_t num_entries = token->size / 2;
   for (size_t entry_idx = 0; entry_idx < num_entries; entry_idx++)
   {
+
     // Get the name field for this entry.
     token++;
     char entry_name[64];
@@ -186,6 +187,7 @@
       return;
     }
     json_string(*token, buffer, entry_name, 64);
+

     // Attempt to decode the configurable object for this entry.
     platypus::Configurable *entry_object;
@@ -243,13 +245,14 @@
         reportError("Expected name field for parameter.", buffer);
         return;
       }
+
       json_string(*token, buffer, param_name, 64);
-
+
       // Get the value field for this parameter.
       token++;
       char param_value[64];
       json_string(*token, buffer, param_value, 64);
-
+
       // Pass this parameter to the entry object.
       if (!entry_object->set(param_name, param_value)) {
         reportError("Invalid parameter set.", buffer);
@@ -275,7 +278,7 @@
   // Initialize sensors
   platypus::sensors[0] = new platypus::ServoSensor(0);
   platypus::sensors[1] = new platypus::Hds5(1);
-  platypus::sensors[2] = new platypus::AtlasSensor(2);
+  platypus::sensors[2] = new platypus::Winch(2,0x80);
   platypus::sensors[3] = new platypus::ES2(3);

   // Initialize motors
@@ -447,7 +450,10 @@
         Serial.print("Arming motor [");
         Serial.print(motor_idx);
         Serial.println("]");
+        //Serial.println("I've turned off the fucking motor arming");
         motor->arm();
+        Serial.println("Motor Armed");
+        //motor->enable
       }
     }
     break;


Bugfix

Bugfix

fixed a buffer overflow timer

--- getnparseforecast.ino
+++ getnparseforecast.ino
@@ -104,7 +104,7 @@
   for (int j = 0; j < num_elements_fr; j++) {
     while (!Serial1.find(forecast[j])) {
       if (timeoutforecast > millis()) timeoutforecast = millis();// se timeoutforecast e' maggiore di millis allora il contatore si e' riavviato, quindi aggiorna la variabile
-      if (timeoutforecast + 20000 < millis())return; // se sono passati piu' di 20 secondi esci
+      if (millis() - timeoutforecast > 20000)return; // se sono passati piu' di 20 secondi esci
     }

     String Str1 = forecast_rename[j];


feat: added bluetooth on/off feature to drive

--- Advanced-Line-follower.ino
+++ Advanced-Line-follower.ino
@@ -1,5 +1,11 @@
 #include "DCMotors.h"
 #include "Sensor.h"
+
+#define START 's'
+#define STOP 't'
+
+bool debug = false;
+bool startDrive = false;

 DCMotors<10,18,19,11,14,15> motors; //enL, L1, L2, enR, R1, R2
 Sensor<2,3,4,5,6,7,8,9> sensors;
@@ -8,27 +14,44 @@
 float P=0, I=0, D=0, PID_value=0;
 int error=0;
 float previous_error=0, previous_I=0;
-//int sensor[8]={0, 0, 0, 0, 0, 0, 0, 0};

 void read_sensor_values(void);
 void calculate_pid(void);
+void btDebug();
 void motor_control(void);

 void setup() {
-  // put your setup code here, to run once:
+
   motors.configure();
   sensors.configure();
   Serial.begin(9600);
+
+  debug = true;

 }

 void loop() {
-  // put your main code here, to run repeatedly:
-    phone();
+
+    if(debug){
+      btDebug();
+    }
+
     sensors.updateError();
     calculate_pid();
-    motors.drive(PID_value);
-    delay(500);
+
+    if(Serial.read() == START) {
+      startDrive = true;
+    }
+
+    if(Serial.read() == STOP){
+      startDrive = false;
+    }
+
+    if(startDrive){
+      motors.drive(PID_value);
+    }
+
+    delay(100);

 }

@@ -72,7 +95,7 @@
    **/
 }

-void phone()
+void btDebug()
 {

   if(Serial.available())


avoid flickering with auto switch of panels

--- ArduCAM_OSD/OSD_Panels.ino
+++ ArduCAM_OSD/OSD_Panels.ino
@@ -439,29 +439,29 @@
 // Status  : done

 void panOff(){
-	static byte new_panel;
-
+    static byte new_panel;
+    static unsigned long last_switch_millis = 0;
+
+    new_panel = panel;
+
     if (warning == 1) {
-        if (panel != panel_auto_switch) {
-          osd_clear = 1;
-          panel = panel_auto_switch;
-        }
-
-        return;  // no switch possible
+          new_panel = panel_auto_switch;  //only change to auto panel
     }
-
-	if (ch_toggle == 4) {		// flight mode -> distance mode
-		if (osd_got_home == 1) {	// only if we have good coords
-			static long distance = osd_home_distance / osd_alt;
-			if (distance > distance_auto_switch) {
-				new_panel = 0;
-			}
-			else {
-				new_panel = 1;
-			}
-		}
-	}
-	else {						// switch mode
+    else if (ch_toggle == 4) {		// flight mode -> distance mode
+	if (osd_got_home == 1) {	// only if we have good coords
+	  static long distance = osd_home_distance / osd_alt;
+
+          if (millis() >  last_switch_millis + 500) {   // switch no faster that 500ms to avoid blinking on edge
+	      if (distance > distance_auto_switch) {
+		new_panel = 0;
+	      }
+	      else {
+	        new_panel = 1;
+	      }
+	  }
+	}
+    }
+    else {						// switch mode
 		if(ch_toggle == 5) ch_raw = chan5_raw;
 		else if(ch_toggle == 6) ch_raw = chan6_raw;
 		else if(ch_toggle == 7) ch_raw = chan7_raw;
@@ -497,6 +497,7 @@
 	if (panel != new_panel) {	// something to switch to
 		osd_clear = 1;
 		panel = new_panel;
+                last_switch_millis = millis();
 	}
 }


Version of code running on prototype and box going to DC

--- frontbox_solo/frontbox_solo.ino
+++ frontbox_solo/frontbox_solo.ino
@@ -14,28 +14,16 @@
 //  PULSE		AI2			25

 // Memory PINOUTS
-// 1-4 GND
-// 2 MISO ATMEGA PIN 18
-//   Arduino Digital PIN 12
-// 3 NC
-// 5 MOSI ATMEGA PIN 17
-//   Arduino Digital PIN 11
-// 6 SCK ATMEGA PIN 19
-//   Arduino Digital PIN 13
-// 7 V_BAT CR2032
-// 8 5V Power
-// Wire Routing
-// Arduino-- 23LC1024
+// Arduino-- SD shield
 // D13 <------> SCK
 // D12 <------> MISO
 // D11 <------> MOSI
 // D10 <------> CS
-// 5V  <------> VCC
-// 5V  <------> HOLD
-// 5V  <-10KR-> CS  //  pullup resistor not needed
-// GND <------> VSS
+// 5V  <------> 5V
+// GND <------> GND

 //#define DEBUG
+//#define _GPS_NO_STATS  // prevent statistics collection code from being compiled

 #include <SPI.h>
 #include <SD.h>
@@ -47,7 +35,6 @@

 // **************** FOR GPS ******************
 TinyGPS gps;
-//SoftwareSerial gps_serial(9, 8);
 float flat=0, flon=0;
 unsigned long age;
 int gps_year;
@@ -70,6 +57,7 @@
 // **************** FOR SHARP SENSOR ****************
 #define SHARP_READ_PIN 3 // Analog PIN 3 ATMEGA 26
 int sharp_dust_val = 0;
+float sharp_voltage=0;

 #define SHARP_LED_PIN 4      // Digital PIN 4 ATMEGA 6
 #define SHARP_DELAY_TIME 280
@@ -99,14 +87,13 @@

 // **************** timer for sensor data collection ****************
 unsigned long sensors_read_time_start;
-unsigned long num_records = 0;
+unsigned num_records = 0;
 #define SENSORS_READ_TIME  2000    // ms

 void setup()
 {
-  Serial.begin(9600); // now using for GPS
-  //gps_serial.begin(9600);
+  Serial.begin(9600); // now using for GPS

   // **************** FOR RTC ****************
   Wire.begin(); // Join I2C bus as a master
@@ -121,10 +108,10 @@

   // **************** FOR MQ7 SENSOR ****************
   pinMode(CO_PWR_SEL_PIN, OUTPUT);
-  CO_timer_start = millis();
   digitalWrite(CO_PWR_SEL_PIN, LOW);// 5v phase
   heaterInHighPhase = true;
-  CO_switch_time = millis() + CO_HEAT_TIME;
+  CO_timer_start = millis();
+  CO_switch_time = CO_timer_start + CO_HEAT_TIME;

   // **************** FOR TEMP & HUMIDITY SENSOR ****************
   dht.begin();
@@ -133,25 +120,29 @@
   // must be left as an output or the SD library functions will not work.
   pinMode(SS, OUTPUT);

-  DateTime saved_time=rtc.now();
-  file_name = "obi-"+ String(saved_time.month() ) + '-' + String(saved_time.day()) +
-      ".txt";
-
-  if ( !SD.begin(CHIP_SELECT_PIN) )
+  // filename will be mm-dd-hh.txt
+  DateTime rtc_time=rtc.now();
+  file_name = String( rtc_time.month() ) + '-' + String( rtc_time.day() ) + '-' +
+      String( rtc_time.hour() ) + ".txt";
+
+  if ( !SD.begin(CHIP_SELECT_PIN) ) {
 #ifdef DEGUB
     Serial.println("SD card initialization failed!");
 #endif
+  }
   delay(100); // otherwise open() will fail
+
   // write header
+
+#ifdef DEBUG
+    Serial.println("Writing header to SD");
+    Serial.flush();
+#endif
+
   myFile = SD.open(file_name.c_str(), FILE_WRITE);
-
-
   if (myFile) {
-#ifdef DEBUG
-    Serial.println("Writing header to SD");
-#endif
-    myFile.print("latitude\tlongitude\tDD/MM/YYYY HH:MM:SS");
-    myFile.println("\tSharp value\tGrove value\tCO value\tHumidity\tTemp (celsius)");
+    myFile.print("Rec. #\tDD/MM/YYYY\tHH:MM:SS\tlatitude\tlongitude\t");
+    myFile.println("Sharp value\tGrove value\tCO read\tCO heat\tHumidity\tTemp (celsius)");
     myFile.close();
   } else {
 #ifdef DEBUG
@@ -173,7 +164,6 @@
   unsigned long chars;
   unsigned short sentences, failed;
 #endif
-  //gps_serial.listen(); // select the GPS softserial port for listening

   // For one second we parse GPS data and report some key values
   for (unsigned long start = millis(); millis() - start < 1000;) {
@@ -190,12 +180,13 @@

       if(!haveClock) { // set clock
         gps.crack_datetime(&gps_year, &gps_month, &gps_day, &gps_hour, &gps_minute, &gps_second);
-         char tmp = gps_hour - 7; // adjust UTC FIXME!
-         if (tmp < 0) {
+         // adjust UTC FIXME!
+         if ( gps_hour < 7) {  // don't subtract from unsigned types
            gps_day -= 1;
-           gps_hour = tmp+24;
-         }
-         //
+           gps_hour += 17;     // instead add 24 - 7
+         } else
+            gps_hour -=7;     // OK to subtract here
+         //  Wants years since 1900?
          rtc.adjust( DateTime(gps_year-2000, gps_month, gps_day, gps_hour, gps_minute, gps_second));
          haveClock=true;
       }
@@ -209,6 +200,7 @@
   Serial.print(sentences);
   Serial.print(" CSUM ERR=");
   Serial.println(failed);
+  Serial.flush();
   if (chars == 0)
     Serial.println("** No characters received from GPS: check wiring **");
 #endif
@@ -231,6 +223,7 @@
 #ifdef DEBUG
     Serial.print("Time since last reading: ");
     Serial.println(millis() - sensors_read_time_start);
+    Serial.flush();
 #endif

   if( (millis() - sensors_read_time_start) > SENSORS_READ_TIME ) {
@@ -256,32 +249,32 @@
   delay(SHARP_DELAY_TIME);  // wait 280ms
   sharp_dust_val = analogRead(SHARP_READ_PIN); // read the dust value via pin 5 on the sensor
   digitalWrite(SHARP_LED_PIN, HIGH); // turn the LED off
-
+  sharp_voltage = sharp_dust_val*4.9/1024;   // convert to voltage
+  sharp_voltage = (sharp_voltage - 0.0356) * 120000; // convert to particles / .01 ft^3
+  if( sharp_voltage < 0 )
+    sharp_voltage = 0;

   // **************** FOR GROVE SENSOR ****************
   ratio = lowpulseoccupancy / (grove_sample_time*10.0);  // Integer percentage 0=>100
-  // using spec sheet curve
+  // using spec sheet curve, gives particles per 0.01 cubic foot
   concentration = 1.1*pow(ratio, 3) - 3.8*pow(ratio, 2) + 520 * ratio + 0.62;
   lowpulseoccupancy = 0;  // reset

   // **************** FOR MQ7 SENSOR ****************
-
-    if (millis() > CO_switch_time) {  // switch to 1.4V phase
+    if (millis() > CO_switch_time) {         // time to switch
       if (heaterInHighPhase) {
-        digitalWrite(CO_PWR_SEL_PIN, HIGH); // 1.4v phase
+        digitalWrite(CO_PWR_SEL_PIN, HIGH);  // 1.4v phase
         heaterInHighPhase = false;
         CO_switch_time = millis() + CO_READ_TIME;
-      } else { // switch to 5V phase
-        digitalWrite(CO_PWR_SEL_PIN, LOW);// 5v phase
+      } else {                               // switch to 5V phase
+        digitalWrite(CO_PWR_SEL_PIN, LOW);   // 5v phase
         heaterInHighPhase = true;
         CO_switch_time = millis() + CO_HEAT_TIME;
       }
   }
-  // readGasLevel
+  // Read gas level regardless
   gasLevel = analogRead(CO_READ_PIN);
- // if (heaterInHighPhase)
- //   gasLevel = 0xFFFF;

   // **************** FOR TEMP & HUMIDITY SENSOR ****************
@@ -292,93 +285,110 @@
     h=255;    f=255;
   }

+  // ********** KEEP TRACK OF HOW MANY RECORDINGS WE'VE TAKEN *********
+  num_records++;
+
 #ifdef DEBUG
   Serial.print("Time to read sensors(ms): ");
   Serial.println(millis() - read_start);
-#endif
-
+  Serial.flush();
+#endif
+
+
+#ifdef DEBUG
   // **************** log data to serial output ****************
-
-#ifdef DEBUG
-
+
+    Serial.print("Rec. # ");    Serial.print(num_records);  Serial.print('\t');
+
     Serial.print(now.month());  Serial.print('/');
     Serial.print(now.day());    Serial.print('/');
-    Serial.print(now.year());   Serial.print(' ');
+    Serial.print(now.year());   Serial.print('\t');
     Serial.print(now.hour());   Serial.print(':');
     Serial.print(now.minute()); Serial.print(':');
     Serial.print(now.second()); Serial.print('\t');

-    Serial.print(flat, 6); Serial.print(" ,");
-    Serial.print(flon, 6); Serial.print(' ');
-
-    Serial.print("\tSharp value: ");         Serial.print(sharp_dust_val);
-    Serial.print("\tGrove Concentration: "); Serial.print(concentration);
-    Serial.print("\tCO: ");                  Serial.print(gasLevel);
-    Serial.print("\tHumidity: ");            Serial.print(h);
-    Serial.print("\tTemp: ");                Serial.println(f);
+    Serial.flush();
+
+    Serial.print(flat, 6); Serial.print('\t');
+    Serial.print(flon, 6); Serial.print('\t');
+
+    Serial.flush();
+
+    Serial.print("\tSharp: ");         Serial.print(sharp_voltage);
+    Serial.print("\tGrove: ");         Serial.print(concentration);
+    if(heaterInHighPhase)
+      Serial.print("\tCO heat: ");
+    else
+      Serial.print("\tCO read: ");
+    Serial.print(gasLevel);
+    Serial.print("\tHumidity: ");      Serial.print(h);
+    Serial.print("\tTemp: ");          Serial.println(f);
+
     Serial.flush();
 #endif

   // **************** WRITE TO SD CARD ****************
 #ifdef DEBUG
-  Serial.println("Logging a record to SD");
+  Serial.println("Logging to SD");
+  Serial.flush();
 #endif

   myFile = SD.open(file_name.c_str(), FILE_WRITE);

-#ifdef DEBUG
-  if (myFile) {
-    Serial.println("File open");
-  } else {
+/* #ifdef DEBUG
+  if (!myFile) {
     Serial.println("Error opening SD file. Record not logged.");
+    Serail.flush();
     return;
   }
 #endif
-
-  // gps
-  myFile.print(flat,6); myFile.print('\t');
-  myFile.print(flon,6); myFile.print('\t');
-  // altitude, speed?
-
+*/
+
+  // record number
+  myFile.print(num_records); myFile.print('\t');
+
   // date and time
   myFile.print(String(now.month()).length()==1 ? String('0') + String(now.month()) : now.month() );
   myFile.print('/');
   myFile.print(String(now.day()).length()==1 ? String('0') + String(now.day()) : now.day() );
   myFile.print('/');
   myFile.print(now.year());
-  myFile.print(' ');
+  myFile.print('\t');
   myFile.print(String(now.hour()).length()==1 ? String('0') + String(now.hour()) : now.hour() );
   myFile.print(':');
   myFile.print(String(now.minute()).length()==1 ? String('0') + String(now.minute()) : now.minute() );
   myFile.print(':');
   myFile.print(String(now.second()).length()==1 ? String('0') + String(now.second()) : now.second() );
   myFile.print('\t');
-
+
+  // gps
+  myFile.print(flat,6); myFile.print('\t');
+  myFile.print(flon,6); myFile.print('\t');
+  // altitude, speed?
+
   // sharp sensor value
-  myFile.print(sharp_dust_val); myFile.print('\t');
+  myFile.print(sharp_voltage); myFile.print('\t');

   //  grove sensor value
   myFile.print(concentration);  myFile.print('\t');

   // MQ7 CO sensor value
-  myFile.print(gasLevel);
-  if(heaterInHighPhase)
-    myFile.print(" (H)");
+   if(heaterInHighPhase) {
+    myFile.print("--\t");
+    myFile.print(gasLevel);
+  } else {
+    myFile.print(gasLevel); myFile.print('\t');
+    myFile.print("--");
+  }
   myFile.print('\t');

-  // DHT22 sensor value
+  // DHT22 sensor values
   myFile.print(h);  myFile.print('\t');
   myFile.print(f);  myFile.println();
   myFile.close();
-
-  // Update how many records we have
-  num_records++;
-
-#ifdef DEBUG
-  Serial.print(" Num records: "); Serial.println(num_records);
-#endif
-
-} //ReadSensors // ISR
-
+
+
+} // ReadSensors()
+


Local scope variables, minor whitespace edits

--- NLMS_AEC/NLMS_AEC.ino
+++ NLMS_AEC/NLMS_AEC.ino
@@ -64,13 +64,8 @@

 //***************NMLS const and settings*************************
 const int16_t numTaps = gg;
-int16_t mu = 13;
-int16_t mu0 = 0;
-int8_t psi = 1;
 int16_t w[numTaps];
 int16_t *pw; // pointer to w
-int16_t yhat = 0;
-int64_t xtdl = 0;

 //define input/source
@@ -150,21 +145,26 @@
 // NMLS algorithm
 // inputs are Mic Signal, far end signal and index of n-1 block wher n is the current block itteration
 // previous block data is used to modify current block data samples
-void NLMS_AEC(int16_t *Mic, int16_t *x){
+void NLMS_AEC(int16_t *Mic, int16_t *x)
+{
+  int16_t yhat = 0;
+  int64_t xtdl = 0;
+  int16_t mu0;
+  int16_t mu = 13;
+  int8_t psi = 1;
+
   for(int h = 0; h<128;h+=1){
     for(int j = gg; j>0;j-=1){
       yhat += (x[j+h]*pw[gg-j])/32768;
       xtdl += x[j+h]*x[j+h];
     }
     error[h] = Mic[gg+h]-yhat;
-    yhat = 0;
     xtdl = xtdl + psi;
     mu0 = (67108864*mu)/xtdl;
-    xtdl = 0;

     //update filter taps
     for(int j = 0; j<gg;j+=1){
-    pw[j] = pw[j] + (x[gg-j+h]*mu0*error[h])/131072;
+      pw[j] = pw[j] + (x[gg-j+h]*mu0*error[h])/131072;
     }//end for
   }//end for outer
 }// end NLMS_AEC


for loops are good

for loops are good

--- NTPclock/NTPclock.ino
+++ NTPclock/NTPclock.ino
@@ -35,21 +35,19 @@
   beginNTP();    //Start up NTP Client & time keeping

   lc1.shutdown(0,false);
-  lc1.setIntensity(0, 10);
+  lc1.setIntensity(0, 10);     // Needs moved out to seperate function.  Plus controls to raise / lower.
 }

 // Main program loop
 void loop() {
   String timeDisplay = NTP.getTimeStr();
-  char minDig1 = timeDisplay.charAt(3);
-  char minDig2 = timeDisplay.charAt(4);
-  char secDig1 = timeDisplay.charAt(6);
-  char secDig2 = timeDisplay.charAt(7);
-  lc1.setChar(0, 0, minDig1, false);
-  lc1.setChar(0, 1, minDig2, false);
-  lc1.setChar(0, 2, secDig1, false);
-  lc1.setChar(0, 3, secDig2, false);
-
+  timeDigits[0] = timeDisplay.charAt(3);
+  timeDigits[1] = timeDisplay.charAt(4);
+  timeDigits[2] = timeDisplay.charAt(6);
+  timeDigits[3] = timeDisplay.charAt(7);
+  for (i=0;i++;i<4;) {
+    lc1.setChar(0, i, timeDigits[i], false);
+  }
   lc1.setChar(0, 4, secDig2, false); //test for progress bar

   Serial.println(timeDisplay);
@@ -66,7 +64,7 @@
   delay(1000);         //   REMOVE DELAY FOR A COUNTER..............................PLEASE!!!!......../////////////////////////
 }

-// Inition connection to WiFi
+// Initial connection to WiFi
 void connectWifi() {
   Serial.print("Connecting to ");
   Serial.print(ssid);


Tidy printed output.

Tidy printed output.

--- examples/MLX90614_demo/MLX90614_demo.ino
+++ examples/MLX90614_demo/MLX90614_demo.ino
@@ -116,7 +116,7 @@
 void setup(void)
 {
   Serial.begin(9600);
-  Serial.println("MLX90614 demo: " __FILE__);
+  Serial.println("MLX90614_demo");

   pinMode(LED_BUILTIN, OUTPUT);


Update LTE_M8321.ino

Update LTE_M8321.ino

--- examples/Modules/LTE_M8321/LTE_M8321.ino
+++ examples/Modules/LTE_M8321/LTE_M8321.ino
@@ -306,7 +306,6 @@
     M5.Power.begin();
     Serial.begin(115200);
     Serial2.begin(115200, SERIAL_8N1, 16, 17);
-    Serial.printf(" STC\n");

     Disbuff.createSprite(320, 100);
     Disbuff.fillRect(0, 0, 320, 100, BLACK);
@@ -547,4 +546,4 @@
 	*/

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


Removed unnecessary printout.

Removed unnecessary printout.

--- examples/TWI/CosaAT24CXX/CosaAT24CXX.ino
+++ examples/TWI/CosaAT24CXX/CosaAT24CXX.ino
@@ -76,18 +76,12 @@
   Watchdog::begin();

   // Check memory map
-  TRACE(&ledPin);
-  TRACE(sizeof(ledPin));
   TRACE(&at24c32);
   TRACE(sizeof(at24c32));
   TRACE(&eeprom);
   TRACE(sizeof(eeprom));
-  TRACE(&uart);
-  TRACE(sizeof(uart));
   TRACE(&twi);
   TRACE(sizeof(twi));
-  TRACE(&trace);
-  TRACE(sizeof(trace));
   TRACE(&x);
   TRACE(&y);
   TRACE(&z);


TFTKanjiDemoにフォントデモ追加: jiskan24,kappa20,ayu18,naga10

--- examples/TFTKanjiDemo/TFTKanjiDemo.ino
+++ examples/TFTKanjiDemo/TFTKanjiDemo.ino
@@ -11,11 +11,18 @@
   const char* message;
 } fonts[] = {
   // XXX: messageはShift_JISエンコード
-  // ILゴシックB
+  // ILゴシック
   // http://ayati.cocolog-nifty.com/blog/2012/08/ipalx322416-64a.html
-  {"ILGZ32XF.FNT", "ILGH32XF.FNT", "IL\x83\x53\x83\x56\x83\x62\x83\x4e\x42(32x32)"},
-  // IL明朝
-  {"ILMZ24XB.FNT", "ILMH24XB.FNT", "IL\x96\xbe\x92\xa9(24x24)"},
+  {"ILGZ32XB.FNT", "ILGH32XB.FNT", "IL\x83\x53\x83\x56\x83\x62\x83\x4e(32x32)"},
+  // jiskan24
+  // http://openlab.ring.gr.jp/efont/japanese/
+  {"jiskan24.fnt", "12x24rk.fnt", "jiskan24(24x24)"},
+  // Kappa 20dot Font
+  // http://www.vector.co.jp/soft/data/writing/se083507.html
+  {"k20m.fnt", "10x20rkm.fnt", "Kappa20(20x20)"},
+  // Ayu 18ドットゴシック
+  // http://x-tt.osdn.jp/ayu.html
+  {"k18gm.fnt", "9x18gm.fnt", "Ayu 18\x83\x68\x83\x62\x83\x67\x83\x53\x83\x56\x83\x62\x83\x4e(18x18)"},
   // ぱう
   // http://udumaki.s36.xrea.com/
   {"PAW16K.FNT", "PAW16A.FNT", "\x82\xcf\x82\xa4(16x16)"},
@@ -34,6 +41,9 @@
   {"k12x10.fnt", "k6x10.fnt", "k12x10(12x10)"},
   // http://www.vector.co.jp/soft/data/writing/se026704.html
   {"GENZN08X.FNT", "GENHN08X.FNT", "genfont(16x8)"},
+  // ナガ10
+  // http://hp.vector.co.jp/authors/VA013391/fonts/
+  {"knj10.fnt", "5x10rk.fnt", "\x83\x69\x83\x4b\x31\x30(10x10)"},
   // 美咲
   // http://www.geocities.jp/littlimi/misaki.htm
   {"MISAKI.FNT", "4X8.FNT", "\x94\xfc\x8d\xe7(8x8)"},
@@ -63,7 +73,7 @@

 SWTFT tft;

-class Screen: public IScreen {
+class Screen: public ITKScreen {
   public:
     virtual void drawPixel(int16_t x, int16_t y, uint16_t color) {
       tft.drawPixel(x, y, color);
@@ -106,8 +116,8 @@
   if (ret != 0) {
     Serial.println("init_sd failed. halt");
     tft.fillScreen(RED);
-    tft.setTextColor(BLACK);
-    tft.println("init_sd failed. halt");
+    //tft.setTextColor(BLACK);
+    //tft.println("init_sd failed. halt");
     while (true) {
     }
   }


Updated URL

Updated URL

--- arduino-canbus-monitor.ino
+++ arduino-canbus-monitor.ino
@@ -5,7 +5,7 @@
 * Made for Arduino with Seeduino/ElecFreaks CAN BUS Shield based on MCP2515
 *
 * Copyright (C) 2015 Anton Viktorov <latonita@yandex.ru>
-*                                    https://github.com/latonita/can-ascii
+*                                    https://github.com/latonita/arduino-canbus-monitor
 *
 * This library is free software. You may use/redistribute it under The MIT License terms.
 *


Handle millis() rollover

Handle millis() rollover

See http://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover

--- arduino/blinkytape_orb.ino
+++ arduino/blinkytape_orb.ino
@@ -176,7 +176,7 @@
     }
   }

-  if (millis() > lastCommand + IDLE_TIMEOUT) {
+  if (millis() - lastCommand > IDLE_TIMEOUT) {
     FastLED.setBrightness(brightnesses[BRIGHTNESS_IDLE]);
   } else {
     // wake up from idle on any change, even invalid commands


Cut out the software-serial based LCD :-(

It causes crashes. I've ordered an I2C / serial based backpack so we can still have a display. This will free up the AVR for sensors, motors, startup/shutdown, and other critical low-power functions.

--- arduino/Main/Main.ino
+++ arduino/Main/Main.ino
@@ -1,23 +1,13 @@
 #include <Wire.h>
 #include <RingBufCPP.h>
-#include "LCD.h"
 #include "Motor.h"

 #define I2C_ADDRESS 0x1A
 #define I2C_BUFFER_SIZE 32
 #define MAX_NUM_ELEMENTS 30
-#define LCD_TX_PIN 10
-#define LCD_ROWS 4
-#define LCD_COLUMNS 20
-#define LCD_ADDRESS 0x00
-#define LCD_COMMAND_WRITE 0x00
-#define LCD_COMMAND_SET_CURSOR 0x01
-#define LCD_COMMAND_SET_BRIGHTNESS 0x02
-#define LCD_COMMAND_CLEAR 0x03
 #define MOTOR1_ADDRESS 0x01
 #define MOTOR2_ADDRESS 0x02

-LCD lcd = LCD(LCD_TX_PIN, LCD_ROWS, LCD_COLUMNS);
 char i2c_buffer[I2C_BUFFER_SIZE];

 struct Event
@@ -30,7 +20,6 @@
 // Remember to use Arduino pins, not physical ones
 Motor motor1 = Motor(2, 3);
 Motor motor2 = Motor(4, 5);
-volatile byte sensor_left, sensor_front, sensor_right;
 RingBufCPP<struct Event, MAX_NUM_ELEMENTS> buf;

 void setup()
@@ -40,19 +29,8 @@
   Wire.begin(I2C_ADDRESS);
   Wire.onReceive(receiveEvent);
   Wire.onRequest(requestEvent);
-  lcd.begin();
-  lcd.clear_screen();
-  lcd.set_brightness(0x77);
-  lcd.set_cursor(0, 5);
-  lcd.print("Pathfinder");
 }

-// Display Reference
-// 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19
-//                   P  a  t  h  f  i  n  d  e  r
-// M  1  :     F  0  5  5     M  2  :     R  0  5  5
-//
-// L  :  0  5  5     F  :  0  5  5     R  :  0  5  5
 void loop()
 {
   struct Event e;
@@ -69,20 +47,15 @@
       break;
     }
   }
-  lcd.set_cursor(1, 0);
-  lcd.print("M1: %s", motor1.status());
-  lcd.set_cursor(1, 9);
-  lcd.print("M2: %s", motor2.status());
-  lcd.set_cursor(3, 0);
-  lcd.print("L:%03d F:%03d R:%03d", sensor_left, sensor_front, sensor_right);
+
   delay(2000);
 }

 void requestEvent()
 {
-  sensor_left = analogRead(A0);
-  sensor_front = analogRead(A1);
-  sensor_right = analogRead(A2);
+  byte sensor_left = analogRead(A0);
+  byte sensor_front = analogRead(A1);
+  byte sensor_right = analogRead(A2);
   Wire.write(sensor_left);
   Wire.write(sensor_front);
   Wire.write(sensor_right);


ADC calibration

ADC calibration

--- hal100/hal100.ino
+++ hal100/hal100.ino
@@ -100,8 +100,8 @@
 		Serial.print("Value rfl=");
 		Serial.println(payload->status.adc.rfl);

-		float rfl = payload->status.adc.rfl;
-		float fwd = payload->status.adc.fwd;
+		float rfl = payload->status.adc.rfl - 12.0;
+		float fwd = payload->status.adc.fwd - 12.0;
 		float p = sqrt(rfl / fwd);
 		valueSWR = (1 + p) / (1 - p);
 		Serial.print("Value SWR=");


IrSensor updated to read messages from a timer.

--- examples/merg_ir_sensor/merg_ir_sensor.ino
+++ examples/merg_ir_sensor/merg_ir_sensor.ino
@@ -2,8 +2,8 @@
 This example implements a ir sensor controller to detect block occupancy.
 It drives 16 ir. Can be more in arduino Mega, but it just an example.
 The module produces ON/OFF events.
-The events can be toogled by the first 2 node variables. 0 means ON when train enters, OFF when trains leaves.
-1 means the oposit. Each bit of the 2 bytes are to set toggle or not.
+The vents can be toogled by the first 2 node variables. 0 means ON when train enters, OFF when trains leaves.
+1 means the oposit. Each bit of the 2 bytes are to ser togle or not.
 Usim FLIM mode teach on/off events.
 It implements all automatic configuration, including learning events.
 It does not handle DCC messages, but you can do it on your user function.
@@ -18,10 +18,10 @@

 #include <Arduino.h>
 #include <SPI.h> //required by the library
+#include <TimerOne.h>
 #include <MergCBUS.h>
 #include <Message.h>
 #include <EEPROM.h> //required by the library
-#include <VarSpeedServo.h>

 //Module definitions
@@ -58,6 +58,11 @@
 //create the merg object
 MergCBUS cbus=MergCBUS(NODE_VARS,NODE_EVENTS,EVENTS_VARS,DEVICE_NUMBERS);

+//timer function to read the can messages
+void readCanMessages(){
+  //read the can message and put then in a circular buffer
+  cbus.cbusRead();
+}

 void setup(){

@@ -74,8 +79,6 @@
   cbus.getNodeId()->setConsumerNode(false);
   cbus.setStdNN(999); //standard node number

-  //setup new memory can push_button1 is pressed while starting
-  //basically resets the node
   if (digitalRead(PUSH_BUTTON1)==LOW){
     Serial.println("Setup new memory");
     cbus.setUpNewMemory();
@@ -87,15 +90,18 @@
   cbus.setDebug(true);//print some messages on the serial port
   cbus.setUserHandlerFunction(&myUserFunc);//function that implements the node logic
   cbus.initCanBus(53,CAN_125KBPS,10,200);  //initiate the transport layer. pin=53, rate=125Kbps,10 tries,200 millis between each try
-  //create the sensors object
+  cbus.setTimerInterval(10000);
+  //create the servos object
   setupSensors();
-
+  //using timer
+  Timer1.initialize(10000);//microseconds
+  Timer1.attachInterrupt(readCanMessages);
   Serial.println("Setup finished");
 }

 void loop (){

-  cbus.run();//do all cbus logic
+  cbus.run();//do all logic

   if (cbus.getNodeState()==NORMAL){
     checkSensors();
@@ -111,7 +117,7 @@
 void myUserFunc(Message *msg,MergCBUS *mcbus){

 }
-//we sample the sensor answers,average them and take decision if on or off upon configuration
+
 void checkSensors(){
   int state;
   int i;
@@ -178,7 +184,6 @@
    }
 }
 //check if we have to togle the event
-//based on the node variables
 bool togleSensor(int sensor){
   byte first,second;
   bool resp=false;


[FW] Re-introduce write delay

[FW] Re-introduce write delay

Otherwise game #9 (Intelligenz I / Labyrinth) does not load correctly.

--- firmware/MultiRomVC4000/MultiRomVC4000.ino
+++ firmware/MultiRomVC4000/MultiRomVC4000.ino
@@ -141,6 +141,7 @@
   digitalWrite(WESRAM, HIGH);
   shiftout(address, data);
   digitalWrite(WESRAM, LOW);
+  delay(1);
   digitalWrite(WESRAM, HIGH);
 }


A second attempt at fill_empty function. Also have a couple starry night functions going, need to test if they look any good though

--- proj/ledvo_lounge_v0/ledvo_lounge_v0.ino
+++ proj/ledvo_lounge_v0/ledvo_lounge_v0.ino
@@ -35,7 +35,7 @@
 const uint8_t frameRate = 100; // FPS
 const uint8_t maxBrightness = 200;
 uint8_t gBrightness = maxBrightness; // CHANGE THIS ONCE YOU HAVE ANOTHER POTENTIOMETER
-const uint8_t numLED = 60;
+const uint16_t numLED = 60;
 CRGB *leds = new CRGB[numLED];

 // Variables for pin interrupts (there's a lot of these babies)
@@ -133,7 +133,7 @@
   // Interrupt for strobing black over current animation.
   //pinMode(BLKSTROBE_INT, INPUT);
   //attachInterrupt(digitalPinToInterrupt(BLKSTROBE_INT), debounce_blk_strobe, RISING);
-
+
   // Interrupt for reversing animation direction. Look for change since this will
   // be a latching button
   //pinMode(REVERS_INT, INPUT);
@@ -143,7 +143,7 @@
 void loop() {
   // Read in global brightness value
   //gBrightness = map(analogRead(VAL_POT), 0, 1253, 0, maxBrightness);
-
+
   // Read color from potentiometer input
   gRGB = CHSV(map(analogRead(HUE_POT), 0, 1253, 0, 255), 255, gBrightness);

@@ -155,18 +155,18 @@
   // Check the palette counter and switch acordingly or go into autopilot mode
   if (palette_autopilot) {
     EVERY_N_SECONDS(30) {
-      gPaletteCounter = (gPaletteCounter+1)%numPalettes;
+      gPaletteCounter = (gPaletteCounter + 1) % numPalettes;
     }
     updateGPalette();
   }
   else {
     //updateGPalette();
   }
-
+
   // Check if we want to autopilot the animations
   if (anim_autopilot) {
     EVERY_N_SECONDS(30) {
-      gAnimCounter = (gAnimCounter+1)%numAnimation;
+      gAnimCounter = (gAnimCounter + 1) % numAnimation;
     }
   }

@@ -178,7 +178,7 @@

   // Select animation to run based on global counter
   /*if (!dj_control) {
-    switch( gAnimCounter ) {
+    switch( gAnimCounter ) {
       case 0:
         theater_chase();
         break;
@@ -210,7 +210,7 @@
         fill_to_empty();
         break;
     }
-  }*/
+    }*/

   //fill_to_empty();

@@ -241,10 +241,10 @@

 // Can't be named strobe for some reason... IDK man
 void strobes() {
-//  EVERY_N_MILLISECONDS_I(thisTimer, 200) {
-//    thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 100, 300));
-//    fill_solid(leds, numLED, CRGB::White);
-//  }
+  //  EVERY_N_MILLISECONDS_I(thisTimer, 200) {
+  //    thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 100, 300));
+  //    fill_solid(leds, numLED, CRGB::White);
+  //  }

   EVERY_N_MILLISECONDS(200) {
     fill_solid(leds, numLED, CRGB::White);
@@ -258,9 +258,9 @@
 // Strobes black over animations, or at least a crude attempt to do so
 void strobe_black() {
   EVERY_N_MILLISECONDS_I(thisTimer, 175) {
-      fill_solid(leds, numLED, CRGB::Black);
-      FastLED.show();
-      FastLED.delay(50);
+    fill_solid(leds, numLED, CRGB::Black);
+    FastLED.show();
+    FastLED.delay(50);
   }
 }

@@ -284,14 +284,14 @@
 // work our way through the global template
 void fill_smooth() {
   static uint8_t brightness = 0;
-  static uint8_t pal_index = 0;
+  static uint8_t pal_index = 0;

   // Some variables to help us smoothly transition between rates and
   // keep track of where we are on the sinwave
   static uint8_t bpm = map(analogRead(RATE_POT), 0, 1253, 120, 10);
   static uint8_t prev_brightness = 0;
   static uint8_t last_second = 99;
-  uint8_t second = (millis()/1000)%60;
+  uint8_t second = (millis() / 1000) % 60;

   // Modulate brigthness at input dependent rate
   prev_brightness = brightness;
@@ -316,15 +316,15 @@
 // A single equalizer type bar
 void palette_eq() {
   static uint8_t pal_index = 0;
-  static uint8_t lead_max = numLED / 2;
-  static uint8_t lead = 0;
+  static uint16_t lead_max = numLED / 2;
+  static uint16_t lead = 0;

   // Some variables to help us smoothly transition between rates and
   // keep track of where we are on the sinwave
   static uint8_t bpm = map(analogRead(RATE_POT), 0, 1253, 120, 10);
   static uint8_t prev = 0;
   static uint8_t last_second = 99;
-  uint8_t second = (millis()/1000)%60;
+  uint8_t second = (millis() / 1000) % 60;

   // Fill bar at input dependent rate. First record the previous lead value
   // so that we can check which diretion we are heading on the sin wave later on
@@ -334,9 +334,9 @@
   // If the eq bar is about to be empty, generate a new max length to fill.
   // Also increment the index of the palette, for a little more modulation cuz
   // why not.
-  if (lead == 0 && (lead - prev) < 0) {
-    pal_index+=16;
-    lead_max = random8(numLED / 3, numLED);
+  if (lead == 0 && (lead - prev) < 0) {
+    pal_index += 16;
+    lead_max = random8(numLED / 3, numLED);
   }

   // Check for rate change here so we don't interrupt the color and length
@@ -375,13 +375,13 @@

 // A theater chase where packets switch directions every once in a while
 void theater_chase_bounce() {
-  static uint8_t pal_index = 0;
+  static uint8_t pal_index = 0;
   static uint8_t bpm = map(analogRead(RATE_POT), 0 , 1253, 60, 20);

   // Some variables to help us smoothly transition between rates
   static uint8_t last_index = 0;
   static uint8_t last_second = 99;
-  uint8_t second = (millis()/1000)%60;
+  uint8_t second = (millis() / 1000) % 60;

   // Update lead LED position at an input dependent rate
   last_index = pal_index;
@@ -391,7 +391,7 @@
     last_second = second;
     bpm = map(analogRead(RATE_POT), 0 , 1253, 60, 20);
   }
-
+
   fill_palette(leds, numLED, pal_index, 4, gPalette, maxBrightness, gBlending);
   FastLED.show();
 }
@@ -454,7 +454,7 @@

   fill_solid(leds, numLED, ColorFromPalette(gPalette, pal_index, brightness, gBlending));
   FastLED.show();
-
+
 }

 // Jump to a fully illuminated strand, then ramp down. Also like a saw wave, but
@@ -490,15 +490,15 @@
   // so that we can check which diretion we are heading on the sin wave later on
   EVERY_N_MILLISECONDS_I(thisTimer, 50) {
     thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 10, 200));
-    lead = (lead+1)%(2*lead_max);
+    lead = (lead + 1) % (2 * lead_max);
   }

   // If the eq bar is about to be empty, generate a new max length to fill.
   // Also increment the index of the palette, for a little more modulation cuz
   // why not.
-  if (lead == 0) {
+  if (lead == 0) {
     pal_index += 16;
-    lead_max = random8(numLED / 3, numLED);
+    lead_max = random8(numLED / 3, numLED);
   }

   // Fill the the bar until we get to lead_max, then work our way back down. This doesn't use
@@ -508,7 +508,7 @@
     fill_solid(leds, lead, ColorFromPalette(gPalette, pal_index, gBrightness, gBlending));
   }
   else {
-    fill_solid(leds, 2*lead_max - lead, ColorFromPalette(gPalette, pal_index, gBrightness, gBlending));
+    fill_solid(leds, 2 * lead_max - lead, ColorFromPalette(gPalette, pal_index, gBrightness, gBlending));
   }
   FastLED.show();
   // Need this so that the decreasing direction animates properly
@@ -526,12 +526,24 @@

   EVERY_N_MILLISECONDS_I(thisTimer, 50) {
     thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 10, 200));
-    lead = (lead+1)%numLED;
-  }
+    lead = (lead + 1) % numLED;
+  }
+
+
+
+  if (fill) {
+    //fill_solid(leds, lead, ColorFromPalette(gPalette, pal_index, gBrightness, gBlending));
+    fill_solid(leds, lead, CRGB::Red);
+  }
+  else {
+    fill_solid(leds, lead, CRGB::Black);
+  }
+  FastLED.show();

   // Switch fill flag if we are done filling. If we are done emptying, switch
-  // the flag and also grab the next color in the palette.
-  if(lead == 0) {
+  // the flag and also grab the next color in the palette. Try this in here
+  // to see if it fixes the issue of missing the switch at 0
+  if (lead == numLED - 1) {
     if (fill) {
       fill = false;
     }
@@ -540,15 +552,6 @@
       pal_index += 16;
     }
   }
-
-  if (fill) {
-    //fill_solid(leds, lead, ColorFromPalette(gPalette, pal_index, gBrightness, gBlending));
-    fill_solid(leds, lead, CRGB::Red);
-  }
-  else {
-    fill_solid(leds, lead, CRGB::Black);
-  }
-  FastLED.show();
 }

@@ -559,22 +562,63 @@
   static uint16_t led = random16(numLED);

   // Now ramp up and down the pixel at an input dependent rate
-  static uint8_t brightness = 0;
+  static uint8_t brightness_counter = 0;
   EVERY_N_MILLISECONDS_I(thisTimer, 100) {
     thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 10, 100));
-    brightness++;
-  }
-
-  // IDK if this will work like I want it to.
-  //leds[led].h = CRGB::White;
-  //leds[led].v = triwave8(brightness);
+    brightness_counter += 4; // Make this ramp up a little bit faster
+  }
+
+  // Ramp all the channels up at the same rate achieve a single
+  // pixel white glowing effect
+  uint8_t brightness = triwave8(brightness_counter);
+  leds[led] = CRGB(brightness, brightness, brightness);
   FastLED.show();

   // If we are back to zero brightness, grab a new led to do this with
-  if (brightness == 0) {
+  if (brightness_counter == 0) {
     led = random16(numLED);
   }
-
+
+}
+
+void starry_night_vector() {
+  // Vector to store the randomly chosen leds
+  static std::vector<uint16_t> stars;
+
+  // If the vector is empty, we are either running for the first time
+  // or we are on the next cycle. Either way we want to set it up
+  if (stars.size() == 0) {
+    uint8_t rnd;
+    for (uint16_t ll = 0; ll < numLED; ll++) {
+      rnd = random8();
+      // Only set ~1/3 of the leds as a star
+      if (rnd < (255 / 3)) {
+        stars.push_back(ll);
+      }
+    }
+  }
+
+  // Increase brightness at an input controlled rate
+  static uint8_t brightness_counter = 0;
+  EVERY_N_MILLISECONDS_I(thisTimer, 100) {
+    thisTimer.setPeriod(map(analogRead(RATE_POT), 0, 1253, 10, 150));
+    brightness_counter += 4;
+  }
+
+  // Now loop over stars and ramp their brightness up and down
+  uint8_t brightness = triwave8(brightness_counter);
+  for (uint16_t ll = 0; ll < stars.size(); ll++ ) {
+    leds[stars[ll]] = CRGB(brightness, brightness, brightness);
+  }
+
+  FastLED.show();
+
+  // Check if we are at the valley of our triwave, and clear the
+  // vector for the next set of stars if we are.
+  if (brightness_counter == 0) {
+    stars.clear();
+  }
+
 }

@@ -582,16 +626,16 @@
 void theater_chase_random() {
   // Vector to hold the widths, since they're randomly
   // determined, we need a vector to deal with varying sizes
-  static std::vector<uint8_t> packet_widths;
+  static std::vector<uint8_t> packet_widths;
   static std::vector<CRGB> packet_colors;
-
+
   // Fill the vector the first time it's run. Use a static variable
   // so we only have to run it once
   static boolean first_run = false;
   if (first_run) {
     uint8_t rnd_width;
     uint8_t num_filled = 0; // Keep track of how many LEDs we've filled
-    uint8_t pal_index=0;
+    uint8_t pal_index = 0;
     while (num_filled < numLED) {
       // Generate new packet length
       rnd_width = random8(2, 5);
@@ -605,9 +649,9 @@

     // Now loop through the vectors and fill the strand
     for (uint8_t vec_index = 0; vec_index < packet_widths.size(); vec_index++) {
-
-    }
-
-  }
-
-}
+
+    }
+
+  }
+
+}


Update mqtt_stream example to do the stream writing in the callback

--- examples/mqtt_stream/mqtt_stream.ino
+++ examples/mqtt_stream/mqtt_stream.ino
@@ -25,13 +25,12 @@
   sram.seek(1);

   // do something with the message
-  for(uint8_t i=0; i<length; i++) {
-    Serial.write(sram.read());
+  for (uint8_t i = 0; i < pub.payload_len(); i++) {
+    sram.write(pub.payload()[i]);
+    Serial.write(pub.payload()[i]);
   }
+
   Serial.println();
-
-  // Reset position for the next message to be stored
-  sram.seek(1);
 }

 PubSubClient client(server);
@@ -44,9 +43,7 @@
   Serial.println();
   Serial.println();

-  client
-    .set_callback(callback)
-    .set_stream(sram);
+  client.set_callback(callback);

   WiFi.begin(ssid, pass);


Testing LED blink when card not detected during job 2

--- module/module.ino
+++ module/module.ino
@@ -253,9 +253,13 @@
 			//delay(pollInterval);
 			lastPollTime = millis();
 		}
-
+
+		unsigned long lastBlink = 0;
 		if (pollCounter > 0) {
-			digitalWrite(ledPin, (digitalRead(ledPin) == HIGH ? LOW : HIGH));
+			if ( (millis() - lastBlink) > 500 ) {
+				digitalWrite(ledPin, (digitalRead(ledPin) == HIGH ? LOW : HIGH));
+				lastBlink = millis();
+			}
 		}
 	}
 }


add comments

add comments

--- engine-room/engine_arduino/engine_arduino.ino
+++ engine-room/engine_arduino/engine_arduino.ino
@@ -1,6 +1,9 @@
 #include <PololuLedStrip.h>

+// instantiate light strip on pin 2
 PololuLedStrip<2> leds;
+
+// list of all led colors in order
 rgb_color colors[4];

 void setup()
@@ -14,6 +17,7 @@
 {
   delay(20);

+  // digitalRead of a pin is high if switch on, else low
   if (digitalRead(53))
   {
     colors[0] = getRed();
@@ -29,7 +33,7 @@

   leds.write(colors, 4);

-  Serial.println('red'); // m is char*
+  Serial.println(10);

   // Sketch of eventual code


Update example11_pir.ino

Update example11_pir.ino

--- 2_example/example11_pir/example11_pir.ino
+++ 2_example/example11_pir/example11_pir.ino
@@ -57,7 +57,7 @@
 }

 void sleep(){
-    digitalWrite(PIN_LED,LOW);              // LEDの消灯
+    digitalWrite(PIN_LED,LOW);              // LEDの消灯/ESP仕様変更に伴い修正
     ESP.deepSleep(SLEEP_P,WAKE_RF_DEFAULT); // スリープモードへ移行する
     while(1){                               // 繰り返し処理
         delay(100);                         // 100msの待ち時間処理


Created by Peter Clarke

Created by Peter Clarke

--- sketches/MagbotBudget/MagbotBudget.ino
+++ sketches/MagbotBudget/MagbotBudget.ino
@@ -1,4 +1,6 @@
 /**
+ Created by Peter Clarke
+
  HC-SR04 Ultrasonic Range Finder.
  Two motors attached to the L293D motor controller.
  speaker/piezo for sound


Updates for handling the new authentication service settings and some other enhancements

--- MakerspaceOSRFIDAuthentication/MakerspaceOSRFIDAuthentication.ino
+++ MakerspaceOSRFIDAuthentication/MakerspaceOSRFIDAuthentication.ino
@@ -59,7 +59,7 @@
 MFRC522 mfrc522(RFID_SS_pin, RFID_RST_pin);

 //Settings-- Adjust as needed.
-
+const String EQUIPMENTID = "1212";
 #define USELED
 //#define USEPINPAD  //Comment out if a pinpad is not being used
 #define USELCD   // Comment out if not using LCD
@@ -203,7 +203,7 @@
 {
       int gotCard = 0;
       String serial;
-      String pin;
+      String pin ="";
       // Disable ethernet
       digitalWrite(ETH_SS_pin, HIGH);
       // Enable RFID
@@ -243,6 +243,8 @@
                 }
               }
             }
+          #else
+            pin = "~";
           #endif
           #ifdef DEBUG
             Serial.println("Card Read...");
@@ -263,8 +265,11 @@
            lcdSerial.write("Starting Card Validation..");
          #endif

+         #ifdef DEBUG
+           Serial.println("/MakerSpaceOS.Services/EquipmentAccessControl.svc/CheckEquipmentAccess/" + EQUIPMENTID +"/" + serial + "/" + pin);
+         #endif
          client.connect(server, 80);
-         client.println("GET /MakerSpaceOS.Services/Access.svc/CheckAccess/" + serial + "/" + pin);
+         client.println("GET /MakerSpaceOS.Services/EquipmentAccessControl.svc/CheckEquipmentAccess/" + EQUIPMENTID +"/" + serial + "/" + pin);
          client.println("Host: localhost");
          client.println("Connection: close");
          client.println();
@@ -311,6 +316,8 @@
          const char* accessAllowed = root["AccessAllowed"] ;
          const char* username  =root["UserName"];
          const char* message  =root["Message"];
+         const int timelimit = root["TimeLimit"];
+
          #ifdef DEBUG
            Serial.println(accessAllowed );
            Serial.println( username );
@@ -338,7 +345,19 @@
                  delay(1000);
                  ClearScreen();
                #endif
-               digitalWrite(RELAY1,HIGH);
+
+
+               digitalWrite(RELAY1,HIGH);
+
+               if(timelimit != 0)
+               {
+                 #ifdef DEBUG
+                   Serial.println(timelimit);
+                 #endif
+                 //Need to add a countdown timer here so that time counts down the time remaining and outputs to the LCD
+                 delay(timelimit * 60000);
+                 digitalWrite(RELAY1,LOW); //Turn off time limit expires.  Need to add the current check and other logic here.  Very basic rightnow.  Delay is not
+               }

            }
            else{
@@ -351,6 +370,7 @@
                #ifdef USELCD
                   ClearScreen();
                   lcdSerial.write("Access Denied");
+                  lcdSerial.write(message);
                #endif
            }
         delay(2000);


reversed analogue inputs and added status LED

--- sounddetector/sounddetector.ino
+++ sounddetector/sounddetector.ino
@@ -17,8 +17,10 @@
 const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
 unsigned int sample;

+const int statusLedPin = 13; // will light up when the channel settings are received
+
 const int ledPins[] = {2, 3, 4, 5, 6, 7};
-const int soundPins[] = {A0, A1, A2, A3, A4, A5};
+const int soundPins[] = {A5, A4, A3, A2, A1, A0}; // soldered them the wrong way, so they're reversed here

 const int pinCount = 6;
 int soundValues[] = {0, 0, 0, 0, 0, 0};
@@ -54,6 +56,10 @@
 /* This function is called once at start up ----------------------------------*/
 void setup()
 {
+  pinMode(statusLedPin, OUTPUT);
+  digitalWrite(statusLedPin, 0);
+
+
   for (int pin = 0; pin < pinCount; ++pin) {
     // register every pin as input:
     pinMode(soundPins[pin], INPUT);
@@ -81,7 +87,7 @@
     // collecting data:

     for (int pin = 0; pin < pinCount; ++pin) {
-      sample = analogRead(pin);
+      sample = analogRead(soundPins[pin]);
       if (sample < 1024) { // toss out spurious readings
          if (sample > signalMax[pin]) {
             signalMax[pin] = sample;  // save just the max levels
@@ -259,6 +265,8 @@

           if(debug) Serial.print("incomming settings of pin ");
           if(debug) Serial.println(pin);
+
+          digitalWrite(statusLedPin, 1); // turn on after first settings are received

           for (int i = 0; i < 4; ++i) {
             uint8_t firstByte;


Corrected a few bugs.

Corrected a few bugs.

--- src/cyclop_plus/cyclop_plus.ino
+++ src/cyclop_plus/cyclop_plus.ino
@@ -213,35 +213,6 @@
   if (options[SHOW_STARTSCREEN_OPTION])
     drawStartScreen();

-  // Mark blocked channels in the softPositions array
-  for (i = 0; i < 48; i++)
-    softPositions[i] = positions[i];
-
-  if (!options[A_BAND_OPTION]) {
-    for (i = 0; i < 8; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-  if (!options[B_BAND_OPTION]) {
-    for (i = 8; i < 16; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-  if (!options[E_BAND_OPTION]) {
-    for (i = 16; i < 24; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-  if (!options[F_BAND_OPTION]) {
-    for (i = 24; i < 32; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-  if (!options[R_BAND_OPTION]) {
-    for (i = 32; i < 40; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-  if (!options[L_BAND_OPTION]) {
-    for (i = 40; i < 48; i++)
-      softPositions[getReversePosition( i )] = 255;
-  }
-
   // Wait at least the delay time before entering screen save mode
   saveScreenTimer = millis() + SAVE_SCREEN_DELAY_MS;
 }
@@ -344,26 +315,6 @@
 }

 //******************************************************************************
-//* function: resetOptions
-//*         : Resets all configuration settings to their default values
-//******************************************************************************
-void resetOptions(void) {
-  options[FLIP_SCREEN_OPTION]      = FLIP_SCREEN_DEFAULT;
-  options[BATTERY_ALARM_OPTION]    = BATTERY_ALARM_DEFAULT;
-  options[ALARM_LEVEL_OPTION]      = ALARM_LEVEL_DEFAULT;
-  options[BATTERY_TYPE_OPTION]     = BATTERY_TYPE_DEFAULT;
-  options[BATTERY_CALIB_OPTION]    = BATTERY_CALIB_DEFAULT;
-  options[SHOW_STARTSCREEN_OPTION] = SHOW_STARTSCREEN_DEFAULT;
-  options[SAVE_SCREEN_OPTION]      = SAVE_SCREEN_DEFAULT;
-  options[A_BAND_OPTION]           = A_BAND_DEFAULT;
-  options[B_BAND_OPTION]           = B_BAND_DEFAULT;
-  options[E_BAND_OPTION]           = E_BAND_DEFAULT;
-  options[F_BAND_OPTION]           = F_BAND_DEFAULT;
-  options[R_BAND_OPTION]           = R_BAND_DEFAULT;
-  options[L_BAND_OPTION]           = L_BAND_DEFAULT;
-}
-
-//******************************************************************************
 //* function: writeEeprom
 //*         : Writes all configuration settings to nonvolatile memory
 //******************************************************************************
@@ -519,7 +470,7 @@
   // Draw screen frame etc
   drawScannerScreen();

-  while ((clickType = getClickType(BUTTON_PIN)) == NO_CLICK) {
+  while (digitalRead(BUTTON_PIN) != BUTTON_PRESSED) {
     scanFrequency += SCANNING_STEP;
     if (scanFrequency > FREQUENCY_MAX)
       scanFrequency = FREQUENCY_MIN;
@@ -530,8 +481,8 @@
     updateScannerScreen(100 - ((FREQUENCY_MAX - scanFrequency) / SCANNING_STEP), rssiDisplayValue );
   }
   // Fine tuning
-  scanFrequency = scanFrequency - 20;
-  for (i = 0; i < 20; i++, scanFrequency += 2) {
+  scanFrequency = scanFrequency - SCANNING_STEP * 4;
+  for (i = 0; i < SCANNING_STEP * 4; i++, scanFrequency += 2) {
     receiver.setFrequency(scanFrequency);
     delay( RSSI_STABILITY_DELAY_MS );
     scanRssi = averageAnalogRead(RSSI_PIN);
@@ -576,9 +527,9 @@
     }
   }
   // Fine tuning
-  scanFrequency = bestFrequency - 20;
+  scanFrequency = bestFrequency - SCANNING_STEP * 4;
   bestRssi = 0;
-  for (i = 0; i < 20; i++, scanFrequency += 2) {
+  for (i = 0; i < SCANNING_STEP * 4; i++, scanFrequency += 2) {
     receiver.setFrequency(scanFrequency);
     delay( RSSI_STABILITY_DELAY_MS );
     scanRssi = averageAnalogRead(RSSI_PIN);
@@ -724,6 +675,69 @@
 }

 //******************************************************************************
+//* function: updateSoftPositions
+//******************************************************************************
+void updateSoftPositions( void ) {
+  unsigned char i;
+
+  // Mark blocked channels in the softPositions array
+  for (i = 0; i < 48; i++)
+    softPositions[i] = positions[i];
+
+  if (!options[A_BAND_OPTION]) {
+    for (i = 0; i < 8; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+  if (!options[B_BAND_OPTION]) {
+    for (i = 8; i < 16; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+  if (!options[E_BAND_OPTION]) {
+    for (i = 16; i < 24; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+  if (!options[F_BAND_OPTION]) {
+    for (i = 24; i < 32; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+  if (!options[R_BAND_OPTION]) {
+    for (i = 32; i < 40; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+  if (!options[L_BAND_OPTION]) {
+    for (i = 40; i < 48; i++)
+      softPositions[getReversePosition( i )] = 255;
+  }
+}
+
+//******************************************************************************
+//* function: resetOptions
+//*         : Resets all configuration settings to their default values
+//******************************************************************************
+
+//******************************************************************************
+//* function: resetOptions
+//*         : Resets all configuration settings to their default values
+//******************************************************************************
+void resetOptions(void) {
+  options[FLIP_SCREEN_OPTION]      = FLIP_SCREEN_DEFAULT;
+  options[BATTERY_ALARM_OPTION]    = BATTERY_ALARM_DEFAULT;
+  options[ALARM_LEVEL_OPTION]      = ALARM_LEVEL_DEFAULT;
+  options[BATTERY_TYPE_OPTION]     = BATTERY_TYPE_DEFAULT;
+  options[BATTERY_CALIB_OPTION]    = BATTERY_CALIB_DEFAULT;
+  options[SHOW_STARTSCREEN_OPTION] = SHOW_STARTSCREEN_DEFAULT;
+  options[SAVE_SCREEN_OPTION]      = SAVE_SCREEN_DEFAULT;
+  options[A_BAND_OPTION]           = A_BAND_DEFAULT;
+  options[B_BAND_OPTION]           = B_BAND_DEFAULT;
+  options[E_BAND_OPTION]           = E_BAND_DEFAULT;
+  options[F_BAND_OPTION]           = F_BAND_DEFAULT;
+  options[R_BAND_OPTION]           = R_BAND_DEFAULT;
+  options[L_BAND_OPTION]           = L_BAND_DEFAULT;
+
+  updateSoftPositions();
+}
+
+//******************************************************************************
 //* function: setOptions
 //******************************************************************************
 void setOptions()
@@ -817,6 +831,7 @@
           break;
       }
   }
+  updateSoftPositions();
 }

 //******************************************************************************
@@ -824,21 +839,16 @@
 //*         : Cycles through alarms, regardless of alarm settings
 //******************************************************************************
 void testAlarm( void ) {
-  uint8_t i;
-
-  for ( i = 0; i < 3; i++) {
-    analogWrite( ALARM_PIN, 32 ); delay(ALARM_MIN_ON);
-    analogWrite( ALARM_PIN, 0 );  delay(ALARM_MIN_OFF);
-  }
-  for (i = 0; i < 3; i++) {
-    analogWrite( ALARM_PIN, 32 ); delay(ALARM_MED_ON);
-    analogWrite( ALARM_PIN, 0 );  delay(ALARM_MED_OFF);
-  }
-  for (i = 0; i < 3; i++) {
-    analogWrite( ALARM_PIN, 32 ); delay(ALARM_MAX_ON);
-    analogWrite( ALARM_PIN, 0 );  delay(ALARM_MAX_OFF);
-  }
-  analogWrite( ALARM_PIN, 0 );
+  unsigned char i;
+
+  while (getClickType(BUTTON_PIN) == NO_CLICK) {
+    for (i = 0; i < 3; i++) {
+      analogWrite( ALARM_PIN, 1 << options[ALARM_LEVEL_OPTION] );
+      delay(ALARM_MAX_ON);
+      analogWrite( ALARM_PIN, 0 );
+      delay(ALARM_MAX_OFF);
+    }
+  }
 }

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


control-test: remove `volatile' keyword from static vars

This was causing problems, apparently.

--- tests/control-test/rgb-i2c/rgb-i2c.ino
+++ tests/control-test/rgb-i2c/rgb-i2c.ino
@@ -84,15 +84,11 @@
 #define HUE_INCREMENT (I_PI/32)

-/* Note that the next two values are marked "volatile" because they can be
-   changed from within an interrupt service routine.  `volatile` basically
-   forces the compiler to disable optimizations that make assumptions based on
-   what the variable was last set to within a given scope. */
 /** Value of `millis()` at which we last received an I2C transmission. */
-static volatile size_t last_receive;
+static size_t last_receive;

 /** Input values. */
-static volatile uint8_t inputs[3];
+static uint8_t inputs[3];

 /** Hue-angle counter for idle mode. */
 static uint16_t theta;


changed to dial tree

changed to dial tree

--- turing-old-rotary.ino
+++ turing-old-rotary.ino
@@ -5,6 +5,11 @@
 used in the Theater Ninjas play Turing Machine.

 Coded by Eric Faehnrich
+
+don't have 0 in file name, must be in root directory of sd card
+
+22khz 16 bit mono
+ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav
 */

 #include <WaveHC.h>
@@ -27,13 +32,13 @@
 FatReader f;      // This holds the information for the file we're play
 WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

-const int hangPin = 6; //pin for reciever switch. closed (HIGH) when hung up, open (LOW) when off the hook
-const int dialPin = 7; //pin for dialing switch. close (HIGH) when  dialing, open (LOW) when not dialing
-const int countPin = 8; //pin for counting switch.  closed (HIGH) for don't count, open (LOW) for each count
-const int ledPin = 13; //LED pin
+#define hangPin  6 //pin for reciever switch. closed (HIGH) when hung up, open (LOW) when off the hook
+#define dialPin 7 //pin for dialing switch. close (HIGH) when  dialing, open (LOW) when not dialing
+#define countPin 8 //pin for counting switch.  closed (HIGH) for don't count, open (LOW) for each count
+#define ledPin 13 //LED pin

 int dialCount = 0;
-#define DIAL_ARRAY_LEN 50
+#define DIAL_ARRAY_LEN 10
 int dialArray[DIAL_ARRAY_LEN];
 int dialIndex = 0;

@@ -52,8 +57,8 @@
 long lastHangDebounceTime = 0;  // the last time the reciever pin was toggled
 long lastDialDebounceTime = 0; // last time the dial switch was toggled
 long lastCountDebounceTime = 0;
-const long debounceDelay = 50;    // the debounce time; increase if the output flickers
-const long countDebounceDelay = 10;
+#define debounceDelay 50    // the debounce time; increase if the output flickers
+#define countDebounceDelay 10

 State phoneState = nodial;

@@ -81,6 +86,58 @@
   wave.play();
 }

+
+#define NUMMAX 10
+short nums[NUMMAX];
+short numindex = 0;//points to first empty space
+char FileName[NUMMAX+5];
+
+void addnum(char num) {
+  if(numindex < NUMMAX) {
+    nums[numindex++] = num;
+  }
+  #ifdef DEBUG
+  else {
+    Serial.println("numindex over max");
+  }
+  #endif//DEBUG
+}
+
+void removenum() {
+  if(numindex > 0) {
+    --numindex;
+  }
+  #ifdef DEBUG
+  else {
+    Serial.println("trying to remove from empty num list");
+  }
+  #endif//DEBUG
+}
+
+short fillnum() {
+  short fnindex;
+  {for(fnindex = 0; fnindex < numindex; ++fnindex) {
+    Serial.println(nums[fnindex]);
+    FileName[fnindex] = (char)(nums[fnindex] + '0');
+  }}
+
+  return fnindex;
+}
+
+void makeFileName() {
+  short fnindex = fillnum();
+
+  FileName[fnindex++] = '.';
+  FileName[fnindex++] = 'w';
+  FileName[fnindex++] = 'a';
+  FileName[fnindex++] = 'v';
+  FileName[fnindex++] = '\0';
+}
+
+void printFileName() {
+  makeFileName();
+  Serial.println(FileName);
+}

 void setup() {

@@ -167,6 +224,7 @@
         #endif
       }
       else {
+        numindex = 0;//empty
         #ifdef DEBUG
         putstring_nl("hang high");
         #endif
@@ -245,10 +303,69 @@
           }

           if(match) {
-            playfile("ESP.WAV");
-          }
-
-
+            //playfile("612.WAV");
+          }
+
+          wave.stop();//seems finding files could fail while playing a file
+                      //maybe checks for files existing fail because lock on playing file
+
+          //if not 10 (0)
+          if(dialCount < 10) {
+            //add number dialed to array
+            addnum(dialCount);
+
+            //convert nums array to string
+
+            printFileName();
+
+
+
+
+            //if there's a file with that name
+            #ifdef DEBUG
+            putstring_nl("before file check");
+            #endif
+            if (f.open(root, FileName)) {
+              //keeping that int in the array
+              //play that file
+              #ifdef DEBUG
+              Serial.println("Found file, playing");
+              #endif//DEBUG
+              playfile(FileName);
+            }
+            //if not
+            else {
+              #ifdef DEBUG
+              Serial.println("File not found");
+              #endif//DEBUG
+              //remove that number (move index)
+
+              --numindex;
+              makeFileName();
+              //play the current error message there again (or default error if not)
+              playfile("error.wav");
+              while(wave.isplaying);
+              //replay this levels message
+              playfile(FileName);
+            }
+          }
+          //else was 10(0) so move up one
+          else {
+            //TODO don't delete the last number
+            #ifdef DEBUG
+            Serial.println("numindex=");
+            Serial.println(numindex);
+            #endif//DEBUG
+
+            removenum();
+
+            #ifdef DEBUG
+            printFileName();
+            #endif//DEBUG
+
+            //play message
+            playfile(FileName);
+          }
         }
       }
     }