Hi all,
I'm newbie in the arduino world and I will be happy to get some help...(i'm sorry about my english)
I have rfid code and I want that the loop for this code will start only if the arduino is get an input signal (from first arduino - the pin is configured to output).
if the input signal is lost, the loop have to stop.
or if it will be more easy that the Relay will work only if there is input signal from the first arduino
the input pin is 7
Code:
/*
- Read a card using a mfrc522 reader on your SPI interface
- Pin layout should be as follows (on Arduino Uno):
- MOSI: Pin 11 / ICSP-4
- MISO: Pin 12 / ICSP-1
- SCK: Pin 13 / ISCP-3
- SS: Pin 10
- RST: Pin 9
- This Code for the LAST reader - Open relay
*/
#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN,RST_PIN);
int relay = A1;
int serNum[5];
int cards[][HEX] = {
{53,220,225,82,90},
{70,98,202,50,22}
};
bool access = false;
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.init();
pinMode(relay, OUTPUT);
pinMode(7, INPUT); //signal from prev arduino
}
void loop(){
// while(digitalRead(7) == HIGH) ****** I try to use with while and if but the loop continue to run without the input signal condition even when the input wire is disconnected.
if(rfid.isCard()){
if(rfid.readCardSerial()){
Serial.print(rfid.serNum[0]);
Serial.print(" ");
Serial.print(rfid.serNum[1]);
Serial.print(" ");
Serial.print(rfid.serNum[2]);
Serial.print(" ");
Serial.print(rfid.serNum[3]);
Serial.print(" ");
Serial.print(rfid.serNum[4]);
Serial.println("");
for(int x = 0; x < sizeof(cards); x++){
for(int i = 0; i < sizeof(rfid.serNum); i++ ){
if(rfid.serNum != cards[x]) {
* access = false;*
* break;*
* } else {*
* access = true;*
* }*
* }*
* if(access) break;*
* }*
* }*
* if(access);{*
* Serial.println("Get In--->");*
// while(digitalRead(7) == HIGH);
* digitalWrite(relay, HIGH);*
* delay(100); *
* } else {*
* Serial.println("You Blocked(-)");*
* delay(100); *
* } *
* }*
* rfid.halt();*
* }*
Thanks for the makers and experts