Recent Changes - Search:

ENTER NEW DAILY DATA HERE:

PmWiki

pmwiki.org

edit SideBar

CODE011910

/* ElmoMasterCodeWorking AUTHORS: Mike Gazes, Nick Wong, Soyoung Park, Eric Beug, Jaymes Dec

 (USING software SERIAL) UPDATE BY JAYMES 011910
 */

// Load the SoftwareSerial Library

  1. include <SoftwareSerial.h>

// Declare the SoftwareSerial pins

  1. define rxPin 3
  2. define txPin 4

// set up a new serial port SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); //byte pinState = 0;

// This is the delay between each move int moveDelay = 1250;

//Elmo Row Arrays int elmoRow1[]={121,120,119}; int elmoRow2[]={118,117,116}; int elmoRow3[]={115,114,113}; int elmoRow4[]={112,111,110}; int elmoRow5[]={109,108,107}; int elmoRow6[]={106,105,104}; int elmoRow7[]={103,102,101};

//Elmo Column Arrays; int elmoColumn1[]={103,106,109,112,115,118,121}; int elmoColumn2[]={102,105,108,111,114,117,120}; int elmoColumn3[]={101,104,107,110,113,116,119};

//*********************************************** //DECLARE VARIABLES FOR PUSH BUTTON SENSING - DO NOT CHANGE int switchPin = 2; int previousState=0; int nowState=0; int stateChange=0; int ledPin=13; //LED turns off while button is pressed

//***********************************************

  1. include "declareElmoSlavePins.h" // See this header file for all other pin declarations

//SETUP PINS AND SERIAL COM - DO NOT CHANGE void setup() {

 pinMode(switchPin, INPUT);
 digitalWrite(switchPin, HIGH); //enable internal pull-up resistor
 pinMode(ledPin, OUTPUT);

// define pin modes for Software Serial pins

 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);

// begin Software Serial communication

 mySerial.begin(9600);

}

//THE LOOP //To run routine, use theRoutine(); //To test, use moveTest(); void loop(){ state();

 if (stateChange == 1 && nowState == 1){ //button is not pressed
  digitalWrite(ledPin,HIGH);
  previousState=nowState;
  state();
 }
 else if (stateChange == 1 && nowState == 0){ //button is pressed
    digitalWrite(ledPin,LOW);
    previousState=nowState;
    state();

   // theRoutine(); //This calls the routine
     moveTest(); //This is a test routine
 }

}

//THE ROUTINE void theRoutine (){ delay(5000); //Time delay before the routine starts, 1000 = 1 second

//All together arms go up and down three times

 for(int j=1; j<=3; j++){
 moveArmUp(ALL, 200, armUp);
 delay(moveDelay);
 moveArmDown(ALL, 200, armDown);
 delay(moveDelay);
 }

delay(750);

//Front row moves arms up, followed by second and so on //Then they move arms down starting with front row and moving backwards int i; for (i=0;i<=2;i++){

 moveArmUp(elmoRow1[i],200,armUp); //elmoRow1 lifts arms up

} delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow2[i],200,armUp); //elmoRow2 lifts arms up

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow3[i],200,armUp);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow4[i],200,armUp);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow5[i],200,armUp);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow6[i],200,armUp);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmUp(elmoRow7[i],200,armUp); //elmoRow7 lifts arms up

}

delay(moveDelay);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow1[i],200,armDown); //elmoRow1 puts arms down

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow2[i],200,armDown); //elmoRow2 puts arms down

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow3[i],200,armDown);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow4[i],200,armDown);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow5[i],200,armDown);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow6[i],200,armDown);

}

delay(moveDelay/7);

for (i=0;i<=2;i++){

 moveArmDown(elmoRow7[i],200,armDown); //elmoRow7 moves arms down

}

delay(moveDelay);

//Middle column raises arms followed by first column then third for (i=0;i<6;i++){

 moveArmUp(elmoColumn2[i],200,armUp);

}

delay(moveDelay/3);

for (i=0;i<6;i++){

 moveArmUp(elmoColumn1[i],200,armUp);

}

delay(moveDelay/3);

for (i=0;i<6;i++){

 moveArmUp(elmoColumn3[i],200,armUp);

}

delay(moveDelay);

//All arms go down at once moveArmDown(ALL, 200, armDown);

delay(moveDelay);

//All do the moveShakeArm moveShakeArm(ALL,200);

delay(moveDelay);

 //All wave arms up and down 90 degrees 3x
 for(int j=1; j<=3; j++){
  moveArmUp(ALL, 200, armStraightAhead);
  delay(moveDelay/3);
  moveArmDown(ALL, 200, armDown);
  delay(moveDelay/3);
 }

delay(moveDelay);

//All wave arms up and down 180 degrees 3x

 for(int j=1; j<=3; j++){
  moveArmUp(ALL, 200, armUp);
  delay(moveDelay/3);
  moveArmDown(ALL, 200, armDown);
  delay(moveDelay/3);
 }

delay(moveDelay);

//All wave arms up and down 270 degrees 3x

 for(int j=1; j<=3; j++){
  moveArmUp(ALL, 200, armReachBack);
  delay(moveDelay/3);
  moveArmDown(ALL, 200, armDown);
  delay(moveDelay/3);
 }

delay(moveDelay);

// All lift arms

 moveArmUp(ALL, 200, armUp);

delay(moveDelay);

// Middle one in midde row drops arm

 moveArmDown(111, 200, armDown);

delay(moveDelay);

// two others in same row drop arms

 moveArmDown(110, 200, armDown);
 moveArmDown(112, 200, armDown);

delay(moveDelay);

// 11. Another row of three drops arms to side

 moveArmDown(116, 200, armDown);
 moveArmDown(117, 200, armDown);
 moveArmDown(118, 200, armDown);

delay(moveDelay);

// Random rows of three drop arms to sides

 moveArmDown(104, 200, armDown);
 moveArmDown(105, 200, armDown);
 moveArmDown(106, 200, armDown);

delay(moveDelay);

 moveArmDown(113, 200, armDown);
 moveArmDown(114, 200, armDown);
 moveArmDown(115, 200, armDown);

delay(moveDelay);

 moveArmDown(101, 200, armDown);
 moveArmDown(102, 200, armDown);
 moveArmDown(103, 200, armDown);

delay(moveDelay);

 moveArmDown(119, 200, armDown);
 moveArmDown(120, 200, armDown);
 moveArmDown(121, 200, armDown);

delay(moveDelay);

 moveArmDown(107, 200, armDown);
 moveArmDown(108, 200, armDown);
 moveArmDown(109, 200, armDown);

delay(moveDelay);

//Elmos wave up from front to back really fast. then wave down really fast. Three times for(int j=1; j<=3; j++){

 for(int i=101; i<=121; i++){
 moveArmUp(i, 200, armUp);
 delay(moveDelay/21);
 }

delay(moveDelay/21);

 for(int i=121; i>=101; i--){
 moveArmDown(i, 200, armDown);
 delay(moveDelay/21);
 }
 }

 //All move arms up and down three times fast
 for(int j=1; j<=3; j++){
 moveArmUp(ALL, 200, armUp);
 delay(moveDelay/3);
 moveArmDown(ALL, 200, armDown);
 delay(moveDelay/3);
 }

 delay(moveDelay);

//FALL DOWN SEQUENCE //"Leader" raises his arm and falls down

 moveArmUp(120, 200, armStraightAhead);
 delay(200);
 moveFallDown(120);

delay(moveDelay);

//Two by two they fall down and are all on the ground

 moveArmUp(119, 200, armStraightAhead);
 moveArmUp(121, 200, armStraightAhead);
 delay(200);
 moveFallDown(119);
 moveFallDown(121);
 delay(200);
 moveArmUp(117, 200, armStraightAhead);
 delay(200);
 moveFallDown(117);
 delay(200);
 moveArmUp(116, 200, armStraightAhead);
 moveArmUp(118, 200, armUp);
 delay(200);
 moveFallDown(116);
 moveFallDown(118);
 delay(200);
 moveArmUp(113, 200, armStraightAhead);
 moveArmUp(115, 200, armStraightAhead);
 delay(200);
 moveFallDown(113);
 moveFallDown(115);
 delay(200);
 moveArmUp(114, 200, armStraightAhead);
 delay(200);
 moveFallDown(114);
 delay(200);
 moveArmUp(111, 200, armStraightAhead);
 delay(200);
 moveFallDown(111);
 delay(200);
 moveArmUp(110, 200, armStraightAhead);
 moveArmUp(112, 200, armStraightAhead);
 delay(200);
 moveFallDown(110);
 moveFallDown(112);
 delay(200);
 moveArmUp(107, 200, armStraightAhead);
 moveArmUp(109, 200, armStraightAhead);
 delay(200);
 moveFallDown(107);
 moveFallDown(109);
 delay(200);
 moveArmUp(108, 200, armStraightAhead);
 delay(200);
 moveFallDown(108);
 delay(200);
 moveArmUp(105, 200, armStraightAhead);
 delay(200);
 moveFallDown(105);
 delay(200);
 moveArmUp(104, 200, armStraightAhead);
 moveArmUp(106, 200, armStraightAhead);
 delay(200);
 moveFallDown(104);
 moveFallDown(106);
 delay(200);
 moveArmUp(101, 200, armStraightAhead);
 moveArmUp(103, 200, armStraightAhead);
 delay(200);
 moveFallDown(101);
 moveFallDown(103);
 delay(200);
 moveArmUp(102, 200, armStraightAhead);
 delay(200);
 moveFallDown(102);
 delay(200);

