-
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.
version 1.0.3. Added a method to reverse the movement. Example with 2…
… servo
- Loading branch information
Showing
9 changed files
with
96 additions
and
10 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,68 @@ | ||
/* | ||
* 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 myServoRight; | ||
SMSSmoothBounce myServoLeft; | ||
Bounce myButton; | ||
|
||
const byte servoRightPin = 4; | ||
const byte servoLeftPin = 3; | ||
const byte buttonPin = 5; | ||
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); | ||
|
||
myServoRight.setMin(750); | ||
myServoRight.setMax(1800); | ||
myServoLeft.setMin(1100); | ||
myServoLeft.setMax(2200); | ||
|
||
myServoRight.setSpeed(1.5); | ||
myServoLeft.setSpeed(1.5); | ||
|
||
myServoLeft.setReverted(true); | ||
|
||
myServoRight.setInitialPosition(0.0); | ||
myServoLeft.setInitialPosition(0.0); | ||
myServoRight.setPin(servoRightPin); | ||
myServoLeft.setPin(servoLeftPin); | ||
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 (myServoRight.isStopped() && myServoLeft.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 */ | ||
myServoRight.goTo(servoTarget); | ||
myServoLeft.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
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