Revert "Changed motor levels to a constant array"

This reverts commit 3cc8a7699352e9d950c78ec26cba77a9075de9ff.

--- embedded/Crossfire_Program/Crossfire_Program.ino
+++ embedded/Crossfire_Program/Crossfire_Program.ino
@@ -1,352 +1,360 @@
-//ENGR 421 Team 4
-//2013
-
-//Written by Dean Reading
-
-
-
-/*******************************************************************************************/
-// Changelog
-/*******************************************************************************************
- * Version control can now be handled by GitHub...
- *
- * Version 0.2
- * Included a timeout when waiting for a character.
- * Added the sendMessage function to communicate with laptop.
- * Added in error messages for invalid command IDs, shooter numbers and angles.
- * Added in lower and upper limits to the angles that can be used.
- *
- *
- * Version 0.1
- * Includes command receiving and execution, with 'Aim' and 'Shoot' commands.
- * <angle> input is a byte that should range from 0 to 180, with 90 being pointing forward.
- * All DC motor pins are set up and PWM is created.
- * setShooterAngle, releaseBall and checkSolenoids functions are included.
- * 'GO' & 0x80 is sent to indicate game start.
- *
- *
- */
-
-/*
-▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- // Pre-Start
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- */
-
-
-// Pins
-/*******************************************************************************************/
-#define pinMotor1 5
-#define pinMotor2 2
-#define pinMotor3 3
-
-#define pinServo1 46
-#define pinServo2 45
-#define pinServo3 44
-
-#define pinSolenoid1 4
-#define pinSolenoid2 6
-#define pinSolenoid3 7
-
-
-// Parameters
-/*******************************************************************************************/
-#define DEBUG //Defining DEBUG turns ON debugging messages
-
-#define commsTimeout 200 //The maximum time that a received serial command can take, in mS
-
-#define ballReleaseTime 500 //The time that the solenoid needs to be activated for to release a ball, in mS
-
-#define angleLowest 30 //The minimum allowable angle
-#define angleHighest 150 //The maximum allowable angle
-
-// Libraries & Objects
-/*******************************************************************************************/
-#include <Servo.h>
-Servo servo1; //Declare 3 instances of servo objects
-Servo servo2;
-Servo servo3;
-
-//Function Prototypes
-void sendMessage (byte CMD,byte in1 = 255, byte in2 = 255, byte in3 = 255);
-
-// Constants
-/*******************************************************************************************/
-byte commandLength[255]; //The number of data bytes for each command type for serial comms
-const byte solenoidPins[] = {
-  0,pinSolenoid1,pinSolenoid2,pinSolenoid3}; //A map for the solenoid pins
-const byte motorPins[] = {
-  0,pinMotor1,pinMotor2,pinMotor3}; //A map for the solenoid pins
-const byte motorLevel[] = {
-  0,255,255,255}; //Individual PWM signal levels for each motor
-
-
-// Global Variables
-/*******************************************************************************************/
-byte commandID=0;
-byte bytesRemaining; //
-char buffer[5];
-unsigned long timer; //A multi-purpose timer
-
-unsigned long ballReleaseTimer[4]; //Saves when the last ball was released.
-boolean ballReleasing[] = {
-  0,0,0,0}; //Indicates whether we are in the process of releasing a ball
-
-/*
-▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- // Setup
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- */
-void setup(){
-  // Constants
-  /*******************************************************************************************/
-  commandLength[1]=2;
-  commandLength[2]=1;
-
-  commandLength[0x80]=0;
-  commandLength[0xE0]=1;
-  commandLength[0xE1]=1;
-  commandLength[0xE2]=2;
-
-  // Pin Modes and Setup
-  /*******************************************************************************************/
-  for (byte i=1;i<4;i++){
-    pinMode(motorPins[i],OUTPUT);
-    pinMode(solenoidPins[i],OUTPUT);
-
-    analogWrite(motorPins[i],motorLevel[i]);
-    digitalWrite(solenoidPins[i],LOW);
-  }
-
-
-
-  // Other Setup Code
-  /*******************************************************************************************/
-  Serial.begin(9600);
-  Serial.setTimeout(commsTimeout);
-#ifdef DEBUG
-  Serial.println("Arduino Start");
-#endif
-
-
-  //Attach the servo objects
-  servo1.attach(pinServo1,900,2100); //Include the maximum and minimum pulse widths.
-  servo2.attach(pinServo2,900,2100);
-  servo3.attach(pinServo3,900,2100);
-
-
-  //Wait until 'Game Start' button is pressed
-
-  //add here later
-  //Send 'Game Start' message to laptop
-  sendMessage(0x80);
-
-
-  //Set up the PWM DC motor control signals
-  analogWrite(pinMotor1,motorLevel1);
-  analogWrite(pinMotor2,motorLevel2);
-  analogWrite(pinMotor3,motorLevel3);
-
-
-  //Prototyping stuff DELETE ME!  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-  //analogWrite(pinMotor1,0);
-
-      releaseBall(1);
-
-  //  while (true) { //Cycle endlessly
-  //    setShooterAngle(1,90);
-  //    delay(1000);
-  //    setShooterAngle(1,45);
-  //    delay(1000);
-  //    setShooterAngle(1,135);
-  //    delay(1000);
-  //  }
-
-}
-
-
-/*
-▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- // Loop
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
- */
-void loop(){
-  checkSerial(); //Check for incoming commands, and execute them
-
-  checkSolenoids(); //Deactivates any solenoids when needed
-
-}
-
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*checkSerial
-/*******************************************************************************************/
-void checkSerial(){
-  if (Serial.available()) {
-    //Search for the initization sequence
-    if (Serial.read()=='G'){
-      timer=millis()+commsTimeout;
-      while (!Serial.available()){ //Wait until another character is available
-        if (millis()>timer) { //Exit the loop if we don't receive another character
-          break;
-        }
-      }
-      if (Serial.peek()=='O'){
-        Serial.read(); //Remove the 'O' from the serial buffer.
-        //Initialization Sequence detected!
-
-#ifdef DEBUG
-        Serial.println("'G O' found!");
-#endif
-
-        timer=millis()+commsTimeout;
-        while (!Serial.available()){ //Wait until another character is available
-          if (millis()>timer) { //Exit the loop if we don't receive another character
-            break;
-          }
-        }
-        commandID=Serial.read(); //This byte is the command ID
-
-        //Now, read the required number of data bytes into the array 'buffer'
-        Serial.readBytes(buffer,commandLength[commandID]);
-
-        //Execute the command
-        executeCommand();
-      }
-    }
-  }
-}
-
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*executeCommand
-/*******************************************************************************************/
-//This function executes whatever the necessary action is, as told by the command and data
-//received through serial comms
-void executeCommand(){
-  switch (commandID){
-  case 1:
-    //Aim shooter <db1> to angle defined by <db2>
-    setShooterAngle(buffer[0],(byte) buffer[1]);
-    break;
-  case 2:
-    //Release a ball on shooter <db1>
-    releaseBall(buffer[0]);
-    break;
-  default:
-#ifdef DEBUG
-    Serial.print("Unrecognized command ID: ");
-    Serial.println(commandID);
-#endif
-    //Send error feedback to laptop
-    sendMessage(0xE0,commandID);
-  }
-}
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*setShooterAngle
-/*******************************************************************************************/
-//This function changes the servo signal for shooter <shooterNum> to the angle defined by
-// <angle>.  <angle> is a byte that ranges from 180, which maps from 900 to 2100 mS.
-void setShooterAngle(byte shooterNum, byte angle){
-
-  //  unsigned int output =   (((unsigned int) angle-1)*137)/29+900; // 137/29 = 4.724 = 1200/254, the scaling factor to get to uS
-
-#ifdef DEBUG
-  Serial.print("Setting shooter ");
-  Serial.print(shooterNum);
-  Serial.print(" to ");
-  Serial.println(angle);
-#endif
-
-  //Set the servo output.  Use a switch statement to use the correct servo object.
-  if (angle<angleLowest || angle>angleHighest) {
-    //The angle is invalid! Don't move the shooter, and send feedback
-    sendMessage(0xE2,shooterNum,angle);
-  }
-  else{
-    switch (shooterNum) {
-    case 1:
-      servo1.write(angle);
-      break;
-    case 2:
-      servo2.write(angle);
-      break;
-    case 3:
-      servo1.write(angle);
-      break;
-    default:
-#ifdef DEBUG
-      Serial.print("Unrecognized shooter Num: ");
-      Serial.println(shooterNum);
-#endif
-      //Send error feedback to laptop
-      sendMessage(0xE1,shooterNum);
-    }
-  }
-}
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*releaseBall
-/*******************************************************************************************/
-//This function releases one BB (hopefully) from shooter <shooterNum>
-void releaseBall(byte shooterNum) {
-
-#ifdef DEBUG
-  Serial.print("Releasing ball from shooter: ");
-  Serial.println(shooterNum);
-#endif
-
-  digitalWrite(solenoidPins[shooterNum],HIGH); //Activate the solenoid: open the passage
-
-  ballReleaseTimer[shooterNum]=millis()+ballReleaseTime; //Set the timer for deactivating the solenoid
-  ballReleasing[shooterNum]=1; //Indicate that we are releasing a ball
-}
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*checkSolenoids
-/*******************************************************************************************/
-//Check whether there are any solenoids that need to be deactivated
-void checkSolenoids(){
-  for (byte i=1;i<4;i++){ //Check all 3 solenoids
-    if (ballReleasing[i]==1){ //If a ball is currently being released
-      if (millis()>ballReleaseTimer[i]){ //If enough time has passed
-        digitalWrite(solenoidPins[i],LOW); //Deactivate the solenoid: close the passage
-        ballReleasing[i]=0; //Indicate that the ball is no longer being released
-#ifdef DEBUG
-        Serial.print("Deactivating solenoid: ");
-        Serial.println(i);
-#endif
-      }
-    }
-  }
-}
-
-
-/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-/*sendMessage
-/*******************************************************************************************/
-//This function sends commands to the laptop.  It has optional inputs.
-void sendMessage (byte CMD,byte in1, byte in2, byte in3) {
-  Serial.print("GO");
-  if (commandLength[CMD]>0){
-    Serial.print(in1);
-    if (commandLength[CMD]>1){
-      Serial.print(in2);
-      if (commandLength[CMD]>2){
-        Serial.print(in3);
-      }
-    }
-  }
-  Serial.println(); //Print a new line character
-}
-
-
-
-
+//ENGR 421 Team 4
+//2013
+
+//Written by Dean Reading
+
+
+
+/*******************************************************************************************/
+// Changelog
+/*******************************************************************************************
+ * Version control can now be handled by GitHub...
+ *
+ * Version 0.2
+ * Included a timeout when waiting for a character.
+ * Added the sendMessage function to communicate with laptop.
+ * Added in error messages for invalid command IDs, shooter numbers and angles.
+ * Added in lower and upper limits to the angles that can be used.
+ *
+ *
+ * Version 0.1
+ * Includes command receiving and execution, with 'Aim' and 'Shoot' commands.
+ * <angle> input is a byte that should range from 0 to 180, with 90 being pointing forward.
+ * All DC motor pins are set up and PWM is created.
+ * setShooterAngle, releaseBall and checkSolenoids functions are included.
+ * 'GO' & 0x80 is sent to indicate game start.
+ *
+ *
+ */
+
+/*
+▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ // Pre-Start
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ */
+
+
+// Pins
+/*******************************************************************************************/
+#define pinMotor1 5
+#define pinMotor2 2
+#define pinMotor3 3
+
+#define pinServo1 46
+#define pinServo2 45
+#define pinServo3 44
+
+#define pinSolenoid1 4
+#define pinSolenoid2 6
+#define pinSolenoid3 7
+
+
+// Parameters
+/*******************************************************************************************/
+#define DEBUG //Defining DEBUG turns ON debugging messages
+
+#define commsTimeout 200 //The maximum time that a received serial command can take, in mS
+
+#define ballReleaseTime 100 //The time that the solenoid needs to be activated for to release a ball, in mS
+
+#define motorLevel1 255
+#define motorLevel2 255
+#define motorLevel3 255
+
+#define angleLowest 30 //The minimum allowable angle
+#define angleHighest 150 //The maximum allowable angle
+
+// Libraries & Objects
+/*******************************************************************************************/
+#include <Servo.h>
+Servo servo1; //Declare 3 instances of servo objects
+Servo servo2;
+Servo servo3;
+
+//Function Prototypes
+void sendMessage (byte CMD,byte in1 = 255, byte in2 = 255, byte in3 = 255);
+
+// Constants
+/*******************************************************************************************/
+byte commandLength[255]; //The number of data bytes for each command type for serial comms
+const byte solenoidPins[] = {
+  0,pinSolenoid1,pinSolenoid2,pinSolenoid3}; //A map for the solenoid pins
+const byte motorPins[] = {
+  0,pinMotor1,pinMotor2,pinMotor3}; //A map for the solenoid pins
+
+
+
+// Global Variables
+/*******************************************************************************************/
+byte commandID=0;
+byte bytesRemaining; //
+char buffer[5];
+unsigned long timer; //A multi-purpose timer
+
+unsigned long ballReleaseTimer[4]; //Saves when the last ball was released.
+boolean ballReleasing[] = {
+  0,0,0,0}; //Indicates whether we are in the process of releasing a ball
+
+/*
+▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ // Setup
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ */
+void setup(){
+  // Constants
+  /*******************************************************************************************/
+  commandLength[1]=2;
+  commandLength[2]=1;
+
+  commandLength[0x80]=0;
+  commandLength[0xE0]=1;
+  commandLength[0xE1]=1;
+  commandLength[0xE2]=2;
+
+  // Pin Modes and Setup
+  /*******************************************************************************************/
+  for (byte i=1;i<4;i++){
+    pinMode(motorPins[i],OUTPUT);
+    pinMode(solenoidPins[i],OUTPUT);
+
+    analogWrite(motorPins[i],255);
+    digitalWrite(solenoidPins[i],LOW);
+  }
+
+
+
+  // Other Setup Code
+  /*******************************************************************************************/
+  Serial.begin(9600);
+  Serial.setTimeout(commsTimeout);
+#ifdef DEBUG
+  Serial.println("Arduino Start");
+#endif
+
+
+  //Attach the servo objects
+  servo1.attach(pinServo1,900,2100); //Include the maximum and minimum pulse widths.
+  servo2.attach(pinServo2,900,2100);
+  servo3.attach(pinServo3,900,2100);
+
+
+  //Wait until 'Game Start' button is pressed
+
+  //add here later
+  //Send 'Game Start' message to laptop
+  sendMessage(0x80);
+
+
+  //Set up the PWM DC motor control signals
+  analogWrite(pinMotor1,motorLevel1);
+  analogWrite(pinMotor2,motorLevel2);
+  analogWrite(pinMotor3,motorLevel3);
+
+
+  //Prototyping stuff DELETE ME!  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+  //analogWrite(pinMotor1,0);
+
+  //    releaseBall(1);
+
+  //  while (true) { //Cycle endlessly
+  //    setShooterAngle(1,90);
+  //    delay(1000);
+  //    setShooterAngle(1,45);
+  //    delay(1000);
+  //    setShooterAngle(1,135);
+  //    delay(1000);
+  //  }
+
+}
+
+
+/*
+▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ // Loop
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ */
+void loop(){
+  checkSerial(); //Check for incoming commands, and execute them
+
+  checkSolenoids(); //Deactivates any solenoids when needed
+
+}
+
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*checkSerial
+/*******************************************************************************************/
+void checkSerial(){
+  if (Serial.available()) {
+    //Search for the initization sequence
+    if (Serial.read()=='G'){
+      timer=millis()+commsTimeout;
+      while (!Serial.available()){ //Wait until another character is available
+        if (millis()>timer) { //Exit the loop if we don't receive another character
+          break;
+        }
+      }
+      if (Serial.peek()=='O'){
+        Serial.read(); //Remove the 'O' from the serial buffer.
+        //Initialization Sequence detected!
+
+#ifdef DEBUG
+        Serial.println("'G O' found!");
+#endif
+
+        timer=millis()+commsTimeout;
+        while (!Serial.available()){ //Wait until another character is available
+          if (millis()>timer) { //Exit the loop if we don't receive another character
+            break;
+          }
+        }
+        commandID=Serial.read(); //This byte is the command ID
+
+        //Now, read the required number of data bytes into the array 'buffer'
+        Serial.readBytes(buffer,commandLength[commandID]);
+
+        //Execute the command
+        executeCommand();
+      }
+    }
+  }
+}
+
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*executeCommand
+/*******************************************************************************************/
+//This function executes whatever the necessary action is, as told by the command and data
+//received through serial comms
+void executeCommand(){
+  switch (commandID){
+  case 1:
+    //Aim shooter <db1> to angle defined by <db2>
+    setShooterAngle(buffer[0],(byte) buffer[1]);
+    break;
+  case 2:
+    //Release a ball on shooter <db1>
+    releaseBall(buffer[0]);
+    break;
+  default:
+#ifdef DEBUG
+    Serial.print("Unrecognized command ID: ");
+    Serial.println(commandID);
+#endif
+    //Send error feedback to laptop
+    sendMessage(0xE0,commandID);
+  }
+}
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*setShooterAngle
+/*******************************************************************************************/
+//This function changes the servo signal for shooter <shooterNum> to the angle defined by
+// <angle>.  <angle> is a byte that ranges from 180, which maps from 900 to 2100 mS.
+void setShooterAngle(byte shooterNum, byte angle){
+
+  //  unsigned int output =   (((unsigned int) angle-1)*137)/29+900; // 137/29 = 4.724 = 1200/254, the scaling factor to get to uS
+
+#ifdef DEBUG
+  Serial.print("Setting shooter ");
+  Serial.print(shooterNum);
+  Serial.print(" to ");
+  Serial.println(angle);
+#endif
+
+  //Set the servo output.  Use a switch statement to use the correct servo object.
+  if (angle<angleLowest || angle>angleHighest) {
+    //The angle is invalid! Don't move the shooter, and send feedback
+    sendMessage(0xE2,shooterNum,angle);
+  }
+  else{
+    switch (shooterNum) {
+    case 1:
+      servo1.write(angle);
+      break;
+    case 2:
+      servo2.write(angle);
+      break;
+    case 3:
+      servo1.write(angle);
+      break;
+    default:
+#ifdef DEBUG
+      Serial.print("Unrecognized shooter Num: ");
+      Serial.println(shooterNum);
+#endif
+      //Send unrecognized shooter num feedback to laptop
+      sendMessage(0xE1,shooterNum);
+    }
+  }
+}
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*releaseBall
+/*******************************************************************************************/
+//This function releases one BB (hopefully) from shooter <shooterNum>
+void releaseBall(byte shooterNum) {
+
+#ifdef DEBUG
+  Serial.print("Releasing ball from shooter: ");
+  Serial.println(shooterNum);
+#endif
+  if (shooterNum<1 || shooterNum>3) { //Check that the shooter number is valid
+    #ifdef DEBUG
+          Serial.print("Unrecognized shooter Num: ");
+          Serial.println(shooterNum);
+    #endif
+          //Send unrecognized shooter num feedback to laptop
+          sendMessage(0xE1,shooterNum);
+  }
+
+  digitalWrite(solenoidPins[shooterNum],HIGH); //Activate the solenoid: open the passage
+
+  ballReleaseTimer[shooterNum]=millis()+ballReleaseTime; //Set the timer for deactivating the solenoid
+  ballReleasing[shooterNum]=1; //Indicate that we are releasing a ball
+}
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*checkSolenoids
+/*******************************************************************************************/
+//Check whether there are any solenoids that need to be deactivated
+void checkSolenoids(){
+  for (byte i=1;i<4;i++){ //Check all 3 solenoids
+    if (ballReleasing[i]==1){ //If a ball is currently being released
+      if (millis()>ballReleaseTimer[i]){ //If enough time has passed
+        digitalWrite(solenoidPins[i],LOW); //Deactivate the solenoid: close the passage
+        ballReleasing[i]=0; //Indicate that the ball is no longer being released
+#ifdef DEBUG
+        Serial.print("Deactivating solenoid: ");
+        Serial.println(i);
+#endif
+      }
+    }
+  }
+}
+
+
+/*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+/*sendMessage
+/*******************************************************************************************/
+//This function sends commands to the laptop.  It has optional inputs.
+void sendMessage (byte CMD,byte in1, byte in2, byte in3) {
+  Serial.print("GO");
+  if (commandLength[CMD]>0){
+    Serial.print(in1);
+    if (commandLength[CMD]>1){
+      Serial.print(in2);
+      if (commandLength[CMD]>2){
+        Serial.print(in3);
+      }
+    }
+  }
+  Serial.println(); //Print a new line character
+}
+


