Iggy Sings a Song

I programmed a friend! His name is Iggy and he is excited to meet you!

Process

Iggy is made up of 6 to 8 characters depending on his pose. I made tons of base characters to draw from. Each base character is only a part of his body. For example, an open mouth, or a closed mouth.

The LCD can only have 8 custom characters, but animating Iggy requires lots of different faces. To get around this limitation, I made pose functions. Each pose is a complete Iggy drawing. He only ever has one pose at a time, so I never use more than 8 custom characters. Making poses also simplified the animation process because I didn’t have to draw Iggy from scratch each time.

I also made action functions. Actions contain multiple poses. For example blinking contains an eyes open pose and an eyes closed pose. This also made animating simpler.

Here I have listed the code in one long chunk, but in my own sketch I have it broken out into several tabs. One tab for setup and loop, which contains the animation, and one tab each for components, poses, and actions. This made it easier to keep track of what was what when there were so many functions.

Eventually it would be fun to combine this animation with the game I made last week.

Code

//Main tab

//libraries
#include <SoftwareSerial.h>

//global variables
SoftwareSerial LCD (3,4); //RX, TX
byte zero=0;

void setup(){

LCD.begin(9600); // Initialize the LCD screen
delay(100);      // delay to give the LCD time to start up
LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear
LCD.write(0x11); // turn backlight on
LCD.write(0x16); // turn curser off
LCD.write(0x85); // position curser
LCD.write(0xDA); //set scale to 5th
LCD.write(0xD2);
LCD.print(“Hi!”);
LCD.write(0x80);
iggyTalk();     // draw iggy
delay (1000);
iggyTalk();
LCD.write(0x99);
LCD.print(“I’m Iggy.”);
LCD.write(0x80);
iggyTalk();
delay(2000);
LCD.write(0x0C); //clear the screen
delay(5);
}
void loop (){
LCD.write(0x80);
iggySmile();
delay(1000);
iggyBlink();
iggyTalk();
LCD.write(0x85);  // position curser
LCD.print(“Let’s play!”);
delay(2000);
iggySmile();
delay(2000);
iggyFrown();
delay(2000);

iggyFurtive();
iggyTalk();
LCD.write(0x85);  // position curser
LCD.print(“What shall “);
LCD.write(0x99);
LCD.print(“we play?”);
delay(2000);
iggyThink();
LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear

iggyIdea();
LCD.write(0x86);  // position curser
LCD.print(“!”);
delay(2000);

LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear

iggySmile();
delay(1000);
iggyTalk();
LCD.write(0x85);  // position curser
LCD.print(“I know,”);
delay(500);
iggyTalk();
LCD.write(0x99);
LCD.print(“let’s sing!”);
delay(2000);
LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear

LCD.write(0x85);  // position curser
LCD.print(“LALALALA”);
LCD.write(0x99);
LCD.print(“LAAAAAAAA!”);
iggySing();
delay(2000);

LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear
iggyDerp();
delay(1000);

iggyTalk();
LCD.write(0x85);  // position curser
LCD.print(“That was”);
LCD.write(0x99);
LCD.print(“fun!”);
delay(2000);

LCD.write(0x0C); // clear the screen
delay(5);        // must delay after clear
}

//action tab================================

//Iggy’s actions are composed of multiple poses

void iggyBlink(){
iggySmile();
delay(500);
iggyEyesClosed();
delay(500);
iggySmile();
delay(500);
}

void iggyTalk(){
iggyMouthClosed();
delay(300);
iggyMouthOpen();
delay(300);
iggyMouthClosed();
}

void iggyThink(){
iggyLookingUp();
delay(2000);
}

void iggyFurtive(){
iggySerious();
delay(500);
iggyLookRight();
delay(1000);
iggyLookLeft();
delay(1000);
iggySerious();
delay(500);
}