// In threes they try to get up-some are successful (maybe)

 moveStandUp(119);
 moveStandUp(120);
 moveStandUp(121);
 delay(250);
 moveStandUp(113);
 moveStandUp(114);
 moveStandUp(115);
 delay(250);
 moveStandUp(116);
 moveStandUp(117);
 moveStandUp(118);
 delay(250);
 moveStandUp(107);
 moveStandUp(108);
 moveStandUp(109);
 delay(250);
 moveStandUp(110);
 moveStandUp(111);
 moveStandUp(112);
 delay(250);
 moveStandUp(101);
 moveStandUp(102);
 moveStandUp(103);
 delay(250);
 moveStandUp(104);
 moveStandUp(105);
 moveStandUp(106);
 delay(250);

delay(moveDelay);

//But immediately they all fall down, doesn't matter where they land

 moveFallDown(ALL);

 delay(moveDelay);

//All shake on the floor a few times moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); delay(1000); moveShakeOnFloor(ALL,200); }

//THE MOVES - DO NOT CHANGE //To call these moves, pass the appropriate variables into the move functions //elmoNumber is the elmoID number //elmoNumber = ALL will call the move function on all elmos //You can experiment with moveSpeed. 200 seems to be a safe level for most moves

void moveBowDown(int elmoNumber, int moveSpeed){

  command(ELMO,elmoNumber,MOVE,arm);
  details(armDown,forward,200);
  command(ELMO,elmoNumber,MOVE,arm);
  details(armStraightAhead,reverse,200);
  delay(100);
  command(ELMO,elmoNumber,MOVE,body);
  details(bodyBent90,forward,moveSpeed);

}

void moveShakeLeg(int elmoNumber, int moveSpeed){

  command(ELMO,elmoNumber,MOVE,shakeTheLeg);

}

void moveBowUp(int elmoNumber, int moveSpeed){

  command(ELMO,elmoNumber,MOVE,body);
  details(bodyStraight,reverse,moveSpeed);
  delay(100);
  command(ELMO,elmoNumber,MOVE,arm);
  details(armDown,forward,200);

}

//moveArmUp and moveArmDown also need to be passed a moveDegree variable //These values for moveDegree do not mean that the elmos will move their arms exactly as described //moveDegree = armDown //moveDegree = armStraightAhead //moveDegree = armUp //moveDegree = armReachBack void moveArmUp(int elmoNumber, int moveSpeed, int moveDegree){

  command(ELMO,elmoNumber,MOVE,arm);
  details(moveDegree,reverse,moveSpeed);

}

void moveArmDown(int elmoNumber, int moveSpeed, int moveDegree){

  command(ELMO,elmoNumber,MOVE,arm);
  details(moveDegree,forward,moveSpeed);

}

void moveFallDown(int elmoNumber){

  command(ELMO,elmoNumber,MOVE,fall);

}

void moveShakeOnFloor(int elmoNumber, int moveSpeed){

  command(ELMO,elmoNumber,MOVE,shakeTheLeg);
  details(bodyStraight, 10, moveSpeed);

}

void moveShakeArm(int elmoNumber, int moveSpeed){

  command(ELMO, elmoNumber,MOVE, shakeTheArm);
 details(armUp, 10, moveSpeed);

}

void moveStandUp(int elmoNumber){

   command(ELMO,elmoNumber,MOVE,stand);

}

//*************END OF MOVES

//This is the test function commented out in the loop void moveTest(){

 moveArmUp(ALL, 200, armUp);
 delay(3000);
 moveArmDown(ALL, 200, armDown);

}

//This is a test funtion to check the id number order of the elmos //They will all raise their arms individually in order starting with 101 //Then they will put their arms down individually and go backwards from 121 //To call it, comment out theRoutine() and moveTest() in the loop and enter line - numberTest(); void numberTest(){

 for(int j=1; j<=3; j++){
 for(int i=101; i<=121; i++){
 moveArmUp(i, 200, armUp);
 delay(moveDelay/2);
 }

delay(moveDelay/21);

 for(int i=121; i>=101; i--){
 moveArmDown(i, 200, armDown);
 delay(moveDelay/2);
 }
 }

}

//BUTTON STATE CHANGE FUNCTION - DO NOT CHANGE void state(){

 nowState=digitalRead(switchPin);
 if (nowState != previousState){
  stateChange=1;
 }
 else {
  stateChange=0;
 }

}

//SEND COMMAND FUNCTION - DO NOT CHANGE void command(int byte1,int byte2,int byte3,int byte4) {

 mySerial.print(byte1, BYTE);
 mySerial.print(byte2, BYTE);
 mySerial.print(byte3, BYTE);
 mySerial.print(byte4, BYTE);

}

//SEND COMMAND DETAILS FUNCTION - DO NOT CHANGE void details(int byte5,int byte6,int byte7) {

 mySerial.print(byte5, BYTE);
 mySerial.print(byte6, BYTE);
 mySerial.print(byte7, BYTE);

}

Edit - History - Print - Recent Changes - Search
Page last modified on January 20, 2010, at 10:35 AM