removed unrequired line

removed unrequired line

--- examples/TMC26XMotorTester/TMC26XMotorTester.ino
+++ examples/TMC26XMotorTester/TMC26XMotorTester.ino
@@ -50,7 +50,6 @@
   pinMode(ENABLE_PIN, OUTPUT);
   digitalWrite(ENABLE_PIN,HIGH);
   #endif
-  // SPI.setClockDivider(SPI_CLOCK_DIV128);
   startSerial();
   startMotor();
   //set this according to you stepper


Fix offsetCalibration example

Fix offsetCalibration example

- Set gain 1 before calibration for better results
- Adjust method names

--- examples/offsetCalibration/offsetCalibration.ino
+++ examples/offsetCalibration/offsetCalibration.ino
@@ -24,15 +24,17 @@
   //Set to continous conversion
   line.contConv();
   delay(100);
+  line.setGainI(1.0);
+  delay(100);
 }

 void loop() {

   Serial.println("\nWithout calibration");
-  line.setOffsetI(0); //Reset previous calibration
+  line.setDcOffsetI(0); //Reset previous calibration
   double foo = line.getInstI();
   Serial.println(foo, 5);
-  line.setOffsetI(-foo); //Calibrate by the last read value
+  line.setDcOffsetI(-foo); //Calibrate by the last read value

   Serial.println("\nCalibrated");
   foo = line.getInstI();


Tweaked pause frequency

Tweaked pause frequency

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -89,7 +89,7 @@

   panTilt.updateAngles();

-  if(random(1001) < 5){
+  if(random(1001) < 8){
     delay(markovPause());

   }


Adjusted shake delay

Adjusted shake delay

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -363,7 +363,7 @@

 void shake(){
   int moveVal = 10;
-  const int shakeDelay = 5;
+  const int shakeDelay = 0;
   panTiltX.angle += moveVal;
   panTilt.updateAngles();
   delay(shakeDelay);


Updated sample project with all letters.

--- TinyfontSample/TinyfontSample.ino
+++ TinyfontSample/TinyfontSample.ino
@@ -7,10 +7,10 @@

 void setup() {
   arduboy.begin();
-  //Serial.begin(9600);
+  Serial.begin(9600);

   // create all ascii letters from 32-126
-  /*
+
   size_t newLineCounter = 0;
   for (size_t i = 0; i < 100; i++) {
     if ((i % 26) == 0) {
@@ -21,7 +21,7 @@
       allLetters[i] = (char) (i+32) - newLineCounter;
     }
   }
-  allLetters[100] = '\0';*/
+  allLetters[100] = '\0';
 }

 void loop() {
@@ -32,13 +32,13 @@
   tinyfont.print("The quick brown fox jumps\nover the lazy dog.", 1, 13);

   // all letters
-  //tinyfont.print(allLetters, 1, 22);
+  tinyfont.print(allLetters, 1, 22);

   // for comparison
   //arduboy.setCursor(1, 52);
   //arduboy.print("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.");

   // screen capture
-  //Serial.write(arduboy.getBuffer(), 128 * 64 / 8);
+  Serial.write(arduboy.getBuffer(), 128 * 64 / 8);
   arduboy.display();
 }


Default button states to all pins disconnected

Because the pins are configured as INPUT_PULLUP, they'll all read as
high if the RF receiver is disconnected.  Match the starting button
states to that initial value, to prevent the first read from detecting
that all 4 buttons are pressed.

--- Arduino/LightPlayer/LightPlayer.ino
+++ Arduino/LightPlayer/LightPlayer.ino
@@ -32,6 +32,7 @@
   const int bc   = b|c;
   const int bd   = b|d;
   const int cd   = c|d;
+  const int all  = abcd;
 }

 apa106<D, 6>   LEDstrip;
@@ -108,7 +109,7 @@

 void handleRfRemoteButtons()
 {
-  static int old_button_states;
+  static int old_button_states = Pressed::all;
   int button_states = PINC & B1111;

   if (button_states == old_button_states) {


Delete Project_10_Door_Monitor.ino

Delete Project_10_Door_Monitor.ino

--- Arduino/Project_10_Door_Monitor/Project_10_Door_Monitor.ino
+++ Arduino/Project_10_Door_Monitor/Project_10_Door_Monitor.ino
@@ -1,73 +0,0 @@
-
-
-#include <LiquidCrystal.h>
-
-
-// Pin allocations
-const int buzzerPin = 11;
-const int backlightPin = 10;
-const int switchPin = A0;
-const int doorPin = 12;
-
-//                RS,E,D4,D5,D6,D7
-LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
-
-boolean mute = false;
-
-void setup()
-{
-  // This because of a defect in common cheap LCD displays
-  // backlight controlled by transistor D10 high can
-  // burn out Arduino pin
-  pinMode(backlightPin, INPUT);
-  pinMode(doorPin, INPUT_PULLUP);
-  lcd.begin(16, 2);
-}
-
-void loop()
-{
-  checkDoor();
-
-  if (analogRead(switchPin) < 1000) // any key pressed
-  {
-    mute = ! mute;
-    if (mute)
-    {
-      noTone(buzzerPin);
-      lcd.setCursor(12, 1);
-      lcd.print("MUTE");
-    }
-    else
-    {
-      lcd.setCursor(12, 1);
-      lcd.print("    ");
-    }
-    delay(300);
-  }
-  delay(100);
-}
-
-void warn(char message[])
-{
-  lcd.setCursor(0, 1);
-  lcd.print(message);
-  delay(100);
-  lcd.setCursor(0, 1);
-  lcd.print("            ");
-  if (!mute)
-  {
-    tone(buzzerPin, 1000);
-    delay(100);
-    noTone(buzzerPin);
-  }
-  delay(100);
-}
-
-void checkDoor()
-{
-  if (digitalRead(doorPin))
-  {
-    warn("DOOR");
-  }
-}
-


Test if daemon resets the serial port or not.

--- cmdMULTIsens/src/sketch.ino
+++ cmdMULTIsens/src/sketch.ino
@@ -74,10 +74,12 @@
 byte ds1w_addr[8];
 byte ds1w_data[12];

+int SerialRequestCounter;     // For debugging purposes
+
 void setup()
 {
   pinMode(ActivityLED, OUTPUT);     // An LED to signal activity
-  digitalWrite(ActivityLED, HIGH);      // Turn the LED on during setup()
+  digitalWrite(ActivityLED, HIGH);  // Turn the LED on during setup()
   Serial.begin(9600);               // Initialise serialport
   Serial.print("... ");

@@ -92,7 +94,8 @@

   delay(2000);                      // Wait 2s for all sensors to come online
   Serial.println(" cmdMULTIsens ready !");   // Print banner
-  digitalWrite(ActivityLED, LOW);       // Turn off the LED at end of setup()
+  SerialRequestCounter = 0;         // For debugging purposes
+  digitalWrite(ActivityLED, LOW);   // Turn off the LED at end of setup()
 }

 int serialRX()
@@ -177,6 +180,7 @@
   if (Serial.available() > 0)
   {
     digitalWrite(ActivityLED, HIGH);      // signal activity detected
+    SerialRequestCounter += 1;            // For debugging purposes

     ActionRequest = serialRX();           // check the input

@@ -279,6 +283,8 @@
           Value = bmp.getTemperature();
           Serial.print(", ");
           Serial.print(Value);
+          Serial.print(", ");
+          Serial.print(SerialRequestCounter);
         }
         break;
       case 'P':
@@ -317,6 +323,12 @@
         Value = readDSTemperature();
         Serial.print(Value);
         break;
+      case 'Z':
+      case 'z':
+        // Number of serial requests
+        // For debugging purposes
+        Serial.print(SerialRequestCounter);
+        break;
       default:
         Serial.print("NaN");          // Invalid ActionRequest returns `NaN`
         break;


econet_from_scratch: Send dummy frames: <flag> 0x42 0x42 ... <flag>

--- econet_from_scratch/firmware/econet.ino
+++ econet_from_scratch/firmware/econet.ino
@@ -189,10 +189,19 @@

   // static uint8_t serial_state = 0;
   // static unsigned long serial_state_time = 0;
+  static int chars_to_write = 0, is_first_char = 0;
   static unsigned long last_char_write = 0;
-  if (sercom2.isDataRegisterEmptyUART() &&
-      digitalRead(PIN_SERIAL_BUFFER_EMPTY) == HIGH &&
-      (last_char_write - millis()) > 50
+
+  // wait 50ms between frames
+  if (!chars_to_write && (last_char_write - millis()) > 50) {
+    chars_to_write = 20;
+    is_first_char = 1;
+  }
+
+
+  if (sercom2.isDataRegisterEmptyUART()
+      && digitalRead(PIN_SERIAL_BUFFER_EMPTY) == HIGH
+      && chars_to_write > 0
   ) {
     digitalWrite(PIN_MCU_IS_TRANSMITTING, HIGH);
   //   serial_state = 1;
@@ -201,7 +210,10 @@
   // if (serial_state == 1 && millis() > serial_state_time + 1) {
     // sercom2.writeDataUART() casts our input to uint8_t, so we have
     // to go straight to the register here.
-    SERCOM2->USART.DATA.reg = (uint16_t)0x142;
+    chars_to_write --;
+    // start and end with flag, and transmit lots of 0x42 in between
+    SERCOM2->USART.DATA.reg = (is_first_char || !chars_to_write) ? (uint16_t)0x17E : (uint16_t)0x42;
+    is_first_char = 0;
     last_char_write = millis();
   //   serial_state = 2;
   }


Delete K_Nearest_Neighbors_Clapper.ino

Delete K_Nearest_Neighbors_Clapper.ino

--- K_Nearest_Neighbors_Clapper/K_Nearest_Neighbors_Clapper.ino
+++ K_Nearest_Neighbors_Clapper/K_Nearest_Neighbors_Clapper.ino
@@ -1,246 +0,0 @@
-
-//#include <UART_TINY_1MHz_38400.h>
-//#include <digitalWriteFast.h>
-
-// Distance Sensor
-// Feature is height
-// Pre-known object of different heights
-// Pattern is see what the object is closest to.
-#include <Arduino.h>
-// arduino-tone-detector - Version: Latest
-#include <ToneDetector.h>
-
-#include "Object.h"
-//#include "CompareObject.h"
-
-// #define IR_SENSOR_PIN_1 6
-
-bool wait = false;
-
-// K Nearest Neighbors
-const int K = 3;
-
-const size_t NUM_OF_KNOWN_OBJECTS = 8;
-const size_t NUM_OF_OBJECT_TYPES = 2;
-// FIXME: Change to sound types
-String Object_Types[NUM_OF_OBJECT_TYPES] = {"Acceptable", "Unacceptable"};
-
-Object knownObjects[NUM_OF_KNOWN_OBJECTS];
-
-// Define max height/weight/etc.
-// FIXME: For each feature
-const int FREQUENCY_MIN = 1000;
-const int FREQUENCY_MAX = 2500;
-const int VOLTAGE_MIN = 0;
-const int VOLTAGE_MAX = 1024;
-const int DELAY_MIN = 0;
-const int DELAY_MAX = 2000;
-
-// FIXME: Change to the correct trigger voltage
-unsigned int trigger_voltage = 800;
-
-// Takes the features from the current object and converts them to strings and integers
-// **
-void ObjectFeatureExtraction(Object &currObject) {
-  // Get the various sound features
-  // Call the sound functions and stuff
-  unsigned int voltage = analogRead(1);
-  uint16_t frequency = readSignal();
-  int num_signals = 0;
-  unsigned long signal_begin;
-  unsigned long signal_end;
-
-  while(1) {
-    voltage = analogRead(1);
-    frequency = readSignal();
-    // If the voltage is loud enough to trigger
-    if(voltage > trigger_voltage && voltage < 1024) { // 1024 is an error
-      // If first time triggered
-      if(num_signals == 0) {
-        signal_begin = millis();
-        num_signals++;
-        currObject.frequency1 = frequency;
-        currObject.voltage1 = voltage;
-      }
-      // If second time triggered
-      else {
-        signal_end = millis();
-        num_signals++;
-        currObject.frequency2 = frequency;
-        currObject.voltage2 = voltage;
-        currObject.delay = signal_end - signal_begin;
-        return;
-      }
-    }
-  }
-}
-
-float RescaleValue(float value, const float min, const float max) {
-  return (value-min)/(max-min);
-}
-
-// Rescale object features to 1-0 range
-void RescaleObject(Object *object) {
-  // FIXME: For each feature
-  object->frequency1 = RescaleValue(object->frequency1, FREQUENCY_MIN, FREQUENCY_MAX);
-  object->frequency2 = RescaleValue(object->frequency2, FREQUENCY_MIN, FREQUENCY_MAX);
-  object->voltage1 = RescaleValue(object->voltage1, VOLTAGE_MIN, VOLTAGE_MAX);
-  object->voltage2 = RescaleValue(object->voltage2, VOLTAGE_MIN, VOLTAGE_MAX);
-  object->delay = RescaleValue(object->delay, DELAY_MIN, DELAY_MAX);
-}
-
-// Computes the euclidean distance between the known and the current object's features
-float ComputeDistanceofObjects(Object currObject, Object knownObject) {
-  // FIXME: For each feature
-  float freq1_dist = (currObject.frequency1 - knownObject.frequency1);
-  float freq2_dist = (currObject.frequency2 - knownObject.frequency2);
-  float volt1_dist = (currObject.voltage1 - knownObject.voltage1);
-  float volt2_dist = (currObject.voltage2 - knownObject.voltage2);
-  float delay_dist = (currObject.delay - knownObject.delay);
-
-  float freq1 = freq1_dist*freq1_dist;
-  float freq2 = freq2_dist*freq2_dist;
-  float volt1 = volt1_dist*volt1_dist;
-  float volt2 = volt1_dist*volt1_dist;
-  float delay = delay_dist*delay_dist;
-  float dist = freq1 + freq2 + volt1 + volt2 + delay;
-
-  return dist;
-}
-
-// Finds the patterns from the current object and compares them to patterns from the given objects
-// **
-String ObjectPatternRecognition(Object currObject, Object knownObjects[]) {
-  int count = 0;
-  int max_count = 0;
-  String most_frequent_type;
-
-  Object kNearestObjects[K];
-
-  // First K known objects are the closest K, obviously, so just fill array
-  for(int i = 0; i < K; ++i) {
-    kNearestObjects[i].type = knownObjects[i].type;
-    kNearestObjects[i].frequency1 = knownObjects[i].frequency1;
-    kNearestObjects[i].frequency2 = knownObjects[i].frequency2;
-    kNearestObjects[i].voltage1 = knownObjects[i].voltage1;
-    kNearestObjects[i].voltage2 = knownObjects[i].voltage2;
-    kNearestObjects[i].delay = knownObjects[i].delay;
-  }
-
-  // Now, determine if each remaining object is among the K closest, and if so insert into array (thus dropping one obj)
-  for(int i = K; i < NUM_OF_KNOWN_OBJECTS; ++i) { // For each remaining known object
-    int j;
-
-    // Find the current max difference in the K nearest objects
-    float max_diff_of_K_nearest = 0;
-    int max_index = 0;
-    float temp_dist = 0;
-
-    for(j = 0; j < K; ++j) {
-      // kNearest Objects is the difference between the currObject and the knownObjects
-      // ComputeDistanceofObjects should compute the total distance for kNearestObjects[j]
-      // May just add this to the above
-      temp_dist = ComputeDistanceofObjects(currObject, kNearestObjects[j]);
-
-      if(temp_dist > max_diff_of_K_nearest) { // Update max
-        max_diff_of_K_nearest = temp_dist;
-        max_index = j;
-      }
-    }
-
-    // If the current known object's difference < the max difference in the current K nearest neighbors
-    temp_dist = ComputeDistanceofObjects(currObject, knownObjects[i]);
-
-    if(temp_dist < max_diff_of_K_nearest) {
-      // Replace the existing neighbor having max_diff_of_K_nearest, by the current known object, in the K nearest neighbors array
-      kNearestObjects[max_index].type = knownObjects[i].type;
-      kNearestObjects[i].frequency1 = knownObjects[i].frequency1;
-      kNearestObjects[i].frequency2 = knownObjects[i].frequency2;
-      kNearestObjects[i].voltage1 = knownObjects[i].voltage1;
-      kNearestObjects[i].voltage2 = knownObjects[i].voltage2;
-      kNearestObjects[i].delay = knownObjects[i].delay;
-    }
-  }
-
-  // For testing purposes
-  for(int i = 0; i < K; ++i) {
-    Serial.println(kNearestObjects[i].type);
-    Serial.println(kNearestObjects[i].frequency1);
-    Serial.println(kNearestObjects[i].frequency2);
-    Serial.println(kNearestObjects[i].voltage1);
-    Serial.println(kNearestObjects[i].voltage2);
-    Serial.println(kNearestObjects[i].delay);
-  }
-
-  // Find out which object type occurs most frequently
-  for(int i = 0; i < NUM_OF_OBJECT_TYPES; ++i) {
-    int j;
-    count = 0;
-    for(j = 0; j < K; ++j) {
-      if(kNearestObjects[j].type == Object_Types[i]) {
-        count++;
-      }
-    }
-    if(count > max_count) {
-      max_count = count;
-      most_frequent_type = Object_Types[i];
-    }
-  }
-
-  return most_frequent_type;
-}
-
-// Prints the type of object that is being passed through the project
-// **
-void Actuation(String object) {
-  if(object != "") {
-    Serial.print("\t");
-    Serial.println(object);
-  }
-}
-
-void PopulateKnownObjects() {
-  // Change values and measure
-  knownObjects[0].type = "Acceptable";
-  knownObjects[0].frequency1 = 200;
-  knownObjects[0].frequency2 = 200;
-  knownObjects[0].voltage1 = 200;
-  knownObjects[0].voltage2 = 200;
-  knownObjects[0].delay = 200;
-
-  knownObjects[1].type = "Unacceptable";
-  knownObjects[1].frequency1 = 200;
-  knownObjects[1].frequency2 = 200;
-  knownObjects[1].voltage1 = 200;
-  knownObjects[1].voltage2 = 200;
-  knownObjects[1].delay = 200;
-}
-
-void setup() {
-  Serial.begin(9600);
-
-  PopulateKnownObjects();
-
-  // May need to use the below for this case
-  //Serial.begin(115200);
-
-  // Microphone function
-  setToneDetectorControlDefaults();
-  // Tone range
-  setToneDetectorMatchValues(1000, 2500);
-}
-
-void loop() {
-  String closestObject;
-
-  Object currObject;
-
-  ObjectFeatureExtraction(currObject);
-
-  closestObject = ObjectPatternRecognition(currObject, knownObjects);
-
-  Actuation(closestObject);
-
-  delay(1000);
-
-}


Updated telemetry channel labels

Updated telemetry channel labels

--- examples/quadcopter/quadcopter.ino
+++ examples/quadcopter/quadcopter.ino
@@ -119,7 +119,7 @@
                                    throttleCurve.get(throttle);

     // set output targets
-    comms.sendTelem(VOLTAGE+2  , throttleOut);
+    comms.sendTelem(AMPERAGE, throttleOut);
     horizon.set(pitchCmd, rollCmd, yawTarget, throttleOut);
 }

@@ -170,10 +170,10 @@
         velocityEst = velocity;
         oldIntegral = newIntegral;

-        comms.sendTelem(VOLTAGE+3, altitudeEst);
-        comms.sendTelem(VOLTAGE+4, velocityEst);
-        comms.sendTelem(VOLTAGE+5, oldIntegral);
-        comms.sendTelem(VOLTAGE+6, altitudeSetpoint);
+        comms.sendTelem(ALTITUDE, altitudeEst);
+        comms.sendTelem(ALTITUDE+1, velocityEst);
+        comms.sendTelem(ALTITUDE+2, oldIntegral);
+        comms.sendTelem(ALTITUDE+3, altitudeSetpoint);
     }

     return throttleOutput;
@@ -192,7 +192,7 @@
         comms.sendTelem(ROLL       , toDeg(orientation.getRoll()));
         comms.sendTelem(GROUNDSPEED, profileTime(0));
         comms.sendTelem(VOLTAGE    , voltage);
-        comms.sendTelem(AMPERAGE   , safe());
+        //comms.sendTelem(AMPERAGE   , safe());
         //comms.sendTelem(ALTITUDE   , altitude.get());

         Serial.println();


Update sketch

Update sketch

--- example/shadow.ino
+++ example/shadow.ino
@@ -1,48 +1,31 @@
 #include "mjson.h"

-static char in[200];
-static int in_len = 0;
-static int ledOn = 0;
+static int ledOn = 0;  // Current LED status

-// Gets called by the RPC engine to send a reply frame
 static int sender(const char *buf, int len, void *privdata) {
-  return Serial.write(buf, len);
+  return Serial.write(buf, len);  // Send RPC reply frame
 }
-
-static int receiver(void *privdata) { return Serial.read(); }

 static void reportState(void) {
   jsonrpc_notify("{\"method\":%Q,\"params\":{\"on\":%s}}", "Shadow.Report",
                  ledOn ? "true" : "false");
 }

-// Handle device shadow delta
-static int on_shadow_delta(char *buf, int len, struct mjson_out *out,
-                           void *userdata) {
-  ledOn = mjson_get_bool(buf, len, "$.on", 0);
-  digitalWrite(LED_BUILTIN, ledOn);
-  reportState();
-  return 0;  // Success
+static int on_delta(char *buf, int len, struct mjson_out *out, void *userdata) {
+  ledOn = mjson_get_bool(buf, len, "$.on", 0);  // Fetch "on" shadow value
+  digitalWrite(LED_BUILTIN, ledOn);             // Set LED to the "on" value
+  reportState();  // Let shadow know our new state
+  return 0;       // Signal sucess to the RPC engine
 }

 void setup() {
-  jsonrpc_init(sender, NULL, "1.0");
-  jsonrpc_export("Shadow.Delta", on_shadow_delta, NULL);
-  pinMode(LED_BUILTIN, OUTPUT);
-  Serial.begin(9600);
-  reportState();
+  jsonrpc_init(sender, NULL, "1.0");                // Init RPC library
+  jsonrpc_export("Shadow.Delta", on_delta, NULL);   // Export "Shadow.Delta"
+  pinMode(LED_BUILTIN, OUTPUT);   // Configure LED pin
+  Serial.begin(9600);             // Init serial comms
+  reportState();                  // Let shadow know our state
 }

 void loop() {
-  if (Serial.available() > 0) {
-    if (in_len >= sizeof(in)) in_len = 0;  // On buffer overflow, reset buffer
-    in[in_len++] = Serial.read();          // Read char, append to the buffer
-    if (in[in_len - 1] == '\n') {  // If that was a new line, parse frame
-      if (in_len > 1) {
-        jsonrpc_process(in, in_len);  // Handle request, send response frame
-        Serial.write('\n');           // Send newline after the response frame
-      }
-      in_len = 0;  // Reset buffer
-    }
-  }
+  if (Serial.available() > 0) jsonrpc_process_byte(Serial.read());
 }


Hvac -> Relay

Hvac -> Relay

--- thermostat.ino
+++ thermostat.ino
@@ -3,13 +3,13 @@
 #include <DS18B20.h>
 #include <RunningSample.h>
 #include <Interval.h>
-#include <Hvac.h>
+#include <Relay.h>

 // init our library classes. the constants come from thermostat.h
 RunningSample Temperatures( SAMPLE_SIZE );
 Interval SampleInterval( SAMPLE_FREQUENCY );
-Hvac Heater( HEATER_PIN );
-//Hvac AC(AC_PIN) /* i don't have an air conditioner */
+Relay Heater( HEATER_PIN );
+//Relay AC(AC_PIN) /* i don't have an air conditioner */
 DS18B20 Therm( THERMO_PIN );

 void setup()


Added a neo pixel to the arduino

Added a neo pixel to the arduino

--- arduino_serial/arduino_serial.ino
+++ arduino_serial/arduino_serial.ino
@@ -1,5 +1,6 @@
 #include <SoftwareSerial.h>
 #include <SabertoothSimplified.h>
+#include <Adafruit_NeoPixel.h>

 #define FULL_SPEED 70
 //Define motors
@@ -9,12 +10,21 @@
 SoftwareSerial SWSerial(NOT_A_PIN, MOTOR_PIN); // RX on no pin (unused), TX on pin 11 (to S1).
 SabertoothSimplified ST(SWSerial); // Use SWSerial as the serial port.

+Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 13, NEO_GRB + NEO_KHZ800);
+
 //Input buffer for serial
 char in[2] = {'a', '\0'};

 void setup() {
+  //Used for Motor Controler
+  SWSerial.begin(9600);
+  //Used for talking to the raspberry pi
   Serial.begin(115200);
-
+
+  //Start up NEO Pixel
+  strip.begin();
+  strip.setPixelColor(0, 255, 0, 0);
+  strip.show();
 }

 void loop() {
@@ -39,16 +49,23 @@
   delay(500);
   ST.motor(RIGHT, 0);
   ST.motor(LEFT, 0);
+  strip.setBrightness(15);
+  strip.setPixelColor(0, 0, 0, 0);
+  strip.show();
 }

 void right(){
   ST.motor(RIGHT, FULL_SPEED);
   ST.motor(LEFT, -FULL_SPEED);
+  strip.setPixelColor(0, 0, 255, 0);
+  strip.show();
   fullStop();
 }

 void left(){
   ST.motor(RIGHT, -FULL_SPEED);
   ST.motor(LEFT, FULL_SPEED);
+  strip.setPixelColor(0, 0, 0, 255);
+  strip.show();
   fullStop();
 }


Available check reenabled

Available check reenabled

--- firmware/Nanpy.ino
+++ firmware/Nanpy.ino
@@ -25,7 +25,9 @@
 }

 void loop() {
-    m = new MethodDescriptor();
-    Register::elaborate(m);
+    if(ComChannel::available()) {
+        m = new MethodDescriptor();
+        Register::elaborate(m);
+    }
 }


serial reward update

serial reward update

--- SerialEnabledRewards/SerialEnabledRewards.ino
+++ SerialEnabledRewards/SerialEnabledRewards.ino
@@ -6,11 +6,12 @@
   a -> activate all wells
   w -> activate individual well
   d -> deactivate individual well
-  s -> check status of all wells
+  l -> toggle LED on/off
+  s -> check status
   r -> reset. deactivates all wells
   p -> select pump to turn-on
-  c -> change pump duration
-  z -> select cue {1,2,3,4}
+  c -> select cue
+  z -> change pump duration
   y -> turn off cue.

   Alex Gonzalez
@@ -29,7 +30,8 @@
 /* Program constants.
 */
 const long BAUD_RATE = 115200; // baud rate for serial communication. must match contro script
-const long DETECT_TIME_THR  = 500; // in ms
+const long DETECT_TIME_THR  = 50; // in ms
+const long DETECT_REFRAC_THR = 15000; // twenty seconds before registering a second detection
 const bool Pump_ON = LOW; // LOW activates the pump
 const bool Pump_OFF = HIGH; // HIGH deactivates the pump.
 const int nWells = 6; // number of reward wells
@@ -62,20 +64,18 @@
 const int Well_LED_Pins[6] = {40, 41, 42, 43, 44, 45};

 // Default values for pump durations
-const long Pump_ON_Default[6]   = {12, 12, 15, 15, 15, 15};
-long Pump_ON_DUR[6]    = {12, 12, 15, 15, 15, 15};
-
-// in ms (100ms=0.25ml; 40ms=0.1ml)
+const long Pump_ON_Default[6]   = {8, 10, 15, 15, 15, 15};
+long Pump_ON_DUR[6]    = {8, 10, 15, 15, 15, 15};
+
 /* **********************************
    End of Declaration of Arduino Pins
 */
-// Setup of Neopixel:
-//Adafruit_NeoPixel NeoPix = Adafruit_NeoPixel(, CUEs1_PIN, NEO_GRB + NEO_KHZ800);
+// Setup of Neopixel Matrix
 Adafruit_NeoMatrix NeoPix = Adafruit_NeoMatrix(8, 8, CUEs1_PIN,
   NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
   NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
   NEO_GRB            + NEO_KHZ800);
-
+
 const uint32_t  NP_blueviolet = NeoPix.Color(120, 0, 110);
 const uint32_t  NP_green = NeoPix.Color(0, 120, 0);
 const uint32_t  NP_off = NeoPix.Color(0, 0, 0);
@@ -113,6 +113,8 @@
 unsigned long Well_Active_Timer[nWells];   // timer indicating how long LED has been on
 unsigned long Well_IR_TimeRef[nWells];  // time reference: for IR detection
 unsigned long Well_IR_Timer[nWells];    // timer for how long IR has been on.
+unsigned long Well_IR_RefracTimeRef[nWells]; // timer for second detection
+
 unsigned long PumpTimeRef[nWells];      // time ref for pump on
 unsigned long PumpTimer[nWells];        // timer for how long pump has been on

@@ -137,6 +139,7 @@
     Well_Active_TimeRef[ii] = 15000UL;
     Well_IR_TimeRef[ii] = 15000UL;
     PumpTimeRef[ii] = 15000UL;
+    Well_IR_RefracTimeRef[ii] = 0;

     Well_Active_Timer[ii] = 0;
     PumpTimer[ii] = 0;
@@ -169,13 +172,13 @@
   NeoPix.setBrightness(60);
   NeoPix.fillScreen(0);
   NeoPix.show();
-
+
   delay(500);
   Serial.begin(BAUD_RATE);
   Serial.println("<");
   Serial.println("<Initiation complete. Waiting for a detection.");
   Serial.print(">");
-}
+} // end setup

 //Main
 void loop() {
@@ -269,16 +272,20 @@

 // Detection Threshold
 void WellDetectThrCheck(int well) {
-  if (Well_Detect_State[well] == false) {
-    if (Well_IR_State[well] == true) {
-      Well_IR_Timer[well] = millis() - Well_IR_TimeRef[well];
-      if (Well_IR_Timer[well] >= DETECT_TIME_THR) {
-        Well_Detect_State[well] = true;
-        ResetDetectTimer(well);
-        Serial.print("<Detection on Well # ");
-        Serial.println(well + 1);
-        Serial.print(">\n");
-        sendEventCode(DD, well + 1);
+  if ((millis() - Well_IR_RefracTimeRef[well])>DETECT_REFRAC_THR) {
+    if (Well_Detect_State[well] == false) {
+      if (Well_IR_State[well] == true) {
+
+        Well_IR_Timer[well] = millis() - Well_IR_TimeRef[well];
+        if (Well_IR_Timer[well] >= DETECT_TIME_THR) {
+          Well_Detect_State[well] = true;
+          ResetDetectTimer(well);
+          Well_IR_RefracTimeRef[well] = millis();
+          Serial.print("<Detection on Well # ");
+          Serial.println(well + 1);
+          Serial.print(">\n");
+          sendEventCode(DD, well + 1);
+        }
       }
     }
   }
@@ -305,6 +312,10 @@
       case 'w':
         SelectWellToActive();
         break;
+      case 'l':
+        // toggle LED On/Off
+        ToggleLED();
+        break;
       case 'd':
         SelectWellToDeActive();
         break;
@@ -329,7 +340,7 @@
         break;
       case 'q':
         reset_states();
-        TurnCueOff();
+        break;
       default:
         Serial.println("<IncorrectSuffix");
         Serial.print(">\n");
@@ -374,7 +385,7 @@
 *****************************************/
 int SelectCueOn() {
   int cue = SerialReadNum();
-  if (cue > 1 && cue <= nCues) {
+  if (cue >= 1 && cue <= nCues) {
     ActiveCUE_ID = cue;
     sendEventCode(CA, cue);
     Serial.print("<Ard. Activated Cue #");
@@ -391,7 +402,7 @@
 }

 void TurnCueOff() {
-  sendEventCode(CD, ActiveCUE_ID);
+  sendEventCode(CD, ActiveCUE_ID + 1);
   SetCueParams(-1);
   CUE_TimeRef = 15000L;
   CUE_Timer   = 0;
@@ -601,11 +612,14 @@
 }

 void ActivateWell(int well) {
+  //if (well<=1){ Well_LED_ON(well); }
+
+  Well_LED_ON(well);
   Well_Active_State[well] = true;
   Well_Active_TimeRef[well] = millis();
   Well_Active_Timer[well] = 0;
-  Well_LED_ON(well);
-  Deliver_Reward(well);
+
+  //Deliver_Reward(well);
   sendEventCode(AW, well + 1);
 }

@@ -619,22 +633,24 @@

 void ActivateAllWells() {
   for (int well = 0; well < nWells; well++) {
+    Well_LED_ON(well);
     ActivateWell(well);
-    Deliver_Reward(well);
-  }
-}
+    //Deliver_Reward(well);
+  }
+}
+
 void reset_states() {
-  for (int ii = 0; ii < nWells; ii++) {
-    DeActivateWell(ii);
-    TurnOFFPump(ii);
-  }
+  for (int well = 0; well < nWells; well++) {
+    DeActivateWell(well);
+    TurnOFFPump(well);
+  }
+  TurnCueOff();
 }

 /****************************************
           Well LED functions
 *****************************************/
 void  Well_LED_ON(int well) {
-  // set LED timers and set LED state to ON
   digitalWrite(Well_LED_Pins[well], HIGH);
   Well_LED_State[well] = true;
 }
@@ -642,6 +658,17 @@
 void  Well_LED_OFF(int well) {
   digitalWrite(Well_LED_Pins[well], LOW);
   Well_LED_State[well] = false;
+}
+
+void ToggleLED(){
+  int well = SerialReadNum();
+  if (well >= 0 && well <= 5){
+    if (Well_LED_State[well] == false){
+      Well_LED_ON(well);
+    }  else {
+      Well_LED_OFF(well);
+    }
+  }
 }

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


Simplify SetTime example, use hard coded time

--- libraries/CurieTime/examples/SetTime/SetTime.ino
+++ libraries/CurieTime/examples/SetTime/SetTime.ino
@@ -1,32 +1,11 @@
 #include <CurieTime.h>
-
-const char *monthName[12] = {
-  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-int Hour, Min, Sec;
-int Day, Month, Year;

 void setup() {
   while (!Serial);
   Serial.begin(9600);

-  // get the date and time the compiler was run
-  if (getDate(__DATE__) && getTime(__TIME__)) {
-    Serial.print("Curie configured Time=");
-    Serial.print(__TIME__);
-    Serial.print(", Date=");
-    Serial.println(__DATE__);
-
-    setTime(Hour, Min, Sec, Day, Month, Year);
-  } else {
-    Serial.print("Could not parse info from the compiler, Time=\"");
-    Serial.print(__TIME__);
-    Serial.print("\", Date=\"");
-    Serial.print(__DATE__);
-    Serial.println("\"");
-  }
+  // set the current time to 14:27:00, December 14th, 2015
+  setTime(14, 27, 00, 14, 12, 2015);
 }

 void loop() {
@@ -51,79 +30,6 @@
   delay(1000);
 }

-bool getTime(const char *str)
-{
-  // Get time from string of format HH:MM:SS
-  String s = str;
-
-  int firstColonIndex = s.indexOf(":");
-  int lastColonIndex = s.lastIndexOf(":");
-
-  if (firstColonIndex == -1) {
-    // first colon not found
-    return false;
-  }
-
-  if (lastColonIndex == -1) {
-    // last colon not found
-    return false;
-  }
-
-  if (firstColonIndex == lastColonIndex) {
-    // only one colon, first and last index are the same
-    return false;
-  }
-
-  String hourString = s.substring(0, firstColonIndex);
-  String minuteString = s.substring(firstColonIndex + 1, lastColonIndex);
-  String secondString = s.substring(lastColonIndex + 1);
-
-  Hour = hourString.toInt();
-  Min = minuteString.toInt();
-  Sec = secondString.toInt();
-
-  return true;
-}
-
-bool getDate(const char *str)
-{
-  // Get Date from string of format MMM DD YYYY
-  String s = str;
-
-  int firstSpaceIndex = s.indexOf(" ");
-  int lastSpaceIndex = s.lastIndexOf(" ");
-
-  if (firstSpaceIndex == -1) {
-    // first space not found
-    return false;
-  }
-
-  if (lastSpaceIndex == -1) {
-    // last space not found
-    return false;
-  }
-
-  if (firstSpaceIndex == lastSpaceIndex) {
-    // only one space, first and last index are the same
-    return false;
-  }
-
-  String monthString = s.substring(0, firstSpaceIndex);
-  String dayString = s.substring(firstSpaceIndex + 1, lastSpaceIndex);
-  String yearString = s.substring(lastSpaceIndex + 1);
-
-  for (Month = 1; Month <= 12; Month++) {
-    if (monthString.equals(monthName[Month - 1])) {
-      break;
-    }
-  }
-
-  Day = dayString.toInt();
-  Year = yearString.toInt();
-
-  return (Month <= 12);
-}
-
 void print2digits(int number) {
   if (number >= 0 && number < 10) {
     Serial.print('0');


Lux and IR added

Lux and IR added

--- SenseBox-Arduino-Sketch/SenseBox-Arduino-Sketch.ino
+++ SenseBox-Arduino-Sketch/SenseBox-Arduino-Sketch.ino
@@ -13,7 +13,10 @@
 const int chipSelect = 4;
 const int soundSensor = A0;

+//Light sensor variables
 Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
+uint16_t ir, full;
+

 //Barometer variables
 float pressure;
@@ -93,7 +96,7 @@
   // If the file opened okay, write to it:
   if (dataFile) {
     //Serial.print("Writing to test.txt...");
-    dataFile.println("row,lat,lon,speed,timestamp,sound,brightness,vibration,altitude");
+    dataFile.println("row,lat,lon,speed,timestamp,sound,luminosity,lux,ir,vibration,altitude");
     // close the file:
     dataFile.close();
     //Serial.println("done.");
@@ -182,6 +185,11 @@

       //Accel/Gyro
       getAccel_Data();
+
+      //Light sensor
+      uint32_t lum = tsl.getFullLuminosity();
+      ir = lum >> 16;
+      full = lum & 0xFFFF;

       //Save collected data to sd card
       dataFile = SD.open("test.csv", FILE_WRITE);
@@ -201,6 +209,10 @@
         dataFile.print(analogRead(soundSensor));
         dataFile.print(seperator);
         dataFile.print(tsl.getLuminosity(TSL2591_VISIBLE));
+        dataFile.print(seperator);
+        dataFile.print(tsl.calculateLux(full,ir));
+        dataFile.print(seperator);
+        dataFile.print(ir);
         dataFile.print(seperator);
         dataFile.print((Axyz[2]), 2);
         dataFile.print(seperator);


Fixing Update Command

Fixing Update Command


More cleanup. Improve printout.

More cleanup. Improve printout.

--- examples/Benchmarks/CosaBenchmarkPins/CosaBenchmarkPins.ino
+++ examples/Benchmarks/CosaBenchmarkPins/CosaBenchmarkPins.ino
@@ -45,10 +45,6 @@

 void setup()
 {
-  uint32_t start, stop;
-  uint32_t ns;
-  uint8_t cnt;
-
   // Start the trace output stream on the serial port
   uart.begin(9600);
   trace.begin(&uart, PSTR("CosaBenchmarkPins: started"));
@@ -68,6 +64,13 @@
   // Start the timers
   RTC::begin();
   Watchdog::begin();
+}
+
+void loop()
+{
+  uint32_t start, stop;
+  uint32_t ns;
+  uint8_t cnt;

   // Measure the time to perform 1,000,000; empty loop block
   start = RTC::micros();
@@ -77,7 +80,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("nop loop:%ul ns\n", ns);
+  INFO("nop:%ul ns\n", ns);

   // Measure the time to perform 1,000,000 input pin reads
   cnt = 0;
@@ -89,7 +92,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("inPin.is_set():%ul ns", ns);
+  INFO("read pin:inPin.is_set():%ul ns", ns);
   if (cnt == 0) TRACE(cnt);

   cnt = 0;
@@ -103,7 +106,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("inPin >> var:%ul ns", ns);
+  INFO("read pin:inPin >> var:%ul ns", ns);
   if (cnt == 0) TRACE(cnt);

   cnt = 0;
@@ -115,7 +118,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("InputPin::read(7):%ul ns\n", ns);
+  INFO("read pin:InputPin::read(7):%ul ns\n", ns);
   if (cnt == 0) TRACE(cnt);

   // Measure the time to perform 1,000,000 output pin writes
@@ -128,7 +131,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("outPin.write(1); outPin.write(0):%ul ns", ns);
+  INFO("write pin:outPin.write(1); outPin.write(0):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -139,7 +142,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("outPin.set; outPin.clear():%ul ns", ns);
+  INFO("write pin:outPin.set; outPin.clear():%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -150,7 +153,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("outPin << 1; outPin << 0:%ul ns", ns);
+  INFO("write pin:outPin << 1; outPin << 0:%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -161,8 +164,30 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("OutputPin::write(8, 1); OutputPin::write(8, 0):%ul ns\n", ns);
-
+  INFO("write pin:OutputPin::write(8, 1); OutputPin::write(8, 0):%ul ns", ns);
+
+  start = RTC::micros();
+  for (uint16_t i = 0; i < 1000; i++)
+    for (uint16_t j = 0; j < 1000; j++) {
+      outPin.toggle();
+      outPin.toggle();
+      __asm__ __volatile__("nop");
+    }
+  stop = RTC::micros();
+  ns = (stop - start) / 1000L;
+  INFO("write pin:outPin.toggle():%ul ns", ns);
+
+  start = RTC::micros();
+  for (uint16_t i = 0; i < 1000; i++)
+    for (uint16_t j = 0; j < 1000; j++) {
+      OutputPin::toggle(8);
+      OutputPin::toggle(8);
+      __asm__ __volatile__("nop");
+    }
+  stop = RTC::micros();
+  ns = (stop - start) / 1000L;
+  INFO("write pin:OutputPin::toggle(8):%ul ns\n", ns);
+
   // Measure the time to perform 1,000,000 output pin toggle
   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -172,7 +197,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("outPin.write(!inPin.read()):%ul ns", ns);
+  INFO("read-write pin:outPin.write(!inPin.read()):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -182,7 +207,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("inPin.is_set/outPin.clear/set():%ul ns", ns);
+  INFO("read-write pin:inPin.is_set/outPin.clear/set():%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -194,7 +219,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("inPin >> var; outPin << !var:%ul ns", ns);
+  INFO("read-write pin:inPin >> var; outPin << !var:%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -204,17 +229,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("outPin.set(inPin.is_clear()):%ul ns", ns);
-
-  start = RTC::micros();
-  for (uint16_t i = 0; i < 1000; i++)
-    for (uint16_t j = 0; j < 1000; j++) {
-      outPin.toggle();
-      __asm__ __volatile__("nop");
-    }
-  stop = RTC::micros();
-  ns = (stop - start) / 1000L;
-  INFO("outPin.toggle():%ul ns", ns);
+  INFO("read-write pin:outPin.set(inPin.is_clear()):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -224,7 +239,7 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("OutputPin::write(8, !InputPin::read(7)):%ul ns", ns);
+  INFO("read-write pin:OutputPin::write(8, !InputPin::read(7)):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
@@ -237,18 +252,8 @@
     }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("OutputPin::read(7)/write(8,0/1):%ul ns", ns);
-
-  start = RTC::micros();
-  for (uint16_t i = 0; i < 1000; i++)
-    for (uint16_t j = 0; j < 1000; j++) {
-      OutputPin::toggle(8);
-      __asm__ __volatile__("nop");
-    }
-  stop = RTC::micros();
-  ns = (stop - start) / 1000L;
-  INFO("OutputPin::toggle(8):%ul ns\n", ns);
-
+  INFO("read-write pin:OutputPin::read(7)/write(8,0/1):%ul ns\n", ns);
+
   // Measure the time to perform 1,000 byte/8,000 bit data transfer
   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -258,7 +263,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("byte data transfer() pin.write(data,clk):%ul ns", ns);
+  INFO("write serial(8):pin.write(data,clk):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -272,7 +277,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("byte data transfer() pin.write();clock.write(1/0):%ul ns", ns);
+  INFO("write serial(8)::pin.write();clock.write(1/0):%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -286,7 +291,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("byte data transfer() pin.write/toggle():%ul ns", ns);
+  INFO("write serial(8):pin.write/toggle():%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -300,7 +305,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("byte data transfer() OutputPin::write():%ul ns", ns);
+  INFO("write serial(8):OutputPin::write():%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -314,7 +319,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 8000L;
-  INFO("byte data transfer() OutputPin::write/toggle():%ul ns", ns);
+  INFO("write serial(8):OutputPin::write/toggle():%ul ns", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -348,7 +353,7 @@

   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("byte data transfer() pin.write/toggle() unrolled:%ul ns\n", ns);
+  INFO("write serial(8):pin.write/toggle() unrolled:%ul ns\n", ns);

   // Measure the time to perform 1,000 analog pin samples
   start = RTC::micros();
@@ -356,7 +361,7 @@
     analogPin.sample();
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("analogPin.sample():%ul us", ns);
+  INFO("read analog pin:analogPin.sample():%ul us", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -365,7 +370,7 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("analogPin.sample_request/await():%ul us", ns);
+  INFO("read analog pin:analogPin.sample_request/await():%ul us", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++) {
@@ -374,14 +379,14 @@
   }
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("analogPin >> var:%ul us", ns);
+  INFO("read analog pin:analogPin >> var:%ul us", ns);

   start = RTC::micros();
   for (uint16_t i = 0; i < 1000; i++)
     AnalogPin::sample(0);
   stop = RTC::micros();
   ns = (stop - start) / 1000L;
-  INFO("AnalogPin::sample():%ul us\n", ns);
+  INFO("read analog pin:AnalogPin::sample():%ul us\n", ns);

   // Measure the time to perform 1,000 analog pin samples
   // Vary prescale division factor from 128 down to 2.
@@ -392,12 +397,11 @@
       analogPin.sample();
     stop = RTC::micros();
     ns = (stop - start) / 1000L;
-    INFO("prescale(%d):analogPin.sample():%ul us", 1 << factor, ns);
+    INFO("read analog pin:prescale(%d):bits(%d):analogPin.sample():%ul us",
+	 1 << factor, factor + 3, ns);
   }
   trace.println();
-}
-
-void loop()
-{
+
+  // Stop the benchmark
   ASSERT(true == false);
 }


Added the rest of the loop function

Added the rest of the loop function


[refact] reduced identical code lines.

[refact] reduced identical code lines.

--- heater_control.ino
+++ heater_control.ino
@@ -222,7 +222,7 @@
   }
 }

-// converto to string and add preceeding zero, if needed
+// convert to string and add preceeding zero, if needed
 String len2(int val)
 {
   if (val>9)
@@ -293,13 +293,20 @@
   return ret;
 }

+float cntAvg(int index)
+{
+  return (cntArr[index].avg_counter / cntArr[index].avg_samples) /
+         (cntArr[index].scale.digital * cntArr[index].scale.analog);
+}
+
 void sendM2X(struct ad *ad,int cnt)
 {
   char chbuf[22];
   char prevtime[22];
   int response;
   time_t ts;
-  float val;
+  float currval;
+  boolean added=false;

   ts=now();
   buildTime(ts,chbuf);
@@ -317,32 +324,19 @@
   // counter build part
   for (int i=0;i<(sizeof(cntArr) / sizeof(struct cnt));i++) {
     if (cntArr[i].flags & FLAGS_DATACHANGE) {
-      if (ts-cntArr[i].last_send > 30) { // value changed and there is more than 30 seconds after prev
-	if (cntArr[i].avg_samples > 3) {
-	  // calculate average from previous samples
-	  val=(cntArr[i].avg_counter / cntArr[i].avg_samples) / (cntArr[i].scale.digital * cntArr[i].scale.analog);
-	}
-	else
-	  val=cntArr[i].prev.analog;
-
-	buildTime(ts-10,prevtime);
-	iot.name(cntArr[i].name);
-	iot.addValue(val,prevtime);
-	iot.addValue(cntArr[i].measured.analog,chbuf);
-	iot.next();
-	cntPrepareForNext(i,ts);
+      if (ts-cntArr[i].last_send > 30) {                   // value changed and there is more than 30 seconds after prev,
+	iot.addValue(cntAvg(i),buildTime(ts-10,prevtime)); // so this time we'll send two samples.
       }
-      else { // value changed quicly after prev
-	iot.name(cntArr[i].name);
-	iot.addValue(cntArr[i].measured.analog,chbuf);
-	iot.next();
-	cntPrepareForNext(i,ts);
-      }
+      currval=cntArr[i].measured.analog;
+      added=true;
     }
     else if (cntArr[i].flags & FLAGS_TIMEOUT) { // no big changes, only timeout
-      val=(cntArr[i].avg_counter / cntArr[i].avg_samples) / (cntArr[i].scale.digital * cntArr[i].scale.analog);
+      currval=cntAvg(i);
+      added=true;
+    }
+    if (added) {
       iot.name(cntArr[i].name);
-      iot.addValue(val,chbuf);
+      iot.addValue(currval,chbuf);
       iot.next();
       cntPrepareForNext(i,ts);
     }


serial: Power scaling corrected.

serial: Power scaling corrected.

--- duplex_serial/duplex_serial.ino
+++ duplex_serial/duplex_serial.ino
@@ -14,8 +14,8 @@

 const uint8_t signalPowerMax = 255;
 const uint8_t signalPowerMin = 0;
-const uint8_t txPowerMax = 122;
-const uint8_t txPowerMin = 65;
+const uint8_t txPowerMax = 123;
+const uint8_t txPowerMin = 33;
 const uint8_t txCoolantOffset = 100;
 const uint8_t txCoolantMin = 65;
 const uint8_t txCoolantMax = 122;
@@ -48,7 +48,7 @@
 void setup() {
   Serial.begin(9600);
   for (int i=0; i<8; ++i) {
-    powerLevels[i] = 100;
+    powerLevels[i] = (uint8_t)(100.0/300.0*255);
   }
   encoders[0] = encoderSetup(53,52);
   encoders[1] = encoderSetup(51,50);
@@ -98,10 +98,10 @@
   interruptChange(&encoders[7]);
 }

-// Should read from analog pin and map it to [0,255]
-uint8_t getPowerLevel(int sliderIndex) {
+// Should read from analog pin and map it to [0,100]
+float getPowerLevel(int sliderIndex) {
   powerLevels[sliderIndex] = powerLevels[sliderIndex] + coolantDelta[sliderIndex]*5;
-  return powerLevels[sliderIndex];
+  return scalePowerSignalToPercentage(powerLevels[sliderIndex]);
 }

 void computeCoolants() {
@@ -119,9 +119,12 @@
   return max(txCoolantMin, min(txCoolantOffset + delta, txCoolantMax));
 }

-uint8_t scalePower(uint8_t power) {
-  uint8_t clampedPower = max(signalPowerMin, min(power, signalPowerMax));
-  return (uint8_t) ((double)(clampedPower - signalPowerMin)/(signalPowerMax-signalPowerMin)*(txPowerMax-txPowerMin)+txPowerMin);
+float scalePowerSignalToPercentage(uint8_t powerSignal) {
+  return max(0.0f, min(100.0f, ((float)powerSignal) / 255.0f));
+}
+
+uint8_t scalePowerToTx(float powerPercentage) {
+  return (uint8_t) (powerPercentage * (txPowerMax-txPowerMin) + txPowerMin);
 }

 void sendMessageHeader(uint8_t messageType, uint8_t messageLength) {
@@ -136,7 +139,7 @@
   sendMessageHeader(msgTypeData, 16);
   for (int i=0;i<8;++i) {
     //Power level should be read here as analogRead
-    Serial.write(scalePower(getPowerLevel(i)));
+    Serial.write(scalePowerToTx(getPowerLevel(i)));
   }
   for (int i=0;i<8;++i) {
     Serial.write(scaleCoolant(coolantDelta[i]));


Removed unecessary variable: tmp_addr

Removed unecessary variable: tmp_addr

--- Arduino/arduino-yun-lockitron-nfc/arduino-yun-lockitron-nfc.ino
+++ Arduino/arduino-yun-lockitron-nfc/arduino-yun-lockitron-nfc.ino
@@ -131,7 +131,6 @@
 void loop(void) {
   uint8_t success;
   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
-  int tmp_addr;
   uint8_t uidLength;    // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
   int i,j;
   boolean save_delete = 0;
@@ -230,10 +229,10 @@
   }

-  if(!digitalRead(LOCK_UNLOCK)){// Select slot
+  if(!digitalRead(LOCK_UNLOCK)){// Unlock or lock door
     state = lock(!state);
   }
-  if(!digitalRead(RESET_MEMORY)){// Select slot
+  if(!digitalRead(RESET_MEMORY)){// Swipe memory
     digitalWrite(STATUS_LED,HIGH);
     delay(5000);
     digitalWrite(STATUS_LED,LOW);


Fix test routine compilation failure

Fix test routine compilation failure

Power-on delay was removed; replace with appropriate functions.

--- examples/TestRoutine/TestRoutine.ino
+++ examples/TestRoutine/TestRoutine.ino
@@ -111,13 +111,7 @@

   // Turn on SIM module as needed
   // Do this in two steps to save time
-  sim.init();
-  long sim_on_time = millis();
-  if (sim.isOn()) {
-    sim_on_time -= SIM_PWR_DELAY;
-  } else {
-    digitalWrite(SIM_PWRKEY_PIN, HIGH);
-  }
+  sim.powerOnStart();

   doTest("LCD Screen", testScreen);
   doTest("Connector", testConnector);
@@ -132,9 +126,8 @@
   doTest("WiFi", testWiFi);
   doTest("Bluetooth", testBluetooth);

-  // Wait until delay has elapsed
-  while ((millis() - sim_on_time) < SIM_PWR_DELAY);
-  digitalWrite(SIM_PWRKEY_PIN, LOW);
+  // Wait until sim is powered on fully
+  sim.powerOnEnd();

   // Perform testing of SIM908
   doTest("SIM908", testSIM);


Updated the example to reflect new class name

--- examples/AssetTrackerExample.ino
+++ examples/AssetTrackerExample.ino
@@ -18,7 +18,7 @@
 AssetTracker t = AssetTracker();

 // Define a client connection name 'signal'
-Signal signal(TOKEN, callback);
+MySignal signal(TOKEN, callback);

 void callback(char* topic, uint8_t* payload, unsigned int length) {
     char p[length + 1];


slightly reduced speed of the ball

slightly reduced speed of the ball

--- examples/arkanoid8/arkanoid8.ino
+++ examples/arkanoid8/arkanoid8.ino
@@ -55,6 +55,8 @@
         NanoRect  platform;
         NanoPoint ball;
         NanoPoint ballSpeed;
+        int8_t   ratioCounter;
+        int8_t   xratio;
         uint8_t   blocks[BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW];
         uint8_t   blocksLeft;
         uint8_t   frames;
@@ -190,11 +192,12 @@
         engine.refreshRect( gameArea.p2.x + 1, 0, 95, 63 );
     }
     engine.refreshPoint( gameState.battleField.ball );
-
+    gameState.battleField.ratioCounter -= gameState.battleField.xratio;
     bool moveBall;
     do
     {
         NanoPoint speed = gameState.battleField.ballSpeed;
+        if (gameState.battleField.ratioCounter > 0) speed.x = 0;
         moveBall = false;
         gameState.battleField.ball.add( speed );
         if (!gameArea.hasX(gameState.battleField.ball.x))
@@ -213,6 +216,19 @@
         {
             moveBall = true;
             gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
+            gameState.battleField.xratio = 2;
+            if (gameState.battleField.ball.x < gameState.battleField.platform.p1.x + 3)
+            {
+                gameState.battleField.ballSpeed.x = -1;
+            }
+            else if (gameState.battleField.ball.x > gameState.battleField.platform.p2.x - 3)
+            {
+                gameState.battleField.ballSpeed.x = +1;
+            }
+            else
+            {
+                gameState.battleField.xratio = 1;
+            }
         }
         if (checkBlockHit())
         {
@@ -221,6 +237,10 @@
     }
     while (moveBall);
     engine.refreshPoint( gameState.battleField.ball );
+    if (gameState.battleField.ratioCounter <= 0)
+    {
+        gameState.battleField.ratioCounter += 2;
+    }
 }

 void loadLevel(void)
@@ -250,6 +270,8 @@
     gameState.battleField.platform.setRect( 20, 56, 31, 58 );
     gameState.battleField.ball.setPoint( 25, 55);
     gameState.battleField.ballSpeed.setPoint( 1, -1);
+    gameState.battleField.xratio = 2;
+    gameState.battleField.ratioCounter = gameState.battleField.xratio;
     engine.drawCallback( drawBattleField );
     engine.loopCallback( battleFieldLoop );
     loadLevel();


- switch pins for Uno

- switch pins for Uno

--- examples/ir_bridge/ir_bridge.ino
+++ examples/ir_bridge/ir_bridge.ino
@@ -6,14 +6,14 @@
 #include <IRremote.h>

 // define pins (varies per shield/board)
-#define BLE_REQ     9
-#define BLE_RDY     8
-#define BLE_RST     7
+#define BLE_REQ     10
+#define BLE_RDY     9
+#define BLE_RST     2

-#define IR_SEND_PIN 13 // pin 3 on Uno
-#define IR_RECV_PIN 2
+#define IR_SEND_PIN 3
+#define IR_RECV_PIN 4

-#define LED_PIN     3
+#define LED_PIN     5

 struct IRValue {
   char type;


[Firmware] Main sketch uses touch sensor now

--- firmware/lm-wifilamp/lm-wifilamp.ino
+++ firmware/lm-wifilamp/lm-wifilamp.ino
@@ -20,7 +20,7 @@
 #define OTA_REQUIRES_PASSWORD 1

 // Enable if you are using touch sensor instead of classic button.
-#define TOUCH_BUTTON 0
+#define TOUCH_BUTTON 1


big edit for one-byte RX TX

big edit for one-byte RX TX

--- arduttons.ino
+++ arduttons.ino
@@ -14,10 +14,9 @@
 const int pins[pinc] = {5,6,7,8}; //physical to logical pin address
 const int eeprom[pinc] = {0,1,2,3}; //pin address in eeprom

-volatile int pineepromstate[pinc] = {0,0,0,0};
 volatile int pinhardstate[pinc] = {0,0,0,0};
 volatile int pinsoftstate[pinc] = {0,0,0,0};
-volatile unsigned long pintime[pinc] = {0,0,0,0};
+int pineepromstate[pinc] = {0,0,0,0};
 int pinreport[pinc] = {0,0,0,0};

 byte mac[] = {0x02, 0x80, 0xC2, 0x00, 0x00, 0x01};
@@ -26,6 +25,16 @@
 byte gateway[] = {192, 168, 12, 1};
 byte mask[] = {255, 255, 255, 0};

+//
+const int BUTTON1 = 1;
+const int BUTTON2 = 2;
+const int BUTTON3 = 4;
+const int BUTTON4 = 8;
+const int TSTMODE = 16;
+const int DORESET = 32;
+const int GETSTAT = 64;
+
+//
 EthernetServer server(2323);

 //
@@ -42,16 +51,12 @@
       //
          pinhardstate[i] = 1;
          pinsoftstate[i] = 1;
-         pineepromstate[i] = 1;
-         EEPROM.write(eeprom[i], 1);
-         pintime[i] = millis();
          }
       else
          if (state==HIGH && pinhardstate[i]==1) // ...button up
             {
          //
             pinhardstate[i] = 0;
-            pintime[i] = millis() - pintime[i];
             }
       }
 }
@@ -76,7 +81,7 @@
       }

    //
-   Timer1.initialize(100000); // 10Hz // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz)
+   Timer1.initialize(10000); // 100Hz
    Timer1.attachInterrupt( timerIsr );

    //Start up the serial port
@@ -87,31 +92,70 @@
    server.begin();
 }

+//
+char getstatus()
+{
+//
+   char result = 0;
+   for (int i = 0; i < pinc; i++)
+      if (pineepromstate[i] == 1) result &= 1 << i;
+   return result;
+}
+
 // the loop routine runs over and over again forever:
 void loop()
 {
-//
+//
+   //process up-down events
+   for (int i = 0; i < pinc; i++)
+      if (pinsoftstate[i]==1)
+         {
+      //
+         EEPROM.write(eeprom[i], 1);
+         pineepromstate[i] = 1;
+         pinsoftstate[i] = 0;
+         pinreport[i] = 0;
+         }
+
+   //down always send to client
    for (int i = 0; i < pinc; i++)
       {
    //
-      //анализ pinsoftstate? без pinreport? где сообщать клиенту?
-      if (pinhardstate[i] == 1 && pinsoftstate[i]==1 && pinreport[i]==0)
+       if (pinreport[i] == 0 && pineepromstate[i]==1)
          {
       //
-         server.println();
-         server.print("pin down["); server.print(i, DEC); server.print("]");
-
+         server.write( getstatus() );
          pinreport[i] = 1;
          }
-      else
-         if (pinhardstate[i] == 0 && pinsoftstate[i]==1 && pinreport[i]==1)
+      }
+
+   //process command from station
+   while (EthernetClient client = server.available())
+      while (client.available())
+         {
+      //
+         char cmd = client.read();
+         if (cmd & TSTMODE)
             {
          //
-            server.println();
-            server.print("pintime["); server.print(i, DEC); server.print("]="); server.print(pintime[i], DEC);
-
-            pinsoftstate[i] = 0;
-            pinreport[i] = 0;
+            cmd &= GETSTAT;
             }
-      }
+         //else
+         if (cmd & DORESET)
+            {
+         //
+            for (int i = 0; i < pinc; i++)
+               {
+            //
+               EEPROM.write(eeprom[i], 0);
+               pineepromstate[i] = 0;
+               }
+            }
+         //else
+         if (cmd & GETSTAT)
+            {
+         //
+            server.write(cmd & getstatus());
+            }
+         }
 }


A NeoClock mockup for 12 LEDs

A NeoClock mockup for 12 LEDs


Switch to using the Adafruit motor shield (v2.3). It is I2C based so uses fewer GPIO but that means twi must be left on.

--- fed-arduino/fed-arduino.ino
+++ fed-arduino/fed-arduino.ino
@@ -1,22 +1,27 @@
+
 #include <avr/sleep.h>
 #include <avr/power.h>
 #include <avr/wdt.h>
 #include <SdFat.h>                // SD and RTC libraries
 #include "RTClib.h"
 #include <Wire.h>
-#include <Stepper.h>
 #include <SPI.h>
 #include <Adafruit_GFX.h>
 #include <Adafruit_SharpMem.h>
 #include <avr/interrupt.h>
 #include <avr/io.h>
 #include <SoftwareSerial.h>
+#include <Adafruit_MotorShield.h>
+#include "utility/Adafruit_PWMServoDriver.h"

 #define FILENAME "PELLET_Cage12.csv"

 #define DISPLAY_SERIAL_RX_PIN 255 // we don't need a receive pin, 255 indicates this
 // Connect the Arduino pin 3 to the rx pin on the 7 segment display
 #define DISPLAY_SERIAL_TX_PIN 9
+
+// Photo interrupter is also the wakeup for the system
+#define PHOTO_INTERRUPTER_PIN 2

 SoftwareSerial LEDserial = SoftwareSerial(DISPLAY_SERIAL_RX_PIN, DISPLAY_SERIAL_TX_PIN);
 SdFat SD;
@@ -34,24 +39,19 @@
 String time;
 File dataFile;

-const int MOTOR_INPUT1_PIN = 7 ;
-const int MOTOR_INPUT2_PIN = 6;
-const int MOTOR_INPUT3_PIN = 5;
-const int MOTOR_INPUT4_PIN = 4;
-const int steps = 64;
-const int MOTOR_STEPS_PER_REVOLUTION = 512;
-const int MOTOR_ENABLE34_PIN = 8;
-const int MOTOR_ENABLE12_PIN = 0;
-const int TTL = 3;
-
+const int TTL_DEBUG_PIN = 3;
+
+const int STEPS_TO_INCREMENT = 64;
+const int MOTOR_STEPS_PER_REVOLUTION = 513;

 int PIState = 1;
 int lastState = 1;
-int PIPin = 2;

 int pelletCount = 0;

-Stepper motor(MOTOR_STEPS_PER_REVOLUTION, MOTOR_INPUT1_PIN, MOTOR_INPUT2_PIN, MOTOR_INPUT3_PIN, MOTOR_INPUT4_PIN);
+// Stepper motor with shield test
+Adafruit_MotorShield gMotorShield = Adafruit_MotorShield();
+Adafruit_StepperMotor *gPtrToStepper = gMotorShield.getStepper(MOTOR_STEPS_PER_REVOLUTION,2);

 int logData() {
   String year, month, day, hour, minute, second;
@@ -89,31 +89,9 @@
   power_spi_disable();
 }

-void setMotorToTurn() {
-    pinMode(MOTOR_INPUT1_PIN, OUTPUT);
-    pinMode(MOTOR_INPUT2_PIN, OUTPUT);
-    pinMode(MOTOR_INPUT3_PIN, OUTPUT);
-    pinMode(MOTOR_INPUT4_PIN, OUTPUT);
-
-    pinMode(MOTOR_ENABLE12_PIN, OUTPUT);
-    pinMode(MOTOR_ENABLE34_PIN, OUTPUT);
-    digitalWrite(MOTOR_ENABLE12_PIN, HIGH);
-    digitalWrite(MOTOR_ENABLE34_PIN, HIGH);
-}
-
-void setMotorToSleep()
-{
-    digitalWrite(MOTOR_ENABLE12_PIN, LOW);
-    digitalWrite(MOTOR_ENABLE34_PIN, LOW);
-
-    pinMode(MOTOR_INPUT1_PIN, INPUT_PULLUP);
-    pinMode(MOTOR_INPUT2_PIN, INPUT_PULLUP);
-    pinMode(MOTOR_INPUT3_PIN, INPUT_PULLUP);
-    pinMode(MOTOR_INPUT4_PIN, INPUT_PULLUP);
-}
-
 void setup()
 {
+
   // make all unused pins inputs with pullups enabled by default, lowest power drain
   // leave pins 0 & 1 (Arduino RX and TX) as they are
   for (byte i=2; i <= 20; i++) {
@@ -135,13 +113,19 @@
   delay(1); // allow a very short delay for display response
   setDisplayValues(pelletCount);

-  pinMode(PIPin, INPUT);
-  pinMode(TTL, OUTPUT);
+  pinMode(PHOTO_INTERRUPTER_PIN, INPUT);
+  pinMode(TTL_DEBUG_PIN, OUTPUT);
   pinMode(CS_pin, OUTPUT);
   pinMode(SS, OUTPUT);

   Wire.begin();
+
+  // both the stepper control and RTC use I2C (the Wire library)
   RTC.begin(); // RTC library needs Wire
+
+  // set up stepper
+  gMotorShield.begin(); // use default I2C address of 0x40
+  gPtrToStepper->setSpeed(30); // rpm, max suggested by Adafruit for this 5V stepper

   if (! RTC.isrunning()) {
     Serial.println(F("RTC is NOT running!"));
@@ -172,34 +156,23 @@
     dataFile.println(F("Time,Pellet Count,Pellet Drop Delay"));
     dataFile.close();
   }
-
-  motor.setSpeed(35);
-  setMotorToTurn();
-
+
   delay (500);

   // get ready for what the system should be doing
-  PIState = digitalRead(PIPin);
+  PIState = digitalRead(PHOTO_INTERRUPTER_PIN);
   lastState = 0;
-
 }

 void loop()
 {
-  PIState = digitalRead(PIPin);
+  PIState = digitalRead(PHOTO_INTERRUPTER_PIN);
   Serial.print("Photointerrupter State: ");
   Serial.println(PIState);
-  digitalWrite(TTL, LOW);
-
-  if (PIState == 1  & PIState != lastState) {
-    setMotorToTurn();
-
-    digitalWrite(TTL, HIGH);
-    delay(50);
-    digitalWrite(MOTOR_INPUT1_PIN, HIGH);
-    digitalWrite(MOTOR_INPUT2_PIN, HIGH);
-    digitalWrite(MOTOR_INPUT3_PIN, HIGH);
-    digitalWrite(MOTOR_INPUT4_PIN, HIGH);
+  digitalWrite(TTL_DEBUG_PIN, LOW);
+
+  if (PIState == 1  & PIState != lastState) {
+    digitalWrite(TTL_DEBUG_PIN, HIGH);
     startTime = millis();
     Serial.print(F("Time Elapsed Check: "));
     Serial.println(timeElapsed);
@@ -208,15 +181,17 @@
     pelletCount ++;
     Serial.println(F("It did work"));
     clearDisplay();
-    delay(1); // allow a very short delay for display response
+    delay(2); // allow a very short delay for display response
     setDisplayValues(pelletCount);
     lastState = PIState;
-
   }
   else if (PIState == 1) {
     Serial.println(F("Turning motor..."));
-    motor.step(-steps / 2);
-    motor.step(steps);
+    power_twi_enable();
+    gPtrToStepper->step(STEPS_TO_INCREMENT/2,FORWARD,DOUBLE);
+    gPtrToStepper->step(STEPS_TO_INCREMENT,BACKWARD,DOUBLE);
+    gPtrToStepper->release();
+    power_twi_disable();
     lastState = PIState;
   }

@@ -225,16 +200,10 @@
     timeElapsed = millis() - startTime;
     Serial.println(timeElapsed);
     lastState = PIState;
-
   }

   else  {
     lastState = PIState;
-    digitalWrite(MOTOR_INPUT1_PIN, LOW);
-    digitalWrite(MOTOR_INPUT2_PIN, LOW);
-    digitalWrite(MOTOR_INPUT3_PIN, LOW);
-    digitalWrite(MOTOR_INPUT4_PIN, LOW);
-    setMotorToSleep();
     enterSleep();
   }


Adjustments for different motors.  Adjustment for 9V battery.

--- linefollow/linefollow.ino
+++ linefollow/linefollow.ino
@@ -8,18 +8,13 @@
 RedBotSensor center = RedBotSensor(A6); // initialize a center sensor object on A6
 RedBotSensor right = RedBotSensor(A7);  // initialize a right sensor object on A7

-#define SPEED 120  // sets the nominal speed. Set to any number from 0 - 255.
+#define SPEED 100
+#define MIN_SPEED 60

-#define SPEED_ADJUSTMENT 30
-
-#define COUNTER_MAX 20
+#define SPEED_ADJUSTMENT 20

 // These thresholds are manually configured.
 #define TAPE_THRESHOLD  150 // below this value, we are looking at the tape
-
-#define NOT_SET 0
-#define TAPE_STATE 1
-#define NOT_TAPE_STATE 2

 RedBotMotors motors;
 int leftSpeed;   // variable used to store the leftMotor speed
@@ -62,7 +57,7 @@
     driftingLeft = true;
     driftingRight = false;

-    rightSpeed -= SPEED_ADJUSTMENT;
+    leftSpeed += SPEED_ADJUSTMENT;
   }

   // drift right
@@ -72,7 +67,7 @@
     driftingRight = true;
     driftingLeft = false;

-    leftSpeed -= SPEED_ADJUSTMENT;
+    rightSpeed += SPEED_ADJUSTMENT;
   }

   // recovery
@@ -80,11 +75,11 @@
   {
     if(driftingLeft) {
       leftSpeed = SPEED;
-      rightSpeed = 70;
+      rightSpeed = MIN_SPEED;
     }
     else if(driftingRight) {
       rightSpeed = SPEED;
-      leftSpeed = 70;
+      leftSpeed = MIN_SPEED;
     }
   }

@@ -111,11 +106,11 @@
 }

 void driveLeftForward(int speed) {
-  motors.leftMotor(-1 * speed);
+  motors.leftMotor(-0.9 * speed);
 }

 void driveLeftBackward(int speed) {
-  motors.leftMotor(speed);
+  motors.leftMotor(0.9 * speed);
 }

 void driveRightForward(int speed) {


minor change 420

minor change 420

--- proj/hypercube/HCS/HCS.ino
+++ proj/hypercube/HCS/HCS.ino
@@ -202,8 +202,11 @@

   // Handle switching between outer shell animations. Don't do this if we're
   // already switching the inner shell though, don't want to figure that out
-  EVERY_N_SECONDS(10) {
+  EVERY_N_SECONDS(30) {
     oAnimCounter = (oAnimCounter + 1) % numAnimation;
+    if((oAnimCounter == 7 || oAnimCounter == 9) && oPaletteCounter == 1) {
+      oAnimCounter++;
+    }
     if(oAnimCounter == 0) {
       oPaletteCounter = (oPaletteCounter + 1) % numPalStyles;
       if(oPaletteCounter == 0) {
@@ -213,16 +216,20 @@
   }

   // Same deal for the inner shell
-  //EVERY_N_SECONDS(125) {
-  //  iAnimCounter = (iAnimCounter + 1) % numAnimation;
-  //}
+  EVERY_N_SECONDS(20) {
+    iAnimCounter = (iAnimCounter + 1) % numAnimation;
+    if((iAnimCounter == 7 || iAnimCounter == 9) && iPaletteCounter == 1) {
+      iAnimCounter++;
+    }
+    if(iAnimCounter == 0) {
+      iPaletteCounter = (iPaletteCounter +1) % numPalStyles;
+    }
+  }
+  updatePaletteScheme();
+  updateGPalette();

   //// Update the global color palette. This is just the color scheme
   //// that we will then repackage to have different spacial distributions
-  //EVERY_N_SECONDS(480) {
-  //  gPaletteCounter = (gPaletteCounter+1)%numPalettes;
-  //}
-  updatePaletteScheme();

   // Update the palette style for the inner and outer shells. This
   // is basically how we package the given color palette.
@@ -236,45 +243,44 @@
   //  // though since it alternates every time the timer is up.
   //    iPaletteCounter = (iPaletteCounter + 1) % numPalStyles;
   //}
-  updateGPalette();

   // Add the random strobe to this list of animations since we aren't going to use it
   // for the overlays
-  //switch (iAnimCounter) {
-  //  case 0:
-  //    chase_straight(INNER, false);
-  //    break;
-  //  case 1:
-  //    shell_wrap(INNER, false, 0);
-  //    break;
-  //  case 2:
-  //    chase_mod(INNER, 0, false);
-  //    break;
-  //  case 3:
-  //    chase_spiral_static(INNER, 16, false);
-  //    break;
-  //  case 4:
-  //    shell_wrap(INNER, false, 1);
-  //    break;
-  //  case 5:
-  //    chase_mod(INNER, 1, false);
-  //    break;
-  //  case 6:
-  //    chase_spiral_mod(INNER, false);
-  //    break;
-  //  case 7:
-  //    shell_wrap(INNER, false, 2);
-  //    break;
-  //  case 8:
-  //    chase_mod(INNER, 2, false);
-  //    break;
-  //  case 9:
-  //    shell_wrap(INNER, false, 3);
-  //    break;
-  //  case 10:
-  //    fill_shell(INNER);
-  //    break;
-  //}
+  switch (iAnimCounter) {
+    case 0:
+      chase_straight(INNER, false);
+      break;
+    case 1:
+      shell_wrap(INNER, false, 0);
+      break;
+    case 2:
+      chase_mod(INNER, 0, false);
+      break;
+    case 3:
+      chase_spiral_static(INNER, 16, false);
+      break;
+    case 4:
+      shell_wrap(INNER, false, 1);
+      break;
+    case 5:
+      chase_mod(INNER, 1, false);
+      break;
+    case 6:
+      chase_spiral_mod(INNER, false);
+      break;
+    case 7:
+      shell_wrap(INNER, false, 2);
+      break;
+    case 8:
+      chase_mod(INNER, 2, false);
+      break;
+    case 9:
+      shell_wrap(INNER, false, 3);
+      break;
+    case 10:
+      fill_shell(INNER);
+      break;
+  }
   switch (oAnimCounter) {
     case 0:
       chase_straight(OUTER, true);


Read frames from serial port. Uses single buffering only.

--- telepulssi_driver.ino
+++ telepulssi_driver.ino
@@ -20,10 +20,12 @@
 */

 void setup() {
-	// Set output pins
+	// Set output pins for LED display
 	DDRC = 0xFF;
 	DDRD = 0xFF;
-	// initialize SPI:
+	// Initialize serial
+	Serial.begin(9600);
+	// initialize SPI
 	SPI.begin();
 	Timer1.initialize(200);
 	Timer1.attachInterrupt(driveDisplay);
@@ -31,8 +33,25 @@

 uint8_t col_i = 0;
 uint8_t row_i = 0;
+int buf_i = 0;

 void loop() {
+	if (Serial.available() > 0) {
+                // read the incoming byte
+                uint8_t data = Serial.read();
+		if (data > 32) {
+			// If sending escape, reset buffer to beginning
+			buf_i = 0;
+			Serial.write('R');
+			return;
+		}
+
+		koira14[buf_i++] = data;
+		if (buf_i == sizeof(koira14)) {
+			buf_i = 0;
+			Serial.write('K');
+		}
+        }
 }

 void driveDisplay() {
@@ -68,6 +87,6 @@
 	// Pull down latch
 	digitalWrite(5, LOW);

-	// Send new data and sleep a bit. FIXME use clock interrupt
+	// Send new data to SPI. Don't wait it to complete
 	SPDR = koira14[8*row_i+col_i];
 }


linear led displaying is working

linear led displaying is working

--- project.ino
+++ project.ino
@@ -34,12 +34,12 @@
   changeColorLinear(distance);
   printDistance(distance);

-  delay(500);
+  delay(1000);
 }

-long changeColorLinear(int distance){
-  int maxDistance = 160;
-  int minDistance = 10;
+void changeColorLinear(int distance){
+  float maxDistance = 200;
+  float minDistance = 10;

   uint32_t leds[strip.numPixels()];

@@ -53,15 +53,14 @@
   distance = max(minDistance, distance);
   distance = min(maxDistance, distance);

-  int height = (maxDistance - minDistance) / (distance - minDistance);
-
+  int height = 16 - (16 * ( (distance - minDistance) / (maxDistance - minDistance) ) );
+
   Serial.print("height: ");
   Serial.print(height);
   Serial.println();

   for(uint16_t i=0; i<strip.numPixels(); i++) {
-
-    if(height >= i){
+    if(i <= height){
       strip.setPixelColor(i, leds[i]);
     }
     else{


Correct typos in comments

Correct typos in comments

--- pseudoRandom_Demo/pseudoRandom_Demo.ino
+++ pseudoRandom_Demo/pseudoRandom_Demo.ino
@@ -13,7 +13,7 @@

 void setup() {
   // put your setup code here, to run once:
-  // Use reading on Analog pin 0 for a randon seed
+  // Use reading on Analog pin 0 for a random seed
   randomSeed(analogRead(0));
   // Initialize each pin in array to Output and Low (off)
   for (int x=0; x<4; x++) {


fixed stepper struct

fixed stepper struct

--- src/resource/Arduino/MRLComm2.ino
+++ src/resource/Arduino/MRLComm2.ino
@@ -853,8 +853,8 @@
 			stepper.speed = 100;

 			if (stepper.type == STEPPER_TYPE_SIMPLE) {
-				stepper.step0 = ioCmd[3]; // dir pin
-				stepper.step1 = ioCmd[4]; // step pin
+				stepper.dirPin = ioCmd[3]; // dir pin
+				stepper.stepPin = ioCmd[4]; // step pin
 			} else {
 				sendError(ERROR_UNKOWN_CMD);
 			}
@@ -1178,17 +1178,17 @@
 				if (stepper.currentPos < stepper.targetPos) {

 				    // step - POLOLU has single step pin (dir is on step0)
-					digitalWrite(stepper.step1, 1);
+					digitalWrite(stepper.stepPin, 1);
 					delayMicroseconds(1); // :P should require another state? loop is ~106us min ?
-					digitalWrite(stepper.step1, 0);
+					digitalWrite(stepper.stepPin, 0);

 					stepper.currentPos++;
 				} else if (stepper.currentPos > stepper.targetPos) {

 				    // step - POLOLU has single step pin (dir is on step0)
-					digitalWrite(stepper.step1, 1);
+					digitalWrite(stepper.stepPin, 1);
 					delayMicroseconds(1); // :P should require another state? loop is ~106us min ?
-					digitalWrite(stepper.step1, 0);
+					digitalWrite(stepper.stepPin, 0);

 					stepper.currentPos--;


Reduce delay from 4 to 2 seconds

Reduce delay from 4 to 2 seconds

--- rf95_client/rf95_client.ino
+++ rf95_client/rf95_client.ino
@@ -58,7 +58,7 @@
   {
     Serial.println("No reply, is rf95_server running?");
   }
-  delay(4000);
+  delay(2000);
 }


Update Triple_IR_and_Motors.ino

Update Triple_IR_and_Motors.ino

--- Testing/Triple_IR_and_Motors/Triple_IR_and_Motors.ino
+++ Testing/Triple_IR_and_Motors/Triple_IR_and_Motors.ino
@@ -1,4 +1,4 @@
-nt left, right, front;
+int left, right, front;

 int E1 = 6;
 int M1 = 7;