|
@@ -0,0 +1,109 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <Servo.h>
|
|
|
|
+#include <AccelStepper.h>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <SPI.h>
|
|
|
|
+#include <MFRC522.h>
|
|
|
|
+
|
|
|
|
+Servo myservo;
|
|
|
|
+int servo_pin = 2;
|
|
|
|
+int door_positions[3]={17, 33, 55};
|
|
|
|
+
|
|
|
|
+AccelStepper stepper(1, 16, 0);
|
|
|
|
+int stepper_maxspeed = 5000;
|
|
|
|
+int stepper_speed = 500;
|
|
|
|
+
|
|
|
|
+int sensor_pin = 2;
|
|
|
|
+bool sensor_read;
|
|
|
|
+
|
|
|
|
+#define RST_PIN 3 // Configurable, see typical pin layout above
|
|
|
|
+#define SS_PIN 4 // Configurable, see typical pin layout above
|
|
|
|
+#define IRQ_PIN 15 // Configurable, depends on hardware
|
|
|
|
+
|
|
|
|
+MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
|
|
|
|
+
|
|
|
|
+MFRC522::MIFARE_Key key;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+void setup() {
|
|
|
|
+ //init serial
|
|
|
|
+ delay(500);
|
|
|
|
+ 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)
|
|
|
|
+ Serial.println("EPITECH STARTED");
|
|
|
|
+ //init NFC
|
|
|
|
+ SPI.begin(); // Init SPI bus
|
|
|
|
+ mfrc522.PCD_Init(); // Init MFRC522 card
|
|
|
|
+ /* read and printout the MFRC522 version (valid values 0x91 & 0x92)*/
|
|
|
|
+ delay(40); // Optional delay. Some board do need more time after init to be ready, see Readme
|
|
|
|
+ mfrc522.PCD_DumpVersionToSerial(); //
|
|
|
|
+
|
|
|
|
+ myservo.attach(servo_pin); // attaches the servo on GIO2 to the servo object
|
|
|
|
+ myservo.write(door_positions[0]);
|
|
|
|
+
|
|
|
|
+ stepper.setMaxSpeed(stepper_maxspeed);
|
|
|
|
+ stepper.setSpeed(stepper_speed);
|
|
|
|
+
|
|
|
|
+ //pinMode(sensor_pin, INPUT);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int previous_read;
|
|
|
|
+int read_ms = 1000;
|
|
|
|
+bool NFCpresent;
|
|
|
|
+
|
|
|
|
+void loop() {
|
|
|
|
+
|
|
|
|
+ if(millis()-previous_read>read_ms){
|
|
|
|
+ NFCpresent = mfrc522.PICC_IsNewCardPresent();
|
|
|
|
+ previous_read = millis();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( !NFCpresent ) {
|
|
|
|
+ stepper.runSpeed();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if (mfrc522.PICC_ReadCardSerial()) {
|
|
|
|
+ mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ myservo.write(door_positions[random(3)]);
|
|
|
|
+ int startTime = millis();
|
|
|
|
+ while(millis()-startTime<3000){
|
|
|
|
+ stepper.runSpeed();
|
|
|
|
+ }
|
|
|
|
+ NFCpresent = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Dump debug info about the card; PICC_HaltA() is automatically called
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Select one of the cards
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// sensor_read = digitalRead(sensor_pin);
|
|
|
|
+// //Serial.println(sensor_read);
|
|
|
|
+// //Serial.println(! mfrc522.PICC_IsNewCardPresent());
|
|
|
|
+//
|
|
|
|
+// if(!sensor_read){
|
|
|
|
+// //Serial.println(mfrc522.PICC_IsNewCardPresent());
|
|
|
|
+// }
|
|
|
|
+// if ( mfrc522.PICC_ReadCardSerial()) {
|
|
|
|
+// mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // Dump debug info about the card; PICC_HaltA() is automatically called
|
|
|
|
+//
|
|
|
|
+// else{
|
|
|
|
+// //stepper.runSpeed();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|