-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding servo examples * Increment version
- Loading branch information
Showing
12 changed files
with
333 additions
and
13 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
Animately.zip | ||
examples/Waveform | ||
|
||
# From: https://github.com/github/gitignore | ||
|
||
# Prerequisites | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// This example slowly goes through various easing/tweening algorithms, increasing the aggressiveness as it goes. It starts with a sine wave, which | ||
// is only slightly modified from linear motion, and ends at exponential, which is super aggressive smoothing compared to linear. | ||
|
||
#include <Servo.h> | ||
|
||
#include <Animately.h> | ||
#include <Core/Timeline.h> | ||
#include <Parts/LED.h> | ||
|
||
#include <Tweens/Sine.h> | ||
#include <Tweens/Quadratic.h> | ||
#include <Tweens/Cubic.h> | ||
#include <Tweens/Quintic.h> | ||
#include <Tweens/Exponential.h> | ||
|
||
using namespace Animately; | ||
|
||
class Scene { | ||
private: | ||
Timeline *timeline; | ||
Sine *sine; | ||
Quadratic *quadratic; | ||
Cubic *cubic; | ||
Quintic *quintic; | ||
Exponential *exponential; | ||
Servo *servo; | ||
|
||
public: | ||
Scene(Timeline *timeline, Servo *servo, Sine *sine, Quadratic *quadratic, Cubic *cubic, Quintic *quinticintic, Exponential *exponential) { | ||
this->timeline = timeline; | ||
this->sine = sine; | ||
this->servo = servo; | ||
this->quadratic = quadratic; | ||
this->cubic = cubic; | ||
this->quintic = quintic; | ||
this->exponential = exponential; | ||
} | ||
|
||
void cueSine(int val) { | ||
LOG("Sine"); | ||
timeline->schedule(0, 180, 0, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(sine, &Sine::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
timeline->schedule(180, 0, 3000, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(sine, &Sine::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
// Schedule the next scene | ||
timeline->schedule(6000, 0, NULL, DELEGATE(this, &Scene::cueQuadratic)); | ||
} | ||
|
||
void cueQuadratic(int val) { | ||
LOG("Quadratic"); | ||
timeline->schedule(0, 180, 0, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quadratic, &Quadratic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
timeline->schedule(180, 0, 3000, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quadratic, &Quadratic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
// Schedule the next scene | ||
timeline->schedule(6000, 0, NULL, DELEGATE(this, &Scene::cueCubic)); | ||
} | ||
|
||
void cueCubic(int val) { | ||
LOG("Cubic"); | ||
timeline->schedule(0, 180, 0, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(cubic, &Cubic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
timeline->schedule(180, 0, 3000, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(cubic, &Cubic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
// Schedule the next scene | ||
timeline->schedule(6000, 0, NULL, DELEGATE(this, &Scene::cueQuintic)); | ||
} | ||
|
||
void cueQuintic(int val) { | ||
LOG("Quintic"); | ||
timeline->schedule(0, 180, 0, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
timeline->schedule(180, 0, 3000, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
// Schedule the next scene | ||
timeline->schedule(6000, 0, NULL, DELEGATE(this, &Scene::cueExponential)); | ||
} | ||
|
||
void cueExponential(int val) { | ||
LOG("Exponential"); | ||
timeline->schedule(0, 180, 0, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(exponential, &Exponential::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
timeline->schedule(180, 0, 3000, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(exponential, &Exponential::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
|
||
// Schedule the next scene | ||
timeline->schedule(6000, 0, NULL, DELEGATE(this, &Scene::cueSine)); | ||
} | ||
}; | ||
|
||
// Setup our timeline, part, tween, and scene | ||
Timeline timeline; | ||
Servo servo; | ||
Sine sine; | ||
Quadratic quadratic; | ||
Cubic cubic; | ||
Quintic quintic; | ||
Exponential exponential; | ||
Scene scene(&timeline, &servo, &sine, &quadratic, &cubic, &quintic, &exponential); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
servo.attach(11); | ||
|
||
// Kick off the animation | ||
scene.cueSine(0); | ||
} | ||
|
||
void loop() { | ||
// Call this at least once per ms. Calling it more often is fine. | ||
timeline.tick(); | ||
} | ||
|
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,94 @@ | ||
// This example shows how to animate a single servo. It utilizes the standard Arduino Servo library, which also shows | ||
// how you can use non-Animately classes as parts as long as their function signature matches. | ||
|
||
#include <Servo.h> // This is the standard Arduino library, not an Animately library | ||
|
||
#include <Animately.h> | ||
#include <Core/Timeline.h> | ||
#include <Parts/LED.h> | ||
#include <Tweens/Quintic.h> | ||
|
||
using namespace Animately; | ||
|
||
class Scene { | ||
private: | ||
Timeline *timeline; | ||
Quintic *quintic; | ||
Servo *servo; | ||
|
||
public: | ||
Scene(Timeline *timeline, Servo *servo, Quintic *quintic) { | ||
this->timeline = timeline; | ||
this->servo = servo; | ||
this->quintic = quintic; | ||
} | ||
|
||
void cue(int val) { | ||
int currTime = 0; | ||
timeline->schedule(0, 180, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
timeline->schedule(180, 45, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
timeline->schedule(45, 0, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
timeline->schedule(0, 90, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
timeline->schedule(90, 180, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
timeline->schedule(180, 0, currTime, 3000, | ||
NULL, | ||
DELEGATE(servo, &Servo::write), | ||
DELEGATE(quintic, &Quintic::inOut), | ||
DELEGATE(servo, &Servo::write)); | ||
currTime += 3000; | ||
|
||
// Schedule it to play again | ||
timeline->schedule(currTime, 0, NULL, DELEGATE(this, &Scene::cue)); | ||
} | ||
}; | ||
|
||
// Setup our timeline, part, tween, and scene | ||
Timeline timeline; | ||
Servo servo; | ||
Quintic quintic; | ||
Scene scene(&timeline, &servo, &quintic); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
servo.attach(11); | ||
|
||
// Kick off the animation | ||
scene.cue(0); | ||
} | ||
|
||
void loop() { | ||
// Call this at least once per ms. Calling it more is fine. | ||
timeline.tick(); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=Animately | ||
version=0.1.1 | ||
version=0.2.0 | ||
author=Nicholas Koza | ||
maintainer=Nicholas Koza | ||
sentence=Precise animation of props or robots without the need for thread-blocking (delay()) or complex state machines. | ||
paragraph=Animately allows for precise animation of props or robots, down to the millisecond, without the need for thread-blocking (delay()) or complex state machines. This frees you to focus on the creative aspects of animating rather than the implementation details. | ||
category=Device Control | ||
url=https://github.com/nickkoza/animately | ||
includes=Animatedly.h,Core/Timeline.h | ||
includes=Animately.h,Core/Timeline.h |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Based on Robert Penner's easing functions: http://robertpenner.com/easing/ | ||
// and adapted from Warren Moore's C conversion: https://github.com/warrenm/AHEasing | ||
// Easing algorithms can be visualized on http://easings.net/ | ||
// | ||
// Robert Penner's easing functions are open-sourced under the BSD License: | ||
// TERMS OF USE - EASING EQUATIONS | ||
// | ||
// Open source under the BSD License. | ||
// | ||
// Copyright © 2001 Robert Penner | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
// following conditions are met: | ||
// | ||
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
// disclaimer in the documentation and/or other materials provided with the distribution. | ||
// Neither the name of the author nor the names of contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
#ifndef CUBIC_H_ | ||
#define CUBIC_H_ | ||
|
||
namespace Animately { | ||
class Cubic { | ||
public: | ||
float in(float p) { | ||
return p * p * p; | ||
} | ||
|
||
float out(float p) { | ||
p = (p - 1.f); | ||
return p * p * p + 1.f; | ||
} | ||
|
||
float inOut(float p) { | ||
if(p < 0.5f) { | ||
return 4.f * p * p * p; | ||
} | ||
p = ((2.f * p) - 2.f); | ||
return 0.5f * p * p * p + 1.f; | ||
} | ||
}; | ||
} | ||
|
||
#endif /* CUBIC_H_ */ |
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
Oops, something went wrong.