void iggySing(){
iggySerious();
delay(200);
iggySmallOpen();
LCD.write(0xDC); //note A
delay(200);
iggyBigOpen();
LCD.write(0xDD); //note A#
delay(200);
iggySmallOpen();
LCD.write(0xDE); //note B
delay(200);
iggyBigOpen();
LCD.write(0xDF); //note C
delay(200);
iggySmallOpen();
LCD.write(0xE0); //note C#
delay(200);
iggyBigOpen();
LCD.write(0xE1); //note D
delay(200);
iggySmallOpen();
LCD.write(0xE2); //note D#
delay(200);
iggyBigOpen();
LCD.write(0xE3); //note E
delay(200);
iggySmallOpen();
LCD.write(0xE4); //note F
delay(200);
iggyBigOpen();
LCD.write(0xE5); //note F#
delay(200);
iggySmallOpen();
LCD.write(0xE6); //note G
delay(200);
iggyBigOpen();
LCD.write(0xE7); //note G#
delay(200);
iggyMouthClosed();
delay(200);
}

//component tab============================

//These are the individual character components that make up Iggy

//eyes open=================================================
void leftEye(){
//0x7,0x8,0x13,0x14,0x15,0x14,0x13,0x10
LCD.write(0xF8); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(0x8);
LCD.write(0x13);
LCD.write(0x14);
LCD.write(0x15);
LCD.write(0x14);
LCD.write(0x13);
LCD.write(0x10);
}

void upperMiddle(){
//    0x1f,0x0,0x11,0xa,0xa,0xa,0x11,0x0
LCD.write(0xF9); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(zero);
LCD.write(0x11);
LCD.write(0xA);
LCD.write(0xA);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void rightEye(){
//0x1c,0x2,0x19,0x5,0x15,0x5,0x19,0x1
LCD.write(0xFA); //LCD.write(0x54); // load custom character
LCD.write(0x1c);
LCD.write(0x2);
LCD.write(0x19);
LCD.write(0x5);
LCD.write(0x15);
LCD.write(0x5);
LCD.write(0x19);
LCD.write(0x1);
}

//eyes left===============================================
void leftLookLeft(){
//void leftEye(){
//0x7,0x8,0x13,0x14,0x16,0x14,0x13,0x10
LCD.write(0xF8); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(0x8);
LCD.write(0x13);
LCD.write(0x14);
LCD.write(0x16);
LCD.write(0x14);
LCD.write(0x13);
LCD.write(0x10);
}

void middleLookLeft(){
//0x1f,0x0,0x11,0xa,0xb,0xa,0x11,0x0
LCD.write(0xF9); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(zero);
LCD.write(0x11);
LCD.write(0xA);
LCD.write(0xB);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void rightLookLeft(){
//0x1c,0x2,0x19,0x5,0x5,0x5,0x19,0x1
LCD.write(0xFA); //LCD.write(0x54); // load custom character
LCD.write(0x1c);
LCD.write(0x2);
LCD.write(0x19);
LCD.write(0x5);
LCD.write(0x5);
LCD.write(0x5);
LCD.write(0x19);
LCD.write(0x1);
}

//eyes right===============================================
void leftLookRight(){
//void leftEye(){
//0x7,0x8,0x13,0x14,0x14,0x14,0x13,0x10
LCD.write(0xF8); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(0x8);
LCD.write(0x13);
LCD.write(0x14);
LCD.write(0x14);
LCD.write(0x14);
LCD.write(0x13);
LCD.write(0x10);
}

void middleLookRight(){
//0x1f,0x0,0x11,0xa,0x1a,0xa,0x11,0x0
LCD.write(0xF9); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(zero);
LCD.write(0x11);
LCD.write(0xA);
LCD.write(0x1A);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void rightLookRight(){
//0x1c,0x2,0x19,0x5,0xd,0x5,0x19,0x1
LCD.write(0xFA); //LCD.write(0x54); // load custom character
LCD.write(0x1c);
LCD.write(0x2);
LCD.write(0x19);
LCD.write(0x5);
LCD.write(0xD);
LCD.write(0x5);
LCD.write(0x19);
LCD.write(0x1);
}

//crosseyed============================================
void middleCross(){
//0x1f,0x0,0x11,0xa,0x1b,0xa,0x11,0x0
LCD.write(0xF9); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(zero);
LCD.write(0x11);
LCD.write(0xA);
LCD.write(0x1B);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

//eyes closed=======================================

void leftClosed(){
//  0x7,0x8,0x10,0x10,0x17,0x10,0x10,0x10
LCD.write(0xF8); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(0x8);
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x17);
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x10);
}

void middleClosed(){
//0x1f,0x0,0x0,0x0,0x1b,0x0,0x0,0x0
LCD.write(0xF9); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x1B);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
}

void rightClosed(){
//  0x1c,0x2,0x1,0x1,0x1d,0x1,0x1,0x1
LCD.write(0xFA); //LCD.write(0x54); // load custom character
LCD.write(0x1c);
LCD.write(0x2);
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x1D);
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x1);
}

//looking up
void leftUp(){
//0x7,0x8,0x13,0x15,0x14,0x14,0x13,0x10
LCD.write(0xF8); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(0x8);
LCD.write(0x13);
LCD.write(0x15);
LCD.write(0x14);
LCD.write(0x14);
LCD.write(0x13);
LCD.write(0x10);
}

void rightUp(){
//0x1c,0x2,0x19,0x15,0x5,0x5,0x19,0x1
LCD.write(0xFA); //LCD.write(0x54); // load custom character
LCD.write(0x1c);
LCD.write(0x2);
LCD.write(0x19);
LCD.write(0x15);
LCD.write(0x5);
LCD.write(0x5);
LCD.write(0x19);
LCD.write(0x1);
}

//lower body==============================================
void lowerLeft(){
//0x10,0x10,0x10,0x10,0x12,0x15,0x19,0x11
LCD.write(0xFB); //LCD.write(0x54); // load custom character
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x12);
LCD.write(0x15);
LCD.write(0x19);
LCD.write(0x11);
}

void lowerRight(){
//0x1,0x1,0x1,0x1,0x9,0x15,0x13,0x11
LCD.write(0xFD); //LCD.write(0x54); // load custom character
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x9);
LCD.write(0x15);
LCD.write(0x13);
LCD.write(0x11);
}

void leftArmOut(){
//0x0,0x0,0x18,0x4,0x2,0x1,0x1,0x1

LCD.write(0xFB); //LCD.write(0x54); // load custom character
LCD.write(zero);
LCD.write(zero);
LCD.write(0x18);
LCD.write(0x4);
LCD.write(0x2);
LCD.write(0x1);
LCD.write(0x1);
LCD.write(0x1);

}

void rightArmOut(){
//0x0,0x0,0x3,0x4,0x8,0x10,0x10,0x10
LCD.write(0xFD); //LCD.write(0x54); // load custom character
LCD.write(zero);
LCD.write(zero);
LCD.write(0x3);
LCD.write(0x4);
LCD.write(0x8);
LCD.write(0x10);
LCD.write(0x10);
LCD.write(0x10);
}

//hands===================================================
void leftHandUp(){
//0x12,0xe,0x2,0x1c,0x0,0x0,0x0,0x0
LCD.write(0xFE); //LCD.write(0x54); // load custom character
LCD.write(0x12);
LCD.write(0xE);
LCD.write(0x2);
LCD.write(0x1C);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
}

void leftHandOut(){
//0x10,0xf,0x2,0x1c,0x0,0x0,0x0,0x0
LCD.write(0xFE); //LCD.write(0x54); // load custom character
LCD.write(0x10);
LCD.write(0xF);
LCD.write(0x2);
LCD.write(0x1C);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
}

void leftHandDown(){
//0x10,0x8,0x4,0x12,0xe,0x2,0x0,0x0
LCD.write(0xFE); //LCD.write(0x54); // load custom character
LCD.write(0x10);
LCD.write(0x8);
LCD.write(0x4);
LCD.write(0x12);
LCD.write(0xE);
LCD.write(0x2);
LCD.write(zero);
LCD.write(zero);
}

void rightHandUp(){
//0xa,0xe,0x1c,0x0,0x0,0x0,0x0,0x0
LCD.write(0xFF); //LCD.write(0x54); // load custom character
LCD.write(0x12);
LCD.write(0xE);
LCD.write(0x2);
LCD.write(0x1C);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
}

void rightHandOut(){
//0x1,0x1e,0x8,0x7,0x0,0x0,0x0,0x0
LCD.write(0xFF); //LCD.write(0x54); // load custom character
LCD.write(0x1);
LCD.write(0x1e);
LCD.write(0x8);
LCD.write(0x7);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
}

void rightHandDown(){
//0x1,0x2,0x4,0xb,0xc,0x8,0x0,0x0
LCD.write(0xFF); //LCD.write(0x54); // load custom character
LCD.write(0x1);
LCD.write(0x2);
LCD.write(0x4);
LCD.write(0xB);
LCD.write(0xC);
LCD.write(0x8);
LCD.write(zero);
LCD.write(zero);
}

//mouths===================================================
void smile(){
//    0x11,0xe,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0x11);
LCD.write(0xE);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void frown(){
//  0xe,0x11,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0xE);
LCD.write(0x11);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void mouthOpen(){
//  0xe,0x1f,0xe,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0xE);
LCD.write(0x1F);
LCD.write(0xE);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void mouthClosed(){
//0xe,0x0,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0xE);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void wideOpen(){
//0x1f,0x1f,0x1f,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(0x1F);
LCD.write(0x1F);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void smallOpen(){
//0xe,0xe,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0xE);
LCD.write(0xE);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void mouthLeft(){
//  0x1c,0x0,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0x1C);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void mouthRight(){
//  0x7,0x0,0x0,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0x7);
LCD.write(zero);
LCD.write(zero);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

void tongue(){
//0x1f,0xa,0xe,0x0,0x4,0xa,0x11,0x0
LCD.write(0xFC); //LCD.write(0x54); // load custom character
LCD.write(0x1F);
LCD.write(0xA);
LCD.write(0xE);
LCD.write(zero);
LCD.write(0x4);
LCD.write(0xA);
LCD.write(0x11);
LCD.write(zero);
}

//Pose tab

//The components are grouped into poses that Iggy can do

//Iggy smile
void iggySmile(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
smile();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

//Iggy frown
void iggyFrown(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
frown();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggySerious(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
mouthClosed();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyMouthOpen(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
mouthOpen();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyBigOpen(){
leftClosed();
middleClosed();
rightClosed();
lowerLeft();
wideOpen();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggySmallOpen(){
leftClosed();
middleClosed();
rightClosed();
lowerLeft();
smallOpen();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyLookRight(){
leftLookRight();
middleLookRight();
rightLookRight();
lowerLeft();
mouthRight();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyLookLeft(){
leftLookLeft();
middleLookLeft();
rightLookLeft();
lowerLeft();
mouthLeft();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyDerp(){
leftLookLeft();
upperMiddle();
rightLookRight();
lowerLeft();
tongue();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyCrossEyed(){
leftLookRight();
middleCross();
rightLookLeft();
lowerLeft();
tongue();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyEyesClosed(){
leftClosed();
middleClosed();
rightClosed();
lowerLeft();
mouthClosed();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyMouthClosed(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
mouthClosed();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyLookingUp(){
leftUp();
upperMiddle();
rightUp();
lowerLeft();
mouthRight();
lowerRight();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
}

void iggyIdea(){
leftEye();
upperMiddle();
rightEye();
lowerLeft();
smile();
rightArmOut();
rightHandUp();
//customCharacter1();
LCD.write(0x80);
LCD.write(zero);
LCD.write(0x01);
LCD.write(0x02);

LCD.write(0x94);
LCD.write(0x03);
LCD.write(0x04);
LCD.write(0x05);
LCD.write(0x06);
}

Advertisements

One thought on “Iggy Sings a Song

  1. Pingback: Physical Computing Experiments | conteximus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s