Delete sequencial_turn_signal_4_8_0zxy.ino

Version 4.8.0 no longer supported. Update to 4.9.3 or later.

--- sequencial_turn_signal_4_8_0zxy/sequencial_turn_signal_4_8_0zxy.ino
+++ sequencial_turn_signal_4_8_0zxy/sequencial_turn_signal_4_8_0zxy.ino
@@ -1,448 +0,0 @@
-/*
-
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-+                                                       +
-+  Program: Sequential Turn Signal Master               +
-+  Version: 4.8.2zxy                                    +
-+  Purpose: Using a 3 taillight per side configuration  +
-+           this program will make them flash           +
-+           sequentially for turn signal and brake.     +
-+           Now and later supports tap signaling.       +
-+  Author: Jason Saler                                  +
-+  First Created: 05/06/2013                            +
-+  Date Last Edited: 06/24/2017                         +
-+                                                       +
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-*/
-
-// Define the input pins: Pin 9 will be right input, Pin 10 will be left input and Pin 11 will be brake input
-// 12 is Mode input which switches the program from sequential pattern to standard pattern
-#define RIGHT_SIGNAL_INPUT 9
-#define LEFT_SIGNAL_INPUT 10
-#define BRAKE_INPUT 11
-#define MODE_INPUT 12
-
-// Depending on the relay board this may need to be reversed
-#define ON LOW
-#define OFF HIGH
-
-// Several standard time lengths in milliseconds
-#define FAST_BLINK 100
-#define QUICK_BLINK 200
-#define MEDIUM_BLINK 250
-#define LONG_BLINK 350
-#define SLOW_BLINK 450
-#define PAUSE_SECOND 1000
-
-// The number of times a turning indicator sequence will run through on a tap
-#define MAX_REPEAT_ON_TAP 3
-
-// Now declare the 8 light output pins, 4 per side. Variable names are quite descriptive
-// Can use basically any pin, but note: Pin 13 has an LED connected on most Arduino boards.
-const int leftMarkers = 1;
-const int leftOuter = 2;
-const int leftMiddle = 3;
-const int leftInner = 4;
-const int rightInner = 5;
-const int rightMiddle = 6;
-const int rightOuter = 7;
-const int rightMarkers = 8;
-
-// Variables
-bool isRightTap = false;
-bool isLeftTap = false;
-int flashCount = 0;
-
-// I. the setup routine runs once when you press reset: This loop will reset all the variables to their starting type and state.
-void setup()
-{
-  // Initialize the LEDs as outputs.
-  pinMode(rightInner, OUTPUT);
-  pinMode(rightMiddle, OUTPUT);
-  pinMode(rightOuter, OUTPUT);
-  pinMode(leftInner, OUTPUT);
-  pinMode(leftMiddle, OUTPUT);
-  pinMode(leftOuter, OUTPUT);
-  pinMode(rightMarkers, OUTPUT);
-  pinMode(leftMarkers, OUTPUT);
-
-  // Initialize the input pins as, well, inputs of course...
-  pinMode(RIGHT_SIGNAL_INPUT, INPUT);
-  pinMode(LEFT_SIGNAL_INPUT, INPUT);
-  pinMode(BRAKE_INPUT, INPUT);
-  pinMode(MODE_INPUT, INPUT);
-
-  // Set the initial inputs as HIGH. Could also be done as low, but then all the states should be reversed throughout the program: 1 to 0 and visa versa.
-  digitalWrite(RIGHT_SIGNAL_INPUT, HIGH);
-  digitalWrite(LEFT_SIGNAL_INPUT, HIGH);
-  digitalWrite(BRAKE_INPUT, HIGH);
-  digitalWrite(MODE_INPUT, HIGH);
-}
-
-// II. The loop routine runs over and over again forever(or at least as long as the board has power and is working...)
-//    This handles all of the actual light blinking and what not.
-void loop()
-{
-  // 1. First the program will check if the brakes are on; if all inputs are 1, then nothing is on.
-  //    So nothing is lit up, set all the lights to LOW which is off.
-  if((digitalRead(RIGHT_SIGNAL_INPUT) == 1) and (digitalRead(LEFT_SIGNAL_INPUT) == 1) and (digitalRead(BRAKE_INPUT) == 1) and (!isRightTap) and (!isLeftTap))
-  {
-    off();
-    resetFlashCount();
-  }
-
-   // 2. Next chack if the brakes are on (when BRAKE_INPUT is 0).
-   if(digitalRead(BRAKE_INPUT) == 0)
-   {
-     if((digitalRead(RIGHT_SIGNAL_INPUT) == 1) and (digitalRead(LEFT_SIGNAL_INPUT) == 1) and (digitalRead(BRAKE_INPUT) == 0) and digitalRead(MODE_INPUT) == 0)
-     {
-       brakeSequenceFlashOn(FAST_BLINK);
-     }
-
-     // 2.1 Keep the lights lit as long as the brake is on
-     while(digitalRead(BRAKE_INPUT) == 0)
-     {
-
-      if((digitalRead(LEFT_SIGNAL_INPUT) == 1) and (digitalRead(RIGHT_SIGNAL_INPUT) == 1))
-      {
-        (digitalRead(MODE_INPUT) == 0) ? (brakeSequenceHoldOn()) : (brake());
-      }
-
-      // 2.2 Here is if the right turn signal and brake are on.
-      if( (digitalRead(LEFT_SIGNAL_INPUT) == 1) and ( (digitalRead(RIGHT_SIGNAL_INPUT) == 0) || (isRightTap) ) )
-      {
-        (digitalRead(MODE_INPUT) == 0) ? (rightSequenceBrake(QUICK_BLINK, QUICK_BLINK)) : (rightBlinkBrake(SLOW_BLINK, MEDIUM_BLINK));
-      }
-
-      // 2.3. Now if the left turn signal and brake are both on
-      if( (digitalRead(RIGHT_SIGNAL_INPUT) == 1) and ( (digitalRead(LEFT_SIGNAL_INPUT) == 0) || (isLeftTap) ) )
-      {
-        (digitalRead(MODE_INPUT) == 0) ? (leftSequenceBrake(QUICK_BLINK, QUICK_BLINK)) : (leftBlinkBrake(SLOW_BLINK, MEDIUM_BLINK));
-      }
-     }
-
-     if((digitalRead(LEFT_SIGNAL_INPUT) == 1) and (digitalRead(RIGHT_SIGNAL_INPUT) == 1) and (digitalRead(MODE_INPUT) == 0) and (!isRightTap) and (!isLeftTap) )
-     {
-       brakeSequenceFlashOff(FAST_BLINK);
-     }
-   }
-
-  // 3. Now checking for the emergency flashers being on, when this happens a fun litle flashing pattern is performed to warn other drivers of emergencies.
-  else if(( digitalRead(RIGHT_SIGNAL_INPUT) == 0) and (digitalRead(LEFT_SIGNAL_INPUT) == 0) and (digitalRead(BRAKE_INPUT) == 1))
-  {
-    (digitalRead(MODE_INPUT) == 0) ? (emergencyFlasherSequence(FAST_BLINK, MEDIUM_BLINK, SLOW_BLINK)) : (emergencyFlasherBlink(SLOW_BLINK, MEDIUM_BLINK));
-  }
-
-  // 4. This is the section if the brakes are on and the emergency flashers are on. A unique flashing pattern will be run in this case.
-  //    Due to unreliability of the arduino, this section has been omitted for real life use. (The board kept confusing which input was received) After removing this section the lights have been working flawlessly
-  if(( digitalRead(RIGHT_SIGNAL_INPUT) == 0) and (digitalRead(LEFT_SIGNAL_INPUT) == 0) and (digitalRead(BRAKE_INPUT) == 0))
-  {
-    if(digitalRead(MODE_INPUT) == 0)
-      brakeSequenceFlashOn(FAST_BLINK);
-
-    while(digitalRead(BRAKE_INPUT) == 0)
-    {
-      (digitalRead(MODE_INPUT) == 0) ? (brakeSequenceHoldOn()) : (brake());
-    }
-
-    if(digitalRead(MODE_INPUT) == 0)
-      brakeSequenceFlashOff(FAST_BLINK);
-  }
-
-  else
-  {
-    // 5. This is if the right turn signal is on, do a cycle through the lights.
-    if( ( (digitalRead(LEFT_SIGNAL_INPUT) == 1) and (digitalRead(BRAKE_INPUT) == 1) ) and ( (digitalRead(RIGHT_SIGNAL_INPUT) == 0) || (isRightTap) ) )
-    {
-      (digitalRead(MODE_INPUT) == 0) ? (rightSequence(QUICK_BLINK, QUICK_BLINK)) : (rightBlink(SLOW_BLINK, MEDIUM_BLINK));
-    }
-
-    // 6. Here is if the left turn signal is on. Cycle through the lights.
-    if( ( (digitalRead(RIGHT_SIGNAL_INPUT) == 1) and (digitalRead(BRAKE_INPUT) == 1) ) and ( (digitalRead(LEFT_SIGNAL_INPUT) == 0) || (isLeftTap) ) )
-    {
-      (digitalRead(MODE_INPUT) == 0) ? (leftSequence(QUICK_BLINK, QUICK_BLINK)) : (leftBlink(SLOW_BLINK, MEDIUM_BLINK));
-    }
-  }
-}
-
-// III. All constructive functions are found below.
-//      Two options are given for each action, a regular blink or a sequential pattern.
-
-void rightSequence(int durationMillis, int pauseDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(ON, OFF, OFF, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(ON, ON, OFF, ON);
-  delay(durationMillis);
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(ON, ON, ON, ON);
-  delay(durationMillis);
-
-  off();
-  delay(pauseDurationMillis);
-
-  updateTapControl();
-}
-
-void rightBlink(int durationMillis, int offDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(OFF, ON, ON, ON);
-  delay(durationMillis);
-
-  off();
-  delay(offDurationMillis);
-
-  updateTapControl();
-}
-
-void leftSequence(int durationMillis, int pauseDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(ON, OFF, OFF, OFF);
-  selectRightOn(OFF, OFF, OFF, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, ON, OFF, ON);
-  selectRightOn(OFF, OFF, OFF, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, ON, ON, ON);
-  selectRightOn(OFF, OFF, OFF, OFF);
-  delay(durationMillis);
-
-  off();
-  delay(pauseDurationMillis);
-
-  updateTapControl();
-}
-
-void leftBlink(int onDurationMillis, int offDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(OFF, ON, ON, ON);
-  selectRightOn(OFF, OFF, OFF, OFF);
-  delay(onDurationMillis);
-
-  off();
-  delay(offDurationMillis);
-
-  updateTapControl();
-}
-
-void rightSequenceBrake(int durationMillis, int pauseDurationMillis)
-{
-  checkIsTap();
-
-  selectRightOn(ON, OFF, OFF, OFF);
-  selectLeftOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectRightOn(ON, ON, OFF, ON);
-  selectLeftOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectRightOn(ON, ON, ON, ON);
-  selectLeftOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectRightOn(OFF, OFF, OFF, OFF);
-  selectLeftOn(ON, ON, ON, OFF);
-  delay(pauseDurationMillis);
-
-  updateTapControl();
-}
-
-void rightBlinkBrake(int onDurationMillis, int offDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(OFF, ON, ON, OFF);
-  selectRightOn(OFF, ON, ON, ON);
-  delay(onDurationMillis);
-
-  selectLeftOn(OFF, ON, ON, OFF);
-  selectRightOn(OFF, OFF, OFF, OFF);
-  delay(offDurationMillis);
-
-  updateTapControl();
-}
-
-void leftSequenceBrake(int durationMillis, int pauseDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(ON, OFF, OFF, OFF);
-  selectRightOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, ON, OFF, ON);
-  selectRightOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, ON, ON, ON);
-  selectRightOn(ON, ON, ON, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(ON, ON, ON, OFF);
-  delay(pauseDurationMillis);
-
-  updateTapControl();
-}
-
-void leftBlinkBrake(int onDurationMillis, int offDurationMillis)
-{
-  checkIsTap();
-
-  selectLeftOn(OFF, ON, ON, ON);
-  selectRightOn(OFF, ON, ON, OFF);
-  delay(onDurationMillis);
-
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(OFF, ON, ON, OFF);
-  delay(offDurationMillis);
-
-  updateTapControl();
-}
-
-void brakeSequenceFlashOn(int durationMillis)
-{
-  selectLeftOn(ON, OFF, OFF, OFF);
-  selectRightOn(ON, OFF, OFF, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, ON, OFF, OFF);
-  selectRightOn(ON, ON, OFF, OFF);
-  delay(durationMillis);
-}
-
-void brakeSequenceFlashOff(int durationMillis)
-{
-  selectLeftOn(ON, ON, OFF, OFF);
-  selectRightOn(ON, ON, OFF, OFF);
-  delay(durationMillis);
-
-  selectLeftOn(ON, OFF, OFF, OFF);
-  selectRightOn(ON, OFF, OFF, OFF);
-  delay(durationMillis);
-}
-
-void brakeSequenceHoldOn()
-{
-  selectLeftOn(ON, ON, ON, OFF);
-  selectRightOn(ON, ON, ON, OFF);
-}
-
-void brake()
-{
-  selectLeftOn(OFF, ON, ON, OFF);
-  selectRightOn(OFF, ON, ON, OFF);
-}
-
-void emergencyFlasherSequence(int flashDurationMillis, int offDurationMillis, int onDurationMillis)
-{
-  brakeSequenceFlashOn(flashDurationMillis);
-  selectLeftOn(ON, ON, ON, ON);
-  selectRightOn(ON, ON, ON, ON);
-  delay(onDurationMillis);
-
-  brakeSequenceFlashOff(flashDurationMillis);
-  off();
-  delay(offDurationMillis);
-}
-
-void emergencyFlasherBlink(int onDurationMillis, int offDurationMillis)
-{
-
-  selectLeftOn(OFF, ON, ON, ON);
-  selectRightOn(OFF, ON, ON, ON);
-  delay(onDurationMillis);
-
-  off();
-  delay(offDurationMillis);
-}
-
-void off()
-{
-  selectLeftOn(OFF, OFF, OFF, OFF);
-  selectRightOn(OFF, OFF, OFF, OFF);
-}
-
-//IIIa. Functions that handle the actual digital write actions.
-//      Separate function for left side and right side.
-
-void selectLeftOn(boolean  leftInnerPower, boolean leftMiddlePower, boolean leftOuterPower, boolean leftMarkersPower)
-{
-    digitalWrite(leftInner, leftInnerPower);
-    digitalWrite(leftMiddle,leftMiddlePower);
-    digitalWrite(leftOuter, leftOuterPower);
-    digitalWrite(leftMarkers, leftMarkersPower);
-}
-
-void selectRightOn(boolean rightInnerPower, boolean rightMiddlePower, boolean rightOuterPower, boolean rightMarkersPower)
-{
-    digitalWrite(rightInner, rightInnerPower);
-    digitalWrite(rightMiddle, rightMiddlePower);
-    digitalWrite(rightOuter, rightOuterPower);
-    digitalWrite(rightMarkers, rightMarkersPower);
-}
-
-// IIIb. Tap Logic Functions
-
-void checkIsTap()
-{
-  if(flashCount > 0)
-  {
-    if( (digitalRead(RIGHT_SIGNAL_INPUT) == 0) )
-    {
-      isRightTap = false;
-      resetFlashCount();
-    }
-    else if( (digitalRead(LEFT_SIGNAL_INPUT) == 0) )
-    {
-      isLeftTap = false;
-      resetFlashCount();
-    }
-  }
-  else
-  {
-    if( (digitalRead(RIGHT_SIGNAL_INPUT) == 0) )
-      isRightTap = true;
-    else if( (digitalRead(LEFT_SIGNAL_INPUT) == 0) )
-      isLeftTap = true;
-  }
-}
-
-void updateTapControl()
-{
-  flashCount++;
-  if( (flashCount > MAX_REPEAT_ON_TAP) and (isRightTap) )
-  {
-    isRightTap = false;
-    resetFlashCount();
-  }
-  else if( (flashCount > MAX_REPEAT_ON_TAP) and (isLeftTap) )
-  {
-    isLeftTap = false;
-    resetFlashCount();
-  }
-}
-
-void resetFlashCount()
-{
-  flashCount = 0;
-}
-
-


