0% found this document useful (0 votes)
17 views3 pages

Cartoes

Uploaded by

bxdaharts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Cartoes

Uploaded by

bxdaharts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Aguardando cartões...

UID do cartão: 63 41 7C 05
UID do cartão: D3 E3 F9 0D
UID do cartão: D3 00 68 19
UID do cartão: 63 41 7C 05
UID do cartão: E3 F8 C8 0F
UID do cartão: D3 00 68 19
UID do cartão: D3 E3 F9 0D
UID do cartão: 43 82 A2 A6
UID do cartão: 53 32 76 09
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define BUTTON_A 2
#define BUTTON_B 3
#define BUTTON_C 4
#define BUTTON_D 5
#define BUTTON_E 6

int voteA = 0;
int voteB = 0;
int voteC = 0;
int voteD = 0;
int voteE = 0;

void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();

lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Por favor, apresente");
lcd.setCursor(0, 1);
lcd.print("o cartao RFID...");
Serial.print("o cartao RFID...");
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
pinMode(BUTTON_D, INPUT_PULLUP);
pinMode(BUTTON_E, INPUT_PULLUP);
}

void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

String uid = getUID();


displayMessage("Aguardando voto...");
displayMessage("UID: " + uid);
Serial.println("UID: " + uid);

while (true) {
if (digitalRead(BUTTON_A) == LOW) {
voteA++;
break;
}
if (digitalRead(BUTTON_B) == LOW) {
voteB++;
break;
}
if (digitalRead(BUTTON_C) == LOW) {
voteC++;
break;
}
if (digitalRead(BUTTON_D) == LOW) {
voteD++;
break;
}
if (digitalRead(BUTTON_E) == LOW) {
voteE++;
break;
}
}
displayVotes();
}

String getUID() {
String content = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
return content;
}

void displayMessage(String message) {


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(message);
Serial.println(message);
}

void displayVotes() {
Serial.println("Votos:");
Serial.println("A: " + String(voteA));
Serial.println("B: " + String(voteB));
Serial.println("C: " + String(voteC));
Serial.println("D: " + String(voteD));
Serial.println("E: " + String(voteE));

displayMessage("Votos:");
displayMessage("A:" + String(voteA) + " B:" + String(voteB) + " C:" +
String(voteC) + " D:" + String(voteD) + " E:" + String(voteE));
}

You might also like