Hi there!
I've been trying to add in speed control to my code that controls servo motion activated with an RFID tag. Right now, the servo moves much to fast because it's trying to get where I'm telling it to go as fast as possible. I tried adjusting the delay, but that isn't working. I researched some topics on the varspeedservo library but can't seem to work out how this would fit into my code.
Any guidance would be greatly appreciated.
Here is the code I am currently using
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
Servo servo;
int flag = 1;
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Put your card to the reader...");
Serial.println();
servo.attach(3);
servo.write(50);
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "9A 13 CE 58") //change here the UID of the card/cards that you want to give access
{
if(flag%2 == 1)
{
servo.write(130);
flag++;
delay(1000);
}
else
{
servo.write(15);
flag++;
delay(1000);
}
}
else
{
delay(1000);
servo.write(130);
}
}