GSM added

GSM added

--- Arduino/Tracky/Tracky.ino
+++ Arduino/Tracky/Tracky.ino
@@ -2,7 +2,7 @@
 #include "CurieIMU.h"

 SoftwareSerial GPS(2, 3); // Rx, Tx
-//SoftwareSerial GSMmodule(4, 5); // Rx, Tx
+SoftwareSerial GSMmodule(4, 5); // Rx, Tx

 int Gpsdata;             // for incoming serial data
 unsigned int finish = 0; // indicate end of message
@@ -14,6 +14,19 @@
 char lt[20];            // latitude array
 char lg[20];             // longitude array

+char m_num_my[] = {"+918871408244"}; // Enter your number here
+char Rec_Data = 0;
+int msg_flg = 0;
+byte msg_flag_2 = 0;
+byte call_flag = 0;
+byte reply_flag = 0;
+byte delete_flag = 0;
+byte d_count = 0;
+byte i = 0;
+byte j = 0;
+char number[15];
+char message[160];
+
 int avgX = 0;
 int avgY = 0;
 int avgZ = 0;
@@ -25,27 +38,41 @@
 // Functions
 void setReference();
 void GPSData();
+void modem_initialization(void);
+void send_message(void);
+void command_match(void);
+void gsm_read_message();
 //void ring();
 /*******************************************************************************************
 Function Name: Setup
 *******************************************************************************************/
 void setup() {
+  delay(3000);
+  //Serial.begin(9600);
   Serial1.begin(9600); // initialize serial communication for BT
   GPS.begin(9600); // initialize serial communication for GPS
-  //GSMmodule.begin(9600); // initialize serial communication for GSM
+  GSMmodule.begin(9600); // initialize serial communication for GSM

-  // initialize device
   Serial1.println("Initializing IMU device...");
-  CurieIMU.begin();
-
-  // Set the accelerometer range to 3G
-  CurieIMU.setAccelerometerRange(3);
+  CurieIMU.begin(); // initialize device
+  CurieIMU.setAccelerometerRange(3); // Set the accelerometer range to 3G
+
+  Serial1.println("Modem initializing");
+  modem_initialization(); // initialize GSM modem
+  Serial1.println("Modem initialised");
   delay(1000);
 }
 /*******************************************************************************************
 Function Name: Loop
 *******************************************************************************************/
 void loop() {
+  gsm_read_message();//wait for message or call
+  if ( reply_flag == 1 ) //only if valid message received
+  {
+    Serial1.println(message);
+    command_match();
+    reply_flag = 0;
+  }
   //ring();
   if (Serial1.available() > 0) {
     char ch = Serial1.read();
@@ -60,6 +87,10 @@
     } else if (ch == '2') {
       Serial1.println("GPS");
       GPSData();
+      Serial1.print("G_");
+      Serial1.print(lt);
+      Serial1.print("_");
+      Serial1.println(lg);
     }
   }

@@ -92,6 +123,23 @@
   delay(50);
 }
 /*******************************************************************************************
+Function Name: command_match
+*******************************************************************************************/
+void command_match(void)
+{
+  if (strcmp(message, "1") == 0)
+  {
+    send_message();
+    delay(50);
+  }
+  /*else if ((strcmp(message, "off") == 0) || (strcmp(message, "OFF") == 0))
+  {
+    digitalWrite(light, LOW);
+    Serial.println("Turning LED off");
+    delay(50);
+  }*/
+}
+/*******************************************************************************************
 Function Name: setReference
 *******************************************************************************************/
 void setReference() {
@@ -123,8 +171,8 @@
 Function Name: GPSData
 *******************************************************************************************/
 void GPSData() {
-  while (!finish) {
-  Serial1.println(GPS.available());
+  //while (!finish) {
+  //Serial1.println(GPS.available());
     while (GPS.available() > 0) {       // Check GPS data
       Gpsdata = GPS.read();
       //Serial1.write(Gpsdata);
@@ -159,9 +207,422 @@
         finish  = 1;
       }
     }
-  }
-}
-
+  //}
+}
+/*******************************************************************************************
+Function Name: modem_initialization
+*******************************************************************************************/
+void modem_initialization(void)
+{
+  char rec_data;
+  byte network_status = 0 ;//network_status initialized as zero
+  byte status_check = 0 ;//status_check initialized as zero
+  byte gsm_cnt = 0;//gsm_cnt initialized as zero
+  byte ok_flag = 0; //ok_flag initialized as zero
+  //byte count = 0; //count initialized as zero
+  clear_rx_buffer();//clearing receiving buffer
+  while (gsm_cnt < 5) // repeat entire loop until gsm_cnt less than seven
+  {
+    switch (gsm_cnt)
+    {
+      case 0: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("AT");// Attention command to wake up GSM modem
+        delay(1000);
+        break;
+      case 1: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("ATE0");//Command for disable echo
+        delay(1000);
+        break;
+      case 2: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("ATV0");// Command for numeric response after this '0'(zero) will be recieved instead of "OK"
+        delay(1000);
+        break;
+      case 3: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("AT&W");// Command TO SAVE SETTINGS
+        delay(1000);
+        break;
+      case 4: gsm_cnt = 5;// exit from the loop
+        break;
+      default : break;
+    }
+    while (GSMmodule.available() > 0)
+    {
+      rec_data = GSMmodule.read();
+      if (rec_data == 'O' ) // 'o' is recieved
+        ok_flag = 1;
+      else if (ok_flag == 1 && rec_data == 'K' ) // 'K' is recieved
+      {
+        gsm_cnt ++;
+        ok_flag = 0;
+      }
+      else if (rec_data == '0' )// '0'(zero) is recieved (numeric response)
+      {
+        gsm_cnt ++;
+        ok_flag = 0;
+      }
+      else if (rec_data == '+' )// '+' is recieved message
+      {
+        clear_rx_buffer();//clearing receiving buffer
+
+        if ( gsm_cnt > 0 )
+          gsm_cnt --;
+      }
+    }
+  }
+  gsm_cnt = 0;
+  ok_flag = 0;
+  while (network_status == 0 ) //wait for PIN READY
+  {
+    if (status_check == 0 )
+    {
+      delay(1000);
+      status_check = 1 ;
+      clear_rx_buffer();//clearing receiving buffer
+      GSMmodule.println("AT+CPIN?"); //checkin PIN return ready(+CPIN: READY) with a valid simcard otherwise error
+    }
+    while (GSMmodule.available() > 0)
+    {
+      rec_data = GSMmodule.read();
+      if ( rec_data == '+' && status_check == 1 ) // '+' is recieved
+        status_check = 2 ;
+      else if ( rec_data == 'C' && status_check == 2 ) // 'C' is recieved
+        status_check = 3 ;
+      else if ( rec_data == 'P' && status_check == 3 ) // 'P' is recieved
+        status_check = 4 ;
+      else if ( rec_data == 'I' && status_check == 4 ) // 'I' is recieved
+        status_check = 5 ;
+      else if ( rec_data == 'N' && status_check == 5 ) // 'N' is recieved
+        status_check = 6 ;
+      else if ( rec_data == ':' && status_check == 6 ) // ':' is recieved
+        status_check = 7 ;
+      else if ( rec_data == ' ' && status_check == 7 ) // ' ' is recieved
+        status_check = 8 ;
+      else if ( rec_data == 'R' && status_check == 8 ) // 'R' is recieved
+        status_check = 9 ;
+      else if ( rec_data == 'E' && status_check == 9 ) // 'E' is recieved
+        status_check = 10 ;
+      else if ( rec_data == 'A' && status_check == 10 ) // 'A' is recieved
+        status_check = 11 ;
+      else if ( rec_data == 'D' && status_check == 11 ) // 'D' is recieved
+        status_check = 12 ;
+      else if ( rec_data == 'Y' && status_check == 12 ) // 'Y' is recieved
+        status_check = 13 ;
+      else if ( rec_data == 0X0D && status_check == 13 ) //Carriage return
+        status_check = 14 ;
+      else if ( rec_data == 0X0A && status_check == 14 ) //Line Feed
+        status_check = 15 ;
+      else if ( rec_data == '0' && status_check == 15 ) // '0' is recieved
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 1; //goto next step
+      }
+      else if ( rec_data != 'R' && status_check == 8 ) //+CPIN: NOT READY
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 0; //repeat current step
+      }
+      else if ( rec_data == 'M' && status_check == 3 ) // in case of any message
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 0; //repeat current step
+      }
+    }
+  }
+  while (network_status == 1 ) //wait for SIM network registration
+  {
+    if (status_check == 0 )
+    {
+      delay(1000);
+      status_check = 1 ;
+      clear_rx_buffer();//clearing receiving buffer
+      GSMmodule.println("AT+CREG?"); //checking for SIM card registration ,if registerd "+CREG: 0,1" will receive
+    }
+    while (GSMmodule.available() > 0)
+    {
+      rec_data = GSMmodule.read();
+      if ( rec_data == '+' && status_check == 1 ) // '+' is recieved
+        status_check = 2 ;
+      else if ( rec_data == 'C' && status_check == 2 ) // 'C' is recieved
+        status_check = 3 ;
+      else if ( rec_data == 'R' && status_check == 3 ) // 'R' is recieved
+        status_check = 4 ;
+      else if ( rec_data == 'E' && status_check == 4 ) // 'E' is recieved
+        status_check = 5 ;
+      else if ( rec_data == 'G' && status_check == 5 ) // 'G' is recieved
+        status_check = 6 ;
+      else if ( rec_data == ':' && status_check == 6 ) // ':' is recieved
+        status_check = 7 ;
+      else if ( rec_data == ' ' && status_check == 7 ) // ' ' is recieved
+        status_check = 8 ;
+      else if ( rec_data == '0' && status_check == 8 ) // '0' is recieved
+        status_check = 9 ;
+      else if ( rec_data == ',' && status_check == 9 ) // ',' is recieved
+        status_check = 10 ;
+      else if ( rec_data == '1' && status_check == 10 ) // '1' is recieved
+        status_check = 11 ;
+      else if ( rec_data == 0X0D && status_check == 11 ) //Carriage return
+        status_check = 12 ;
+      else if ( rec_data == 0X0A && status_check == 12 ) //Line Feed
+        status_check = 13 ;
+      else if ( rec_data == '0' && status_check == 13 ) // '0' is recieved
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 2; //goto next step
+      }
+      else if ( rec_data != '1' && status_check == 10 ) // +CREG: 0,2 not registered
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 1; //repeat current step
+      }
+      else if ( rec_data == 'M' && status_check == 3 ) // in case of any message
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        status_check = 0 ;
+        network_status = 1; //repeat current step
+      }
+    }
+  }
+  gsm_cnt = 0;
+  while (gsm_cnt < 4) // repeat entire loop until gsm_cnt less than nine
+  {
+    switch (gsm_cnt)
+    {
+      case 0: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("AT+CMGF=1");// Attention command to wake up GSM modem
+        delay(1000);
+        break;
+      case 1: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("AT+CNMI=2,1,0,0,0");//Command to configure new message indication
+        delay(1000);
+        break;
+      case 2: clear_rx_buffer();//clearing receiving buffer
+        GSMmodule.println("AT+CMGD=1,4");// Command to delete all received messages
+        delay(1000);
+        break;
+      case 3: gsm_cnt = 4;// exit from the loop
+        break;
+      default : break;
+    }
+    while (GSMmodule.available() > 0)
+    {
+      rec_data = GSMmodule.read();
+      if (rec_data == '0' )// '0'(zero) is recieved (numeric response)
+      {
+        gsm_cnt ++;
+      }
+      else if (rec_data == '+'  )// '+' recieved ,before "AT+CIICR" command,may be any message
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        if ( gsm_cnt > 0 )
+          gsm_cnt --;
+      }
+
+      else if (rec_data == '4' && gsm_cnt > 2)// '4' recieved (error),in gprs initialisation commands
+      {
+        clear_rx_buffer();//clearing receiving buffer
+        gsm_cnt = 4;
+      }
+    }
+  }
+  gsm_cnt = 0;
+}
+/*******************************************************************************************
+Function Name: gsm_read_message
+*******************************************************************************************/
+void gsm_read_message(void)
+{
+  while (GSMmodule.available() > 0)
+  {
+    Rec_Data = GSMmodule.read();
+    //Serial.write(Rec_Data);
+    if ( Rec_Data == '+'  && msg_flg == 0 ) // '+' is recieved
+      msg_flg = 1;
+    else if ( Rec_Data == 'C' && msg_flg == 1 ) // 'C' is recieved
+      msg_flg = 2;
+    else if ( Rec_Data == 'M' && msg_flg == 2 ) // 'M' is recieved
+      msg_flg = 3;
+    else if ( Rec_Data == 'T' && msg_flg == 3 ) // 'T' is recieved
+      msg_flg = 4;
+    else if ( Rec_Data == 'I' && msg_flg == 4 ) // 'I' is recieved (INCOMING MESSAGE )
+    {
+      clear_rx_buffer();//clearing receiving buffer
+      Rec_Data = 0;
+      msg_flg = 0;
+      delay(300);//Delay for GSM module become ready
+      array_clear();//Clear both message and number arrays
+      GSMmodule.println("AT+CMGR=1");//Command for message read from location one
+      i = 0; j = 0;
+    }
+    else if ( Rec_Data == 'G' && msg_flg == 3 ) // 'G' is recieved
+      msg_flg = 4;
+    else if ( Rec_Data == 'R' && msg_flg == 4 ) // 'R' is recieved,Readind message
+      msg_flg = 5;
+    else if ( Rec_Data == ':' && msg_flg == 5 ) // ':' is recieved
+      msg_flg = 6;
+    else if ( Rec_Data == '"' && msg_flg == 6  ) // Counting double quotes
+      d_count++;
+    else if ( Rec_Data != '"' && d_count == 3 && msg_flg == 6) // Saving number to message array from between third and fourth double quotes
+      number[i++] = Rec_Data;
+    else if ( Rec_Data == 0X0D && msg_flg == 6) //Carriage return
+      msg_flg = 7;
+    else if ( Rec_Data == 0X0A && msg_flg == 7) //Line feed
+      msg_flg = 8;
+    else if ( Rec_Data == '*' && d_count >= 5 &&  msg_flg == 8 ) //Start symbol '*' is recieved
+      msg_flag_2 = 1;
+    else if ( Rec_Data != '#' && msg_flag_2 == 1 &&  msg_flg == 8 && Rec_Data != 0X0D && Rec_Data != 0X0A ) //Data between start and stop symbols were saved to message array
+      message[j++] = Rec_Data;
+    else if ( Rec_Data == '#' && msg_flag_2 == 1 &&  msg_flg == 8) //Stop symbol '#' is recieved
+    {
+      msg_flag_2 = 2;
+      number[i] = '\0';
+      message[j] = '\0';
+      i = 0; j = 0;
+    }
+    else if (Rec_Data == 0X0D && msg_flg == 8) //Carriage return (end of message)
+    {
+      clear_rx_buffer();//clearing receiving buffer
+      msg_flg = 0;
+      delete_flag = 1;
+      delay(300);//Delay for GSM module become ready
+      GSMmodule.println("AT+CMGD=1,4");// Command for delete all messages in SIM card
+    }
+    else if ( Rec_Data == '0' && msg_flg == 0 && delete_flag == 1 ) //Response for delete command ,sucess all messages were deleted
+    {
+      if ( msg_flag_2 == 2 )
+        reply_flag = 1;//If the message have start and stop symbols it must be checked otherwise no need to check the recieved message
+      else
+        reply_flag = 0;//No need to check recieved message
+      msg_flg = 0;
+      msg_flag_2 = 0;
+      d_count = 0;
+      delete_flag = 0;
+    }
+    else if ( Rec_Data == '2' && msg_flg == 0 ) // '2' is recieved,incoming call
+    {
+      call_flag = 1;
+      delay(300);
+      GSMmodule.println("ATH");//Command for hang up incomming call,all calls must be filtered no need to answer a call
+    }
+    else if ( Rec_Data == '0' && msg_flg == 0 && call_flag == 1 ) // '0' (zero) is recieved,call sucessfully rejected
+    {
+      msg_flg = 0;
+      call_flag = 0;
+      msg_flag_2 = 0;
+      d_count = 0;
+      reply_flag = 0;
+    }
+    else if ( (Rec_Data == '3' || Rec_Data == '4' || Rec_Data == '7'  ) && msg_flg == 0 ) //incase of any error,nocarrier and busy
+    {
+      msg_flg = 0;
+      call_flag = 0;
+      msg_flag_2 = 0;
+      d_count = 0;
+      reply_flag = 0;
+    }
+  }
+}
+/*******************************************************************************************
+Function Name: send_message
+*******************************************************************************************/
+void send_message(void)
+{
+  byte msg_flg = 0;
+  char rec_data = 0;
+  GPSData();
+  delay(1000);
+  GSMmodule.print("AT+CMGS=");//Command to send message ,(AT+CMGS="+91phone number"<enter>)
+  GSMmodule.print('"');
+  GSMmodule.print(m_num_my);
+  GSMmodule.println('"');
+  delay(400);//Delay for GSM module become ready
+  while (GSMmodule.available() > 0)
+  {
+    rec_data = GSMmodule.read();
+    if ( rec_data == '>'  ) // '>'(greater than symbol) is recieved while message sending,after AT+CMGD="number" command
+    {
+      delay(400);//Delay for GSM module become ready
+      GSMmodule.print("G_");
+      GSMmodule.print(lt);
+      GSMmodule.print("_");
+      GSMmodule.println(lg);
+      //GSMmodule.println("From - Tracky"); //Transmitting whole string to be sent as SMS
+      GSMmodule.write(26);//'ctrl+z' command
+
+      //delay(5000);//Delay for GSM module become ready
+      msg_flg = 0;
+    }
+    else if ( rec_data == '+' && msg_flg == 0 ) // '+' is recieved
+      msg_flg = 1 ;
+    else if ( rec_data == 'C' && msg_flg == 1 ) // 'C' is recieved
+      msg_flg = 2 ;
+    else if ( rec_data == 'M' && msg_flg == 2 ) // 'M' is recieved
+      msg_flg = 3 ;
+    else if ( rec_data == 'G' && msg_flg == 3 ) // 'M' is recieved
+      msg_flg = 4 ;
+    else if ( rec_data == 'S' && msg_flg == 4 )//// 'S' is recieved after a sucessful message ("+CMSGS:  ")
+      msg_flg = 5 ;
+    else if ( rec_data == ':' && msg_flg == 5 )// ':' is recieved
+      msg_flg = 6 ;
+    else if ( rec_data == 0x0D && msg_flg == 6 )//Carriage return
+      msg_flg = 7 ;
+    else if ( rec_data == 0x0A && msg_flg == 7 )//Line feed
+      msg_flg = 8 ;
+    else if ( rec_data == '0' && msg_flg == 8 )// '0' (zero) is recieved
+    {
+      clear_rx_buffer();//clearing receiving buffer
+      msg_flg = 0;
+      msg_flag_2 = 0;
+      reply_flag = 0;
+    }
+    else if ( rec_data == '4' && msg_flg == 0  )// '4' (Four) is recieved
+    {
+      clear_rx_buffer();//clearing receiving buffer
+      msg_flg = 0;
+      msg_flag_2 = 0;
+      reply_flag = 0;
+    }
+    else if ( Rec_Data == '2' && msg_flg == 0 ) // '2' is recieved,incoming call
+    {
+      call_flag = 1;
+      delay(300);
+      GSMmodule.println("ATH");//Command for hang up incomming call,all calls must be filtered no need to answer a call
+    }
+    else if ( Rec_Data == '0' && msg_flg == 0 && call_flag == 1 ) // '0' (zero) is recieved,call sucessfully rejected
+    {
+      msg_flg = 0;
+      call_flag = 0;
+      msg_flag_2 = 0;
+      d_count = 0;
+      reply_flag = 0;
+    }
+  }
+  finish = 0; pos_cnt = 0;
+}
+/*******************************************************************************************
+Function Name: clear_rx_buffer
+*******************************************************************************************/
+void clear_rx_buffer(void)
+{
+  char rec_data = 0;
+  while (GSMmodule.available() > 0)
+    rec_data = GSMmodule.read();
+}
+/*******************************************************************************************
+Function Name: array_clear
+*******************************************************************************************/
+void array_clear(void)
+{
+  byte k = 0;
+  for ( k = 0; k < 15; k++)
+    number[k] = '\0';
+  for ( k = 0; k < 160; k++)
+    message[k] = '\0';
+}
 /*
 void ring()
 {
@@ -174,4 +635,3 @@
   noTone(8);
   delay(100);
 }*/
-


Added DEFAULTDELAY & changed Baudrate

Added DEFAULTDELAY & changed Baudrate

--- arduino_wifi_duck/arduino_wifi_duck.ino
+++ arduino_wifi_duck/arduino_wifi_duck.ino
@@ -1,127 +1,130 @@
-#include <Keyboard.h>
-#define BAUD_RATE 115200
-#define ExternSerial Serial1
+#include <Keyboard.h>
+#define BAUD_RATE 9600
+
+#define ExternSerial Serial1
+
+String bufferStr = "";
+String last = "";
+
+int defaultDelay = 0;
+
+void Line(String _line)
+{
+  int firstSpace = _line.indexOf(" ");
+  if(firstSpace == -1) Press(_line);
+  else if(_line.substring(0,firstSpace) == "STRING"){
+    for(int i=firstSpace+1;i<_line.length();i++) Keyboard.write(_line[i]);
+  }
+  else if(_line.substring(0,firstSpace) == "DELAY"){
+    int delaytime = _line.substring(firstSpace + 1).toInt();
+    delay(delaytime);
+  }
+  else if(_line.substring(0,firstSpace) == "DEFAULTDELAY") defaultDelay = _line.substring(firstSpace + 1).toInt();
+  else if(_line.substring(0,firstSpace) == "REM"){} //nothing :/
+  else if(_line.substring(0,firstSpace) == "REPLAY") {
+    int replaynum = _line.substring(firstSpace + 1).toInt();
+    while(replaynum)
+    {
+      Line(last);
+      --replaynum;
+    }
+  } else{
+      String remain = _line;
+
+      while(remain.length() > 0){
+        int latest_space = remain.indexOf(" ");
+        if (latest_space == -1){
+          Press(remain);
+          remain = "";
+        }
+        else{
+          Press(remain.substring(0, latest_space));
+          remain = remain.substring(latest_space + 1);
+        }
+        delay(5);
+      }
+  }
+
+  Keyboard.releaseAll();
+  delay(defaultDelay);
+}
+
+
+void Press(String b){
+  if(b.length() == 1) Keyboard.press(char(b[0]));
+  else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
+  else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
+  else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
+  else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
+  else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
+  else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
+  else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
+  else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
+  else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
+  else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
+  else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
+  else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
+  else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
+  else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
+  else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
+  else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
+  else if (b.equals("END")) Keyboard.press(KEY_END);
+  else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
+  else if (b.equals("F1")) Keyboard.press(KEY_F1);
+  else if (b.equals("F2")) Keyboard.press(KEY_F2);
+  else if (b.equals("F3")) Keyboard.press(KEY_F3);
+  else if (b.equals("F4")) Keyboard.press(KEY_F4);
+  else if (b.equals("F5")) Keyboard.press(KEY_F5);
+  else if (b.equals("F6")) Keyboard.press(KEY_F6);
+  else if (b.equals("F7")) Keyboard.press(KEY_F7);
+  else if (b.equals("F8")) Keyboard.press(KEY_F8);
+  else if (b.equals("F9")) Keyboard.press(KEY_F9);
+  else if (b.equals("F10")) Keyboard.press(KEY_F10);
+  else if (b.equals("F11")) Keyboard.press(KEY_F11);
+  else if (b.equals("F12")) Keyboard.press(KEY_F12);
+  else if (b.equals("SPACE")) Keyboard.press(' ');
+  //else Serial.println("not found :'"+b+"'("+String(b.length())+")");
+}
+
+void setup() {
+
+  Serial.begin(BAUD_RATE);
+  ExternSerial.begin(BAUD_RATE);
+
+  pinMode(13,OUTPUT);
+  digitalWrite(13,HIGH);
+
+  Keyboard.begin();
+}
+
+void loop() {
+  if(ExternSerial.available()) {
+    bufferStr = ExternSerial.readStringUntil("END");
+    Serial.println(bufferStr);
+  }
+
+  if(bufferStr.length() > 0){
+
+    bufferStr.replace("\r","\n");
+    bufferStr.replace("\n\n","\n");
+
+    while(bufferStr.length() > 0){
+      int latest_return = bufferStr.indexOf("\n");
+      if(latest_return == -1){
+        Serial.println("run: "+bufferStr);
+        Line(bufferStr);
+        bufferStr = "";
+      } else{
+        Serial.println("run: '"+bufferStr.substring(0, latest_return)+"'");
+        Line(bufferStr.substring(0, latest_return));
+        last=bufferStr.substring(0, latest_return);
+        bufferStr = bufferStr.substring(latest_return + 1);
+      }
+    }
+
+    bufferStr = "";
+    ExternSerial.write(0x99);
+    Serial.println("done");
+  }
+}

-String bufferStr = "";
-String last = "";
-
-void Line(String _line)
-{
-  int firstSpace = _line.indexOf(" ");
-  if(firstSpace == -1) Press(_line);
-  else if(_line.substring(0,firstSpace) == "STRING"){
-    for(int i=firstSpace+1;i<_line.length();i++) Keyboard.write(_line[i]);
-  }
-  else if(_line.substring(0,firstSpace) == "DELAY"){
-    int delaytime = _line.substring(firstSpace + 1).toInt();
-    delay(delaytime);
-  }
-  else if(_line.substring(0,firstSpace) == "REM"){
-    //nothing :/
-  }
-  else if(_line.substring(0,firstSpace) == "REPLAY")
-  {
-    int replaynum = _line.substring(firstSpace + 1).toInt();
-    while(replaynum)
-    {
-      Line(last);
-      --replaynum;
-    }
-  }
-  else{
-      String remain = _line;
-
-      while(remain.length() > 0){
-        int latest_space = remain.indexOf(" ");
-        if (latest_space == -1){
-          Press(remain);
-          remain = "";
-        }
-        else{
-          Press(remain.substring(0, latest_space));
-          remain = remain.substring(latest_space + 1);
-        }
-        delay(5);
-      }
-  }
-
-  Keyboard.releaseAll();
-}
-
-
-void Press(String b)
-{
-  if(b.length() == 1) Keyboard.press(char(b[0]));
-  else if (b.equals("ENTER")) Keyboard.press(KEY_RETURN);
-  else if (b.equals("CTRL")) Keyboard.press(KEY_LEFT_CTRL);
-  else if (b.equals("SHIFT")) Keyboard.press(KEY_LEFT_SHIFT);
-  else if (b.equals("ALT")) Keyboard.press(KEY_LEFT_ALT);
-  else if (b.equals("GUI")) Keyboard.press(KEY_LEFT_GUI);
-  else if (b.equals("UP") || b.equals("UPARROW")) Keyboard.press(KEY_UP_ARROW);
-  else if (b.equals("DOWN") || b.equals("DOWNARROW")) Keyboard.press(KEY_DOWN_ARROW);
-  else if (b.equals("LEFT") || b.equals("LEFTARROW")) Keyboard.press(KEY_LEFT_ARROW);
-  else if (b.equals("RIGHT") || b.equals("RIGHTARROW")) Keyboard.press(KEY_RIGHT_ARROW);
-  else if (b.equals("DELETE")) Keyboard.press(KEY_DELETE);
-  else if (b.equals("PAGEUP")) Keyboard.press(KEY_PAGE_UP);
-  else if (b.equals("PAGEDOWN")) Keyboard.press(KEY_PAGE_DOWN);
-  else if (b.equals("HOME")) Keyboard.press(KEY_HOME);
-  else if (b.equals("ESC")) Keyboard.press(KEY_ESC);
-  else if (b.equals("INSERT")) Keyboard.press(KEY_INSERT);
-  else if (b.equals("TAB")) Keyboard.press(KEY_TAB);
-  else if (b.equals("END")) Keyboard.press(KEY_END);
-  else if (b.equals("CAPSLOCK")) Keyboard.press(KEY_CAPS_LOCK);
-  else if (b.equals("F1")) Keyboard.press(KEY_F1);
-  else if (b.equals("F2")) Keyboard.press(KEY_F2);
-  else if (b.equals("F3")) Keyboard.press(KEY_F3);
-  else if (b.equals("F4")) Keyboard.press(KEY_F4);
-  else if (b.equals("F5")) Keyboard.press(KEY_F5);
-  else if (b.equals("F6")) Keyboard.press(KEY_F6);
-  else if (b.equals("F7")) Keyboard.press(KEY_F7);
-  else if (b.equals("F8")) Keyboard.press(KEY_F8);
-  else if (b.equals("F9")) Keyboard.press(KEY_F9);
-  else if (b.equals("F10")) Keyboard.press(KEY_F10);
-  else if (b.equals("F11")) Keyboard.press(KEY_F11);
-  else if (b.equals("F12")) Keyboard.press(KEY_F12);
-  else if (b.equals("SPACE")) Keyboard.press(' ');
-  //else Serial.println("not found :'"+b+"'("+String(b.length())+")");
-}
-
-void setup() {
-  Serial.begin(BAUD_RATE);
-  ExternSerial.begin(BAUD_RATE);
-
-  Keyboard.begin();
-}
-
-void loop() {
-
-  if(ExternSerial.available() > 0) {
-    bufferStr = ExternSerial.readString();
-    Serial.println(bufferStr);
-  }
-
-  if(bufferStr.length() > 0){
-
-    bufferStr.replace("\r","\n");
-    bufferStr.replace("\n\n","\n");
-
-    while(bufferStr.length() > 0){
-      int latest_return = bufferStr.indexOf("\n");
-      if(latest_return == -1){
-        Serial.println("run: "+bufferStr);
-        Line(bufferStr);
-        bufferStr = "";
-      } else{
-        Serial.println("run: '"+bufferStr.substring(0, latest_return)+"'");
-        Line(bufferStr.substring(0, latest_return));
-        last=bufferStr.substring(0, latest_return);
-        bufferStr = bufferStr.substring(latest_return + 1);
-      }
-    }
-
-    bufferStr = "";
-    ExternSerial.write(0x99);
-  }
-
-}
-


