[chronojump/michrolab: 2/57] Pins adapted to SportAnalyzer pinout




commit ec09abb5409f95809b9b647a8fa8765b44151a25
Author: Xavier Padullés <testing chronojump org>
Date:   Wed Mar 23 18:56:00 2022 +0100

    Pins adapted to SportAnalyzer pinout

 arduino/ForceSensorTFT/ForceSensorTFT.ino | 72 +++++++++++++------------------
 1 file changed, 31 insertions(+), 41 deletions(-)
---
diff --git a/arduino/ForceSensorTFT/ForceSensorTFT.ino b/arduino/ForceSensorTFT/ForceSensorTFT.ino
index 30eaf406f..3d5556a44 100644
--- a/arduino/ForceSensorTFT/ForceSensorTFT.ino
+++ b/arduino/ForceSensorTFT/ForceSensorTFT.ino
@@ -27,8 +27,8 @@
 #include <LiquidCrystal.h>
 #include <MsTimer2.h>
 
-#define DOUT  5
-#define CLK  4
+#define DOUT  2
+#define CLK  3
 
 //Version number //it always need to start with: "Force_Sensor-"
 //Device commented for memory optimization
@@ -70,9 +70,9 @@ bool elapsed200 = false;  //Wether it has passed 200 ms since the start
 bool elapsed100 = false;  //Wether it has passed 100 ms since the start
 
 
-unsigned long currentTime = 0;  //Direct value from micros()
+unsigned long rcaTime = 0;  //Time at which RCA changed
 unsigned long elapsedTime = 0;  //Elapsed time between 2 consecutives measures. No overflow manage
-unsigned long totalTime = 0;    //Elapsed time since start of capture. Overflow managed
+elapsedMicros totalTime = 0;
 
 /* Not used in order to optimize memory
   //Used to sync 2 evices
@@ -80,10 +80,10 @@ unsigned long totalTime = 0;    //Elapsed time since start of capture. Overflow
   unsigned int samples = 0;
 */
 
-const unsigned short redButtonPin = 13;
+const unsigned short redButtonPin = 4;
 bool redButtonState;
 
-const unsigned short blueButtonPin = 6;
+const unsigned short blueButtonPin = 5;
 bool blueButtonState;
 
 //TODO. Manage it with timer interruptions
