Herbal Tea Shop
Arduino Code
#include <Wire.h> #include <SPI.h> #include <Adafruit_PN532.h> // If using the breakout with SPI, define the pins for SPI communication. #define PN532_SCK (2) #define PN532_MOSI (3) #define PN532_SS (4) #define PN532_MISO (5) // If using the breakout or shield with I2C, define just the pins connected // to the IRQ and reset lines. Use the values below (2, 3) for the shield! #define PN532_IRQ (2) #define PN532_RESET (3) // Not connected by default on the NFC Shield // Uncomment just _one_ line below depending on how your breakout or shield // is connected to the Arduino: // Use this line for a breakout with a SPI connection: Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); void setup(void) { Serial.begin(115200); // Serial.begin(9600); while (!Serial) delay(10); // for Leonardo/Micro/Zero Serial.println("Hello!"); nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC); // Set the max number of retry attempts to read from a card // This prevents us from waiting forever for a card, which is // the default behaviour of the PN532. nfc.setPassiveActivationRetries(0xFF); // configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A card"); } void loop(void) { Serial.println("waiting"); boolean success; uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { // Reader here Serial.println("Found a card!"); Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); Serial.print("UID Value: "); for (uint8_t i=0; i < uidLength; i++) { Serial.print(" 0x");Serial.print(uid[i], HEX); } Serial.println(""); // Comparison here if ((uid[0] == 0x90) && (uid[1] == 0xEF) && (uid[2] == 0x95) && uid[3] == 0x4A) { Serial.print("potatoe"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } if ((uid[0] == 0x50) && (uid[1] == 0x61) && (uid[2] == 0x96) && uid[3] == 0x4A) { Serial.print("orange"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } if ((uid[0] == 0xC0) && (uid[1] == 0xD1) && (uid[2] == 0x95) && uid[3] == 0x4A) { Serial.print("pineapple"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } if ((uid[0] == 0x90) && (uid[1] == 0xF6) && (uid[2] == 0x95) && uid[3] == 0x4A) { Serial.print("banana"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } if ((uid[0] == 0xC0) && (uid[1] == 0xD9) && (uid[2] == 0x95) && uid[3] == 0x4A) { Serial.print("kiwi"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } if ((uid[0] == 0xB0) && (uid[1] == 0xE1) && (uid[2] == 0x95) && uid[3] == 0x4A) { Serial.print("corn"); Serial.println(""); Serial.print("tapped"); Serial.println(""); } delay(500); } else { // PN532 probably timed out waiting for a card Serial.println("Timed out waiting for a card"); } }
Processing3.0 Code
import processing.serial.Serial; import processing.video.*; //Serial Link static final int PORT_INDEX = 3, BAUDS = 115200; String myString; boolean auto = true; boolean state = false; Movie myMovie[]; float t0; float t; int index = 0; void setup() { fullScreen(P2D, 1); final String[] ports = Serial.list(); printArray(ports); new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER); //println(myString); myMovie = new Movie[3]; frameRate(120); myMovie[0] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loops.mp4"); myMovie[1] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loop_orange.mp4"); myMovie[2] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loop_potatoe.mp4"); myMovie[0].pause(); myMovie[1].pause(); myMovie[2].pause(); if(state == false){ println("I just woke up"); state = false; myMovie[1].stop(); myMovie[2].stop(); myMovie[0].loop(); index = 0; t0 = millis()/1000; println("looping first boot"); } } void draw() { background(0); println("Tapped or not auto on / off: "+auto); image(myMovie[index], 0, 0, width, height); //image(main,0,0,width,height); if (myMovie[index].available() ) { myMovie[index].read(); } if (t > myMovie[index].duration() + t0) { println("finished! "+index); //ONLY WHEN THE VIDEO IS FINISHED state = true; //Check if it it came from a normal switch and auto end - auto if(index != 0 && auto == true){ if(state == true && index != 0){ println("I shall be looping after looping"); state = false; myMovie[1].stop(); myMovie[2].stop(); myMovie[0].loop(); //This makes sure that IT DOES NOT GO BACK TO INIT index = 0; state = true; auto = true; t0 = millis()/1000; println("looping is after start"); } } //Check if it it came from a normal switch and auto end - no auto if(index != 0 && auto == false){ if(state == true && index != 0){ println("I have just been tapped"); //state = false; //myMovie[1].stop(); //myMovie[2].stop(); //myMovie[0].loop(); //This makes sure that IT DOES NOT GO BACK TO INIT //index = 0; state = true; auto = true; t0 = millis()/1000; println("no loop from taps"); } } //if(state == true && index != 0 && auto == true){ // println("I shall be looping after looping"); // state = false; // myMovie[1].stop(); // myMovie[2].stop(); // myMovie[0].loop(); // //This makes sure that IT DOES NOT GO BACK TO INIT // index = 0; // t0 = millis()/1000; // println("looping is after start"); //} } //When the other tag is tapped when the initial one has been tapped, it registers it as a >0 and a true state thus causing the replay to occur t = millis()/1000; } void serialEvent(final Serial s) { myString = s.readString().trim(); if (myString.equals("orange")) { state = false; myMovie[0].stop(); myMovie[2].stop(); myMovie[1].play(); index = 1; t0 = millis()/1000; println("orange is playing"); } if (myString.equals("potatoe")) { state = false; myMovie[0].stop(); myMovie[1].stop(); myMovie[2].play(); index = 2; t0 = millis()/1000; println("potatoe is playing"); } if(myString.equals("tapped")){ auto = false; println("It has been tapped"); } //else{ // auto = true; //} }
Changes to Be Made to the Code
VARIABLES MEANING AND CHANGES (ARDUINO)
Stored RFID Hex Code
(uid[0] == 0x50) && (uid[1] == 0x66) && (uid[2] == 0x96) && uid[3] == 0x4A)
VARIABLES MEANING AND CHANGES (PROCESSING CODE)
Selecting the correct port to obtain data from Arduino
static final int PORT_INDEX = 3, BAUDS = 115200;
Location of the movie files
myMovie[0] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loops.mp4");
myMovie[1] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loop_orange.mp4");
myMovie[2] = new Movie(this, "/Users/marcusfoo/Desktop/ExampleV3_5/loop_potatoe.mp4");
Function which obtains data from Arduino
void serialEvent(final Serial s)