From acadb47837decb0ee462f79033f00c77a3d0c1cd Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 11 Mar 2026 18:29:42 +0100 Subject: [PATCH] add switch read --- include/main.h | 2 ++ include/utils.h | 2 ++ src/main.cpp | 2 ++ src/utils.cpp | 8 ++++++++ 4 files changed, 14 insertions(+) diff --git a/include/main.h b/include/main.h index 1e70bce..f660ccd 100644 --- a/include/main.h +++ b/include/main.h @@ -47,6 +47,8 @@ struct Step { // Servo Moteur #define SERVO_PIN 15 #define EMG_PIN 5 +// Bouton de sélection de côté +#define SWITCH_PIN 14 #endif diff --git a/include/utils.h b/include/utils.h index cffd182..9711c8e 100644 --- a/include/utils.h +++ b/include/utils.h @@ -9,4 +9,6 @@ int getStepsForDistance(float cm); int getRotationSteps(float angleDeg); +int readSwitchOnce(int pin); + #endif // PAMI_UTILS_H diff --git a/src/main.cpp b/src/main.cpp index f5a3878..0c49b34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -225,6 +225,8 @@ void loop() { Serial.println("Trigger initialized"); } else if (digitalRead(TIRETTE_PIN) == HIGH && tirettePose) { Serial.println("Trigger removed"); + Serial.print("Switch : "); + Serial.println(readSwitchOnce(SWITCH_PIN) ? "OFF" : "ON"); delay(START_DELAY); Serial.println("Starting the script"); startTime = millis(); diff --git a/src/utils.cpp b/src/utils.cpp index be4d8d4..9eee4d2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -29,3 +29,11 @@ int getRotationSteps(float angleDeg) { return (int) round(microStepsForAngle); } + +int readSwitchOnce(int pin) { + pinMode(SWITCH_PIN, INPUT_PULLUP); + delay(10); + const bool switchState = digitalRead(SWITCH_PIN); + pinMode(SWITCH_PIN, INPUT); // retire le pull-up + return switchState; +}