I'm trying to switch out my all my delays for millis but It's just not working for me. I see all over to look at the blimk without delay example, and I have it up next to my sketch, but I'm just not getting it.
here's my code
/* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK : Pin 13 / ICSP-3
* SS : Pin 4,8,7 (Configurable)
* RST : Pin 9 (Configurable)
*/
#include <SPI.h>
#include <MFRC522.h>
#include <VarSpeedServo.h>
#define SS1_PIN 4
#define SS2_PIN 7
#define SS3_PIN 8
#define RST_PIN 9
//#define redLed 7
VarSpeedServo feeder;
VarSpeedServo cover1;
VarSpeedServo cover2;
VarSpeedServo cover3;
MFRC522 readerOne(SS1_PIN, RST_PIN);
MFRC522 readerTwo(SS2_PIN, RST_PIN);
MFRC522 readerThree(SS3_PIN, RST_PIN);
long coverDuration = 20;
long closeTime = 0;
void setup() {
//pinMode(redLed, OUTPUT);
SPI.begin();
readerOne.PCD_Init();
readerTwo.PCD_Init();
readerThree.PCD_Init();
feeder.attach(10);
feeder.write(0,255,true);
cover1.attach(3);
cover1.write(0,255,true);
cover2.attach(5);
cover2.write(0,255,true);
cover3.attach(6);
cover3.write(5,255,true);
}
int myCat = 0x03;
int readTagOne;
int readTagTwo;
int readTagThree;
void loop() {
unsigned long currentMillis1 = millis();
if (readerOne.PICC_IsNewCardPresent()){
readerOne.PICC_ReadCardSerial();
readTagOne = (readerOne.uid.uidByte[0]);
if(readTagOne == myCat){
cover1.write(160,255,false);
closeTime = currentMillis1;
if(currentMillis1 - closeTime > coverDuration) {
cover1.write(0,255,true);
}
}
}
if (readerTwo.PICC_IsNewCardPresent()){
readerTwo.PICC_ReadCardSerial();
readTagTwo = (readerTwo.uid.uidByte[0]);
if(readTagTwo == myCat){
cover2.write(140,255,true);
delay(2000);
cover2.write(0,255,true);
}
}
if (readerThree.PICC_IsNewCardPresent()){
readerThree.PICC_ReadCardSerial();
readTagThree = (readerThree.uid.uidByte[0]);
if(readTagThree == myCat){
cover3.write(160,255,true);
delay(2000);
cover3.write(0,255,true);
}
}
}
here is the specific part I want to use the millis and my current attempt.
unsigned long currentMillis1 = millis();
if (readerOne.PICC_IsNewCardPresent()){
readerOne.PICC_ReadCardSerial();
readTagOne = (readerOne.uid.uidByte[0]);
if(readTagOne == myCat){
cover1.write(160,255,false);
closeTime = currentMillis1;
if(currentMillis1 - closeTime > coverDuration) {
cover1.write(0,255,true);
}
}
}
Any help would be greatly appreciated.
Thanks