From 76962684a47b457863d0202ad454e16f1959b68a Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Sun, 4 Sep 2022 09:05:48 +0200 Subject: [PATCH] Improved ButtonPress --- src/config.h | 4 ++-- src/main.cpp | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/config.h b/src/config.h index 6792387..91197e0 100644 --- a/src/config.h +++ b/src/config.h @@ -66,10 +66,10 @@ #define Calibration_TimeToMiddle 3000 #define Calibration_messureTime 5 #define Calibration_messureCount 10 -// Langer druck Zeit -#define Button_LongPressTime 1000 // Kurzer druck Zeit #define Button_ShortPressTime 300 +// Code fertig Zeit +#define Button_FinishedTime 1000 // Beep Geschwindigkeit #define buzzSpeed 1 diff --git a/src/main.cpp b/src/main.cpp index b82d598..ec36b54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -224,36 +224,30 @@ void joystickButtonPress() { int Code[] = {}; //0 = short, 1 = long int CodeLenght = 0; bool Finished = false; - bool abort = false; - while(!Finished && !abort){ + while(!Finished){ int buttonTime = 0; - while(digitalRead(joystick_button_Pin) == LOW){ - buttonTime+= 10; - delay(10); + while(digitalRead(joystick_button_Pin) == LOW) { + buttonTime+= 1; + delay(1); } - if(buttonTime < Button_ShortPressTime){ + if(buttonTime < Button_ShortPressTime) { Code[CodeLenght] = 0; Serial.println("short press"); - } - else if(buttonTime < Button_LongPressTime){ + } else { Code[CodeLenght] = 1; Serial.println("long press"); } - else{ - abort = true; - Serial.println("Code aborted!"); - } CodeLenght++; buttonTime = 0; - while(digitalRead(joystick_button_Pin) == HIGH && !Finished && !abort){ - buttonTime+= 10; - delay(10); + while(digitalRead(joystick_button_Pin) == HIGH && !Finished){ + buttonTime+= 1; + delay(1); - if(buttonTime >= Button_LongPressTime){ + if(buttonTime >= Button_FinishedTime){ Finished = true; Serial.println("Code fineshed!"); }