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
When calling the `stop` method, it is possible to pass a delay in milliseconds. This delay will be used when the servos are moved to their neutral position during the stop mode. To get to the neutral position, the current position will either be increased or decreased by 1. The delay therefore controls how fast or smooth this movement will take place. The default value for this parameter is `20`.
myBlenderAnimation.stop(30); // Servos will reset slower
180
+
```
181
+
177
182
To use the `live` method, we have to pass a stream instance which will be used for reading serial commands. For example, we can pass `Serial` if we want to use the standard USB connection of an Arduino compatible board:
178
183
179
184
```ino
180
185
voidsetup() {
181
-
Serial.begin(115200);
182
-
myBlenderAnimation.live(Serial);
186
+
Serial.begin(115200);
187
+
myBlenderAnimation.live(Serial);
188
+
}
189
+
```
190
+
191
+
To get the current animation mode, we can simply call the `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:
192
+
193
+
```ino
194
+
byte currentMode = myBlenderAnimation.getMode();
195
+
196
+
switch (currentMode) {
197
+
case Animation::MODE_DEFAULT:
198
+
// Do something
199
+
break;
200
+
case Animation::MODE_PLAY:
201
+
// Do something else
202
+
break;
203
+
...
204
+
}
205
+
```
206
+
207
+
On top of manually checking the animation mode, we can also register a callback function which is triggered as soon as the animation mode has changed. The function will receive both the previous mode and the new mode as `byte` values. To register the function, we can call the `onModeChange` method:
208
+
209
+
```ino
210
+
voidmodeChanged(byte prevMode, byte newMode) {
211
+
// Do something (e.g. using another switch)
212
+
}
213
+
214
+
void setup() {
215
+
myBlenderAnimation.onModeChange(modeChanged);
183
216
}
184
217
```
185
218
186
-
Make sure to check out the [examples](examples) to get started quickly and learn more about using this library with your Arduino sketches / programs.
219
+
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.
0 commit comments