-
Notifications
You must be signed in to change notification settings - Fork 0
/
COPY_IC.ino
127 lines (117 loc) · 3.35 KB
/
COPY_IC.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
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <MFRC522.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
#define NEW_UID {0x00, 0x00, 0x00, 0x00}
byte ID[4];
byte newUid[4]{0x00, 0x00, 0x00, 0x00};
MFRC522::MIFARE_Key key;
int Mode_A=0,Mode_B=0;
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
if(digitalRead(4)==HIGH&&digitalRead(5)==LOW){
Mode_B=0;
if(Mode_A ==0){
display.clearDisplay();
}
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Find UID");
display.println("");
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
byte *id = mfrc522.uid.uidByte;
byte idSize = mfrc522.uid.size;
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
for (byte i = 0; i < idSize; i++) {
Serial.print("id[");
Serial.print(i);
Serial.print("]: ");
Serial.println(id[i], HEX);
newUid[i]=newUid[i]+id[i];
if(i%2==0){
display.print("id[");
display.print(i);
display.print("]:0X");
display.print(id[i], HEX);
display.print(" ");
}
else{
display.print("id[");
display.print(i);
display.print("]:0X");
display.println(id[i], HEX);
}
}
Serial.println();
mfrc522.PICC_HaltA();
}
Mode_A++;
delay(100);
}
else if(digitalRead(4)==LOW&&digitalRead(5)==HIGH){
Mode_A=0;
if(Mode_B ==0){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Copy");
display.println("");
}
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}
//byte newUid[] = NEW_UID[0]+ID[0],NEW_UID[1]+ID[1],NEW_UID[2]+ID[2],NEW_UID[3]+ID[3];
//for(int i=0;i<4;i++){
//newUid[i]=newUid[i]+ID[i];
//}
if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
Serial.println(F("Finish"));
display.println("Finish");
}
Mode_B++;
delay(300);
}
else{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(" By Gsx_Joker");
display.println(" V2.0");
display.println(" !!!Warning!!!");
display.println(" Check before use");
display.display();
delay(200);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(" By Gsx_Joker");
display.println(" V2.0");
display.println(" ");
display.println(" Check before use");
display.display();
delay(200);
Mode_B =0;
Mode_A =0;
}
display.display();
}