Interactive Tigger

about the project: interactive-tigger

code:

// Tigger Hide and Seek
// by Jason Read
int play = 12;       // choose the pin for the play pause function
int skip = 8;        // chose the pin for the skip function
int back = 10;       // chose the pin for the back function
int repeat1 = 0;     // keeps track from repeating
int repeat2 = 0;     // keeps track from repeating
int repeat3 = 0;     // keeps track from repeating
int repeat4 = 0;     // keeps track from repeating
int interactions = 0;        // keeps track of interactions
void setup() {
Serial.begin(9600); // connect to the serial port
pinMode(play, OUTPUT);      // sets the digital pin as output
pinMode(skip, OUTPUT);      // sets the digital pin as output
pinMode(back, OUTPUT);     // sets the digital pin as output
pinMode(0, INPUT);      // sets the digital pin as output
}

void loop() {
 
char flag = 1; 
int  val = 0;
char code[10];
int bytesread = 0;
char target [][10] = {{0,0,’1′,’5′,’0′,’0′,’D’,’0′,’2′,’A’},
                      {0,0,’1′,’5′,’0′,’0′,’D’,’0′,’3′,’A’},
                      {0,0,’1′,’5′,’0′,’0′,’C’,’F’,’D’,’B’},
                      {0,0,’1′,’5′,’0′,’0′,’D’,’0′,’1′,’4′}};
                     
                          

if(interactions == 0) {
  Serial.print(“introduction”);
  interactions = 1;                       // inhibits repetition                         
  digitalWrite(play,HIGH);                // hits play
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing play
  delay(375);
  digitalWrite(play,HIGH);                // hits play
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing play
  delay(2000);                            // delays program until sounds program is finished
  digitalWrite(play,HIGH);                // hits pause
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing pause
  delay(875);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
}

if(interactions == 4) {
  Serial.print(“Finale”);
  delay(500);
  interactions = 1;                       // inhibits repetition
  repeat4 = 1;                            // inhibits repetition
    digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(play,HIGH);                // hits play
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing play
  delay(13900);                            // delays program until sounds program is finished
  digitalWrite(play,HIGH);                // hits play
  delay(275);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing pause
  delay(575);
  digitalWrite(skip,HIGH);                // hits back
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing back
  delay(575);
  digitalWrite(skip,HIGH);                // hits back
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing back
  delay(575);
  digitalWrite(skip,HIGH);                // hits back
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing back
  repeat1 = 0;
  repeat2 = 0;
  repeat3 = 0;
  repeat4 = 0;
  interactions = 1;
  delay(10000);
}
 
  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }
          code[bytesread] = val;         // add the digit          
          bytesread++;                   // ready to read next digit 
        }
      }
      if(bytesread == 10) {              // if 10 digit read is complete
//        Serial.print(“TAG code is: “);   // possibly a good TAG
//        Serial.println(code);            // print the TAG code //
      }
      bytesread = 0;
    }
  }
  for (int i=2;i<10 && flag==1;i++)
    if(code[i]!=target[0][i])
     flag = 0;
    
     if(flag==1 && repeat1==0) {
     Serial.print(“interaction 1 “);
  repeat1 = 1;                            // inhibits repetition
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(play,HIGH);                // hits play
  delay(175);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing play
  delay(13750);                            // delays program until sounds program is finished
 digitalWrite(play,HIGH);                // hits play
  delay(175);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing play
  delay(875);                            // delays program until sounds program is finished
  digitalWrite(skip,HIGH);                // hits skip
  delay(475);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(475);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(475);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(475);
  digitalWrite(skip,HIGH);                // hits skip
  delay(475);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(475);
  digitalWrite(skip,HIGH);                // hits skip
  delay(475);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(875);
  interactions = interactions + 1;
     }
    
flag = 1;
    
    for (int i=2;i<10 && flag==1;i++)
    if(code[i]!=target[1][i])
     flag = 0;

     if(flag==1 && repeat2==0) {
     Serial.print(“Interaction 2”);
  repeat2 = 1;                            // inhibits repetition
  digitalWrite(skip,HIGH);                // skips a track
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);                              // waits for a second
  digitalWrite(play,HIGH);                // hits play
  delay(175);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing play
  delay(6500);                            // delays program until sounds program is finished
  digitalWrite(play,HIGH);                // hits pause
  delay(175);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing pause
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  interactions = interactions + 1;
     }
    
flag = 1;
    
  for (int i=2;i<10 && flag==1;i++)
    if(code[i]!=target[2][i])
     flag = 0;
 
     if(flag==1 && repeat3==0) {
  Serial.print(“Interaction 3”); 
  repeat3 = 1;                            // inhibits repetition
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);     
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);                              // waits for a second
  digitalWrite(skip,HIGH);                // skips a track
  delay(375);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(375);     
  digitalWrite(play,HIGH);                // hits play
  delay(175);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing play
  delay(13000);                            // delays program until sounds program is finished
  digitalWrite(play,HIGH);                // hits pause
  delay(575);                              // waits for a second
  digitalWrite(play,LOW);                // stops pushing pause
  delay(675);
  digitalWrite(skip,HIGH);                // hits back
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing back
  delay(675);
  digitalWrite(skip,HIGH);                // hits back
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing back 
  delay(800);
  interactions = interactions + 1;
     }

flag = 1;

    for (int i=2;i<10 && flag==1;i++)
    if(code[i]!=target[3][i])
     flag = 0;

     if(flag==1 && repeat4==0) {
       repeat4 = 1;
  Serial.print(“introduction”);
  interactions = 1;                       // inhibits repetition
  digitalWrite(play,HIGH);                // hits play
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing play
  delay(375);
  digitalWrite(play,HIGH);                // hits play
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing play
  delay(2000);                            // delays program until sounds program is finished
  digitalWrite(play,HIGH);                // hits pause
  delay(375);                              // waits for a second
  digitalWrite(play,LOW);                 // stops pushing pause
  delay(875);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  delay(575);
  digitalWrite(skip,HIGH);                // hits skip
  delay(575);                              // waits for a second
  digitalWrite(skip,LOW);                 // stops pushing skip
  repeat1 = 0;
  repeat2 = 0;
  repeat3 = 0;
  repeat4 = 0;
  interactions = 0;
  delay(5000);
     }
 
  if (bytesread>0)
     Serial.print(“it wasn’t any”);
 
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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