• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
UNO + ETHERNET + RC522
#3
Kod:
#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>

#define RST_PIN         1          // Configurable, see typical pin layout above
#define SS_PIN          2         // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0 , 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }


 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
 SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init();        // Init MFRC522
    mfrc522.PCD_DumpVersionToSerial();    // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}
 
}


void loop() {
 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
   Serial.println("new client");
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       Serial.write(c);
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {
         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println("Connection: close");  // the connection will be closed after completion of the response
         client.println("Refresh: 5");  // refresh the page automatically every 5 sec
         client.println();
         client.println("<!DOCTYPE HTML>");
         client.println("<html>");
         // output the value of each analog input pin
         for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
           int sensorReading = analogRead(analogChannel);
           client.print("analog input ");
           client.print(analogChannel);
           client.print(" is ");
           client.print(sensorReading);
           client.println("<br />");
         }
         client.println("</html>");
         break;
       }
       if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
       } else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
   Serial.println("client disconnected");
   Ethernet.maintain();
 }
 {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
    }

    // Dump debug info about the card; PICC_HaltA() is automatically called
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
}
 
Odpowiedź
  


Wiadomości w tym wątku
UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:30
RE: UNO + ETHERNET + RC522 - przez JasQ - 22-01-2016, 21:34
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:40
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:41
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:53
RE: UNO + ETHERNET + RC522 - przez wojtekizk - 22-01-2016, 22:25
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 22:31
RE: UNO + ETHERNET + RC522 - przez wojtekizk - 22-01-2016, 22:43
RE: UNO + ETHERNET + RC522 - przez awachowski - 23-01-2016, 00:53
RE: UNO + ETHERNET + RC522 - przez awachowski - 23-01-2016, 13:18
RE: UNO + ETHERNET + RC522 - przez awachowski - 24-01-2016, 20:14
RE: UNO + ETHERNET + RC522 - przez setim - 28-01-2016, 12:56
RE: UNO + ETHERNET + RC522 - przez awachowski - 28-01-2016, 13:34
RE: UNO + ETHERNET + RC522 - przez setim - 28-01-2016, 14:55
RE: UNO + ETHERNET + RC522 - przez adix - 30-01-2016, 00:59

Skocz do:


Przeglądający: 2 gości