Hello there,
I really need some help.
I have no idea how to use an Arduino so i went on 'upwork' to hire someone to help me write the code for a project I'm trying to complete. Unfortunately they have gone MIA and I don't know anything about coding. Our agreement was that he would talk me through how to use the code, and modify it as I needed. But all i have is a code I don't understand. I was hoping someone could translate it for me as I'm not sure what he has given me, or if it is at all what i had requested.
The project was a box which opens when a button is pressed by 'servo motors'. Once open 6 RFID readers are exposed which communicate through the 'arduino' to an RPi which would play a short video linked to the different cards.
Thank is advance
/************************* Libraries *********************************/
#include <MFRC522.h> //https://github.com/miguelbalboa/rfid
#include <Servo.h>
/************************* Constants *********************************/
#define SS_PIN 5
#define RST_PIN 0
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
Servo myServo5;
int index;
// constants won't change. They're used here to set pin numbers:
const int BUTTON_PIN = 7; // the number of the pushbutton pin
// Variables will change:
int lastState = LOW; // the previous state from the input pin
int currentState; // the current reading from the input pin
/************************* Parameters *********************************/
String id_allowed[] = { "4a88f980", "a7607cb4", "d4fadae9", "40b28d4d", "196a7be", "061854d" };
/********************* Global connection instances **************************/
MFRC522 rfid(SS_PIN, RST_PIN);
String ID_Card, op_name;
byte nuidPICC[4];
void setup() {
myServo1.attach(5); //servo1
myServo2.attach(6); //servo2
myServo3.attach(9); //servo3
myServo4.attach(10); //servo4
myServo5.attach(11); //servo5
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600);
//init rfid
SPI.begin(); // init SPI bus
rfid.PCD_Init(); // init MFRC522
Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");
myServo1.write(0);
myServo2.write(0);
myServo3.write(0);
myServo4.write(0);
myServo5.write(0);
}
void loop() {
String idcard;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
// Initialisé la boucle si aucun badge n'est présent
if (!rfid.PICC_IsNewCardPresent())
return;
// Vérifier la présence d'un nouveau badge
if (!rfid.PICC_ReadCardSerial())
return;
// Enregistrer l'ID du badge (4 octets)
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
// Affichage de l'ID
Serial.println("Un badge est détecté");
Serial.println(" L'UID du tag est:");
idcard = "";
for (byte i = 0; i < 4; i++) {
idcard += String(rfid.uid.uidByte[i], HEX);
}
Serial.println(idcard);
if (idcard == "a7607cb4") {
index = "0";
do {
Serial.write(index);
} while (Serial.read() != index);
}
// Re-Init RFID
rfid.PICC_HaltA(); // Halt PICC
rfid.PCD_StopCrypto1(); // Stop encryption on PCD
// read the state of the switch/button:
currentState = digitalRead(BUTTON_PIN);
if (lastState == LOW && currentState == HIGH) {
for (int pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myServo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myServo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myServo3.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myServo4.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
// in steps of 1 degree
myServo5.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// save the last state
lastState = currentState;
}
if (lastState == HIGH && currentState == LOW) {
for (int pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myServo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myServo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myServo3.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myServo4.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myServo5.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// save the last state
lastState = currentState;
}
}