-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnerd_door.ino
137 lines (111 loc) · 2.91 KB
/
nerd_door.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
/*
nfc.ino
This program was adapted from the available manufacturer example.
This program will send the data (id from a nfcTag) through serial
Made some changes in the library function: nfc.readPassiveTargetID
October 2016
*/
//This example reads all MIFARE memory block from 0x00 to 0x63.
//It is tested with a new MIFARE 1K cards. Uses default keys for authenication.
//Contributed by Seeed Technology Inc (www.seeedstudio.com)
#include <PN532.h>
#include <SPI.h>
#include <Print.h>
#include <Servo.h>
/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define NFC_DEMO_DEBUG 1
#define PN532_CS 10
#define DEG_CLOSED 35
#define DEG_OPEN 130
#define SERVO_PIN 9
#define buttonPin 5
#define DELAY_HOLD_OPEN 2500
PN532 nfc(PN532_CS);
char temp;
int servoDegree = 0;
Servo myservo; // create servo object to control a servo
extern uint32_t acceptCards[];
extern size_t card_count;
void setup(void) {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
while (1); // halt
}
// configure board to read RFID tags and cards
nfc.SAMConfig();
//starting servo on closed position
myservo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object
myservo.write(DEG_CLOSED);
delay(2000);
myservo.detach();
}
void loop(void) {
//servoCalib();
uint32_t id = 0;
if (digitalRead(buttonPin) == LOW) {
Serial.print("OPEN " + buttonPin);
moveServo();
}
// look for MiFare type cards
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
for (int i = 0; i < card_count; i++) {
if (id == acceptCards[i]) {
Serial.print("chupa!!, id validated");
Serial.println();
moveServo();
break;
}
}
Serial.print("new id found!: ");
Serial.print(id);
Serial.println();
} else {
Serial.print("anyid");
Serial.println();
}
delay(500);
}
//servo calibration func
void servoCalib() {
while (1) {
temp = Serial.read();
if (temp == '1') {
servoDegree += 5;
myservo.write(servoDegree);
Serial.print(servoDegree);
Serial.println();
}
if (temp == '2') {
servoDegree += 10;
myservo.write(servoDegree);
Serial.print(servoDegree);
Serial.println();
}
if (temp == '3') {
servoDegree -= 5;
myservo.write(servoDegree);
Serial.print(servoDegree);
Serial.println();
}
if (temp == '4') {
servoDegree -= 10;
myservo.write(servoDegree);
Serial.print(servoDegree);
Serial.println();
}
}
}
void moveServo(){
myservo.attach(SERVO_PIN);
myservo.write(DEG_OPEN);
delay(DELAY_HOLD_OPEN);
myservo.write(DEG_CLOSED);
delay(1000);
myservo.detach();
}