// Aisha Dev, Chileshe Otieno, Erin Fuller, Victoria Yong
// Intelligent Environments Spring 2019 Project: Curbside Chats
/// MP3 PLAYER PROJECT reference
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////
//RFID reference
//https://howtomechatronics.com/tutorials/arduino/rfid-works-make-arduino-//based-rfid-door-lock/
#include "SoftwareSerial.h"
#include <SPI.h>
#include <MFRC522.h>
SoftwareSerial mySerial(3, 5);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
#define SS_PIN 10
#define RST_PIN 9
# define ACTIVATED LOW
/*RFID code */
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
int code[] = {32,154,149,117}; //This is the stored UID (Unlock Card)
int codeRead = 0;
String uidString;
bool have_read = false;
int last_read = 0;
/*RFID code*/
boolean isPlaying = false;
void setup () {
//RFID
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
//MP3
mySerial.begin(9600);
}
void loop () {
if ((rfid.PICC_IsNewCardPresent())&&(last_read == 0)){
Serial.print("working");
last_read += 1;
if (have_read == false){
playFirst();
have_read = true;
}
else{
play();
}
}
if (last_read > 800){
last_read = 0;
pause();
}
else if (last_read > 0){
last_read += 1;
}
}
void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(25);
delay(500);
execute_CMD(0x11,0,1);
delay(500);
}
void pause()
{
execute_CMD(0x0E,0,0);
delay(500);
}
void play()
{
execute_CMD(0x0D,0,1);
delay(500);
}
void playNext()
{
execute_CMD(0x01,0,1);
delay(500);
}
void playPrevious()
{
execute_CMD(0x02,0,1);
delay(500);
}
void setVolume(int volume)
{
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(2000);
}
void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}
/* RFID CODE */
void readRFID()
{
rfid.PICC_ReadCardSerial();
Serial.print(F("\nPICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));
Serial.println("Scanned PICC's UID:");
printDec(rfid.uid.uidByte, rfid.uid.size);
uidString = String(rfid.uid.uidByte[0])+" "+String(rfid.uid.uidByte[1])+" "+String(rfid.uid.uidByte[2])+ " "+String(rfid.uid.uidByte[3]);
int i = 0;
boolean match = true;
while(i<rfid.uid.size)
{
if(!(int(rfid.uid.uidByte[i]) == int(code[i])))
{
match = false;
}
i++;
}
if(match)
{
Serial.println("\n*** Unlock ***");
}else
{
Serial.println("\nUnknown Card");
}
Serial.println("============================");
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .