-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
+---------------------------------------------------------------------------+ | ||
| SlowMotionServo changelog | | ||
+---------------------------------------------------------------------------+ | ||
1.0.2 Default min and max have been changed to 1000 and 2000. | ||
More accurate SMSSmoothBounce trajectory. | ||
Fixed a problem with the initial position. | ||
Added PushButton example. | ||
1.0.1 Fix a typo in the library.properties | ||
1.0 Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Drive a servo by using a push button | ||
* Uses the Bounce2 library. This library can be installed using the library manager | ||
*/ | ||
|
||
#include <Servo.h> | ||
#include <SlowMotionServo.h> | ||
#include <Bounce2.h> | ||
|
||
SMSSmoothBounce myServo; | ||
Bounce myButton; | ||
|
||
const byte servoPin = 3; | ||
const byte buttonPin = 4; | ||
const byte ledPin = 13; | ||
|
||
void setup() | ||
{ | ||
pinMode(ledPin, OUTPUT); | ||
/* when the button is pressed, the input is LOW */ | ||
pinMode(buttonPin, INPUT_PULLUP); | ||
|
||
myButton.attach(buttonPin); | ||
/* scan interval for debounce */ | ||
myButton.interval(5); | ||
|
||
myServo.setMin(800); | ||
myServo.setMax(2200); | ||
myServo.setSpeed(1.5); | ||
myServo.setInitialPosition(0.0); | ||
myServo.setPin(servoPin); | ||
digitalWrite(ledPin, HIGH); | ||
} | ||
|
||
void loop() | ||
{ | ||
static float servoTarget = 0.0; | ||
|
||
/* update the state of the button */ | ||
myButton.update(); | ||
/* update the position of the servo */ | ||
SlowMotionServo::update(); | ||
|
||
if (myServo.isStopped()) { | ||
digitalWrite(ledPin, LOW); | ||
if (myButton.fell()) { | ||
/* look at the button only when the servo is stopped */ | ||
/* change the target */ | ||
servoTarget = 1.0 - servoTarget; | ||
/* set the new target for the servo */ | ||
myServo.goTo(servoTarget); | ||
digitalWrite(ledPin, HIGH); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters