Skip to content

Commit 040b494

Browse files
committed
complete show documentation
1 parent 9dcf4bf commit 040b494

File tree

1 file changed

+85
-16
lines changed

1 file changed

+85
-16
lines changed

README.md

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,21 @@ This is usually done inside the `setup` function after the servo objects have be
133133
Alternatively, we can also create an array of servos and call the `addServos` method instead:
134134

135135
```ino
136+
Animation myBlenderAnimation(30, 1000);
137+
136138
Servo myBlenderServos[] = {
137139
Servo(0, BoneA, move),
138140
Servo(1, BoneB, move),
139141
Servo(2, BoneC, move),
140-
...
141142
}
142143

143-
Animation myBlenderAnimation(30, 1000);
144-
145144
void setup() {
146-
myBlenderAnimation.addServos(myBlenderServos);
145+
myBlenderAnimation.addServos(myBlenderServos, 3);
147146
}
148147
```
149148
149+
> Note: the `addServos` function expects the amount of servos in the array to be passed via the second argument.
150+
150151
### Updating the Animation State
151152
152153
The animation needs to be triggered regularly in order to update its state and check if any servos have to be moved. We therefore need to call the `run` method during each `loop`:
@@ -218,15 +219,15 @@ On top of manually checking the animation mode, we can also register a callback
218219

219220
```ino
220221
void modeChanged(byte prevMode, byte newMode) {
221-
// Do something (e.g. using another switch)
222+
// Do something (e.g. using a switch statement)
222223
}
223224

224225
void setup() {
225226
myBlenderAnimation.onModeChange(modeChanged);
226227
}
227228
```
228229
229-
The [SwitchModeButton example](examples/SwitchModeButton) shows how to combine all mode methods to control an animation based on a single button. Make sure to also check out the other [examples](examples) to get started quickly.
230+
The [SwitchModeButton example](examples/SwitchModeButton) shows how to combine all mode methods to control an animation based on a single button.
230231
231232
## Defining a Show
232233
@@ -249,19 +250,87 @@ This is usually done inside the `setup` function after the animation and servo o
249250
Alternatively, we can also create an array of animations and call the `addAnimations` method instead:
250251

251252
```ino
252-
Animations myBlenderAnimations[] = {
253-
Animation()
253+
Show myBlenderShow;
254+
255+
Animation animations[3] = {
256+
{FPS, FRAMES_A},
257+
{FPS, FRAMES_B},
258+
{FPS, FRAMES_C},
259+
};
260+
261+
void setup() {
262+
myBlenderShow.addAnimations(animations, 3);
254263
}
255-
Servo myBlenderServos[] = {
256-
Servo(0, BoneA, move),
257-
Servo(1, BoneB, move),
258-
Servo(2, BoneC, move),
259-
...
264+
```
265+
266+
> Note: the `addAnimations` function expects the amount of servos in the array to be passed via the second argument.
267+
268+
### Updating the Show State
269+
270+
Just like single animations, we have to regularly trigger the show instance in order to update its state and internally handle the servo movement of the current animation. We therefore need to call the `run` method during each `loop`:
271+
272+
```ino
273+
void loop() {
274+
myBlenderShow.run();
260275
}
276+
```
261277

262-
Animation myBlenderAnimation(30, 1000);
278+
### Show Modes
279+
280+
The show modes are similar to the previously mentioned animation modes. In addition to those, there are various playback modes to handle a multitude of animations.
281+
282+
Just like with animation modes, a show will be in the default mode at first. The following table is focusing on the differences and additions of the show modes compared to the animation modes:
283+
284+
| Constant | Method | Description |
285+
|----------|--------|-------------|
286+
| MODE_PLAY | play() | Start or resume playing the show once |
287+
| MODE_PLAY_SINGLE | playSingle(index) | Start or resume playing a single animation once |
288+
| MODE_PLAY_RANDOM | playRandom() | Start or resume randomly playing animations of the show |
289+
290+
The modes can be changed or triggered by calling the respective methods on the show object:
291+
292+
```ino
293+
myBlenderShow.play();
294+
myBlenderShow.playSingle(index);
295+
myBlenderShow.playRandom();
296+
myBlenderShow.pause();
297+
myBlenderShow.loop();
298+
myBlenderShow.stop();
299+
myBlenderShow.live(stream);
300+
```
301+
302+
> Note: the default mode can not be triggered as it is only handled internally.
303+
304+
To get the current show mode, we can again call a `getMode` method. This will return a `byte` representing one of the mode constants mentioned in the table above. We can then compare the return value to those constants to act according to the current mode:
305+
306+
```ino
307+
byte currentMode = myBlenderShow.getMode();
308+
309+
switch (currentMode) {
310+
case Show::MODE_DEFAULT:
311+
// Do something
312+
break;
313+
case Show::MODE_PLAY:
314+
// Do something else
315+
break;
316+
...
317+
}
318+
```
319+
320+
> Note: The actual byte values of the show modes differ from the animation modes. For example, `Show::MODE_PAUSE != Animation::MODE_PAUSE`.
321+
322+
As with animations, we can also register an `onModeChange` callback function:
323+
324+
```ino
325+
void modeChanged(byte prevMode, byte newMode) {
326+
// Do something (e.g. using a switch statement)
327+
}
263328

264329
void setup() {
265-
myBlenderAnimation.addServos(myBlenderServos);
330+
myBlenderShow.onModeChange(modeChanged);
266331
}
267-
```
332+
```
333+
334+
There is also a specific [Show example](examples/Show) to illustrate a simple setup based on 2 different animations.
335+
336+
Make sure to also check out the other [examples](examples) to get started more quickly.

0 commit comments

Comments
 (0)