Back to Parent

#include <SPI.h>
#include <MFRC522.h>
#include <Adafruit_NeoPixel.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above

#define LED_PIN    6
#define LED_COUNT 24


MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
int triggernum;


//****************************************************************************************//
bool cardRemoved = false;
int counter = 0;
bool current, previous;

//*****************************************************************************************//
void setup() {
  Serial.begin(9600);
  // Initialize serial communications with the PC
  SPI.begin();                                                  // Init SPI bus
  mfrc522.PCD_Init();                                              // Init MFRC522 card
  mfrc522.PCD_SetRegisterBitMask(mfrc522.RFCfgReg, (0x07<<4));
  //Serial.println(F("Read Private AI ID on a MIFARE PICC:"));    //shows in serial that it is ready to read
}

//*****************************************************************************************//
void loop() {
  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

  //some variables we need
  byte block;
  byte len;
  MFRC522::StatusCode status;

  //-------------------------------------------

  // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    Serial.println(0);
    return;
  } 
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  //Serial.println(F("**Card Detected:**"));

  //-------------------------------------------

  //mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card

  //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));      //uncomment this to see all blocks in hex

  //-------------------------------------------
  byte buffer2[18];
  block = 1;

  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
  if (status != MFRC522::STATUS_OK) {
    //Serial.print(F("Authentication failed: "));
    //Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

  status = mfrc522.MIFARE_Read(block, buffer2, &len);
  if (status != MFRC522::STATUS_OK) {
    //Serial.print(F("Reading failed: "));
    //Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }


triggernum=buffer2[0]-'0';

  
  //----------------------------------------


   
  delay(1000); //change value if you want to read cards faster

 // mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();

  //------------------------------------------

previous = !mfrc522.PICC_IsNewCardPresent();

while(!cardRemoved){
      current =!mfrc522.PICC_IsNewCardPresent();

      if (current && previous) counter++;

      previous = current;
      cardRemoved = (counter>2);      
      delay(50);
      Serial.println(triggernum);

    }
cardRemoved=false;
counter=0;

  //-----------------------------------------

}
//*****************************************************************************************//

Processing Code:
import processing.serial.*; 
import processing.video.*;

Movie firstyear, thirdyear, seventhyear;

Serial port;

String myString="";
int triggernum=0;
String trimmedinput="";
int oldtriggernum=0;

int screen_width=2736; 
int screen_height=1824;

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

void setup() {
 port = new Serial(this, Serial.list()[2], 9600);
 size(1000, 800);
 firstyear = new Movie(this, "Year_1.mp4");
 thirdyear = new Movie(this, "Year_3.mp4");
 seventhyear = new Movie(this, "Year_7.mp4");
 
 //println( "Setup complete" );
}
//**************************************************************//
void movieEvent(Movie video){
  video.read();
}
void draw(){
  while (port.available() > 0) {
    // Read the port 
    myString= port.readStringUntil('\n');
    myString=trim(myString);
    //println(myString);
    if(myString!=null){
    triggernum= Integer.parseInt(myString); 
    }
    if( triggernum ==0 ){
       if(oldtriggernum==1){ 
         firstyear.stop();
          fill(0);
         rect(0,0,screen_width,screen_height);
       }
       if( oldtriggernum ==3){ 
         thirdyear.stop();
          fill(0);
         rect(0,0,screen_width,screen_height);
       }
       if(oldtriggernum==7 ){ 
         seventhyear.stop();
          fill(0);
         rect(0,0,screen_width,screen_height);
       }
          
    }
   
   //println(triggernum);
  
     if(triggernum==1){
       firstyear.play();
       image(firstyear,0,0,1000,800);
     }
     if(triggernum==3){
       thirdyear.play();
       image(thirdyear,0,0,1000,800);
     }
     if(triggernum==7){
       seventhyear.play();
       image(seventhyear,0,0,1000,800);
     }
   
     oldtriggernum =triggernum;
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0