add switch read

This commit is contained in:
Florent
2026-03-11 18:29:42 +01:00
parent 5f36968eaa
commit acadb47837
4 changed files with 14 additions and 0 deletions

View File

@@ -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

View File

@@ -9,4 +9,6 @@ int getStepsForDistance(float cm);
int getRotationSteps(float angleDeg);
int readSwitchOnce(int pin);
#endif // PAMI_UTILS_H

View File

@@ -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();

View File

@@ -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;
}