#include <Servo.h>
#include <SoftwareSerial.h>
#include <rdm6300.h>
//RFID
SoftwareSerial serRFID(2, 3);
Rdm6300 rdm6300;
//Servo
Servo motor;
int pos;
const uint8_t motorPin = 6;
const int openPos = 0;
const int closedPos = 90;
const uint32_t PHATCAT_ID = 0x12345678; //change to match the tag fat kitty is wearing
void startRFID()
{
serRFID.begin(RDM6300_BAUDRATE);
rdm6300.begin(&serRFID);
}//startRFID
void startSerial(){
Serial.begin(9600);
Serial.println("Starting up");
}//startSerial
void startServo()
{
motor.attach(motorPin);
motor.write(openPos);
}//startServo
bool teste = false;
void setup()
{
startSerial();
startServo();
startRFID();
}//setup
void loop()
{
static uint8_t
state = 0;
static uint32_t
tSample = 0ul,
tWaitPhatty = 0ul;
uint32_t tNow = millis();
switch( state )
{
case 0:
if( tNow - tSample >= 250ul )
{
tSample = tNow;
//wait for a new RFID to be seen
if( rdm6300.get_tag_id() == PHATCAT_ID )
{
tWaitPhatty = tNow;
motor.write(closedPos);
state++;
}//if
}//if
break;
case 1:
//wait for phatCat to leave and be gone for a few of seconds...
if( rdm6300.get_tag_id() == PHATCAT_ID )
{
//still sensing the fat cat...reset the delay
tWaitPhatty = tNow;
}//if
else
{
if( tNow - tWaitPhatty >= 3000ul )
{
motor.write( openPos );
state = 0;
}//if
}//else
break;
}//switch
}//loop