Désactivation UART avec le lecteur RFID quand porte non-fermée+immobile

This commit is contained in:
Pierrick C 2017-11-26 21:26:39 +01:00
parent a26a275be6
commit 6fbb763d9c
1 changed files with 20 additions and 3 deletions

View File

@ -6,7 +6,7 @@
#include <EEPROM.h> #include <EEPROM.h>
//Configuration //Configuration
const float SERVO_SPEED = 0.8; const float SERVO_SPEED = 1.8;
const float OPEN_ANGLE = 10.0; const float OPEN_ANGLE = 10.0;
const float CLOSED_ANGLE = 160.0; const float CLOSED_ANGLE = 160.0;
@ -182,6 +182,20 @@ void disableServo() {
} }
} }
void updateSerial() {
//Désactive la connexion au lecteur RFID quand la
//trappe est en mouvement ou ouverte pour éviter les
// parasite
if (RFID and (door_state or door_move)) {
RFID.end();
}
else {
//Active la connexion au lecteur RFID quand la
//trappe est fermée et immobile
RFID.begin(9600);
}
}
void updateDoor() { void updateDoor() {
//Check if the need to move and move it //Check if the need to move and move it
@ -411,10 +425,12 @@ void setup() {
void loop() { void loop() {
tag_ok = -1; tag_ok = -1;
if (!door_state and !door_move and RFID.available() > 0 ) { //Lecture RFID
if (Serial and RFID.available() > 0 ) {
readRFID(); readRFID();
} }
//Ouverture manuelle
if (!digitalRead(DOOR_BUTTON)) { if (!digitalRead(DOOR_BUTTON)) {
Serial.println("Ouverture par l'utilisateur."); Serial.println("Ouverture par l'utilisateur.");
door_state = 1; door_state = 1;
@ -433,7 +449,8 @@ void loop() {
if (door_state and !door_move and catIsHere()) { if (door_state and !door_move and catIsHere()) {
door_timer = millis() + DOOR_OPENED_TIME; door_timer = millis() + DOOR_OPENED_TIME;
} }
updateSerial();
updateDoor(); updateDoor();
updateLED(); updateLED();