Skip to content

Commit fbe614e

Browse files
Tasmanian DevilTasmanian Devil
Tasmanian Devil
authored and
Tasmanian Devil
committed
Added ability to remove card
1 parent 03fdf35 commit fbe614e

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

RFID_master_slave_cards/RFID_master_slave_cards.ino

+61-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define STATE_SCAN_VALID 4
1414
#define STATE_SCAN_MASTER 5
1515
#define STATE_ADDED_CARD 6
16+
#define STATE_REMOVED_CARD 7
1617

1718
#define REDPIN 6
1819
#define GREENPIN 7
@@ -93,6 +94,36 @@ void addReadCard()
9394
}
9495
}
9596

97+
//------------------------------------------------------------------------------------
98+
void removeReadCard()
99+
{
100+
int cardIndex;
101+
int index;
102+
boolean found = false;
103+
104+
for(cardIndex = 0; cardIndex < cardsStored; cardIndex++)
105+
{
106+
if (found == true)
107+
{
108+
for(index = 0; index < 4; index++)
109+
{
110+
cardArr[cardIndex-1][index] = cardArr[cardIndex][index];
111+
cardArr[cardIndex][index] = 0;
112+
}
113+
}
114+
115+
if ((memcmp(readCard, cardArr[cardIndex], 4)) == 0)
116+
{
117+
found = true;
118+
}
119+
}
120+
121+
if (found == true)
122+
{
123+
cardsStored--;
124+
}
125+
}
126+
96127
//------------------------------------------------------------------------------------
97128
void updateState(byte aState)
98129
{
@@ -139,6 +170,10 @@ void updateState(byte aState)
139170
digitalWrite(REDPIN, LOW);
140171
digitalWrite(GREENPIN, HIGH);
141172
}
173+
else if (currentState == STATE_REMOVED_CARD)
174+
{
175+
return;
176+
}
142177
else
143178
{
144179
lcd.clear();
@@ -152,19 +187,35 @@ void updateState(byte aState)
152187
}
153188
break;
154189
case STATE_SCAN_VALID:
155-
if (currentState == STATE_ADDED_CARD)
190+
if (currentState == STATE_SCAN_MASTER)
191+
{
192+
removeReadCard();
193+
aState = STATE_REMOVED_CARD;
194+
195+
lcd.clear();
196+
lcd.setCursor(0,0);
197+
lcd.print("Card Scanned");
198+
lcd.setCursor(0,1);
199+
lcd.print("Card Removed");
200+
StateWaitTime = 2000;
201+
digitalWrite(REDPIN, LOW);
202+
digitalWrite(GREENPIN, HIGH);
203+
}
204+
else if (currentState == STATE_ADDED_CARD)
156205
{
157206
return;
158207
}
159-
160-
lcd.clear();
161-
lcd.setCursor(0,0);
162-
lcd.print("Card Scanned");
163-
lcd.setCursor(0,1);
164-
lcd.print("valid Card");
165-
StateWaitTime = 2000;
166-
digitalWrite(REDPIN, LOW);
167-
digitalWrite(GREENPIN, HIGH);
208+
else
209+
{
210+
lcd.clear();
211+
lcd.setCursor(0,0);
212+
lcd.print("Card Scanned");
213+
lcd.setCursor(0,1);
214+
lcd.print("valid Card");
215+
StateWaitTime = 2000;
216+
digitalWrite(REDPIN, LOW);
217+
digitalWrite(GREENPIN, HIGH);
218+
}
168219
break;
169220
case STATE_SCAN_MASTER:
170221
lcd.clear();

0 commit comments

Comments
 (0)