Skip to content

Commit

Permalink
introduce scene based library approach
Browse files Browse the repository at this point in the history
  • Loading branch information
timhendriks93 committed Jan 10, 2024
1 parent 9052a49 commit 4076e09
Show file tree
Hide file tree
Showing 69 changed files with 2,113 additions and 2,222 deletions.
37 changes: 37 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"files.associations": {
"*.tcc": "cpp",
"exception": "cpp",
"memory_resource": "cpp",
"iosfwd": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"__bit_reference": "cpp",
"__string": "cpp",
"algorithm": "cpp",
"deque": "cpp",
"ios": "cpp",
"string": "cpp",
"type_traits": "cpp",
"cstddef": "cpp",
"array": "cpp",
"bitset": "cpp",
"vector": "cpp",
"string_view": "cpp",
"functional": "cpp",
"iomanip": "cpp",
"istream": "cpp",
"limits": "cpp",
"ratio": "cpp",
"tuple": "cpp",
"__config": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"iterator": "cpp",
"locale": "cpp",
"thread": "cpp"
}
}
14 changes: 6 additions & 8 deletions examples/AdafruitPCA9685/AdafruitPCA9685.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ void move(byte servoID, int position) {
}

// Animation object to represent the original Blender animation
Animation animation(FPS, FRAMES);

// Servo objects to manage the positions
Servo neckLeftServo(0, NeckLeft, move);
Servo neckRightServo(1, NeckRight, move);
Animation animation;

