-
Notifications
You must be signed in to change notification settings - Fork 0
/
FridgeJam.ino
152 lines (120 loc) · 3.48 KB
/
FridgeJam.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*SFX*/
#include <PCM.h>
/*MPR121*/
#include <Wire.h>
#include "Adafruit_MPR121.h"
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0; // Keeps track of the last pins touched
uint16_t currtouched = 0; // so we know when buttons are 'released'
/*MFRC522*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
/*MFRC522 Initialization*/
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
/*Detects MPR121*/
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found");
while (1);
} Serial.println("MPR121 found!");
Serial.write(200);
}
void loop()
{
nfcReader();
}
void nfcReader() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
if (mfrc522.uid.uidByte[0] == 0x04 &&
mfrc522.uid.uidByte[1] == 0xb3 &&
mfrc522.uid.uidByte[2] == 0xfc &&
mfrc522.uid.uidByte[3] == 0x1a &&
mfrc522.uid.uidByte[4] == 0x4f &&
mfrc522.uid.uidByte[5] == 0x65 &&
mfrc522.uid.uidByte[6] == 0x80) {
ctaSFX();}
if (mfrc522.uid.uidByte[0] == 0x04 &&
mfrc522.uid.uidByte[1] == 0x4a &&
mfrc522.uid.uidByte[2] == 0x88 &&
mfrc522.uid.uidByte[3] == 0xd2 &&
mfrc522.uid.uidByte[4] == 0xe8 &&
mfrc522.uid.uidByte[5] == 0x6b &&
mfrc522.uid.uidByte[6] == 0x80) {
pianoSFX();}
}
void ctaSFX() {
currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
//if is touched, send touched number to serial
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.write(i);
}
//when not touched, send a default to the serial
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.write(200);
}
}
// reset our state
lasttouched = currtouched;
// comment out this line for detailed data from the sensor!
return;
}
void pianoSFX() {
currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
//if is touched, send touched number to serial
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.write(i+8);
}
//when not touched, send a default to the serial
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.write(200);
}
}
// reset our state
lasttouched = currtouched;
// comment out this line for detailed data from the sensor!
return;
}
/*#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
Serial.println("Scan a card to input sound");
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
Serial.print("Card UID:");
Serial.println(mfrc522.uid.size);
/*for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
//Serial.println(mfrc522.uid.uidByte[7]);
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}*/