You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-16Lines changed: 85 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -133,20 +133,21 @@ This is usually done inside the `setup` function after the servo objects have be
133
133
Alternatively, we can also create an array of servos and call the `addServos` method instead:
134
134
135
135
```ino
136
+
Animation myBlenderAnimation(30, 1000);
137
+
136
138
Servo myBlenderServos[] = {
137
139
Servo(0, BoneA, move),
138
140
Servo(1, BoneB, move),
139
141
Servo(2, BoneC, move),
140
-
...
141
142
}
142
143
143
-
Animation myBlenderAnimation(30, 1000);
144
-
145
144
void setup() {
146
-
myBlenderAnimation.addServos(myBlenderServos);
145
+
myBlenderAnimation.addServos(myBlenderServos, 3);
147
146
}
148
147
```
149
148
149
+
> Note: the `addServos` function expects the amount of servos in the array to be passed via the second argument.
150
+
150
151
### Updating the Animation State
151
152
152
153
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
218
219
219
220
```ino
220
221
voidmodeChanged(byte prevMode, byte newMode) {
221
-
// Do something (e.g. using another switch)
222
+
// Do something (e.g. using a switch statement)
222
223
}
223
224
224
225
void setup() {
225
226
myBlenderAnimation.onModeChange(modeChanged);
226
227
}
227
228
```
228
229
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.
230
231
231
232
## Defining a Show
232
233
@@ -249,19 +250,87 @@ This is usually done inside the `setup` function after the animation and servo o
249
250
Alternatively, we can also create an array of animations and call the `addAnimations` method instead:
250
251
251
252
```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
+
voidsetup() {
262
+
myBlenderShow.addAnimations(animations, 3);
254
263
}
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
+
voidloop() {
274
+
myBlenderShow.run();
260
275
}
276
+
```
261
277
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
+
voidmodeChanged(byte prevMode, byte newMode) {
326
+
// Do something (e.g. using a switch statement)
327
+
}
263
328
264
329
void setup() {
265
-
myBlenderAnimation.addServos(myBlenderServos);
330
+
myBlenderShow.onModeChange(modeChanged);
266
331
}
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