int animation0[] = {3,
0, 5000, 2,
0, 9000, 3,
0, 12000, 8};
int animation1[] = {1,
0, 5000, 38};
int animation2[] = {3,
1, 0, 2,
0, 2000, 3,
0, 3000, 8};
int animation3[] = {5,
0, 0, 38,
0, 2000, 3,
0, 3000, 8,
0, 5000, 38,
0, 10000, 98};
#define DEBUG_OFF 0
#define DEBUG_ON 1
#define DEBUG_FULL 2
// Enumeration of the animation Packets
#define indexDevice 0
#define indexTime 1
#define indexCommand 2
int debugState = DEBUG_ON;
unsigned long time_now = 0;
int soundHasPlayed = 0;
int choice = 1;
void setup() {
// put your setup code here, to run once:
time_now = millis();
Serial.begin(9600);
if(debugState>=DEBUG_ON){
Serial.print(time_now);
Serial.println(": Starting Scheduler");
}
}
void loop() {
// put your main code here, to run repeatedly:
if(choice!=0) playAnimations(animation3);
}
// Playing Animations based on Animation Packets
/**
{[ NUMBERofANIMATIONS ], [ DEVICE, WHENtoPLAY, COMMANDtoPLAY ] }
int animationConecpt[] = {1, 0, 5000, 38};
1 Animation, MP3 Player, @ 5000 ms, Play Track038.mp3
**/
int playAnimations(int currentAnimation[]){
int numberofAnimations = currentAnimation[0]; // Number of Animations
int currentFrame = 1; // Keep track of what frame we are currently on
for(int frameIndex=1;frameIndex<(numberofAnimations * 3)+1;frameIndex+=3){
if(debugState>=DEBUG_FULL){
Serial.print(millis());
Serial.print(": Frame ");
Serial.print(currentFrame);
Serial.print(" - frameIndex: ");
Serial.print(frameIndex);
Serial.print(" - soundHasPlayed : ");
Serial.println(soundHasPlayed);
//delay(200);
}
if(millis() >= time_now + currentAnimation[frameIndex+indexTime] && soundHasPlayed==currentFrame-1){
if(debugState>=DEBUG_ON){
Serial.print(millis());
Serial.print(": Frame (");
Serial.print(currentFrame);
Serial.print("/");
Serial.print(numberofAnimations);
Serial.print(") [");
Serial.print(currentAnimation[frameIndex+indexDevice]);
Serial.print(", ");
Serial.print(currentAnimation[frameIndex+indexTime]);
Serial.print(", ");
Serial.print(currentAnimation[frameIndex+indexCommand]);
Serial.print("] ");
// delay(20);
}
// MP3 Player is DEVICE 0
if(currentAnimation[frameIndex+indexDevice]==0){
if(debugState>=DEBUG_ON){
Serial.print(": Playing Sound : ");
Serial.println(currentAnimation[frameIndex+indexCommand]);
}
// MP3player.playTrack(animation0[frameIndex+indexCommand]);
}
// MOUTH LED is DEVICE 1
else if(currentAnimation[frameIndex+indexDevice]==1){
if(debugState>=DEBUG_ON){
Serial.print(": Changing Eyes to : ");
Serial.println(currentAnimation[frameIndex+indexCommand]);
}
// animation0[frameIndex+indexCommand] = index of animation table
}
soundHasPlayed++;
}
currentFrame++;
}
// When Finished with all Animations - Leave the loop
if(soundHasPlayed>=numberofAnimations && soundHasPlayed!=99){
choice=0;
soundHasPlayed=99;
if(debugState>=DEBUG_ON){
Serial.println("Done playing sounds!");
}
}
return soundHasPlayed;
}