Advertisement
muezza29

beli token v2

Jul 11th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.85 KB | None | 0 0
  1. // Library NFC
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <Adafruit_PN532.h>
  5.  
  6. #define PN532_SCK  (PA5)
  7. #define PN532_MOSI (PA7)
  8. #define PN532_SS   (PA4)
  9. #define PN532_MISO (PA6)
  10. #define PN532_IRQ   (2)
  11. #define PN532_RESET (3)
  12.  
  13.  
  14. // Library OLED
  15. #include "Arduino.h"
  16. #include "Wire.h"
  17. #include "Adafruit_GFX.h"
  18. #include "Adafruit_SSD1306.h"
  19.  
  20. #define OLED_RESET 4
  21. Adafruit_SSD1306 display(OLED_RESET);
  22.  
  23. Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
  24.  
  25. #if defined(ARDUINO_ARCH_SAMD)
  26. #define Serial SerialUSB
  27. #endif
  28.  
  29. void setup(void)
  30. {
  31. #ifndef ESP8266
  32. #endif
  33.   Serial.begin(115200);
  34.   Serial.println("Hello Arif!");
  35.  
  36.   nfc.begin();
  37.  
  38.   uint32_t versiondata = nfc.getFirmwareVersion();
  39.   if (! versiondata) {
  40.     Serial.print("Didn't find PN53x board");
  41.     while (1); // halt
  42.   }
  43.  
  44.   nfc.SAMConfig();
  45.  
  46.   Serial.println("Tempelkan kartu pelanggan");
  47.  
  48.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  49.   display.clearDisplay();
  50. }
  51.  
  52. String str1, str3;
  53. String str2 = "0x49 0xB3 0x9E 0x2B";
  54. void loop(void)
  55. {
  56.   uint8_t success;
  57.   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  58.   uint8_t uidLength;                          // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  59.  
  60.   success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  61.  
  62.   if (success)
  63.   {
  64.     String str22 = hexify(uid, uidLength);
  65.     results(str22);
  66.   }
  67. }
  68.  
  69. String hexify(uint8_t u[], byte len)
  70. {
  71.   String out = "";
  72.   for (byte i = 0; i < len; i++)
  73.   {
  74.     String a = String(u[i], HEX);
  75.     a.toUpperCase();
  76.     if (a.length() == 1) a = "0" + a;
  77.     out += "0x" + a + " ";
  78.   }
  79.   out.trim();
  80.   return out;
  81. }
  82.  
  83. void results(String str)
  84. {
  85.   if (str == str2)
  86.   {
  87.     display.clearDisplay();
  88.     display.setTextSize(1);
  89.     display.setTextColor(WHITE);
  90.  
  91.     display.setCursor(0, 0);
  92.     display.print("Pelanggan dikenali");
  93.  
  94.     display.setCursor(0, 8);
  95.     display.print("sebagai :");
  96.  
  97.     display.setCursor(0, 16);
  98.     display.print(" > 1303167045");
  99.     display.display();
  100.  
  101.     Serial.println("\n  1303167045");
  102.     jeda();
  103.   }
  104.   else
  105.   {
  106.     display.clearDisplay();
  107.     display.setTextSize(1);
  108.     display.setTextColor(WHITE);
  109.  
  110.     display.setCursor(0, 0);
  111.     display.print("Tag NFC tidak");
  112.  
  113.     display.setCursor(0, 8);
  114.     display.print("dikenali");
  115.  
  116.     display.setCursor(0, 16);
  117.     display.print(" > Bukan pelanggan");
  118.     display.display();
  119.  
  120.     Serial.println("\n  Bukan pelanggan");
  121.   }
  122.   Serial.print("");
  123. }
  124.  
  125. void jeda()
  126. {
  127.   delay(2000);
  128.  
  129.   display.clearDisplay();
  130.   display.setTextSize(1);
  131.   display.setTextColor(WHITE);
  132.  
  133.   display.setCursor(0, 0);
  134.   display.print("> 10K");
  135.  
  136.   display.setCursor(0, 8);
  137.   display.print("> 20K");
  138.   display.display();
  139.  
  140.   display.setCursor(0, 16);
  141.   display.print("> 50K");
  142.   display.display();
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement