Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Library NFC
- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_PN532.h>
- #define PN532_SCK (PA5)
- #define PN532_MOSI (PA7)
- #define PN532_SS (PA4)
- #define PN532_MISO (PA6)
- #define PN532_IRQ (2)
- #define PN532_RESET (3)
- // Library OLED
- #include "Arduino.h"
- #include "Wire.h"
- #include "Adafruit_GFX.h"
- #include "Adafruit_SSD1306.h"
- #define OLED_RESET 4
- Adafruit_SSD1306 display(OLED_RESET);
- Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
- #if defined(ARDUINO_ARCH_SAMD)
- #define Serial SerialUSB
- #endif
- void setup(void)
- {
- #ifndef ESP8266
- #endif
- Serial.begin(115200);
- Serial.println("Hello Arif!");
- nfc.begin();
- uint32_t versiondata = nfc.getFirmwareVersion();
- if (! versiondata) {
- Serial.print("Didn't find PN53x board");
- while (1); // halt
- }
- nfc.SAMConfig();
- Serial.println("Tempelkan kartu pelanggan");
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- display.clearDisplay();
- }
- String str1, str3;
- String str2 = "0x49 0xB3 0x9E 0x2B";
- void loop(void)
- {
- uint8_t success;
- uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
- uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
- if (success)
- {
- String str22 = hexify(uid, uidLength);
- results(str22);
- }
- }
- String hexify(uint8_t u[], byte len)
- {
- String out = "";
- for (byte i = 0; i < len; i++)
- {
- String a = String(u[i], HEX);
- a.toUpperCase();
- if (a.length() == 1) a = "0" + a;
- out += "0x" + a + " ";
- }
- out.trim();
- return out;
- }
- void results(String str)
- {
- if (str == str2)
- {
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.print("Pelanggan dikenali");
- display.setCursor(0, 8);
- display.print("sebagai :");
- display.setCursor(0, 16);
- display.print(" > 1303167045");
- display.display();
- Serial.println("\n 1303167045");
- jeda();
- }
- else
- {
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.print("Tag NFC tidak");
- display.setCursor(0, 8);
- display.print("dikenali");
- display.setCursor(0, 16);
- display.print(" > Bukan pelanggan");
- display.display();
- Serial.println("\n Bukan pelanggan");
- }
- Serial.print("");
- }
- void jeda()
- {
- delay(2000);
- byte pilihan = 1;
- byte jumlah_pilihan = 3;
- refresh_pilihan_token(pilihan);
- while (1)
- {
- if (check_nfc())
- {
- pilihan++;
- if (pilihan > jumlah_pilihan)
- pilihan = 1;
- refresh_pilihan_token(pilihan);
- }
- }
- }
- void refresh_pilihan_token(byte pilihan)
- {
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- switch (pilihan) {
- case 1:
- display.setCursor(0, 0);
- display.print("> 10K");
- display.setCursor(0, 8);
- display.print(" 20K");
- display.setCursor(0, 16);
- display.print(" 50K");
- break;
- case 2:
- display.setCursor(0, 0);
- display.print(" 10K");
- display.setCursor(0, 8);
- display.print("> 20K");
- display.setCursor(0, 16);
- display.print(" 50K");
- break;
- case 3:
- display.setCursor(0, 0);
- display.print(" 10K");
- display.setCursor(0, 8);
- display.print(" 20K");
- display.setCursor(0, 16);
- display.print("> 50K");
- break;
- }
- display.display();
- }
- bool check_nfc()
- {
- uint8_t success;
- uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
- uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
- if (success) {
- String str22 = hexify(uid, uidLength);
- if (str22.equals(str2)) return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement