Quinn Sullivan
Published © CC BY

Do You Want to Make a (Dancing) Snowman?

Winter is coming, which makes this the perfect time for a spectacular indoor craft project!

BeginnerFull instructions provided3 hours811
Do You Want to Make a (Dancing) Snowman?

Things used in this project

Hardware components

chipKIT uC32
chipKIT uC32
×1
Digilent Solderless Breadboard Kit
×1
Analog Parts Kit by Analog Devices: Companion Parts Kit for the Analog Discovery
×1
Digilent GWS Servo S03TXF STD
×1
Digilent Battery Holder (4 x AA)
×1

Software apps and online services

MPLAB Code Configurator
Microchip MPLAB Code Configurator

Story

Read more

Code

Do You Want to Make a (Dancing) Snowman?

Arduino
//Needed Library

#include <Servo.h>



//Global Variables

Servo dancingSnowman;           //this is a needed declaration saying what our servo motor is to be called
Servo dancingSnowman2;           //this is a needed declaration saying what our servo motor is to be called

int box = 11;                   //this is the digital pin that we are sending data from the microcontroller to the servo motor

int degree = 40;                //this is a variable to keep track of what angle the motor is currently located at

int Speed = 2;                  //this has a maximum speed value of 6, as per the physical limitations of the servo motor

int closedMouthAngle = 90;      //this has a minimum value of 0, as per both library and phyiscal limitations of the servo motor

int openedMouthAngle = 130;     //this has a maximum angle value of 180, as per both library and phyiscal limitations of the servo motor



////////////////////////////////////////

//                                    //

//           Setup function           //

//                                    //

////////////////////////////////////////



void setup(){

  delay(10);                    //delay a little bit

  dancingSnowman.attach(box);       //a library function to say which pin data is being sent out on

  delay(5);                     //another small delay of 5 milliseconds

  dancingSnowman.write(degree);     //telling the dancingSnowman to go to this initial position (mostly closed mouth)

  delay(750);                   //delay for another 750 ms before going into our infinite loop function
  delay(10);                    //delay a little bit

  dancingSnowman2.attach(box);       //a library function to say which pin data is being sent out on

  delay(5);                     //another small delay of 5 milliseconds

  dancingSnowman2.write(degree);     //telling the dancingSnowman to go to this initial position (mostly closed mouth)

  delay(750);                   //delay for another 750 ms before going into our infinite loop function

}//END of setup



////////////////////////////////////////

//                                    //

//            Loop function           //

//                                    //

////////////////////////////////////////



void loop(){

  

  //open and close the mouth a little bit

  openMouth(closedMouthAngle+30);
  openMouth2(closedMouthAngle+30);

  closeMouth(closedMouthAngle);
  closeMouth2(closedMouthAngle);

  openMouth(closedMouthAngle+30);
  openMouth2(closedMouthAngle+30);

  closeMouth(closedMouthAngle);
  closeMouth2(closedMouthAngle);

  delay(300);

  

}//END of loop; repeat the entire loop again



//////////////////////////////////////////////////////

//                                                  //

//               User Defined Functions             //

//                                                  //

//////////////////////////////////////////////////////


void openMouth(int angle){

  while(degree < angle){            //while the current degree angle is less than the desired angle...

    degree = degree + Speed;        //increase the degree angle by a set amount

    dancingSnowman.write(degree);       //move the servo motor to that new angle

    delay(23);                      //delay a little bit to give motor time to move

  }

}//END of openMouth

void openMouth2(int angle){

  while(degree < angle){            //while the current degree angle is less than the desired angle...

    degree = degree + Speed;        //increase the degree angle by a set amount

    dancingSnowman2.write(degree);       //move the servo motor to that new angle

    delay(23);                      //delay a little bit to give motor time to move

  }

}//END of openMouth2



void closeMouth(int angle){

  while(degree > angle){            //while the current degree angle is greater than the desired angle...

    degree = degree - Speed;        //decrease the degree angle by a set amount

    dancingSnowman.write(degree);       //move the servo motor to that new angle

    delay(23);                      //delay a little bit to give motor time to move

  }

}//END of closeMouth

void closeMouth2(int angle){

  while(degree > angle){            //while the current degree angle is greater than the desired angle...

    degree = degree - Speed;        //decrease the degree angle by a set amount

    dancingSnowman2.write(degree);       //move the servo motor to that new angle

    delay(23);                      //delay a little bit to give motor time to move

  }

}//END of closeMouth2

Credits

Quinn Sullivan
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.