@@ -270,11 +270,11 @@ bool PCControlled = false;
 long tareValue = 0;
 
 void setup() {
-  pinMode(redButtonPin, INPUT);
-  pinMode(blueButtonPin, INPUT);
+  pinMode(redButtonPin, INPUT_PULLUP);
+  pinMode(blueButtonPin, INPUT_PULLUP);
   lcd.begin(16, 2);
 
-  Serial.begin(115200);
+  Serial.begin(256000);
 
   //Activate interruptions activated by any RCA state change
   attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
@@ -319,7 +319,7 @@ void loop()
   if (!capturing)
   {
     //The blue button navigates through the Menu options
-    blueButtonState = digitalRead(blueButtonPin);
+    blueButtonState = !digitalRead(blueButtonPin);
     if (blueButtonState) {
       blueButtonState = false;
       menu++;
@@ -329,7 +329,7 @@ void loop()
     delay(100);
 
     //The red button activates the menu option
-    redButtonState = digitalRead(redButtonPin);
+    redButtonState = !digitalRead(redButtonPin);
     if (redButtonState)
     {
       redButtonState = false;
@@ -360,6 +360,9 @@ void loop()
   {
     capture();
   }
+
+  //With Teensy serialEvent is not called automatically after loop
+  if (Serial.available()) serialEvent();
 }
 
 void showMenu(void)
@@ -408,8 +411,7 @@ void capture(void)
   {
     //Checking the RCA state
     if (rcaState != lastRcaState) {       //Event generated by the RCA
-      checkTimeOverflow();                //If micros had an overflow it is detected and corrected
-      Serial.print(totalTime);
+      Serial.print(rcaTime);
       Serial.print(";");
 
       if (rcaState) {
@@ -422,8 +424,7 @@ void capture(void)
 
       //If no RCA event, read the force as usual
     } else {
-      currentTime = micros();
-      checkTimeOverflow();
+      //rcaTime = totalTime;
       measured = scale.get_units();
 
       //When current Force Slot is equal to size of the buffer it starts over to 0
@@ -501,9 +502,10 @@ void capture(void)
     }
 
     //Pressing blue or red button ends the capture
-    redButtonState = digitalRead(redButtonPin);
-    blueButtonState = digitalRead(blueButtonPin);
+    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
@@ -773,25 +775,13 @@ void get_transmission_format()
 void changingRCA() {
   //TODO: Check the overflow of the lastTriggerTime
   detachInterrupt(digitalPinToInterrupt(rcaPin));
-  currentTime = micros();
+  rcaTime = totalTime;
 
   rcaState = digitalRead(rcaPin);
 
   attachInterrupt(digitalPinToInterrupt(rcaPin), changingRCA, CHANGE);
 }
 
-void checkTimeOverflow() {
-
-  //Managing the timer overflow
-  if (currentTime > lastTime)     //No overflow
-    elapsedTime = currentTime - lastTime;
-  else  if (currentTime <= lastTime) //Overflow
-    elapsedTime = (4294967295 - lastTime) + currentTime; //Time from the last measure to the overflow event 
plus the currentTime
-
-  //calculations
-  totalTime += elapsedTime;
-  lastTime = currentTime;
-}
 
 /* Disabled due to memory optimization
   //void sendSyncSignal() {
@@ -903,8 +893,8 @@ void calibrateLCD(void) {
       }
     }
 
-    redButtonState = digitalRead(redButtonPin);
-    blueButtonState = digitalRead(blueButtonPin);
+    redButtonState = !digitalRead(redButtonPin);
+    blueButtonState = !digitalRead(blueButtonPin);
     Serial.println(redButtonState);
   }
   delay(1000);
@@ -942,10 +932,10 @@ void showSystemInfo() {
   lcd.print("submenu: ");
   lcd.print(submenu);
   delay(1000);
-  redButtonState = digitalRead(redButtonPin);
+  redButtonState = !digitalRead(redButtonPin);
   submenu = 0;
   while (!redButtonState) {
-    blueButtonState = digitalRead(blueButtonPin);
+    blueButtonState = !digitalRead(blueButtonPin);
     if (blueButtonState) {
       delay(200);
       submenu++;
@@ -967,7 +957,7 @@ void showSystemInfo() {
         lcd.print(submenu);
       }
     }
-    redButtonState = digitalRead(redButtonPin);
+    redButtonState = !digitalRead(redButtonPin);
   }
   MsTimer2::start();
 }
@@ -993,8 +983,8 @@ void showResults() {
   printLcdFormat(maxMeanForce1s, 11, 1, 1);
   //Red button exits results
   while (!redButtonState) {
-    blueButtonState = digitalRead(blueButtonPin);
-    redButtonState = digitalRead(redButtonPin);
+    blueButtonState = !digitalRead(blueButtonPin);
+    redButtonState = !digitalRead(redButtonPin);
     //Blue button changes menu option
     if (blueButtonState) {
       blueButtonState = false;
@@ -1052,8 +1042,8 @@ void showSystem()
   while (!exitFlag) {
     while (!blueButtonState && !redButtonState)
     {
-      redButtonState = digitalRead(redButtonPin);
-      blueButtonState = digitalRead(blueButtonPin);
+      redButtonState = !digitalRead(redButtonPin);
+      blueButtonState = !digitalRead(blueButtonPin);
     }
 
     //Blue button pressed. Change submenu option
@@ -1164,8 +1154,8 @@ void showSteadinessResults()
   while (!redButtonState && !blueButtonState)
   {
     delay(50);
-    redButtonState = digitalRead(redButtonPin);
-    blueButtonState = digitalRead(blueButtonPin);
+    redButtonState = !digitalRead(redButtonPin);
+    blueButtonState = !digitalRead(blueButtonPin);
   }
   delay(200);
   MsTimer2::start();


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