From 53e94d69f61fb6f12a795c4bf366314f3979cc4a Mon Sep 17 00:00:00 2001 From: Myres <myres> Date: Thu, 27 Jun 2024 10:33:00 +0200 Subject: [PATCH] Define servoshutter behaviour without switch (or switch in open state). --- ServoShutter/CHANGELOG.md | 7 +++++++ ServoShutter/ServoShutter.ino | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ServoShutter/CHANGELOG.md b/ServoShutter/CHANGELOG.md index 63f2548..34ed4ec 100644 --- a/ServoShutter/CHANGELOG.md +++ b/ServoShutter/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## 1.2.0 + +### Changed + +- Switch uses internal pullup for defined behavior. + + ## 1.1.0 ### Added diff --git a/ServoShutter/ServoShutter.ino b/ServoShutter/ServoShutter.ino index f9b589c..64534c1 100644 --- a/ServoShutter/ServoShutter.ino +++ b/ServoShutter/ServoShutter.ino @@ -10,7 +10,7 @@ o? queries the current output state (independent whether it has been set via com "l" returns the current state and manual mode (tab separated) **************************** */ -const String version = "1.1.0"; // Version of this script +const String version = "1.2.0"; // Version of this script // Servo setup #include <Servo.h> @@ -31,8 +31,8 @@ void setup() // Read initial state delay(100); - val = analogRead(switchPin); - if ( val >= 512 ){ + pinMode(switchPin, INPUT_PULLUP); + if ( !digitalRead(switchPin) ){ state = -2; } } @@ -97,13 +97,13 @@ void loop() } if ( manual ){ - val = analogRead(switchPin); + val = digitalRead(switchPin); // If the analog value changed from the known state or known switch, change shutter. - if(val >= 512 && (state == 0 || state == -1)) + if( !val && (state == 0 || state == -1)) { openShutter(); } - else if(val < 512 && (state == 1 || state == -2)) + else if( val && (state == 1 || state == -2)) { closeShutter(); } -- GitLab