Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.32 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <hd44780.h>
  3. #include <hd44780ioClass/hd44780_pinIO.h>
  4.  
  5.  
  6. //Display PinSetup
  7. //const int rs = 12, en = 11, db4 = 10, db5 = 9, db6 = 8, db7 = 7;
  8. //Piazo Pin Setup
  9. const int buzzer = 2;
  10. int PowerOn = 0;
  11. hd44780_pinIO lcd(12, 11, 10, 9, 8, 7);
  12. const int LCDCols = 20;
  13. const int LCDRow = 4;
  14.  
  15. #define LCD_COLS 20
  16. #define LCD_ROWS 4
  17. #define HD44780_LCDOBJECT
  18.  
  19.  
  20.  
  21. String HITAG1 = "h";
  22. String HITAG2 = "H";
  23. String EM4102 = "U";
  24. String EM4150 = "T";
  25.  
  26.  
  27. String ver;
  28. String id;
  29. String lastscan;
  30. String idshort;
  31. String MTid;
  32.  
  33. void setup()   {
  34.                     pinMode(buzzer, OUTPUT);
  35.                     Serial1.begin(9600);
  36.                     Serial1.setTimeout(50);
  37.                     lcd.begin(20, 4);
  38.                 }
  39.                                
  40.  
  41.  
  42.  
  43.  
  44.  
  45. void loop()
  46.                         {  
  47.                             if ( ( (PowerOn) == 1 ) && ( (ver.length()) >= 4 ) )
  48.                                 {
  49.                                     Scannen();
  50.                                 }
  51.                             else VersionCheck();
  52.  
  53.  
  54.                         }
  55.  
  56. //Ruft die Version des Kekses ab und Speichert ihn als String ver
  57. String VersionCheck ()      {   Serial.println("Version");
  58.                                 digitalWrite(buzzer, HIGH);
  59.                                 delay(800);
  60.                                 digitalWrite(buzzer, LOW);
  61.                                 lcd.print ("Scanner 01");
  62.                                 lcd.setCursor(0,1);
  63.                                 Serial1.write("v");
  64.                                 while (!Serial1.available())
  65.                                 {
  66.                                 }
  67.                                 ver = Serial1.readString();                      
  68.                                 ver.trim();
  69.                                 lcd.print(String(ver));
  70.                                 delay(1500);
  71.                                 PowerOn=1;
  72.                                 return (ver);
  73.                             }
  74.  
  75.  
  76.  
  77. //Scannt die ID und übergibt den String
  78. String Scannen()
  79.                         {
  80.                                         Serial1.write("rid");
  81.  
  82.                                         while (!Serial1.available())
  83.                                         {
  84.                                         Serial.println("while");
  85.  
  86.                                         }
  87.  
  88.                                         id = Serial1.readString();                      
  89.                                         id.trim();
  90.                                         Serial.println(id);
  91.                                        
  92.                                         Serial1.flush();
  93.  
  94.                                         if ((id.length()) > 4 && id != lastscan )
  95.                                                
  96.                                                 {
  97.                                                     lcd.setCursor(0,1);
  98.                                                     lcd.print("                  ");
  99.                                                     lcd.setCursor(0,1);
  100.                                                     digitalWrite(buzzer, HIGH);
  101.                                                     delay(50);
  102.                                                     digitalWrite(buzzer, LOW);
  103.                                                     lcd.print("ID:" + id);
  104.                                                     lcd.setCursor(0,1);
  105.                                                     Serial.println("SCAN1");
  106.                                                     idshort = id;
  107.                                                     idshort.remove(0,1);
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.                                                    
  117.                                                     if ( id.startsWith(HITAG1) )
  118.  
  119.                                                                 {
  120.                                                                     lcd.setCursor(0,3);
  121.                                                                     lcd.print("Typ: HITAG 1");
  122.                                                                     lcd.setCursor(0,1);
  123.                                                                 }
  124.                                                    
  125.                                                     else if ( id.startsWith(HITAG2) )
  126.  
  127.                                                                 {
  128.                                                                     lcd.setCursor(0,3);
  129.                                                                     lcd.print("Typ: HITAG 2");
  130.                                                                     lcd.setCursor(0,1);
  131.                                                                 }
  132.  
  133.                                                     else if ( id.startsWith(EM4102) )
  134.  
  135.                                                                 {  
  136.                                                                     lcd.setCursor(0,2);
  137.                                                                     lcd.print("MTID:" + byte0i);
  138.                                                                     lcd.setCursor(0,3);
  139.                                                                     lcd.print("Typ: EM4102");
  140.                                                                     lcd.setCursor(0,1);
  141.                                                                 }
  142.                                                     else if ( id.startsWith(EM4150) )
  143.  
  144.                                                                 {
  145.                                                                     lcd.setCursor(0,3);
  146.                                                                     lcd.print("Typ: EM4150");
  147.                                                                     lcd.setCursor(0,1);
  148.                                                                 }
  149.                                                    
  150.                                                     else        {
  151.                                                                     lcd.setCursor(0,3);
  152.                                                                     lcd.print("Typ: UNBEKANNT");
  153.                                                                     lcd.setCursor(0,1);
  154.                                                                 }
  155.  
  156.                                                 }
  157.  
  158.  
  159.  
  160.                                         else if ( ((id.length()) <= 4 ) && id != lastscan)
  161.                                                 {
  162.                                                             lcd.setCursor(0,1);
  163.                                                             lcd.print("KEIN TAG ERKANNT!");
  164.                                                             lcd.setCursor(0,3);
  165.                                                             lcd.print("                    ");
  166.                                                             lcd.setCursor(0,1);
  167.                                                 }
  168.  
  169.                                        
  170.  
  171.                                         lastscan = id;
  172.                                        
  173.                                         return id;
  174.                                
  175.                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement