[chronojump/michrolab: 11/57] Plotting at configurable period




commit ceb0c5800f82dd26cdb9058b8d9613a595cc9315
Author: Xavier Padullés <testing chronojump org>
Date:   Wed Apr 27 12:15:08 2022 +0200

    Plotting at configurable period

 arduino/ForceSensorTFT/ForceSensorTFT.ino | 1492 +++++++++++++++--------------
 1 file changed, 754 insertions(+), 738 deletions(-)
---
diff --git a/arduino/ForceSensorTFT/ForceSensorTFT.ino b/arduino/ForceSensorTFT/ForceSensorTFT.ino
index 06edf4250..22c52fc32 100644
--- a/arduino/ForceSensorTFT/ForceSensorTFT.ino
+++ b/arduino/ForceSensorTFT/ForceSensorTFT.ino
@@ -1056,6 +1056,8 @@ void capture(void)
   double xDivN = 3;
   double yBuffer[320];
 
+  int plotPeriod = 2;
+
   bool resized = true;
 
   for (int i = xMin; i < xMax; i++)
@@ -1072,10 +1074,16 @@ void capture(void)
   tft.fillScreen(BLACK);
   while (capturing)
   {
+    Serial.println();
+    Serial.print("Deleting: ");
     xGraph = 0;
     //Deleting the previous plotted points
     for (int i = xMin; i < xMax; i++)
     {
+//      Serial.print(i);
+//      Serial.print(",");
+//      Serial.print(yBuffer[i]);
+//      Serial.print("\t");
       Graph(tft, i, yBuffer[i], graphX, graphY, graphW, graphH, xMin, xMax, xDivSize, graphMin, graphMax, 
yDivSize, "", "", "", WHITE, WHITE, BLACK, WHITE, BLACK, display1);
     }
     display1 = true;
@@ -1086,860 +1094,868 @@ void capture(void)
     yDivSize = (graphMax - graphMin) / yDivN;
     redrawAxes(tft, graphX, graphY, graphW, graphH, xMin, xMax, graphMin, graphMax, yDivSize, "", "", "", 
WHITE, WHITE, BLACK, WHITE, BLACK, resized);
     resized = false;
-
+//    Serial.println();
+//    Serial.print("Drawing: ");
     while (xGraph < xMax) {
-      //Checking the RCA state
-      if (rcaState != lastRcaState) {       //Event generated by the RCA
-        Serial.print(rcaTime);
-        Serial.print(";");
-
-        if (rcaState) {
-          Serial.println("R");
-          forceTrigger = measured;
-        } else {
-          Serial.println("r");
-        }
-        lastRcaState = rcaState;
+      for (int n = 0; n < plotPeriod; n++)
+      {
+        //Checking the RCA state
+        if (rcaState != lastRcaState) {       //Event generated by the RCA
+          Serial.print(rcaTime);
+          Serial.print(";");
+
+          if (rcaState) {
+            Serial.println("R");
+            forceTrigger = measured;
+          } else {
+            Serial.println("r");
+          }
+          lastRcaState = rcaState;
 
-        //If no RCA event, read the force as usual
-      } else {
-        //rcaTime = totalTime;
-        measured = scale.get_units();
+          //If no RCA event, read the force as usual
+        } else {
+          //rcaTime = totalTime;
+          measured = scale.get_units();
 
-        //When current Force Slot is equal to size of the buffer it starts over to 0
-        currentFSlot = (currentFSlot + 1) % freq;
-        //wHEN current Time Slot is equal to the size of the buffer it starts over to 0
-        currentTSlot = (currentTSlot + 1) % samples200ms;
+          //When current Force Slot is equal to size of the buffer it starts over to 0
+          currentFSlot = (currentFSlot + 1) % freq;
+          //wHEN current Time Slot is equal to the size of the buffer it starts over to 0
+          currentTSlot = (currentTSlot + 1) % samples200ms;
 
-        if (currentTSlot > 0) elapsed1Sample = true;    //There's a previous sample
-        if (currentTSlot >= (samples200ms - 1)) elapsed200 = true;
-        if (currentTSlot >= (samples100ms - 1)) elapsed100 = true;
+          if (currentTSlot > 0) elapsed1Sample = true;    //There's a previous sample
+          if (currentTSlot >= (samples200ms - 1)) elapsed200 = true;
+          if (currentTSlot >= (samples100ms - 1)) elapsed100 = true;
 
-        forces1s[currentFSlot] = measured;
-        totalTimes1s[currentTSlot] = totalTime;
+          forces1s[currentFSlot] = measured;
+          totalTimes1s[currentTSlot] = totalTime;
 
-        //Calculating the average during 1s
-        float sumForces = 0;
-        for (unsigned short i = 0; i < freq; i++) {
-          sumForces += forces1s[i];
-        }
+          //Calculating the average during 1s
+          float sumForces = 0;
+          for (unsigned short i = 0; i < freq; i++) {
+            sumForces += forces1s[i];
+          }
 
-        //Mean forces = sum of the forces divided by the number of samples in 1 second
-        meanForce1s = sumForces / freq;
+          //Mean forces = sum of the forces divided by the number of samples in 1 second
+          meanForce1s = sumForces / freq;
 
-        if (abs(meanForce1s) > abs(maxMeanForce1s)) maxMeanForce1s = meanForce1s;
+          if (abs(meanForce1s) > abs(maxMeanForce1s)) maxMeanForce1s = meanForce1s;
 
-        //In the final phase of steadiness measure. Actual calculation
-        if (capturingSteadiness)
-        {
-          sumSSD += (sq(measured - lastMeasure));
-          sumMeasures += measured;
-          samplesSSD++;
-          lastMeasure = measured;
-          RMSSD = sqrt(sumSSD / (samplesSSD - 1));
-          cvRMSSD = 100 * RMSSD / ( sumMeasures / samplesSSD);
-          if (samplesSSD >= 5 * (freq - 1))
+          //In the final phase of steadiness measure. Actual calculation
+          if (capturingSteadiness)
           {
-            end_steadiness();
+            sumSSD += (sq(measured - lastMeasure));
+            sumMeasures += measured;
+            samplesSSD++;
+            lastMeasure = measured;
+            RMSSD = sqrt(sumSSD / (samplesSSD - 1));
+            cvRMSSD = 100 * RMSSD / ( sumMeasures / samplesSSD);
+            if (samplesSSD >= 5 * (freq - 1))
+            {
+              end_steadiness();
+            }
           }
-        }
 
 
-        //RFD stuff start ------>
-
-        //To go backwards N slots use [currentSlot + TotalPositions - N]
-        if (elapsed1Sample) {
-          impulse += (((measured + forces1s[(currentFSlot + freq - 1) % freq])  / 2) *      //Mean force 
between 2 samples
-                      (totalTime - totalTimes1s[(currentTSlot + samples200ms - 1) % samples200ms]) / 1e6);  
//Elapsed time between 2 samples
-        }
+          //RFD stuff start ------>
 
-        if (elapsed200) {
-          RFD200 = (measured - forces1s[(currentFSlot + freq - samples200ms) % freq]) /     //Increment of 
the force in 200ms
-                   ((totalTime - totalTimes1s[(currentTSlot + 1) % samples200ms]) / 1e6);          
//Increment of time
-          if (abs(maxRFD200) < abs(RFD200)) maxRFD200 = RFD200;
-        }
+          //To go backwards N slots use [currentSlot + TotalPositions - N]
+          if (elapsed1Sample) {
+            impulse += (((measured + forces1s[(currentFSlot + freq - 1) % freq])  / 2) *      //Mean force 
between 2 samples
+                        (totalTime - totalTimes1s[(currentTSlot + samples200ms - 1) % samples200ms]) / 1e6); 
 //Elapsed time between 2 samples
+          }
 
-        if (elapsed100) {
-          RFD100 = (measured - forces1s[(currentFSlot + freq - samples100ms) % freq]) /     //Increment of 
the force in 200ms
-                   ((totalTime - totalTimes1s[(currentTSlot + samples200ms - samples100ms) % samples200ms]) 
/ 1e6); //Increment of time
-          if (abs(maxRFD100) < abs(RFD100)) maxRFD100 = RFD100;
-        }
-        //<------- RFD stuff end
+          if (elapsed200) {
+            RFD200 = (measured - forces1s[(currentFSlot + freq - samples200ms) % freq]) /     //Increment of 
the force in 200ms
+                     ((totalTime - totalTimes1s[(currentTSlot + 1) % samples200ms]) / 1e6);          
//Increment of time
+            if (abs(maxRFD200) < abs(RFD200)) maxRFD200 = RFD200;
+          }
 
-        //Negative numbers treated as positives to calculate the max
-        if (abs(measured) > abs(measuredLcdDelayMax)) {
-          measuredLcdDelayMax = measured;
-        }
-        if (measured > newGraphMax) {
-          newGraphMax = measured;
-          resized = true;
-        }
-        if (measured < newGraphMin) {
-          newGraphMin = measured;
-          resized = true;
-        }
+          if (elapsed100) {
+            RFD100 = (measured - forces1s[(currentFSlot + freq - samples100ms) % freq]) /     //Increment of 
the force in 200ms
+                     ((totalTime - totalTimes1s[(currentTSlot + samples200ms - samples100ms) % 
samples200ms]) / 1e6); //Increment of time
+            if (abs(maxRFD100) < abs(RFD100)) maxRFD100 = RFD100;
+          }
+          //<------- RFD stuff end
 
+          //Negative numbers treated as positives to calculate the max
+          if (abs(measured) > abs(measuredLcdDelayMax)) {
+            measuredLcdDelayMax = measured;
+          }
+          if (measured > newGraphMax) {
+            newGraphMax = measured;
+            resized = true;
+          }
+          if (measured < newGraphMin) {
+            newGraphMin = measured;
+            resized = true;
+          }
 
-        Serial.print(totalTime); Serial.print(";");
-        Serial.println(measured, 2); //scale.get_units() returns a float
-        yBuffer[(int)xGraph] = measured;
-        //                        Serial.print(measured);
-        //                        Serial.print("\t");
-        //                Serial.println(yBuffer[(int)xGraph]);
-        Graph(tft, xGraph, measured, graphX, graphY, graphW, graphH, xMin, xMax, xDivSize, graphMin, 
graphMax, yDivSize, "", "", "", WHITE, WHITE, BLUE, WHITE, BLACK, display1);
-        xGraph++;
-      }
 
-      //Pressing blue or red button ends the capture
-      redButtonState = !digitalRead(redButtonPin);
-      blueButtonState = !digitalRead(blueButtonPin);
-      if (redButtonState || blueButtonState) {
-        Serial.println("Button pressed");
-        redButtonState = false;
-        blueButtonState = false;
-        if (! (capturingPreSteadiness || capturingSteadiness)) //Not in any steadiness phase
-        {
-          end_capture();
-          xGraph = 300;
-        } else if (capturingPreSteadiness)  //In Pre steadiness. Showing force until button pressed
-        {
-          //        Serial.println("BeginSteadiness");
-          capturingPreSteadiness = false;
-          capturingSteadiness = true;
-          start_capture();
+          Serial.print(totalTime); Serial.print(";");
+          Serial.println(measured, 2); //scale.get_units() returns a float
+
+          //Pressing blue or red button ends the capture
+          redButtonState = !digitalRead(redButtonPin);
+          blueButtonState = !digitalRead(blueButtonPin);
+          if (redButtonState || blueButtonState) {
+            Serial.println("Button pressed");
+            redButtonState = false;
+            blueButtonState = false;
+            if (! (capturingPreSteadiness || capturingSteadiness)) //Not in any steadiness phase
+            {
+              end_capture();
+              xGraph = 300;
+            } else if (capturingPreSteadiness)  //In Pre steadiness. Showing force until button pressed
+            {
+              //        Serial.println("BeginSteadiness");
+              capturingPreSteadiness = false;
+              capturingSteadiness = true;
+              start_capture();
+            }
+          }
         }
       }
+//      Serial.print(xGraph);
+//      Serial.print(", ");
+//      Serial.print(measured);
+//      Serial.print("\t");
+      yBuffer[(int)xGraph] = measured;
+      //                        Serial.print(measured);
+      //                        Serial.print("\t");
+      //                Serial.println(yBuffer[(int)xGraph]);
+      Graph(tft, xGraph, measured, graphX, graphY, graphW, graphH, xMin, xMax, xDivSize, graphMin, graphMax, 
yDivSize, "", "", "", WHITE, WHITE, BLUE, WHITE, BLACK, display1);
+      xGraph++;
     }
+    MsTimer2::start();
   }
-  MsTimer2::start();
 }
 
-void printLcdFormat (float val, int xStart, int y, int decimal) {
+  void printLcdFormat (float val, int xStart, int y, int decimal) {
 
-  /*How many characters are to the left of the units number.
-     Examples:
-     1.23   -> 0 charachters
-     12.34  -> 1 characters
-     123.45 -> 2 characters
-  */
-  int fontSize = 2;
-  int charWidth[3] = {10, 15, 20};
+    /*How many characters are to the left of the units number.
+       Examples:
+       1.23   -> 0 charachters
+       12.34  -> 1 characters
+       123.45 -> 2 characters
+    */
+    int fontSize = 2;
+    int charWidth[3] = {10, 15, 20};
 
-  int valLength = floor(log10(abs(val)));
+    int valLength = floor(log10(abs(val)));
 
-  // Adding the extra characters to the left
-  if (valLength > 0) {
-    xStart = valLength * charWidth[fontSize];
-  }
+    // Adding the extra characters to the left
+    if (valLength > 0) {
+      xStart = valLength * charWidth[fontSize];
+    }
 
-  // In negatives numbers the units are in the same position and the minus one position to the left
-  if (val < 0) {
-    xStart - charWidth[fontSize];
+    // In negatives numbers the units are in the same position and the minus one position to the left
+    if (val < 0) {
+      xStart - charWidth[fontSize];
+    }
+    tft.setCursor(xStart * charWidth[fontSize]  , y);
+    tft.print(val, decimal);
   }
-  tft.setCursor(xStart * charWidth[fontSize]  , y);
-  tft.print(val, decimal);
-}
 
-void printTftFormat (float val, int xStart, int y, int fontSize, int decimal) {
+  void printTftFormat (float val, int xStart, int y, int fontSize, int decimal) {
 
-  /*How many characters are to the left of the units number.
-     Examples:
-     1.23   -> 0 charachters
-     12.34  -> 1 characters
-     123.45 -> 2 characters
-  */
-
-  //Font sizes: 5x8, 10x16, 15x24, or 20x32
-  //Theres a pixel between characters
-  int charWidth = 5 * fontSize + 1;
-  int valLength = floor(log10(abs(val)));
+    /*How many characters are to the left of the units number.
+       Examples:
+       1.23   -> 0 charachters
+       12.34  -> 1 characters
+       123.45 -> 2 characters
+    */
 
-  // Adding the extra characters to the left
-  if (valLength > 0) {
-    xStart = xStart - valLength * charWidth;
-  }
+    //Font sizes: 5x8, 10x16, 15x24, or 20x32
+    //Theres a pixel between characters
+    int charWidth = 5 * fontSize + 1;
+    int valLength = floor(log10(abs(val)));
 
-  // In negatives numbers the units are in the same position and the minus one position to the left
-  if (val < 0) {
-    xStart = xStart - charWidth;
-  }
+    // Adding the extra characters to the left
+    if (valLength > 0) {
+      xStart = xStart - valLength * charWidth;
+    }
 
-  tft.setCursor(xStart , y);
-  tft.print(val, decimal);
-}
+    // In negatives numbers the units are in the same position and the minus one position to the left
+    if (val < 0) {
+      xStart = xStart - charWidth;
+    }
 
-void serialEvent() {
-  String inputString = Serial.readString();
-  String commandString = inputString.substring(0, inputString.lastIndexOf(":"));
-
-
-  if (commandString == "start_capture") {
-    PCControlled = true;
-    start_capture();
-    //capture();
-  } else if (commandString == "end_capture") {
-    end_capture();
-  } else if (commandString == "get_version") {
-    get_version();
-  } else if (commandString == "get_calibration_factor") {
-    get_calibration_factor();
-  } else if (commandString == "set_calibration_factor") {
-    set_calibration_factor(inputString);
-  } else if (commandString == "calibrate") {
-    calibrate(inputString);
-  } else if (commandString == "get_tare") {
-    get_tare();
-  } else if (commandString == "set_tare") {
-    set_tare(inputString);
-  } else if (commandString == "tare") {
-    tare();
-  } else if (commandString == "get_transmission_format") {
-    get_transmission_format();
-    /* Commented due to memory optimization
-      //  } else if (commandString == "send_sync_signal") {
-      //    sendSyncSignal();
-      //  } else if (commandString == "listen_sync_signal") {
-      //    listenSyncSignal();
-    */
-  } else {
-    Serial.println("Not a valid command");
+    tft.setCursor(xStart , y);
+    tft.print(val, decimal);
   }
-  inputString = "";
 
-}
+  void serialEvent() {
+    String inputString = Serial.readString();
+    String commandString = inputString.substring(0, inputString.lastIndexOf(":"));
+
+
+    if (commandString == "start_capture") {
+      PCControlled = true;
+      start_capture();
+      //capture();
+    } else if (commandString == "end_capture") {
+      end_capture();
+    } else if (commandString == "get_version") {
+      get_version();
+    } else if (commandString == "get_calibration_factor") {
+      get_calibration_factor();
+    } else if (commandString == "set_calibration_factor") {
+      set_calibration_factor(inputString);
+    } else if (commandString == "calibrate") {
+      calibrate(inputString);
+    } else if (commandString == "get_tare") {
+      get_tare();
+    } else if (commandString == "set_tare") {
+      set_tare(inputString);
+    } else if (commandString == "tare") {
+      tare();
+    } else if (commandString == "get_transmission_format") {
+      get_transmission_format();
+      /* Commented due to memory optimization
+        //  } else if (commandString == "send_sync_signal") {
+        //    sendSyncSignal();
+        //  } else if (commandString == "listen_sync_signal") {
+        //    listenSyncSignal();
+      */
+    } else {
+      Serial.println("Not a valid command");
+    }
+    inputString = "";
 
-void start_capture()
-{
-  //Disabling the battery level indicator
-  MsTimer2::stop();
-  Serial.println("Starting capture...");
-  totalTime = 0;
-  lastTime = micros();
-  measuredMax = scale.get_units();
-  impulse = 0;
-
-  //filling the array of forces ant times with initial force
-  lastMeasure = scale.get_units();
-  for (unsigned short i = 0; i < freq; i++) {
-    forces1s[i] = lastMeasure;
   }
 
-  for (short i = 0; i < samples200ms; i++) {
-    totalTimes1s[i] = 0;
-  }
+  void start_capture()
+  {
+    //Disabling the battery level indicator
+    MsTimer2::stop();
+    Serial.println("Starting capture...");
+    totalTime = 0;
+    lastTime = micros();
+    measuredMax = scale.get_units();
+    impulse = 0;
+
+    //filling the array of forces ant times with initial force
+    lastMeasure = scale.get_units();
+    for (unsigned short i = 0; i < freq; i++) {
+      forces1s[i] = lastMeasure;
+    }
 
-  maxMeanForce1s = lastMeasure;
+    for (short i = 0; i < samples200ms; i++) {
+      totalTimes1s[i] = 0;
+    }
 
-  //Initializing variability variables
-  sumSSD = 0.0;
-  sumMeasures = lastMeasure;
-  samplesSSD = 0;
-  lcd.clear();
-  capturing = true;
-}
+    maxMeanForce1s = lastMeasure;
 
-void end_capture()
-{
-  capturing = false;
-  Serial.println("Capture ended:");
-  delay(500);
-
-  //If the device is controlled by the PC the results menu is not showed
-  //because during the menu navigation the Serial is not listened.
-  if (!PCControlled) {
-    //Restoring tare value in the EEPROM. Necessary after Tare&Capture
-    EEPROM.get(tareAddress, tareValue);
-    scale.set_offset(tareValue);
-    Serial.println(scale.get_offset());
+    //Initializing variability variables
+    sumSSD = 0.0;
+    sumMeasures = lastMeasure;
+    samplesSSD = 0;
     lcd.clear();
-    lcd.setCursor(4, 0);
-    lcd.print("Results:");
-    showResults();
+    capturing = true;
   }
 
-  //Activating the Battery level indicator
-  MsTimer2::start();
-  showMenu();
-}
+  void end_capture()
+  {
+    capturing = false;
+    Serial.println("Capture ended:");
+    delay(500);
+
+    //If the device is controlled by the PC the results menu is not showed
+    //because during the menu navigation the Serial is not listened.
+    if (!PCControlled) {
+      //Restoring tare value in the EEPROM. Necessary after Tare&Capture
+      EEPROM.get(tareAddress, tareValue);
+      scale.set_offset(tareValue);
+      Serial.println(scale.get_offset());
+      lcd.clear();
+      lcd.setCursor(4, 0);
+      lcd.print("Results:");
+      showResults();
+    }
 
-void get_version()
-{
-  //Device string not in a variable due to memory optimization
-  Serial.print("Force_Sensor-");
-  Serial.println(version);
-}
+    //Activating the Battery level indicator
+    MsTimer2::start();
+    showMenu();
+  }
 
-void get_calibration_factor()
-{
-  Serial.println(scale.get_scale());
-}
+  void get_version()
+  {
+    //Device string not in a variable due to memory optimization
+    Serial.print("Force_Sensor-");
+    Serial.println(version);
+  }
 
-void set_calibration_factor(String inputString)
-{
-  //Reading the argument of the command. Located within the ":" and the ";"
-  String calibration_factor = get_command_argument(inputString);
-  //Serial.println(calibration_factor.toFloat());
-  scale.set_scale(calibration_factor.toFloat());
-  float stored_calibration = 0.0f;
-  EEPROM.get(calibrationAddress, stored_calibration);
-  if (stored_calibration != calibration_factor.toFloat()) {
-    EEPROM.put(calibrationAddress, calibration_factor.toFloat());
+  void get_calibration_factor()
+  {
+    Serial.println(scale.get_scale());
   }
-  Serial.println("Calibration factor set");
-}
 
-void calibrate(String inputString)
-{
-  //Reading the argument of the command. Located within the ":" and the ";"
-  String weightString = get_command_argument(inputString);
-  float weight = weightString.toFloat();
-  //mean of 255 values comming from the cell after resting the offset.
-  double offsetted_data = scale.get_value(50);
-
-  //offsetted_data / calibration_factor
-  float calibration_factor = offsetted_data / weight / 9.81; //We want to return Newtons.
-  scale.set_scale(calibration_factor);
-  EEPROM.put(calibrationAddress, calibration_factor);
-  Serial.print("Calibrating OK:");
-  Serial.println(calibration_factor);
-}
+  void set_calibration_factor(String inputString)
+  {
+    //Reading the argument of the command. Located within the ":" and the ";"
+    String calibration_factor = get_command_argument(inputString);
+    //Serial.println(calibration_factor.toFloat());
+    scale.set_scale(calibration_factor.toFloat());
+    float stored_calibration = 0.0f;
+    EEPROM.get(calibrationAddress, stored_calibration);
+    if (stored_calibration != calibration_factor.toFloat()) {
+      EEPROM.put(calibrationAddress, calibration_factor.toFloat());
+    }
+    Serial.println("Calibration factor set");
+  }
 
-void tare()
-{
-  lcd.clear();
-  lcd.setCursor(3, 0);
-  lcd.print("Taring...");
-  scale.tare(50); //Reset the scale to 0 using the mean of 255 raw values
-  EEPROM.put(tareAddress, scale.get_offset());
-  Serial.print("Taring OK:");
-  Serial.println(scale.get_offset());
-
-
-  lcd.setCursor(3, 0);
-  lcd.print("  Tared  ");
-  delay(300);
-}
+  void calibrate(String inputString)
+  {
+    //Reading the argument of the command. Located within the ":" and the ";"
+    String weightString = get_command_argument(inputString);
+    float weight = weightString.toFloat();
+    //mean of 255 values comming from the cell after resting the offset.
+    double offsetted_data = scale.get_value(50);
+
+    //offsetted_data / calibration_factor
+    float calibration_factor = offsetted_data / weight / 9.81; //We want to return Newtons.
+    scale.set_scale(calibration_factor);
+    EEPROM.put(calibrationAddress, calibration_factor);
+    Serial.print("Calibrating OK:");
+    Serial.println(calibration_factor);
+  }
 
-void tareTemp()
-{
-  lcd.clear();
-  lcd.setCursor(3, 0);
-  lcd.print("Taring...");
-  scale.tare(50); //Reset the scale to 0 using the mean of 255 raw values
-  lcd.setCursor(3, 0);
-  lcd.print("  Tared  ");
-  delay(300);
-}
+  void tare()
+  {
+    lcd.clear();
+    lcd.setCursor(3, 0);
+    lcd.print("Taring...");
+    scale.tare(50); //Reset the scale to 0 using the mean of 255 raw values
+    EEPROM.put(tareAddress, scale.get_offset());
+    Serial.print("Taring OK:");
+    Serial.println(scale.get_offset());
 
-void get_tare()
-{
-  Serial.println(scale.get_offset());
-}
 
-void set_tare(String inputString)
-{
-  String tare = get_command_argument(inputString);
-  long value = tare.toInt();
-  scale.set_offset(value);
-  long stored_tare = 0;
-  EEPROM.get(tareAddress, stored_tare);
-  if (stored_tare != value) {
-    EEPROM.put(tareAddress, value);
-    Serial.println("updated");
+    lcd.setCursor(3, 0);
+    lcd.print("  Tared  ");
+    delay(300);
   }
-  Serial.println("Tare set");
-}
 
-String get_command_argument(String inputString)
-{
-  return (inputString.substring(inputString.lastIndexOf(":") + 1, inputString.lastIndexOf(";")));
-}
+  void tareTemp()
+  {
+    lcd.clear();
+    lcd.setCursor(3, 0);
+    lcd.print("Taring...");
+    scale.tare(50); //Reset the scale to 0 using the mean of 255 raw values
+    lcd.setCursor(3, 0);
+    lcd.print("  Tared  ");
+    delay(300);
+  }
 
-void get_transmission_format()
-{
-  if (binaryFormat)
+  void get_tare()
   {
-    Serial.println("binary");
-  } else
+    Serial.println(scale.get_offset());
+  }
+
+  void set_tare(String inputString)
   {
-    Serial.println("text");
+    String tare = get_command_argument(inputString);
+    long value = tare.toInt();
+    scale.set_offset(value);
+    long stored_tare = 0;
+    EEPROM.get(tareAddress, stored_tare);
+    if (stored_tare != value) {
+      EEPROM.put(tareAddress, value);
+      Serial.println("updated");
+    }
+    Serial.println("Tare set");
   }
-}
 
-void changingRCA() {
-  //TODO: Check the overflow of the lastTriggerTime
-  detachInterrupt(digitalPinToInterrupt(rcaPin));
-  rcaTime = totalTime;
+  String get_command_argument(String inputString)
+  {
+    return (inputString.substring(inputString.lastIndexOf(":") + 1, inputString.lastIndexOf(";")));
+  }
 
-  rcaState = digitalRead(rcaPin);
+  void get_transmission_format()
+  {
+    if (binaryFormat)
+    {
+      Serial.println("binary");
+    } else
+    {
+      Serial.println("text");
+    }
+  }
 
-  attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
-}
+  void changingRCA() {
+    //TODO: Check the overflow of the lastTriggerTime
+    detachInterrupt(digitalPinToInterrupt(rcaPin));
+    rcaTime = totalTime;
 
-void calibrateLCD(void) {
-  MsTimer2::stop();
-  short increment = 1;
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print((menu + 1) % 4 + 1);
-  lcd.print("-Calibrate    >");
-  int weight = 1;
-  submenu = 0;
-  bool exitFlag = false;
-  String calibrateCommand = calibrateCommand + String(weight, DEC) + ";";
-  //  showCalibrateLoad(String(weight, DEC));
-  lcd.setCursor(15, 0);
-  lcd.print(">");
-  lcd.setCursor(2, 1);
-  lcd.print(" Current:" );
-  lcd.print(weight);
-  lcd.setCursor(14, 1);
-  lcd.print("+");
-  lcd.print(increment);
-  delay(200);
-  redButtonState = false;
-  while (!exitFlag) {
-    if (submenu == 0) {
+    rcaState = digitalRead(rcaPin);
 
-      if (redButtonState) {
-        weight += increment;
-        if (weight == 101) {
-          weight = 1;
-          lcd.setCursor(12, 1);
-          lcd.print("  ");
-        }
+    attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
+  }
 
-        lcd.setCursor(11, 1);
-        lcd.print(weight);
-
-        if (weight == 5) {
-          increment = 5;
-          lcd.setCursor(14, 1);
-          lcd.print("+");
-          lcd.print(increment);
-        } else if (weight == 100) {
-          increment = 1;
-          lcd.setCursor(14, 1);
-          lcd.print("+");
-          lcd.print(increment);
-        }
+  void calibrateLCD(void) {
+    MsTimer2::stop();
+    short increment = 1;
+    lcd.clear();
+    lcd.setCursor(0, 0);
+    lcd.print((menu + 1) % 4 + 1);
+    lcd.print("-Calibrate    >");
+    int weight = 1;
+    submenu = 0;
+    bool exitFlag = false;
+    String calibrateCommand = calibrateCommand + String(weight, DEC) + ";";
+    //  showCalibrateLoad(String(weight, DEC));
+    lcd.setCursor(15, 0);
+    lcd.print(">");
+    lcd.setCursor(2, 1);
+    lcd.print(" Current:" );
+    lcd.print(weight);
+    lcd.setCursor(14, 1);
+    lcd.print("+");
+    lcd.print(increment);
+    delay(200);
+    redButtonState = false;
+    while (!exitFlag) {
+      if (submenu == 0) {
 
-        calibrateCommand = calibrateCommand + String(weight, DEC) + ";";
-        delay(200);
-      }
-      if (blueButtonState) {
-        //Change to Calibrate execution
-        lcd.clear();
-        lcd.setCursor(10, 0);
-        lcd.print("Cancel");
-        lcd.setCursor(0, 1);
-        lcd.print("StartCalibration");
-        submenu = 1;
-        blueButtonState = false;
-        delay(200);
-      }
-    }
+        if (redButtonState) {
+          weight += increment;
+          if (weight == 101) {
+            weight = 1;
+            lcd.setCursor(12, 1);
+            lcd.print("  ");
+          }
 
-    if (submenu == 1) {
-      if (redButtonState) {
-        lcd.clear();
-        lcd.setCursor(1, 0);
-        lcd.print("Calibrating...");
-        calibrate(calibrateCommand);
-        lcd.clear();
-        lcd.setCursor(2, 0);
-        lcd.print("Calibrated");
-        exitFlag = true;
-        delay(200);
+          lcd.setCursor(11, 1);
+          lcd.print(weight);
+
+          if (weight == 5) {
+            increment = 5;
+            lcd.setCursor(14, 1);
+            lcd.print("+");
+            lcd.print(increment);
+          } else if (weight == 100) {
+            increment = 1;
+            lcd.setCursor(14, 1);
+            lcd.print("+");
+            lcd.print(increment);
+          }
+
+          calibrateCommand = calibrateCommand + String(weight, DEC) + ";";
+          delay(200);
+        }
+        if (blueButtonState) {
+          //Change to Calibrate execution
+          lcd.clear();
+          lcd.setCursor(10, 0);
+          lcd.print("Cancel");
+          lcd.setCursor(0, 1);
+          lcd.print("StartCalibration");
+          submenu = 1;
+          blueButtonState = false;
+          delay(200);
+        }
       }
-      if (blueButtonState) {
-        exitFlag = true;
+
+      if (submenu == 1) {
+        if (redButtonState) {
+          lcd.clear();
+          lcd.setCursor(1, 0);
+          lcd.print("Calibrating...");
+          calibrate(calibrateCommand);
+          lcd.clear();
+          lcd.setCursor(2, 0);
+          lcd.print("Calibrated");
+          exitFlag = true;
+          delay(200);
+        }
+        if (blueButtonState) {
+          exitFlag = true;
+        }
       }
-    }
 
-    redButtonState = !digitalRead(redButtonPin);
-    blueButtonState = !digitalRead(blueButtonPin);
-    Serial.println(redButtonState);
+      redButtonState = !digitalRead(redButtonPin);
+      blueButtonState = !digitalRead(blueButtonPin);
+      Serial.println(redButtonState);
+    }
+    delay(1000);
+    MsTimer2::start();
+    showMenu();
   }
-  delay(1000);
-  MsTimer2::start();
-  showMenu();
-}
 
-void showBatteryLevel() {
-  float sensorValue = analogRead(A0);
-  if (sensorValue >= 788) {
-    lcd.createChar(0, battery5);
-  } else if (sensorValue < 788 && sensorValue >= 759) {
-    lcd.createChar(0, battery4);
-  } else if (sensorValue < 759 && sensorValue >= 730) {
-    lcd.createChar(0, battery3);
-  } else if (sensorValue < 730 && sensorValue >= 701) {
-    lcd.createChar(0, battery2);
-  } else if (sensorValue < 701 && sensorValue >= 672) {
-    lcd.createChar(0, battery1);
-  } else if (sensorValue <= 701) {
-    lcd.createChar(0, battery0);
+  void showBatteryLevel() {
+    float sensorValue = analogRead(A0);
+    if (sensorValue >= 788) {
+      lcd.createChar(0, battery5);
+    } else if (sensorValue < 788 && sensorValue >= 759) {
+      lcd.createChar(0, battery4);
+    } else if (sensorValue < 759 && sensorValue >= 730) {
+      lcd.createChar(0, battery3);
+    } else if (sensorValue < 730 && sensorValue >= 701) {
+      lcd.createChar(0, battery2);
+    } else if (sensorValue < 701 && sensorValue >= 672) {
+      lcd.createChar(0, battery1);
+    } else if (sensorValue <= 701) {
+      lcd.createChar(0, battery0);
+    }
+    lcd.setCursor(0, 1);
+    lcd.write(byte (0));
   }
-  lcd.setCursor(0, 1);
-  lcd.write(byte (0));
-}
 
-//TODO: Add more information or eliminate
-void showSystemInfo() {
-  MsTimer2::stop();
-  lcd.clear();
-  lcd.setCursor(2, 0);
-  lcd.print("Ver: ");
-  lcd.print(version);
-  lcd.setCursor(2, 1);
-  lcd.print("submenu: ");
-  lcd.print(submenu);
-  delay(1000);
-  redButtonState = !digitalRead(redButtonPin);
-  submenu = 0;
-  while (!redButtonState) {
-    blueButtonState = !digitalRead(blueButtonPin);
-    if (blueButtonState) {
-      delay(200);
-      submenu++;
-      submenu = submenu % 3;
-      if (submenu == 0) {
-        lcd.setCursor(2, 0);
-        lcd.print("Ver: ");
-        lcd.print(version);
-        lcd.setCursor(2, 1);
-        lcd.print("submenu: ");
-        lcd.print(submenu);
-      } else if (submenu == 1) {
-        lcd.setCursor(2, 1);
-        lcd.print("submenu: ");
-        lcd.print(submenu);
-      } else if (submenu == 2) {
-        lcd.setCursor(2, 1);
-        lcd.print("submenu: ");
-        lcd.print(submenu);
+  //TODO: Add more information or eliminate
+  void showSystemInfo() {
+    MsTimer2::stop();
+    lcd.clear();
+    lcd.setCursor(2, 0);
+    lcd.print("Ver: ");
+    lcd.print(version);
+    lcd.setCursor(2, 1);
+    lcd.print("submenu: ");
+    lcd.print(submenu);
+    delay(1000);
+    redButtonState = !digitalRead(redButtonPin);
+    submenu = 0;
+    while (!redButtonState) {
+      blueButtonState = !digitalRead(blueButtonPin);
+      if (blueButtonState) {
+        delay(200);
+        submenu++;
+        submenu = submenu % 3;
+        if (submenu == 0) {
+          lcd.setCursor(2, 0);
+          lcd.print("Ver: ");
+          lcd.print(version);
+          lcd.setCursor(2, 1);
+          lcd.print("submenu: ");
+          lcd.print(submenu);
+        } else if (submenu == 1) {
+          lcd.setCursor(2, 1);
+          lcd.print("submenu: ");
+          lcd.print(submenu);
+        } else if (submenu == 2) {
+          lcd.setCursor(2, 1);
+          lcd.print("submenu: ");
+          lcd.print(submenu);
+        }
       }
+      redButtonState = !digitalRead(redButtonPin);
     }
-    redButtonState = !digitalRead(redButtonPin);
+    MsTimer2::start();
   }
-  MsTimer2::start();
-}
 
-void showResults() {
-  int textSize = 2;
-  Serial.println("In showResults");
-  int submenu = 4;
-  redButtonState = false;
-  tft.fillScreen(BLACK);
-  tft.setTextSize(3);
-  tft.setCursor(100, 0);
-  tft.print("Results");
+  void showResults() {
+    int textSize = 2;
+    Serial.println("In showResults");
+    int submenu = 4;
+    redButtonState = false;
+    tft.fillScreen(BLACK);
+    tft.setTextSize(3);
+    tft.setCursor(100, 0);
+    tft.print("Results");
+
+    tft.drawLine(0, 20, 320, 20, GREY);
+    tft.drawLine(160, 240, 160, 20, GREY);
+    tft.setTextSize(textSize);
+
+    tft.setCursor(0, 40);
+    tft.print("Fmax");
+    printTftFormat(measuredMax, 100, 40, textSize, 1);
+
+    tft.setCursor(170, 40);
+    tft.print("Fmax1s");
+    printTftFormat(maxMeanForce1s, 280, 40, textSize, 1);
+
+    tft.setCursor(0, 80);
+    tft.print("Ftrig");
+    printTftFormat(forceTrigger, 100, 80, textSize, 1);
+
+    tft.setCursor(170, 80);
+    tft.print("Imp");
+    printTftFormat(impulse, 280, 80, textSize, 1);
+
+    tft.setCursor(0, 120);
+    tft.print("RFD100");
+    printTftFormat(maxRFD100, 124, 120, textSize, 0);
+
+    tft.setCursor(170, 120);
+    tft.print("RFD200");
+    printTftFormat(maxRFD200, 304, 120, textSize, 0);
+
+    tft.setCursor(0, 160);
+    tft.print("RMSSD");
+    printTftFormat(RMSSD, 100, 160, textSize, 1);
+
+    tft.setCursor(170, 160);
+    tft.print("cvRMSSD");
+    printTftFormat(RMSSD, 280, 160, textSize, 1);
+
+    //Red button exits results
+    while (!redButtonState) {
+      blueButtonState = !digitalRead(blueButtonPin);
+      redButtonState = !digitalRead(redButtonPin);
+      //Blue button changes menu option
+      if (blueButtonState) {
+        Serial.println("Blue pressed");
+        blueButtonState = false;
+      }
+    }
+    Serial.println("Red pressed");
+    redButtonState = false;
+    //delay(200);
+    tft.fillRect(0, 20, 320, 240, BLACK);
+    drawMenuBackground();
+  }
 
-  tft.drawLine(0, 20, 320, 20, GREY);
-  tft.drawLine(160, 240, 160, 20, GREY);
-  tft.setTextSize(textSize);
+  void showSystem()
+  {
+    bool exitFlag = false;
 
-  tft.setCursor(0, 40);
-  tft.print("Fmax");
-  printTftFormat(measuredMax, 100, 40, textSize, 1);
+    showSystemMenu();
 
-  tft.setCursor(170, 40);
-  tft.print("Fmax1s");
-  printTftFormat(maxMeanForce1s, 280, 40, textSize, 1);
+    blueButtonState = false;
+    redButtonState = false;
 
-  tft.setCursor(0, 80);
-  tft.print("Ftrig");
-  printTftFormat(forceTrigger, 100, 80, textSize, 1);
+    while (!exitFlag) {
+      while (!blueButtonState && !redButtonState)
+      {
+        redButtonState = !digitalRead(redButtonPin);
+        blueButtonState = !digitalRead(blueButtonPin);
+      }
 
-  tft.setCursor(170, 80);
-  tft.print("Imp");
-  printTftFormat(impulse, 280, 80, textSize, 1);
+      //Blue button pressed. Change submenu option
+      if (blueButtonState) {
+        blueButtonState = false;
+        submenu = (submenu + 1) % 3;
+        showSystemMenu();
 
-  tft.setCursor(0, 120);
-  tft.print("RFD100");
-  printTftFormat(maxRFD100, 124, 120, textSize, 0);
+      }
+      //Red button pressed. Execute the menu option
+      if (redButtonState) {
+        redButtonState = false;
+        exitFlag = true;
+        if (submenu == 0) {
+          tare();
+          menu = 0;
+          showMenu();
+        } else if (submenu == 1)
+        {
+          calibrateLCD();
+          menu = 0;
+          showMenu();
+        } else if (submenu == 2) {
+          showSystemInfo();
+          menu = 0;
+          showMenu();
+        }
+      }
+    }
+    delay(200);
+  }
 
-  tft.setCursor(170, 120);
-  tft.print("RFD200");
-  printTftFormat(maxRFD200, 304, 120, textSize, 0);
+  void showSystemMenu() {
+    Serial.println(submenu);
+    String configOptions[] = {
+      "1-Tare",
+      "2-Calibrate",
+      "3-Info",
+    };
 
-  tft.setCursor(0, 160);
-  tft.print("RMSSD");
-  printTftFormat(RMSSD, 100, 160, textSize, 1);
 
-  tft.setCursor(170, 160);
-  tft.print("cvRMSSD");
-  printTftFormat(RMSSD, 280, 160, textSize, 1);
+    Serial.println(configOptions[submenu]);
 
-  //Red button exits results
-  while (!redButtonState) {
-    blueButtonState = !digitalRead(blueButtonPin);
-    redButtonState = !digitalRead(redButtonPin);
-    //Blue button changes menu option
-    if (blueButtonState) {
-      Serial.println("Blue pressed");
-      blueButtonState = false;
+    lcd.clear();
+    lcd.setCursor(0, 0);
+    lcd.print(configOptions[submenu]);
+
+    lcd.setCursor(14, 0);
+    lcd.print((submenu + 1) % 3 + 1);
+
+    //The up arrow is associated to the blue button
+    lcd.createChar(6, upArrow);
+    lcd.setCursor(15, 0);
+    lcd.write(byte (6));
+    //the down arrow is associated to the red button
+    lcd.createChar(7, downArrow);
+    lcd.setCursor(15, 1);
+    lcd.write(byte (7));
+
+    if (submenu == 0) {         //Tare option
+      lcd.setCursor(11, 1);
+      lcd.print("Start");
+    } else if (submenu == 1) {  //Calibrate option
+      lcd.setCursor(11, 1);
+      lcd.print("Start");
+    } else if (submenu == 2) {  //Info option
+      lcd.setCursor(12, 1);
+      lcd.print("Show");
     }
+
+    delay(200);
   }
-  Serial.println("Red pressed");
-  redButtonState = false;
-  //delay(200);
-  tft.fillRect(0, 20, 320, 240, BLACK);
-  drawMenuBackground();
-}
 
-void showSystem()
-{
-  bool exitFlag = false;
+  void start_steadiness()
+  {
+    totalTime = 0;
+    lastTime = micros();
 
-  showSystemMenu();
+    lcd.clear();
+    capturing = true;
+    capturingPreSteadiness = true;
+    delay(200);
+  }
 
-  blueButtonState = false;
-  redButtonState = false;
+  void end_steadiness()
+  {
+    capturing = false;
+    capturingSteadiness = false;
+    showSteadinessResults();
+  }
 
-  while (!exitFlag) {
-    while (!blueButtonState && !redButtonState)
+  void showSteadinessResults()
+  {
+    lcd.clear();
+    lcd.setCursor(0, 0);
+    lcd.print("RMSSD ");
+    printLcdFormat(RMSSD, 11, 0, 1);
+    lcd.setCursor(0, 1);
+    lcd.print("cvRMSSD  ");
+    printLcdFormat(cvRMSSD, 11, 1, 1);
+    lcd.createChar(7, exitChar);
+    lcd.setCursor(15, 1);
+    lcd.write(byte (7));
+    delay(1000);
+    redButtonState = false;
+    blueButtonState = false;
+    //Checking buttons state every 50 ms
+    while (!redButtonState && !blueButtonState)
     {
+      delay(50);
       redButtonState = !digitalRead(redButtonPin);
       blueButtonState = !digitalRead(blueButtonPin);
     }
-
-    //Blue button pressed. Change submenu option
-    if (blueButtonState) {
-      blueButtonState = false;
-      submenu = (submenu + 1) % 3;
-      showSystemMenu();
-
-    }
-    //Red button pressed. Execute the menu option
-    if (redButtonState) {
-      redButtonState = false;
-      exitFlag = true;
-      if (submenu == 0) {
-        tare();
-        menu = 0;
-        showMenu();
-      } else if (submenu == 1)
-      {
-        calibrateLCD();
-        menu = 0;
-        showMenu();
-      } else if (submenu == 2) {
-        showSystemInfo();
-        menu = 0;
-        showMenu();
-      }
-    }
-  }
-  delay(200);
-}
-
-void showSystemMenu() {
-  Serial.println(submenu);
-  String configOptions[] = {
-    "1-Tare",
-    "2-Calibrate",
-    "3-Info",
-  };
-
-
-  Serial.println(configOptions[submenu]);
-
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print(configOptions[submenu]);
-
-  lcd.setCursor(14, 0);
-  lcd.print((submenu + 1) % 3 + 1);
-
-  //The up arrow is associated to the blue button
-  lcd.createChar(6, upArrow);
-  lcd.setCursor(15, 0);
-  lcd.write(byte (6));
-  //the down arrow is associated to the red button
-  lcd.createChar(7, downArrow);
-  lcd.setCursor(15, 1);
-  lcd.write(byte (7));
-
-  if (submenu == 0) {         //Tare option
-    lcd.setCursor(11, 1);
-    lcd.print("Start");
-  } else if (submenu == 1) {  //Calibrate option
-    lcd.setCursor(11, 1);
-    lcd.print("Start");
-  } else if (submenu == 2) {  //Info option
-    lcd.setCursor(12, 1);
-    lcd.print("Show");
+    delay(200);
+    MsTimer2::start();
+    showMenu();
   }
 
-  delay(200);
-}
-
-void start_steadiness()
-{
-  totalTime = 0;
-  lastTime = micros();
-
-  lcd.clear();
-  capturing = true;
-  capturingPreSteadiness = true;
-  delay(200);
-}
-
-void end_steadiness()
-{
-  capturing = false;
-  capturingSteadiness = false;
-  showSteadinessResults();
-}
+  /*
+    function to draw a cartesian coordinate system and plot whatever data you want
+    just pass x and y and the graph will be drawn
+    huge arguement list
+    &d name of your display object
+    x = x data point
+    y = y datapont
+    gx = x graph location (lower left)
+    gy = y graph location (lower left)
+    w = width of graph
+    h = height of graph
+    xlo = lower bound of x axis
+    xhi = upper bound of x asis
+    xinc = division of x axis (distance not count)
+    ylo = lower bound of y axis
+    yhi = upper bound of y asis
+    yinc = division of y axis (distance not count)
+    title = title of graph
+    xlabel = x axis label
+    ylabel = y axis label
+    gcolor = graph line colors
+    acolor = axis line colors
+    pcolor = color of your plotted data
+    tcolor = text color
+    bcolor = background color
+    &redraw = flag to redraw graph on fist call only
+  */
 
-void showSteadinessResults()
-{
-  lcd.clear();
-  lcd.setCursor(0, 0);
-  lcd.print("RMSSD ");
-  printLcdFormat(RMSSD, 11, 0, 1);
-  lcd.setCursor(0, 1);
-  lcd.print("cvRMSSD  ");
-  printLcdFormat(cvRMSSD, 11, 1, 1);
-  lcd.createChar(7, exitChar);
-  lcd.setCursor(15, 1);
-  lcd.write(byte (7));
-  delay(1000);
-  redButtonState = false;
-  blueButtonState = false;
-  //Checking buttons state every 50 ms
-  while (!redButtonState && !blueButtonState)
+  void Graph(Adafruit_ILI9341 & d, double x, double y, double gx, double gy, double w, double h, double xlo, 
double xhi, double xinc, double ylo, double yhi, double yinc, String title, String xlabel, String ylabel, 
unsigned int gcolor, unsigned int acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, 
boolean & redraw)
   {
-    delay(50);
-    redButtonState = !digitalRead(redButtonPin);
-    blueButtonState = !digitalRead(blueButtonPin);
-  }
-  delay(200);
-  MsTimer2::start();
-  showMenu();
-}
-
-/*
-  function to draw a cartesian coordinate system and plot whatever data you want
-  just pass x and y and the graph will be drawn
-  huge arguement list
-  &d name of your display object
-  x = x data point
-  y = y datapont
-  gx = x graph location (lower left)
-  gy = y graph location (lower left)
-  w = width of graph
-  h = height of graph
-  xlo = lower bound of x axis
-  xhi = upper bound of x asis
-  xinc = division of x axis (distance not count)
-  ylo = lower bound of y axis
-  yhi = upper bound of y asis
-  yinc = division of y axis (distance not count)
-  title = title of graph
-  xlabel = x axis label
-  ylabel = y axis label
-  gcolor = graph line colors
-  acolor = axis line colors
-  pcolor = color of your plotted data
-  tcolor = text color
-  bcolor = background color
-  &redraw = flag to redraw graph on fist call only
-*/
+    double ydiv, xdiv;
+    // initialize old x and old y in order to draw the first point of the graph
+    // but save the transformed value
+    // note my transform funcition is the same as the map function, except the map uses long and we need 
doubles
+    //static double ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
+    //static double oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+    double i;
+    double temp;
+    int rot, newrot;
+
+    //Mapping values to coordinates
+    x =  (x - xlo) * ( w) / (xhi - xlo) + gx;
+    y =  (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
+
+    if (redraw == true)
+    {
 
-void Graph(Adafruit_ILI9341 &d, double x, double y, double gx, double gy, double w, double h, double xlo, 
double xhi, double xinc, double ylo, double yhi, double yinc, String title, String xlabel, String ylabel, 
unsigned int gcolor, unsigned int acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, 
boolean &redraw)
-{
-  double ydiv, xdiv;
-  // initialize old x and old y in order to draw the first point of the graph
-  // but save the transformed value
-  // note my transform funcition is the same as the map function, except the map uses long and we need 
doubles
-  //static double ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
-  //static double oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
-  double i;
-  double temp;
-  int rot, newrot;
-
-  //Mapping values to coordinates
-  x =  (x - xlo) * ( w) / (xhi - xlo) + gx;
-  y =  (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
-
-  if (redraw == true)
-  {
+      redraw = false;
+      //In redraw, a point is plotted at the most left point
+      ox = x;
+      oy = y;
+    }
 
-    redraw = false;
-    //In redraw, a point is plotted at the most left point
+    //graph drawn now plot the data
+    // the entire plotting code are these few lines...
+    // recall that ox and oy are initialized as static above
+    //Drawing 3 lines slows the drawing and erasing
+    d.drawLine(ox, oy, x, y, pcolor);
+    //  d.drawLine(ox, oy + 1, x, y + 1, pcolor);
+    //  d.drawLine(ox, oy - 1, x, y - 1, pcolor);
     ox = x;
     oy = y;
-  }
-
-  //graph drawn now plot the data
-  // the entire plotting code are these few lines...
-  // recall that ox and oy are initialized as static above
-  //Drawing 3 lines slows the drawing and erasing
-  d.drawLine(ox, oy, x, y, pcolor);
-//  d.drawLine(ox, oy + 1, x, y + 1, pcolor);
-//  d.drawLine(ox, oy - 1, x, y - 1, pcolor);
-  ox = x;
-  oy = y;
 
-}
+  }
 
-void redrawAxes(Adafruit_ILI9341 &d, double gx, double gy, double w, double h, double xlo, double xhi, 
double ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, 
unsigned int acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, boolean &resize)
-{
-  double ydiv, xdiv;
-  // initialize old x and old y in order to draw the first point of the graph
-  // but save the transformed value
-  // note my transform funcition is the same as the map function, except the map uses long and we need 
doubles
-  //static double ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
-  //static double oy = (y - ylo) * (- h) / (yhi - ylo) + gy;
-  double i;
-  double yAxis;
-  double xAxis;
-
-  //Vertical line
-  d.drawLine(gx, gy, gx, gy - h, acolor);
-  
-  // draw y scale
-  for ( i = ylo; i <= yhi; i += yinc)
+  void redrawAxes(Adafruit_ILI9341 & d, double gx, double gy, double w, double h, double xlo, double xhi, 
double ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, 
unsigned int acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, boolean & resize)
   {
-    // compute the transform
-    yAxis =  (i - ylo) * (-h) / (yhi - ylo) + gy;
-
-    d.drawLine(gx, yAxis, gx + w, yAxis, acolor);
-    if (resize)
+    double ydiv, xdiv;
+    // initialize old x and old y in order to draw the first point of the graph
+    // but save the transformed value
+    // note my transform funcition is the same as the map function, except the map uses long and we need 
doubles
+    //static double ox = (x - xlo) * ( w) / (xhi - xlo) + gx;
+    //static double oy = (y - ylo) * (- h) / (yhi - ylo) + gy;
+    double i;
+    double yAxis;
+    double xAxis;
+
+    //Vertical line
+    d.drawLine(gx, gy, gx, gy - h, acolor);
+
+    // draw y scale
+    for ( i = ylo; i <= yhi; i += yinc)
     {
-      d.setTextSize(1);
-      d.setTextColor(tcolor, bcolor);
-      printTftFormat(i, gx-6, yAxis - 3, 1, 0);
+      // compute the transform
+      yAxis =  (i - ylo) * (-h) / (yhi - ylo) + gy;
+
+      d.drawLine(gx, yAxis, gx + w, yAxis, acolor);
+      if (resize)
+      {
+        d.setTextSize(1);
+        d.setTextColor(tcolor, bcolor);
+        printTftFormat(i, gx - 6, yAxis - 3, 1, 0);
+      }
     }
-  }
 
-  //  xAxis =  (-xlo) * ( w) / (xhi - xlo) + gx;
-  //  d.drawLine(gx, gy, gx, gy - h, acolor);
+    //  xAxis =  (-xlo) * ( w) / (xhi - xlo) + gx;
+    //  d.drawLine(gx, gy, gx, gy - h, acolor);
 
-  //now draw the labels
-  d.setTextSize(2);
-  d.setTextColor(tcolor, bcolor);
-  d.setCursor(gx , gy - h - 30);
-  d.println(title);
+    //now draw the labels
+    d.setTextSize(2);
+    d.setTextColor(tcolor, bcolor);
+    d.setCursor(gx , gy - h - 30);
+    d.println(title);
 
-  d.setTextSize(1);
-  d.setTextColor(acolor, bcolor);
-  d.setCursor(gx , gy + 20);
-  d.println(xlabel);
+    d.setTextSize(1);
+    d.setTextColor(acolor, bcolor);
+    d.setCursor(gx , gy + 20);
+    d.println(xlabel);
 
-  d.setTextSize(1);
-  d.setTextColor(acolor, bcolor);
-  d.setCursor(gx - 30, gy - h - 10);
-  d.println(ylabel);
-}
+    d.setTextSize(1);
+    d.setTextColor(acolor, bcolor);
+    d.setCursor(gx - 30, gy - h - 10);
+    d.println(ylabel);
+  }
 
-void drawMenuBackground() {
-  tft.fillRect(0, 0, 320, 50, BLACK);
-  tft.fillRoundRect(0, 0, 30, 50, 10, WHITE);
-  tft.fillRoundRect(290, 0, 30, 50, 10, WHITE);
-  tft.setTextSize(3);
-  tft.setCursor(30, 20);
-}
+  void drawMenuBackground() {
+    tft.fillRect(0, 0, 320, 50, BLACK);
+    tft.fillRoundRect(0, 0, 30, 50, 10, WHITE);
+    tft.fillRoundRect(290, 0, 30, 50, 10, WHITE);
+    tft.setTextSize(3);
+    tft.setCursor(30, 20);
+  }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]