설치 필요한 라이브러리
LiquidCrystal_I2C 라이브러리
MFRC 라이브러리 추가
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define RST_PIN 5
#define SS_PIN 15
MFRC522 mfrc522(SS_PIN, RST_PIN);
int select;
typedef struct product{
char buffName[20];
int buffprice;
}product;
product productList[7] = { //구조체 추가 및 변경
{"3D Printer", 230000},
{"Arduino Starter Kit", 110000},
{"LG Gram 2020", 1799000},
{"MacBook Pro CTO", 3120000},
{"4k Monitor", 399000},
{"7.1ch Speakers", 1684300},
{"Desk & Chair", 362650}
};
struct account{
String name_;
String authority;
int totalPrice;
String recent5Namelog[5];
int recent5Pricelog[5];
};
struct account Master = {"MakeItNow","Admin",0,{},{}};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
SPI.begin();
Wire.begin(2, 0);
lcd.begin();
mfrc522.PCD_Init();
Serial.println(" ");
Serial.println("카드를 리더기에 가까이 대 주세요");
Serial.println();
pinMode(A0,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
select = map(analogRead(A0),0,1023,0,6);
lcd.setCursor(0,0);
lcd.print(productList[select].buffName);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(productList[select].buffprice);
lcd.print(" ");
if(!mfrc522.PICC_IsNewCardPresent()){
return;
}
if(!mfrc522.PICC_ReadCardSerial()){
return;
}
Serial.println("\n----------------------------");
Serial.print("\nUID tag : ");
String content= "";
byte letter;
for(byte i = 0; i < mfrc522.uid.size; i++){
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i],HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
Serial.println();
if(content.substring(1) == "E9 6E 0E 5D"){ //UID 변경 필수
Serial.println("승인된 카드입니다.\n");
Serial.print("User Name : ");
Serial.println(Master.name_);
Serial.print("Authority : ");
Serial.println(Master.authority);
if( (Master.recent5Namelog[0]) && (Master.recent5Pricelog[0]) ){
for(int i = 3; i>=0; i--){
Master.recent5Namelog[i+1] = Master.recent5Namelog[i];
Master.recent5Pricelog[i+1] = Master.recent5Pricelog[i];
}
Master.recent5Namelog[0] = productList[select].buffName;
Master.recent5Pricelog[0] = productList[select].buffprice;
Master.totalPrice+=productList[select].buffprice;
}
else{
Master.recent5Namelog[0] = productList[select].buffName;
Master.recent5Pricelog[0] = productList[select].buffprice;
Master.totalPrice+=productList[select].buffprice;
}
Serial.println("\nRecent Logs");
Serial.println();
for(int i = 0; i<5; i++){
if(Master.recent5Namelog[i] != 0){
Serial.print(Master.recent5Namelog[i]);
Serial.print(" : ");
Serial.println(Master.recent5Pricelog[i]);
}
else{
break;
}
}
Serial.println();
Serial.print("Total : ");
Serial.println(Master.totalPrice);
Serial.print("\n\n");
lcd.setCursor(0,0);
lcd.print("Thank you!");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Total: ");
lcd.print(Master.totalPrice);
}
else{
Serial.println("승인되지 않은 카드입니다.");
lcd.setCursor(0,0);
lcd.print("ErrCode 1: CARD");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("UNREGISTERED");
}
Serial.println("——————————————");
delay(2000);
}
사업자 정보 표시
메이크잇나우 | 김건욱 | (우 : 13487) 경기도 성남시 분당구 대왕판교로645번길 12 (경기창조경제혁신센터) 9층 | 사업자 등록번호 : 646-35-00394 | TEL : 070-8887-0703 | Mail : kgu0724@makeitnow.kr | 통신판매신고번호 : 2018-성남분당-0517호 | 사이버몰의 이용약관 바로가기
'메이커 자료' 카테고리의 다른 글
아두이노 레오나르도로 만드는 메이키메이키 (0) | 2020.04.12 |
---|---|
라즈베리파이 설치 및 기본 세팅 (0) | 2020.03.25 |
NodeMCU mfrc522와 서보모터 구동 코드 (0) | 2020.01.31 |
아두이노 시작하기 (0) | 2019.07.23 |
아두이노 기초 교육 자료 [LED, 조도센서, 버튼] (0) | 2019.06.19 |