Servo is now updated with Timer 5, servo value message should be between 0-100, gets remapped on the arduino

--- Arduino/ros_code/Ros_arduino_servo/Ros_arduino_servo.ino
+++ Arduino/ros_code/Ros_arduino_servo/Ros_arduino_servo.ino
@@ -1,64 +1,71 @@
 /*
-
-Will move the servo back and forth
-
-Motor:
-Connect to h-bridge
-Brown, A-
-Orange, A+
-
-
-Potentiometer:
-Connect to arduino.
-White, 3.3V NOTE FOR THIS SHIT TO WORK, otherwise change readValue limits
-Black, GND
-Red, A8.
-*/
-
-
+To start ros node in terminal:
+ rosrun rosserial_python serial_node.py /dev/ttyACM0
+
+ Will move the servo back and forth
+
+ Motor:
+ Connect to h-bridge
+ Brown, A-
+ Orange, A+
+
+
+ Potentiometer:
+ Connect to arduino.
+ White, 3.3V NOTE FOR THIS SHIT TO WORK, otherwise change readValue limits
+ Black, GND
+ Red, A8.
+ */

 #include <ros.h>
 #include <std_msgs/UInt16.h>
 #include <std_msgs/String.h>

+
 #define MAX_RIGHT 410
 #define MAX_LEFT 640
 #define MID_POS 525
+#define SERVO_SPEED 30

 int servo_speed_pwm_pin = 3; // Channel A speed
 int servo_direction_pin0 = 4; // Channel A direction 0
 int servo_direction_pin1 = 5; // Channel A direction 1
-int servo_dir[] = {1,0};
+int servo_dir[] = {
+  1,0};
 int readValue = 0;
-int speed = 30;
 int servo_position_pin = A8;
-int servo_value = MID_POS;
+int servo_value = MID_PO;

 ros::NodeHandle nh;
 std_msgs::String str_msg;
 ros::Publisher info_pub("info", &str_msg);

-void setServoPosition(int pos, int speed){
+//void setServoPosition(int pos, int speed){
+//SIGNAL(TIMER0_COMPA_vect)
+ISR(TIMER3_COMPA_vect)
+{
   int current_pos = analogRead(servo_position_pin);
+  int pos = servo_value;
   if(pos < current_pos-5){        // We need to turn right
     servo_dir[0] = 1;
     servo_dir[1] = 0;
-  }else if(pos > current_pos + 5){  //Need to turn left
+  }
+  else if(pos > current_pos + 5){  //Need to turn left
     servo_dir[0] = 0;
     servo_dir[1] = 1;
-
-  }else{                        //At position, send speed 0 and return
+
+  }
+  else{                        //At position, send speed 0 and return
     analogWrite(servo_speed_pwm_pin, 0);
     return;
   }
   digitalWrite(servo_direction_pin0, servo_dir[0]);
   digitalWrite(servo_direction_pin1, servo_dir[1]);
-  analogWrite(servo_speed_pwm_pin, speed);
+  analogWrite(servo_speed_pwm_pin, SERVO_SPEED);
 }

 void servo_cb( const std_msgs::UInt16& cmd_msg){
-  servo_value = cmd_msg.data;
-
+  servo_value = map(cmd_msg.data,0,100,MAX_RIGHT,MAX_LEFT);
 }

@@ -66,21 +73,42 @@

 void setup(){
-
+
   nh.initNode();
   nh.subscribe(servo_sub);
   nh.advertise(info_pub);
-
+
   pinMode(servo_position_pin,INPUT);
   pinMode(servo_speed_pwm_pin, OUTPUT); // Set control pins to be outputs
   pinMode(servo_direction_pin0, OUTPUT);
   pinMode(servo_direction_pin1, OUTPUT);
-
+
+
+  //Timer0, calling compareA function every 1 ms
+  OCR0A = 0xAF;
+  TIMSK0 |= _BV(OCIE0A);
+
+  noInterrupts();
+  //Timer3  16bit timer
+
+  TCCR3A = 0;  //Sets tccr3a register to 0
+  TCCR3B = 0;  //sets tccr3b register to 0
+  TCNT3 = 0;   //initialize counter value to 0
+
+    // compare match register for 100 hz increments
+  OCR3A = 32150;  //= (16*10 upphöjt 6) / (100*1024) - 1
+  TCCR3A |= (1 << WGM33); //turn on CTC mode
+  TCCR3B |= (1 << CS32); //Set prescaler to 1024
+  TIMSK3 |= (1 << OCIE3A); //Enable timer compare interrupt
+
+  interrupts();
+
 }

 void loop(){
   nh.spinOnce();
-  setServoPosition(servo_value, 30);
+  //setServoPosition(servo_value, SERVO_SPEED);
   delay(1);
 }
+


Fixed serialprint compilation error

Fixed serialprint compilation error

--- MicTest/MicTest.ino
+++ MicTest/MicTest.ino
@@ -9,11 +9,15 @@
 bool checkingMicrophone = true;
 bool hearingStartSound = false;

+long getFreqCount() {
+  return freqCount;
+}
+
 void checkMicrophone() {
   // Measure sound:
   if (FreqCount.available()) {
     freqCount = FreqCount.read();
-    Serial.println(String(freqCount);
+    Serial.println(String(getFreqCount()));
   } else {
     freqCount = 0;
   }


Fix broken pin mode settings + use RSSI pullup again

--- src/rx5808-pro-diversity/rx5808-pro-diversity.ino
+++ src/rx5808-pro-diversity/rx5808-pro-diversity.ino
@@ -80,25 +80,19 @@
 void setupPins() {
     pinMode(PIN_LED, OUTPUT);
     pinMode(PIN_BUZZER, OUTPUT);
-
-    pinMode(PIN_BUTTON_UP, INPUT);
-    pinMode(PIN_BUTTON_MODE, INPUT);
-    digitalWrite(PIN_BUTTON_UP, INPUT_PULLUP);
-    digitalWrite(PIN_BUTTON_MODE, INPUT_PULLUP);
-
-    pinMode(PIN_BUTTON_DOWN, INPUT);
-    pinMode(PIN_BUTTON_SAVE, INPUT);
-    digitalWrite(PIN_BUTTON_DOWN, INPUT_PULLUP);
-    digitalWrite(PIN_BUTTON_SAVE, INPUT_PULLUP);
+    pinMode(PIN_BUTTON_UP, INPUT_PULLUP);
+    pinMode(PIN_BUTTON_MODE, INPUT_PULLUP);
+    pinMode(PIN_BUTTON_DOWN, INPUT_PULLUP);
+    pinMode(PIN_BUTTON_SAVE, INPUT_PULLUP);

     pinMode(PIN_LED_A,OUTPUT);
     #ifdef USE_DIVERSITY
         pinMode(PIN_LED_B,OUTPUT);
     #endif

-    pinMode(PIN_RSSI_A, INPUT);
+    pinMode(PIN_RSSI_A, INPUT_PULLUP);
     #ifdef USE_DIVERSITY
-        pinMode(PIN_RSSI_B, INPUT);
+        pinMode(PIN_RSSI_B, INPUT_PULLUP);
     #endif

     pinMode(PIN_SPI_SLAVE_SELECT, OUTPUT);


Changed Ubiquiti and Eth power control pins to constants

--- ArduinoWeatherStation.ino
+++ ArduinoWeatherStation.ino
@@ -53,7 +53,15 @@
 const byte WSPEED = 3;
 const byte RAIN = 2;
 const byte STAT1 = 7;
-const byte STAT2 = 8;
+const byte STAT2 = 8; //TODO: This pin (second status LED) seems wrong
+
+const byte PIN_ETH_DISABLE = 8; // Ethernet power control; on=LOW, off=HIGH
+const byte ETH_DISABLED = HIGH;
+const byte ETH_ENABLED = LOW;
+
+const byte PIN_UBIQUITI_ENABLE = 28; // Ubiquiti power control; off=LOW, on=HIGH
+const byte UBIQUITI_DISABLED = LOW;
+const byte UBIQUITI_ENABLED = HIGH;

 // analog I/O pins
 const byte WDIR = A0;
@@ -88,7 +96,7 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 unsigned long lastSecond;   //The millis counter to see when a second rolls by
 unsigned long loopCounter;  //see how often we loop
-unsigned long loopDelta;    //see how many loops since the last print
+unsigned long loopDelta;    //see how many loops since the last printu
 unsigned long msTemp;       //store millis() now and then to see how long something took, for Serial.print()s all over
 unsigned long usTemp;       //store micros() now and then to see how long something took. Much smaller than millis!
 byte seconds;               //When it hits 60, increase the current minute
@@ -384,11 +392,11 @@
   	  pinMode(30, OUTPUT);     //             common GND source for "YYD-3" FET switches.
       digitalWrite(30, LOW);   //             must always be low

-      pinMode(28, OUTPUT);     //             prepares Ubiquiti power control pin
-      digitalWrite(28, LOW);   //             turns Ubiquiti off (on=HIGH / off=low, default=on)
-
-      pinMode(8, OUTPUT);      //             prepares ETH power control pin
-      digitalWrite(8, HIGH);   //             turns ETH shield off (on=low / off=HIGH, default=on)
+      pinMode(PIN_UBIQUITI_ENABLE, OUTPUT);                  // prepares Ubiquiti power control pin
+      digitalWrite(PIN_UBIQUITI_ENABLE, UBIQUITI_DISABLED); // turns Ubiquiti off
+
+      pinMode(PIN_ETH_DISABLE, OUTPUT);      // prepares ETH power control pin
+      digitalWrite(PIN_ETH_DISABLE, ETH_DISABLED); // turns ETH shield off

     } else {
 	    Serial.print("Turning on Eth and Ubiquity... ");
@@ -397,11 +405,11 @@
       pinMode(30, OUTPUT);     //             common GND source for "YYD-3" FET switches.
       digitalWrite(30, LOW);   //             must always be low

-      pinMode(28, OUTPUT);     //             prepares Ubiquiti power control pin
-      digitalWrite(28, HIGH);  //             turns Ubiquiti on (on=HIGH / off=low, default=on)
-
-      pinMode(8, OUTPUT);      //             prepares ETH power control pin
-      digitalWrite(8, LOW);    //             turns ETH shield on (on=low / off=HIGH, default=on)
+      pinMode(PIN_UBIQUITI_ENABLE, OUTPUT);            // prepares Ubiquiti power control pin
+      digitalWrite(PIN_UBIQUITI_ENABLE, ETH_ENABLED); // turns Ubiquiti on
+
+      pinMode(PIN_ETH_DISABLE, OUTPUT);      // prepares ETH power control pin
+      digitalWrite(PIN_ETH_DISABLE, ETH_ENABLED); // turns ETH shield on

   	}
     Serial.println("Done.");
@@ -839,11 +847,11 @@
           if (!EEPROM.read(eePowerSave)) EEPROM.update(eePowerSave, true);
         }

-        pinMode(28, OUTPUT);     //             prepares Ubiquiti power control pin
-        digitalWrite(28, LOW);   //             turns Ubiquiti off (on=HIGH / off=low, default=on)
-
-        pinMode(8, OUTPUT);      //             prepares ETH power control pin
-        digitalWrite(8, HIGH);   //             turns ETH shield off (on=low / off=HIGH, default=on)
+        pinMode(PIN_UBIQUITI_ENABLE, OUTPUT);                  // prepares Ubiquiti power control pin
+        digitalWrite(PIN_UBIQUITI_ENABLE, UBIQUITI_DISABLED); // turns Ubiquiti off
+
+        pinMode(PIN_ETH_DISABLE, OUTPUT);             // prepares ETH power control pin
+        digitalWrite(PIN_ETH_DISABLE, ETH_DISABLED); // turns ETH shield off

       } else {
 	    Serial.print(", which is Day time. We will switch to night at minute #");
@@ -855,11 +863,11 @@

 		  //if powerSave was set, that means we're transitioning to daytime now.
 		  // Until I figure out how to restart the Ethernet, just force a watchdog timeout with delays.
-		    pinMode(28, OUTPUT);     //             prepares Ubiquiti power control pin
-        digitalWrite(28, HIGH);  //             turns Ubiquiti on (on=HIGH / off=low, default=on)
-
-        pinMode(8, OUTPUT);      //             prepares ETH power control pin
-        digitalWrite(8, LOW);    //             turns ETH shield on (on=low / off=HIGH, default=on)
+		    pinMode(PIN_UBIQUITI_ENABLE, OUTPUT);                 // prepares Ubiquiti power control pin
+        digitalWrite(PIN_UBIQUITI_ENABLE, UBIQUITI_ENABLED); // turns Ubiquiti on
+
+        pinMode(PIN_ETH_DISABLE, OUTPUT);            // prepares ETH power control pin
+        digitalWrite(PIN_ETH_DISABLE, ETH_ENABLED); // turns ETH shield on

 		  Serial.println(F("   ! ! !   We just switched to DAY. Since we can't reset ETHERNET very well, we are rebooting soon!!! ! ! "));
 		  delay(10000);
@@ -868,11 +876,11 @@
         }

 		//This below kind of doesn't count, because of the reboot above. We really should never get here.
-		    pinMode(28, OUTPUT);     //             prepares Ubiquiti power control pin
-        digitalWrite(28, HIGH);  //             turns Ubiquiti on (on=HIGH / off=low, default=on)
-
-        pinMode(8, OUTPUT);      //             prepares ETH power control pin
-        digitalWrite(8, LOW);    //             turns ETH shield on (on=low / off=HIGH, default=on)
+		    pinMode(PIN_UBIQUITI_ENABLE, OUTPUT);                 // prepares Ubiquiti power control pin
+        digitalWrite(PIN_UBIQUITI_ENABLE, UBIQUITI_ENABLED); // turns Ubiquiti on
+
+        pinMode(PIN_ETH_DISABLE, OUTPUT);            // prepares ETH power control pin
+        digitalWrite(PIN_ETH_DISABLE, ETH_ENABLED); // turns ETH shield on

       } // End of night/day figuring out (for power save)


