From 1249ccafec888eb1a1c7089d392c64e779610f39 Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Sun, 15 May 2022 18:40:55 +0200 Subject: [PATCH] Added auto Recalibration --- Firmware 2.0/src/main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Firmware 2.0/src/main.cpp b/Firmware 2.0/src/main.cpp index de9e36d..d0aea5e 100644 --- a/Firmware 2.0/src/main.cpp +++ b/Firmware 2.0/src/main.cpp @@ -261,7 +261,10 @@ void joystickButtonPress(){ } void Autoplay(){ - if(autoplayLoop+1 >= sizeof(autoplayPos)/sizeof(autoplayPos[0])) autoplayLoop = 0; + if(autoplayLoop+1 >= sizeof(autoplayPos)/sizeof(autoplayPos[0])) { + autoplayLoop = 0; + calibrateMiddle(); + } if(autoplayStart) { autoplayStart = false; @@ -308,8 +311,14 @@ void loop(){ if(joystick_LX == 0 && joystick_LY == 0 && joystick_RX == 0 && joystick_RY == 0){ noTone(BuzzerPin); - if (TimeToAutoplay > offtime) - offtime++; + + if (TimeToAutoplay > offtime) offtime++; + + if(offtime >= TimeToAutoplay) { + Autoplay(); + } else if(offtime == TimeToDetach){ + detachAttach(true); + } } else{ offtime = 0; @@ -365,13 +374,6 @@ void loop(){ servoWrite(); } - if(offtime >= TimeToAutoplay){ - Autoplay(); - } - else if(offtime >= TimeToDetach){ - detachAttach(true); - } - if(digitalRead(joystick_button_Pin) == LOW){ detachAttach(true); joystickButtonPress();