diff --git a/ServoShutter/CHANGELOG.md b/ServoShutter/CHANGELOG.md index 63f2548ec380c27c43446bd214c4cb704715171e..34ed4ec2b883b94f76ad3ef69f23ab2038de1ea5 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 f9b589c9c41807cb9477e24b0b4c45e0fe7c3f09..64534c1d8faf8279ba53c0e4a6c6ecf72cedfbd4 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(); }