tracker

tracker

--- CarTracker/CarTracker.ino
+++ CarTracker/CarTracker.ino
@@ -109,60 +109,9 @@
         while (1)
             ;
     }
-//    type = fona.type();
     Serial.println(F("FONA is OK"));
-//    Serial.print(F("Found "));
-//    switch (type)
-//    {
-//    case FONA800L:
-//        Serial.println(F("FONA 800L"));
-//        break;
-//    case FONA800H:
-//        Serial.println(F("FONA 800H"));
-//        break;
-//    case FONA808_V1:
-//        Serial.println(F("FONA 808 (v1)"));
-//        break;
-//    case FONA808_V2:
-//        Serial.println(F("FONA 808 (v2)"));
-//        break;
-//    case FONA3G_A:
-//        Serial.println(F("FONA 3G (American)"));
-//        break;
-//    case FONA3G_E:
-//        Serial.println(F("FONA 3G (European)"));
-//        break;
-//    default:
-//        Serial.println(F("???"));
-//        break;
-//    }
-
-    // Print module IMEI number.
-//    char imei[15] =
-//    { 0 }; // MUST use a 16 character buffer for IMEI!
-//    uint8_t imeiLen = fona.getIMEI(imei);
-//    if (imeiLen > 0)
-//    {
-//        Serial.print("Module IMEI: ");
-//        Serial.println(imei);
-//    }
-
-    // Optionally configure a GPRS APN, username, and password.
-    // You might need to do this to access your network's GPRS/data
-    // network.  Contact your provider for the exact APN, username,
-    // and password values.  Username and password are optional and
-    // can be removed, but APN is required.
-    //fona.setGPRSNetworkSettings(F("your APN"), F("your username"), F("your password"));
+
     fona.setGPRSNetworkSettings(F(APN));
-
-//    delay(1000);
-
-//    Serial.print(F("RSSI = "));
-//    Serial.println(fona.getRSSI());
-
-    // enable network time sync
-//	if (!fona.enableNetworkTimeSync(true))
-//		Serial.println(F("Failed to enable network time sync"));

 #ifdef SIM_PIN
     while (! fona.unlockSIM(SIM_PIN))
@@ -175,17 +124,10 @@

     while (read_network_status() == 2)	//searching
     {
+        Serial.println(F("network_status: searching"));
         delay(1000);
         tone(PIN_SPEAKER, 500, 10);
     }
-
-    // turn GPRS on
-    while (!fona.enableGPRS(true))
-    {
-        Serial.println(F("Failed to turn on GPRS"));
-        delay(1000);
-    }
-    Serial.println(F("GPRS OK"));

     // read the network/cellular status
     uint8_t n = fona.getNetworkStatus();
@@ -204,6 +146,14 @@
         Serial.println(F("Unknown"));
     if (n == 5)
         Serial.println(F("Registered roaming"));
+
+    // turn GPRS on
+    while (!fona.enableGPRS(true))
+    {
+        Serial.println(F("Failed to turn on GPRS"));
+        delay(2000);
+    }
+    Serial.println(F("GPRS OK"));

 }

@@ -232,8 +182,6 @@
 uint16_t vbat;
 uint8_t rssi;
 uint8_t motion;
-//float gsmlat;
-//float gsmlon;
 float temp;
 char gpsbuffer[70];
 char *longp=0;
@@ -273,7 +221,8 @@
     if (!fona.getBattVoltage(&vbat))
     {
         Serial.println(F("Failed to read Batt"));
-        HALT();
+        delay(1000);
+        return;
     }
     else
     {
@@ -298,11 +247,10 @@
     else
     {
         Serial.println(F("getGSMLoc Failed!"));
-        HALT();
-    }
-
-//    phant.add("a", 72);
-//	phant.url()
+        delay(1000);
+        return;
+    }
+

     // read website URL
     uint16_t statuscode;
@@ -318,19 +266,8 @@
 //	Serial.println(url);

 //    tone(PIN_SPEAKER, 200, 10);
