Skip to content

Commit 3b2a022

Browse files
committed
add live mode example
1 parent 5e36bc7 commit 3b2a022

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

examples/AdafruitPCA9685/AdafruitPCA9685.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "ik.h"
1010
#include <Adafruit_PWMServoDriver.h>
1111
#include <BlenderServoAnimation.h>
12-
#include <Wire.h>
1312

1413
// Using the namespace to have short class references (Animation and Servo)
1514
using namespace BlenderServoAnimation;

examples/AdafruitPCA9685/ik.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Blender Animation Servo Positions
2+
Blender Servo Animation Positions
33
44
FPS: 30
55
Frames: 100
@@ -11,10 +11,13 @@
1111

1212
#include <Arduino.h>
1313

14+
// Servo ID: 0
1415
const int NeckLeft[100] PROGMEM = {
1516
375, 376, 377, 380, 384, 387, 391, 396, 400, 403, 406, 408, 410, 410, 409, 406, 402, 396, 390, 382, 373, 364, 355, 346, 338, 330, 323, 318, 314, 311, 309, 307, 305, 305, 305, 305, 306, 307, 309, 311, 314, 317, 320, 323, 327, 331, 335, 339, 343, 347,
1617
351, 356, 360, 364, 369, 374, 380, 386, 392, 398, 404, 410, 415, 420, 425, 429, 432, 435, 436, 437, 437, 436, 435, 434, 432, 430, 428, 426, 423, 421, 418, 415, 412, 409, 406, 403, 400, 397, 394, 391, 388, 386, 384, 381, 380, 378, 377, 376, 375, 375,
1718
};
19+
20+
// Servo ID: 1
1821
const int NeckRight[100] PROGMEM = {
1922
375, 376, 379, 383, 388, 394, 401, 409, 417, 426, 434, 443, 450, 457, 463, 468, 471, 472, 471, 469, 466, 462, 457, 452, 447, 441, 437, 432, 428, 424, 420, 416, 411, 407, 402, 398, 394, 389, 384, 380, 375, 370, 366, 361, 356, 352, 347, 342, 337, 333,
2023
328, 324, 319, 315, 312, 309, 308, 307, 306, 306, 306, 307, 308, 309, 310, 311, 312, 313, 313, 313, 313, 314, 315, 316, 318, 320, 322, 324, 327, 329, 332, 335, 338, 341, 344, 347, 350, 353, 356, 359, 362, 364, 366, 369, 370, 372, 373, 374, 375, 375,

examples/LiveMode/LiveMode.ino

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Sending live servo positions via serial commands.
3+
4+
This example requires a USB connection to your PC and a running Blender
5+
instance with the Blender Servo Animation Add-on. We use a single servo which
6+
is controlled via the standard Arduino servo library.
7+
*/
8+
9+
#include <BlenderServoAnimation.h>
10+
#include <Servo.h>
11+
12+
// Servo object to send positions
13+
Servo myServo;
14+
15+
// Callback function which is called whenever a servo needs to be moved
16+
void move(byte servoID, int angle) {
17+
// Ignore the servoID (there is only one servo) and write the current angle
18+
myServo.write(angle);
19+
}
20+
21+
// Animation object to manage the servos
22+
// We skip providing fps or frames as we just want to use the live mode
23+
BlenderServoAnimation::Animation animation;
24+
25+
// Servo object to manage the positions
26+
BlenderServoAnimation::Servo myBlenderServo(0, move);
27+
28+
void setup() {
29+
Serial.begin(115200);
30+
31+
// Attach the servo to pin 9
32+
myServo.attach(9);
33+
34+
// Add the Blender servo object to the animation
35+
animation.addServo(myBlenderServo);
36+
37+
// Trigger the animation live mode
38+
animation.live(Serial);
39+
}
40+
41+
void loop() {
42+
// Update the animation state on each loop
43+
animation.run();
44+
}

examples/StandardServoLib/StandardServoLib.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@
1717
#define FRAMES 100
1818

1919
// Servo object to send positions
20-
Servo myservo;
20+
Servo myServo;
2121

2222
// Callback function which is called whenever a servo needs to be moved
2323
void move(byte servoID, int angle) {
2424
// Ignore the servoID (there is only one servo) and write the current angle
25-
myservo.write(angle);
25+
myServo.write(angle);
2626
}
2727

2828
// Animation object to represent the original Blender animation
2929
BlenderServoAnimation::Animation animation(FPS, FRAMES);
3030

3131
// Servo object to manage the positions
32-
BlenderServoAnimation::Servo myblenderservo(0, Bone, move);
32+
BlenderServoAnimation::Servo myBlenderServo(0, Bone, move);
3333

3434
void setup() {
3535
// Attach the servo to pin 9
36-
myservo.attach(9);
36+
myServo.attach(9);
3737

3838
// Add the Blender servo object to the animation
39-
animation.addServo(myblenderservo);
39+
animation.addServo(myBlenderServo);
4040

4141
// Trigger the animation play mode
4242
animation.play();

examples/StandardServoLib/simple.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*
2-
Blender Animation Servo Positions
2+
Blender Servo Animation Positions
33
44
FPS: 30
55
Frames: 100
66
Seconds: 3
77
Bones: 1
88
Armature: Armature
9-
File: example.blend
9+
File: simple.blend
1010
*/
1111

1212
#include <Arduino.h>
1313

14+
// Servo ID: 0
1415
const int Bone[100] PROGMEM = {
1516
90, 90, 89, 89, 88, 87, 86, 84, 83, 81, 80, 78, 76, 74, 72, 70, 68, 65, 63, 61, 59, 57, 55, 54, 52, 51, 49, 48, 47, 46, 46, 45, 45, 45, 46, 47, 49, 51, 53, 55, 58, 61, 65, 68, 72, 76, 80, 84, 88, 92,
1617
96, 100, 104, 108, 112, 115, 119, 122, 125, 127, 129, 131, 133, 134, 135, 135, 135, 135, 134, 133, 132, 131, 130, 129, 127, 126, 124, 122, 120, 118, 116, 114, 112, 111, 109, 107, 105, 103, 101, 99, 98, 96, 95, 94, 93, 92, 91, 90, 90, 90,

0 commit comments

Comments
 (0)