[chronojump/FS-LCD-Menu: 17/17] Added calibrate




commit f2e4b2b55643f7c20ad8cdedefe547756b14dd8d
Author: Xavier Padullés <x padulles gmail com>
Date:   Wed Dec 1 16:27:52 2021 +0100

    Added calibrate

 arduino/ForceSensorLCD/ForceSensorLCD.ino | 138 +++++++++---------------------
 1 file changed, 42 insertions(+), 96 deletions(-)
---
diff --git a/arduino/ForceSensorLCD/ForceSensorLCD.ino b/arduino/ForceSensorLCD/ForceSensorLCD.ino
index 3e7261100..a11d4da8b 100644
--- a/arduino/ForceSensorLCD/ForceSensorLCD.ino
+++ b/arduino/ForceSensorLCD/ForceSensorLCD.ino
@@ -204,9 +204,13 @@ void loop()
     } else if (menu == 2)
     {
       tare();
+      menu = 0;
+      showMenu();
     } else if (menu == 3)
     {
-      lcd.print("calibrating");
+      calibrateLCD();
+      menu = 0;
+      showMenu();
     } else if (menu == 4)
     {
       lcd.print("system info");
@@ -217,8 +221,6 @@ void loop()
 void showMenu(void)
 {
     lcd.clear();
-    lcd.setCursor(1, 0);
-    lcd.print(menu);
     lcd.setCursor(3, 0);
     lcd.print(menuList[menu]);
     lcd.setCursor(2, 1);
@@ -240,99 +242,6 @@ void showMenu(void)
       lcd.print("Red: System Info");
     }
 }
-//void loop()
-//{
-//  blueButtonState = digitalRead(blueButtonPin);
-//  if (blueButtonState == 1) {
-//    lcd.clear();
-//    lcd.setCursor(3, 0);
-//    lcd.print("Taring...");
-//    tare();
-//    lcd.setCursor(3, 0);
-//    lcd.print("Taring OK");
-//    delay(1000);
-//    lcd.setCursor(2, 0);
-//    lcd.print("CHRONOJUMP");
-//    lcd.setCursor(2, 1);
-//    lcd.print("Boscosystem");
-//    //    lcd.setCursor(2,1);
-//    //    lcd.print("Press Start");
-//
-//  }
-//  redButtonState = digitalRead(redButtonPin); //Red button
-//
-//  if(sendSyncTime) {
-//    Serial.print("sync:");
-//    Serial.println(syncTime);
-//    sendSyncTime = false;
-//  }
-//
-//  if (capturing)
-//  {
-//
-//    //Checking the RCA state
-//    if (rcaState != lastRcaState) {       //Event generated by the RCA
-//      checkTimeOverflow();
-//      Serial.print(totalTime);
-//      Serial.print(";");
-//
-//      if (rcaState) {
-//        Serial.println("R");
-//      } else {
-//        Serial.println("r");
-//      }
-//      lastRcaState = rcaState;
-//
-//    } else {                             //If no RCA event, read the force as usual
-//
-//      currentTime = micros();
-//      checkTimeOverflow();
-//      float measured = scale.get_units();
-//
-//      //RFD stuff start ------>
-//      if (rfdDataPre2Ok) {
-//        float rfdValue =  (measured - rfdMeasuredPre2) / ((elapsedTime + rfdTimePre) / 1000000.0);
-//        rfdCalculed = true;
-//        if (rfdValue > rfdValueMax) {
-//          rfdValueMax = rfdValue;
-//        }
-//      }
-//
-//      if (rfdDataPreOk) {
-//        rfdTimePre2 = rfdTimePre;
-//        rfdMeasuredPre2 = rfdMeasuredPre;
-//        rfdDataPre2Ok = true;
-//      }
-//
-//      rfdTimePre = elapsedTime;
-//      rfdMeasuredPre = measured;
-//      rfdDataPreOk = true;
-//      //<------- RFD stuff end
-//
-//      if (abs(measured) > abs(measuredLcdDelayMax)) {
-//        measuredLcdDelayMax = measured;
-//      }
-//      if (abs(measured) > abs(measuredMax)) {
-//        measuredMax = measured;
-//      }
-//
-//      Serial.print(totalTime); Serial.print(";");
-//      Serial.println(measured, 2); //scale.get_units() returns a float
-//
-//      printOnLcd();
-////      if (rcaState) {
-////        end_capture();
-////      }
-//    }
-//    if (redButtonState) {
-//      end_capture();
-//    }
-//  } else if (!capturing) {
-//    if (redButtonState) {
-//      start_capture();
-//    }
-//  }
-//}
 
 void capture(void)
 {
@@ -734,3 +643,40 @@ void getSyncTime() {
   //detachInterrupt(digitalPinToInterrupt(rcaPin));
   attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, FALLING);
 }
+
+void calibrateLCD(void) {
+  String weights[] = {"10", "20", "30", "40"};
+  short int submenu = 0;
+  bool exitFlag = false;
+  String calibrateCommand = "calibrate:";
+  showCalibrateMenu(weights[submenu]);
+  redButtonState = digitalRead(redButtonPin);
+  while(!exitFlag){
+    if(redButtonState){
+      Serial.println("Red pressed");
+      calibrateCommand = calibrateCommand + weights[submenu] + ";";
+      calibrate(calibrateCommand);
+      showMenu();
+      exitFlag = true;
+    }
+    if(blueButtonState){
+      submenu++;
+      submenu = submenu % 5;
+      showCalibrateMenu(weights[submenu]);
+    }
+    redButtonState = digitalRead(redButtonPin);
+    blueButtonState = digitalRead(blueButtonPin);
+  }
+  Serial.println("Exit bucle");
+  delay(1000);
+}
+
+void showCalibrateMenu(String weight){
+  lcd.setCursor(3, 0);
+  lcd.print("Calibrate ");
+  lcd.print(weight);
+  lcd.print(" kg");
+  lcd.setCursor(2,1);
+  lcd.print("Change Weight");
+  delay(500);
+}


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