-    Serial.println(F("****"));
-
-//    Serial.print(F("url: "));
-//    Serial.println(phant.url());
-//
-//    String xx = phant.url();
-//    Serial.print(F("url: "));
-//    Serial.println((char*) (xx.c_str()));
-
-//    Serial.print(F("url: "));
-//    Serial.println((char*) (phant.url().c_str()));
-//    HALT();
-//    return;
+    Serial.println(F("sending.."));
+

     if (!HTTP_GET_start(&statuscode, (uint16_t *) &length))
 //    if (!fona.HTTP_GET_start((char*) (phant.url().c_str()), &statuscode,


Fixed Calibration

Fixed Calibration

Fixed calibration

--- DataLogger/DataLogger.ino
+++ DataLogger/DataLogger.ino
@@ -21,7 +21,9 @@
   * MISO Pin: 12
   * Clock Pin: 13
   * SDA and SCL are used for the ADS1115.
-  * Peristaltic Pump (PP) Pin: 3. Note: PWN is required for speed adjustment.
+  * Peristaltic Pump (PP) Pin: 3. Note: Adjust voltage on supply
+  * to adjust the speed of the motor. It's cheaper than creating
+  * a voltage divider with digital potentiometers.
   */

 //The ADS1015 library facilitates reading from the ADS1115.
@@ -30,10 +32,25 @@
 Adafruit_ADS1115 ads1115; //Creates instance of ads1115
 Adafruit_ADS1115 ads(0x48); //Sets base address
 //Create variables for displaying on LCD and saving to SD Card
-float cVoltage; //16 bit variable reading from ADC's A0
+const String voltage = "mV"; //Change as needed
+const String conductivityText = "uS"; //Change as needed
+const String timeText = "ms"; //Change as needed
+double cVoltage; //Variable reading from ADC's A0
 String resultmV; //String containing reading from ADC in mV
-String resultV; //String containing reading from ADC in V
-
+String resultS; //String variable containing result in microsiemens.
+double resultSd; //Double variable for deciding if measurement is not error
+const double intercept = 2663.862; //Intercept for conductivity meter
+const double slope = 3.062497; //Slope for conductivity meter
+/*Note: Voltage in mV for 1000uS/cm conductivity is mV.
+//CALIBRATE USING THAT VOLTAGE. Ensure the Vernier conductivity meter's range is
+*set to 0 to 20,000 uS/cm (0 to 10,000 mg/L TDS).
+*/
+
+/*IMPORTANT NOTE REGARDING THE PUMP:
+* 40mL/minute speed is at 9v.
+* 20mL/minute speed is at 6v.
+* 10mL/minute speed is at 4v.
+*/

 //The LiquidCrystal library facilitates usage of the  LCD screen
 #include <LiquidCrystal.h>
@@ -46,9 +63,9 @@
 SdFat SD; //Added for backwards compatability. This was suggested on the Arduino forum
 //by user Scottrockcafe to user trilbytim (https://forum.arduino.cc/index.php?topic=231495.0).
 //Create file for saving to SD Card
-File resultFile;
-String fileName = "test.txt"; //Change as needed
+String fileName = "calibration.txt"; //Change as needed
 #define SD_CS_PIN SS //Defines CS pin as SS for SD card
+SdFile file;

 //Set pins for MISO/MOSI/SS/PP
@@ -60,6 +77,18 @@
 const int clk = 13; //Clock pin
 const int PP = 3; //Peristaltic pump pin

+//Time-keeping variable
+//unsigned long time;
+
+//Set values for time it takes to circulate the 100mL
+//bulk solution 5x through apparatus at pump speeds
+const int mlSpeed40 = 150000;
+const int mlSpeed20 = 300000;
+const int mlSpeed10 = 600000;
+
+//Record how many times water has been circulated through apparatus
+int cycle = 0;
+
 void setup() {
   //Set pin modes
   pinMode(MOSIpin, OUTPUT);
@@ -73,15 +102,42 @@
   ads1115.begin(); //Initializes ADC

   titleAndInitialize();
-  lcd.clear();
-  void loop();
-}
-
+  LCDwrite("Beginning", "Logging");
+  delay(3000);
+  lcd.clear();
+  File file = SD.open(fileName, FILE_WRITE);
+  if (file) {
+    file.println(conductivityText + "," + voltage + "," + timeText); //writes to SD card
+    file.close();
+  } else{
+    LCDwrite("Error writing to", fileName);
+    while(1);
+    }
+    delay(100);
+}
+
+/*
+ * If void loop() isn't running...
+ * Does the ADC have power?
+ * Does the SD card module have power?
+ * Does everything that should have power have power?
+ * Is there enough power?
+ * Are there any shorts?
+ * Are all necessary wires connected?
+ */
 void loop() {
+  digitalWrite(PP, HIGH); //Sets speed of peristaltic pump to a constant value
   writeResult();
-}
-
-void LCDwrite(String s, String s2){
+  unsigned long ms = millis(); //millis() is an unsigned long
+//  if (mlSpeed40 - ms <= 0){
+//    LCDwrite("Data Collection", "Completed");
+//    while(1);
+//    } else {
+    delay(300);
+//  }
+}
+
+void LCDwrite(String s, String s2){ //Fix problem: 100ms delay makes screen almost unreadable
   lcd.setCursor(0, 0); //Write to LCD
   lcd.print(s);
   lcd.setCursor(0,1);
@@ -101,24 +157,31 @@
    * multiply that by 0.1875, and divide that by 1000 to get voltage
    * in volts.
    */
-  resultmV = cVoltage;
-  resultV = cVoltage/1000;
+   resultSd = (cVoltage-intercept)*slope;
+   resultS = resultSd;
+   resultmV = cVoltage;
 }

 void SDwrite() {
-  resultFile = SD.open(fileName, FILE_WRITE);
-  if(!resultFile){
-    LCDwrite("Cannot open", fileName);
-    delay(1000);
-    }
-  lcd.clear();
-  resultFile.println(resultmV + ","); //writes to SD card
+  File file = SD.open(fileName, FILE_WRITE);
+  if (!file){
+    LCDwrite("Error writing to", fileName);
+    while(1);
+    }
+    else {
+      if (resultSd > 0) {
+    file.println(resultS + "," + resultmV + "," + millis()); //writes to SD card
+    file.close();
+  } else {
+    delay(0);
+    }
+    }
 }

 void writeResult(){ //Writes result to SD card and LCD Screen
   readADS(); //Reads data from ADC
   SDwrite(); //Write data to SD card
-  LCDwrite((resultV + " V"), (resultmV + " mV ")); //Space keeps unnecessary "V" from appearing
+  LCDwrite((resultS + " uS    "), (resultmV + " mV    ")); //Space keeps unnecessary "V" from appearing
 }

 void titleAndInitialize(){
@@ -133,6 +196,7 @@
   LCDwrite("Detecting SD..", "");
   delay(500);
   LCDwrite("Detecting SD...", "");
+  delay(500);
   //Begin SD Card module
   if (!SD.begin(SD_CS_PIN)) {
     lcd.clear();
@@ -145,8 +209,14 @@
     delay(3000);
     lcd.clear();
   }
-  }
-
-
-
-
+  char filename[fileName.length()+1];
+  fileName.toCharArray(filename, sizeof(filename));
+  if (!SD.open(fileName, FILE_WRITE)) {
+    LCDwrite("Error opening", fileName);
+    while(1);
+  }
+  file.close();
+  LCDwrite("Writing to", fileName);
+  delay(3000);
+  lcd.clear();
+  }


Create parsing.ino

Create parsing.ino


Travis IR test 2

Travis IR test 2

--- IROptional/IROptional.ino
+++ IROptional/IROptional.ino
@@ -31,24 +31,26 @@
     if (results.value == BUTON1)
     {
       Serial.println("1. Kademe Sulama Yapiliyor... / Step 1 Watering...");
-      motor.write(60);
+      /* motor.write(60);
       delay(1000);
       motor.write(0);
-
+      */
     }
     if (results.value == BUTON2)
     {
       Serial.println("2. Kademe Sulama Yapiliyor... / Step 2 Watering...");
-      motor.write(180);
+      /* motor.write(180);
       delay(1500);
       motor.write(0);
+      */
     }
     if (results.value == BUTON3)
     {
       Serial.println("3. Kademe Sulama Yapiliyor... / Step 3 Watering...");
-      motor.write(270);
+      /* motor.write(270);
       delay(2000);
       motor.write(0);
+      */
     }
     irrecv.resume();
   }


More removal of bad

More removal of bad

--- Kirbi/src/kirbi/kirbi.ino
+++ Kirbi/src/kirbi/kirbi.ino
@@ -16,9 +16,7 @@
       //}
       // delay(500);
       Serial.begin(115200);
-//      while (!Serial);
       Serial.println("finished setup");
-//      Serial.println("finished setup");

 }


Testing

Testing

--- module/module.ino
+++ module/module.ino
@@ -149,7 +149,7 @@
 */
 unsigned long accumulator(void) {
 	unsigned char A[bufferSize];
-	unsigned long startTime = 0;
+	unsigned long startTime, endTime = 0;
 	unsigned int periodX, periodY;
 	unsigned int lastPeriodX, lastPeriodY;
 	unsigned long periodCount, sendCount = 0;
@@ -174,10 +174,11 @@
 			if (pollCounter == pollTimeout) {
 				soundFeedback(reject);
 				Serial.print(messages.cancel);
+				endTime = (millis() - startTime)/1000;
 				while(1) {
-					Serial.println(sendCount);
+					Serial.println(endTime);
 				}
-				return sendCount;
+				return endTime;
 			}
 		}
 		else {