void setup() {
// Add the Blender servo objects to the animation
animation.addServo(neckLeftServo);
animation.addServo(neckRightServo);
// Set the position callback
animation.onPositionChange(move);

// Add a scene based on PROGMEM data
animation.addScene(ANIMATION_DATA, LENGTH, FPS, FRAMES);

// Trigger the animation loop mode
animation.loop();
Expand Down
34 changes: 24 additions & 10 deletions examples/AdafruitPCA9685/ik.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@

const byte FPS = 30;
const int FRAMES = 100;
const int LENGTH = 1100;

// Servo ID: 0
const int NeckLeft[FRAMES] PROGMEM = {
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,
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,
};

// Servo ID: 1
const int NeckRight[FRAMES] PROGMEM = {
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,
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,
const byte PROGMEM ANIMATION_DATA[LENGTH] = {
60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10, 60, 0, 1, 120, 62, 60, 1, 1, 120, 62, 10, 60, 0, 1, 121, 62, 60, 1, 1, 123, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 127, 62, 10, 60, 0, 1, 128, 62, 60,
1, 1, 132, 62, 10, 60, 0, 1, 131, 62, 60, 1, 1, 138, 62, 10, 60, 0, 1, 135, 62, 60, 1, 1, 145, 62, 10, 60, 0, 1, 140, 62, 60, 1, 1, 153, 62, 10, 60, 0, 1, 144, 62, 60, 1, 1, 161, 62, 10, 60,
0, 1, 147, 62, 60, 1, 1, 170, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 178, 62, 10, 60, 0, 1, 152, 62, 60, 1, 1, 187, 62, 10, 60, 0, 1, 154, 62, 60, 1, 1, 194, 62, 10, 60, 0, 1, 154, 62, 60, 1,
1, 201, 62, 10, 60, 0, 1, 153, 62, 60, 1, 1, 207, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 212, 62, 10, 60, 0, 1, 146, 62, 60, 1, 1, 215, 62, 10, 60, 0, 1, 140, 62, 60, 1, 1, 216, 62, 10, 60, 0,
1, 134, 62, 60, 1, 1, 215, 62, 10, 60, 0, 1, 126, 62, 60, 1, 1, 213, 62, 10, 60, 0, 1, 117, 62, 60, 1, 1, 210, 62, 10, 60, 0, 1, 108, 62, 60, 1, 1, 206, 62, 10, 60, 0, 1, 99, 62, 60, 1, 1,
201, 62, 10, 60, 0, 1, 90, 62, 60, 1, 1, 196, 62, 10, 60, 0, 1, 82, 62, 60, 1, 1, 191, 62, 10, 60, 0, 1, 74, 62, 60, 1, 1, 185, 62, 10, 60, 0, 1, 67, 62, 60, 1, 1, 181, 62, 10, 60, 0, 1,
62, 62, 60, 1, 1, 176, 62, 10, 60, 0, 1, 58, 62, 60, 1, 1, 172, 62, 10, 60, 0, 1, 55, 62, 60, 1, 1, 168, 62, 10, 60, 0, 1, 53, 62, 60, 1, 1, 164, 62, 10, 60, 0, 1, 51, 62, 60, 1, 1, 160,
62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 155, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 151, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 146, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 142, 62, 10, 60, 0, 1, 50,
62, 60, 1, 1, 138, 62, 10, 60, 0, 1, 51, 62, 60, 1, 1, 133, 62, 10, 60, 0, 1, 53, 62, 60, 1, 1, 128, 62, 10, 60, 0, 1, 55, 62, 60, 1, 1, 124, 62, 10, 60, 0, 1, 58, 62, 60, 1, 1, 119, 62,
10, 60, 0, 1, 61, 62, 60, 1, 1, 114, 62, 10, 60, 0, 1, 64, 62, 60, 1, 1, 110, 62, 10, 60, 0, 1, 67, 62, 60, 1, 1, 105, 62, 10, 60, 0, 1, 71, 62, 60, 1, 1, 100, 62, 10, 60, 0, 1, 75, 62,
60, 1, 1, 96, 62, 10, 60, 0, 1, 79, 62, 60, 1, 1, 91, 62, 10, 60, 0, 1, 83, 62, 60, 1, 1, 86, 62, 10, 60, 0, 1, 87, 62, 60, 1, 1, 81, 62, 10, 60, 0, 1, 91, 62, 60, 1, 1, 77, 62, 10,
60, 0, 1, 95, 62, 60, 1, 1, 72, 62, 10, 60, 0, 1, 100, 62, 60, 1, 1, 68, 62, 10, 60, 0, 1, 104, 62, 60, 1, 1, 63, 62, 10, 60, 0, 1, 108, 62, 60, 1, 1, 59, 62, 10, 60, 0, 1, 113, 62, 60,
1, 1, 56, 62, 10, 60, 0, 1, 118, 62, 60, 1, 1, 53, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 52, 62, 10, 60, 0, 1, 130, 62, 60, 1, 1, 51, 62, 10, 60, 0, 1, 136, 62, 60, 1, 1, 50, 62, 10, 60,
0, 1, 142, 62, 60, 1, 1, 50, 62, 10, 60, 0, 1, 148, 62, 60, 1, 1, 50, 62, 10, 60, 0, 1, 154, 62, 60, 1, 1, 51, 62, 10, 60, 0, 1, 159, 62, 60, 1, 1, 52, 62, 10, 60, 0, 1, 164, 62, 60, 1,
1, 53, 62, 10, 60, 0, 1, 169, 62, 60, 1, 1, 54, 62, 10, 60, 0, 1, 173, 62, 60, 1, 1, 55, 62, 10, 60, 0, 1, 176, 62, 60, 1, 1, 56, 62, 10, 60, 0, 1, 179, 62, 60, 1, 1, 57, 62, 10, 60, 0,
1, 180, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 181, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 181, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 180, 62, 60, 1, 1, 58, 62, 10, 60, 0, 1, 179, 62, 60, 1, 1,
59, 62, 10, 60, 0, 1, 178, 62, 60, 1, 1, 60, 62, 10, 60, 0, 1, 176, 62, 60, 1, 1, 62, 62, 10, 60, 0, 1, 174, 62, 60, 1, 1, 64, 62, 10, 60, 0, 1, 172, 62, 60, 1, 1, 66, 62, 10, 60, 0, 1,
170, 62, 60, 1, 1, 68, 62, 10, 60, 0, 1, 167, 62, 60, 1, 1, 71, 62, 10, 60, 0, 1, 165, 62, 60, 1, 1, 73, 62, 10, 60, 0, 1, 162, 62, 60, 1, 1, 76, 62, 10, 60, 0, 1, 159, 62, 60, 1, 1, 79,
62, 10, 60, 0, 1, 156, 62, 60, 1, 1, 82, 62, 10, 60, 0, 1, 153, 62, 60, 1, 1, 85, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 88, 62, 10, 60, 0, 1, 147, 62, 60, 1, 1, 91, 62, 10, 60, 0, 1, 144,
62, 60, 1, 1, 94, 62, 10, 60, 0, 1, 141, 62, 60, 1, 1, 97, 62, 10, 60, 0, 1, 138, 62, 60, 1, 1, 100, 62, 10, 60, 0, 1, 135, 62, 60, 1, 1, 103, 62, 10, 60, 0, 1, 132, 62, 60, 1, 1, 106, 62,
10, 60, 0, 1, 130, 62, 60, 1, 1, 108, 62, 10, 60, 0, 1, 128, 62, 60, 1, 1, 110, 62, 10, 60, 0, 1, 125, 62, 60, 1, 1, 113, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 114, 62, 10, 60, 0, 1, 122, 62,
60, 1, 1, 116, 62, 10, 60, 0, 1, 121, 62, 60, 1, 1, 117, 62, 10, 60, 0, 1, 120, 62, 60, 1, 1, 118, 62, 10, 60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10, 60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10,
};
36 changes: 17 additions & 19 deletions examples/MultiplePCA9685/MultiplePCA9685.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@ Adafruit_PWMServoDriver pwmA(0x40);
Adafruit_PWMServoDriver pwmB(0x41);

// Animation object to represent the original Blender animation
Animation animation(FPS, FRAMES);
Animation animation;

// We use a struct to map a servo to a PCA9685 board and channel
struct servoMap {
Servo servo;
struct servoMapping {
byte id;
Adafruit_PWMServoDriver pwm;
byte channel;
};

// Forward declare the callback as it will be referenced in the following array
void setPWM(byte servoID, int position);

// Define an array of servo mapsf
servoMap servoMaps[] = {
// Servo attached to board A on channel 0
{Servo(0, NeckLeft, setPWM), pwmA, 0},
servoMapping servoMappings[] = {
// Servo 0 attached to board A on channel 0
{0, pwmA, 0},

// Servo attached to board B on channel 0
{Servo(1, NeckRight, setPWM), pwmB, 0},
// Servo 1 attached to board B on channel 0
{1, pwmB, 0},
};

// Calculate the amount of servos so that we can easily extend the array
Expand All @@ -47,25 +44,26 @@ void setPWM(byte servoID, int position) {
// Iterate through the available servos
for (int i = 0; i < servoAmount; i++) {
// Check if the current servo ID matches the target servo ID
if (servoMaps[i].servo.getID() == servoID) {
if (servoMappings[i].id == servoID) {
// Get the PWM driver instance and channel from the mapping
Adafruit_PWMServoDriver pwm = servoMaps[i].pwm;
byte channel = servoMaps[i].channel;
Adafruit_PWMServoDriver pwm = servoMappings[i].pwm;
byte channel = servoMappings[i].channel;

// Set the current position as PWM output
pwm.setPWM(channel, 0, position);

// Break the loop as we already handled the servo movement
// Break the for loop as we already handled the servo movement
break;
}
}
}

void setup() {
// Dynamically add the Blender servo objects to the animation
for (int i = 0; i < servoAmount; i++) {
animation.addServo(servoMaps[i].servo);
}
// Set the position callback
animation.onPositionChange(setPWM);

// Add a scene based on PROGMEM data
animation.addScene(ANIMATION_DATA, LENGTH, FPS, FRAMES);

// Trigger the animation loop mode
animation.loop();
Expand Down
34 changes: 24 additions & 10 deletions examples/MultiplePCA9685/ik.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@

const byte FPS = 30;
const int FRAMES = 100;
const int LENGTH = 1100;

// Servo ID: 0
const int NeckLeft[FRAMES] PROGMEM = {
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,
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,
};

// Servo ID: 1
const int NeckRight[FRAMES] PROGMEM = {
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,
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,
const byte PROGMEM ANIMATION_DATA[LENGTH] = {
60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10, 60, 0, 1, 120, 62, 60, 1, 1, 120, 62, 10, 60, 0, 1, 121, 62, 60, 1, 1, 123, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 127, 62, 10, 60, 0, 1, 128, 62, 60,
1, 1, 132, 62, 10, 60, 0, 1, 131, 62, 60, 1, 1, 138, 62, 10, 60, 0, 1, 135, 62, 60, 1, 1, 145, 62, 10, 60, 0, 1, 140, 62, 60, 1, 1, 153, 62, 10, 60, 0, 1, 144, 62, 60, 1, 1, 161, 62, 10, 60,
0, 1, 147, 62, 60, 1, 1, 170, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 178, 62, 10, 60, 0, 1, 152, 62, 60, 1, 1, 187, 62, 10, 60, 0, 1, 154, 62, 60, 1, 1, 194, 62, 10, 60, 0, 1, 154, 62, 60, 1,
1, 201, 62, 10, 60, 0, 1, 153, 62, 60, 1, 1, 207, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 212, 62, 10, 60, 0, 1, 146, 62, 60, 1, 1, 215, 62, 10, 60, 0, 1, 140, 62, 60, 1, 1, 216, 62, 10, 60, 0,
1, 134, 62, 60, 1, 1, 215, 62, 10, 60, 0, 1, 126, 62, 60, 1, 1, 213, 62, 10, 60, 0, 1, 117, 62, 60, 1, 1, 210, 62, 10, 60, 0, 1, 108, 62, 60, 1, 1, 206, 62, 10, 60, 0, 1, 99, 62, 60, 1, 1,
201, 62, 10, 60, 0, 1, 90, 62, 60, 1, 1, 196, 62, 10, 60, 0, 1, 82, 62, 60, 1, 1, 191, 62, 10, 60, 0, 1, 74, 62, 60, 1, 1, 185, 62, 10, 60, 0, 1, 67, 62, 60, 1, 1, 181, 62, 10, 60, 0, 1,
62, 62, 60, 1, 1, 176, 62, 10, 60, 0, 1, 58, 62, 60, 1, 1, 172, 62, 10, 60, 0, 1, 55, 62, 60, 1, 1, 168, 62, 10, 60, 0, 1, 53, 62, 60, 1, 1, 164, 62, 10, 60, 0, 1, 51, 62, 60, 1, 1, 160,
62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 155, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 151, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 146, 62, 10, 60, 0, 1, 49, 62, 60, 1, 1, 142, 62, 10, 60, 0, 1, 50,
62, 60, 1, 1, 138, 62, 10, 60, 0, 1, 51, 62, 60, 1, 1, 133, 62, 10, 60, 0, 1, 53, 62, 60, 1, 1, 128, 62, 10, 60, 0, 1, 55, 62, 60, 1, 1, 124, 62, 10, 60, 0, 1, 58, 62, 60, 1, 1, 119, 62,
10, 60, 0, 1, 61, 62, 60, 1, 1, 114, 62, 10, 60, 0, 1, 64, 62, 60, 1, 1, 110, 62, 10, 60, 0, 1, 67, 62, 60, 1, 1, 105, 62, 10, 60, 0, 1, 71, 62, 60, 1, 1, 100, 62, 10, 60, 0, 1, 75, 62,
60, 1, 1, 96, 62, 10, 60, 0, 1, 79, 62, 60, 1, 1, 91, 62, 10, 60, 0, 1, 83, 62, 60, 1, 1, 86, 62, 10, 60, 0, 1, 87, 62, 60, 1, 1, 81, 62, 10, 60, 0, 1, 91, 62, 60, 1, 1, 77, 62, 10,
60, 0, 1, 95, 62, 60, 1, 1, 72, 62, 10, 60, 0, 1, 100, 62, 60, 1, 1, 68, 62, 10, 60, 0, 1, 104, 62, 60, 1, 1, 63, 62, 10, 60, 0, 1, 108, 62, 60, 1, 1, 59, 62, 10, 60, 0, 1, 113, 62, 60,
1, 1, 56, 62, 10, 60, 0, 1, 118, 62, 60, 1, 1, 53, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 52, 62, 10, 60, 0, 1, 130, 62, 60, 1, 1, 51, 62, 10, 60, 0, 1, 136, 62, 60, 1, 1, 50, 62, 10, 60,
0, 1, 142, 62, 60, 1, 1, 50, 62, 10, 60, 0, 1, 148, 62, 60, 1, 1, 50, 62, 10, 60, 0, 1, 154, 62, 60, 1, 1, 51, 62, 10, 60, 0, 1, 159, 62, 60, 1, 1, 52, 62, 10, 60, 0, 1, 164, 62, 60, 1,
1, 53, 62, 10, 60, 0, 1, 169, 62, 60, 1, 1, 54, 62, 10, 60, 0, 1, 173, 62, 60, 1, 1, 55, 62, 10, 60, 0, 1, 176, 62, 60, 1, 1, 56, 62, 10, 60, 0, 1, 179, 62, 60, 1, 1, 57, 62, 10, 60, 0,
1, 180, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 181, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 181, 62, 60, 1, 1, 57, 62, 10, 60, 0, 1, 180, 62, 60, 1, 1, 58, 62, 10, 60, 0, 1, 179, 62, 60, 1, 1,
59, 62, 10, 60, 0, 1, 178, 62, 60, 1, 1, 60, 62, 10, 60, 0, 1, 176, 62, 60, 1, 1, 62, 62, 10, 60, 0, 1, 174, 62, 60, 1, 1, 64, 62, 10, 60, 0, 1, 172, 62, 60, 1, 1, 66, 62, 10, 60, 0, 1,
170, 62, 60, 1, 1, 68, 62, 10, 60, 0, 1, 167, 62, 60, 1, 1, 71, 62, 10, 60, 0, 1, 165, 62, 60, 1, 1, 73, 62, 10, 60, 0, 1, 162, 62, 60, 1, 1, 76, 62, 10, 60, 0, 1, 159, 62, 60, 1, 1, 79,
62, 10, 60, 0, 1, 156, 62, 60, 1, 1, 82, 62, 10, 60, 0, 1, 153, 62, 60, 1, 1, 85, 62, 10, 60, 0, 1, 150, 62, 60, 1, 1, 88, 62, 10, 60, 0, 1, 147, 62, 60, 1, 1, 91, 62, 10, 60, 0, 1, 144,
62, 60, 1, 1, 94, 62, 10, 60, 0, 1, 141, 62, 60, 1, 1, 97, 62, 10, 60, 0, 1, 138, 62, 60, 1, 1, 100, 62, 10, 60, 0, 1, 135, 62, 60, 1, 1, 103, 62, 10, 60, 0, 1, 132, 62, 60, 1, 1, 106, 62,
10, 60, 0, 1, 130, 62, 60, 1, 1, 108, 62, 10, 60, 0, 1, 128, 62, 60, 1, 1, 110, 62, 10, 60, 0, 1, 125, 62, 60, 1, 1, 113, 62, 10, 60, 0, 1, 124, 62, 60, 1, 1, 114, 62, 10, 60, 0, 1, 122, 62,
60, 1, 1, 116, 62, 10, 60, 0, 1, 121, 62, 60, 1, 1, 117, 62, 10, 60, 0, 1, 120, 62, 60, 1, 1, 118, 62, 10, 60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10, 60, 0, 1, 119, 62, 60, 1, 1, 119, 62, 10,
};
54 changes: 54 additions & 0 deletions examples/MultipleScenes/MultipleScenes.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Setting up a show consisting of 2 animations.

Note the namespaces which are used to distinguish the positions
of one scene / animation from another. It's even possible to
have different playback rates (fps) and frames per animation.
*/

#include "scene-a.h"
#include "scene-b.h"
#include <BlenderServoAnimation.h>

#ifdef ARDUINO_ARCH_ESP32
#include <ESP32Servo.h>
#else
#include <Servo.h>
#endif

// Servo object to send positions
Servo myServo;

// Callback function which is called whenever a servo needs to be moved
void move(byte servoID, int position) {
// Ignore the servoID (there is only one servo) and write the current position
myServo.writeMicroseconds(position);
}

// Animation object to represent the original Blender animation
BlenderServoAnimation::Animation animation;

void setup() {
// Attach the servo to pin 12
myServo.attach(12);

// Set the position callback
animation.onPositionChange(move);

// Add multiple scenes based on PROGMEM data
animation.addScene(SceneA::ANIMATION_DATA, SceneA::LENGTH, SceneA::FPS, SceneA::FRAMES);
animation.addScene(SceneB::ANIMATION_DATA, SceneB::LENGTH, SceneB::FPS, SceneB::FRAMES);

// Trigger the show loop mode
animation.loop();

// There are also other playback options
// show.play(); // Plays all scenes once in the order they have been added
// show.playRandom(); // Randomly plays scenes in a loop
// show.playSingle(1); // Play the scene at the given index once
}

void loop() {
// Update the animation state on each loop
animation.run();
}
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions examples/MultipleScenes/scene-a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Blender Servo Animation Positions

FPS: 30
Frames: 100
Seconds: 3
Bones: 1
Armature: Armature
Scene: SceneA
File: scenes.blend
*/

#include <Arduino.h>

namespace SceneA {

const byte FPS = 30;
const int FRAMES = 100;
const int LENGTH = 600;

const byte PROGMEM ANIMATION_DATA[LENGTH] = {
60, 0, 5, 192, 62, 10, 60, 0, 5, 193, 62, 10, 60, 0, 5, 197, 62, 10, 60, 0, 5, 203, 62, 10, 60, 0, 5, 212, 62, 10, 60, 0, 5, 222, 62, 10, 60, 0, 5, 235, 62, 10, 60, 0, 5, 249, 62, 10, 60, 0,
6, 8, 62, 10, 60, 0, 6, 26, 62, 10, 60, 0, 6, 44, 62, 10, 60, 0, 6, 63, 62, 10, 60, 0, 6, 83, 62, 10, 60, 0, 6, 104, 62, 10, 60, 0, 6, 125, 62, 10, 60, 0, 6, 146, 62, 10, 60, 0, 6, 168,
62, 10, 60, 0, 6, 190, 62, 10, 60, 0, 6, 211, 62, 10, 60, 0, 6, 232, 62, 10, 60, 0, 6, 253, 62, 10, 60, 0, 7, 17, 62, 10, 60, 0, 7, 36, 62, 10, 60, 0, 7, 54, 62, 10, 60, 0, 7, 72, 62, 10,
60, 0, 7, 87, 62, 10, 60, 0, 7, 101, 62, 10, 60, 0, 7, 114, 62, 10, 60, 0, 7, 124, 62, 10, 60, 0, 7, 133, 62, 10, 60, 0, 7, 139, 62, 10, 60, 0, 7, 143, 62, 10, 60, 0, 7, 144, 62, 10, 60, 0,
7, 142, 62, 10, 60, 0, 7, 134, 62, 10, 60, 0, 7, 122, 62, 10, 60, 0, 7, 106, 62, 10, 60, 0, 7, 87, 62, 10, 60, 0, 7, 63, 62, 10, 60, 0, 7, 36, 62, 10, 60, 0, 7, 7, 62, 10, 60, 0, 6, 231,
62, 10, 60, 0, 6, 196, 62, 10, 60, 0, 6, 159, 62, 10, 60, 0, 6, 121, 62, 10, 60, 0, 6, 81, 62, 10, 60, 0, 6, 41, 62, 10, 60, 0, 5, 255, 62, 10, 60, 0, 5, 213, 62, 10, 60, 0, 5, 171, 62, 10,
60, 0, 5, 129, 62, 10, 60, 0, 5, 87, 62, 10, 60, 0, 5, 47, 62, 10, 60, 0, 5, 7, 62, 10, 60, 0, 4, 225, 62, 10, 60, 0, 4, 188, 62, 10, 60, 0, 4, 153, 62, 10, 60, 0, 4, 121, 62, 10, 60, 0,
4, 92, 62, 10, 60, 0, 4, 65, 62, 10, 60, 0, 4, 41, 62, 10, 60, 0, 4, 22, 62, 10, 60, 0, 4, 6, 62, 10, 60, 0, 3, 250, 62, 10, 60, 0, 3, 242, 62, 10, 60, 0, 3, 240, 62, 10, 60, 0, 3, 241,
62, 10, 60, 0, 3, 245, 62, 10, 60, 0, 3, 250, 62, 10, 60, 0, 4, 2, 62, 10, 60, 0, 4, 11, 62, 10, 60, 0, 4, 22, 62, 10, 60, 0, 4, 35, 62, 10, 60, 0, 4, 49, 62, 10, 60, 0, 4, 64, 62, 10,
60, 0, 4, 81, 62, 10, 60, 0, 4, 98, 62, 10, 60, 0, 4, 117, 62, 10, 60, 0, 4, 136, 62, 10, 60, 0, 4, 155, 62, 10, 60, 0, 4, 175, 62, 10, 60, 0, 4, 196, 62, 10, 60, 0, 4, 216, 62, 10, 60, 0,
4, 236, 62, 10, 60, 0, 5, 1, 62, 10, 60, 0, 5, 21, 62, 10, 60, 0, 5, 40, 62, 10, 60, 0, 5, 59, 62, 10, 60, 0, 5, 78, 62, 10, 60, 0, 5, 95, 62, 10, 60, 0, 5, 112, 62, 10, 60, 0, 5, 127,
62, 10, 60, 0, 5, 141, 62, 10, 60, 0, 5, 154, 62, 10, 60, 0, 5, 165, 62, 10, 60, 0, 5, 174, 62, 10, 60, 0, 5, 182, 62, 10, 60, 0, 5, 187, 62, 10, 60, 0, 5, 191, 62, 10, 60, 0, 5, 192, 62, 10,
};

} // namespace SceneA
Loading

0 comments on commit 4076e09

Please sign in to comment.