57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#include <SPI.h>
|
|
#include <Ethernet3.h>
|
|
|
|
// Configure MAC address and IP:
|
|
byte mac[] = {0x61, 0x2C, 0xF2, 0x09, 0x73, 0xBE};
|
|
IPAddress ip(10, 11, 1, 22);
|
|
|
|
// Define CS and RST pins:
|
|
#define W5500_CS_PIN 10
|
|
#define W5500_RST_PIN 9
|
|
|
|
const int pin_5V = 6;
|
|
const int pin_GND = 4;
|
|
|
|
EthernetClient client;
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(pin_5V, OUTPUT);
|
|
pinMode(pin_GND, OUTPUT);
|
|
|
|
digitalWrite(pin_5V, HIGH);
|
|
digitalWrite(pin_GND, LOW);
|
|
|
|
Serial.begin(9600);
|
|
|
|
// Reset W5500:
|
|
pinMode(W5500_RST_PIN, OUTPUT);
|
|
digitalWrite(W5500_RST_PIN, HIGH);
|
|
delay(250);
|
|
digitalWrite(W5500_RST_PIN, LOW);
|
|
delay(250);
|
|
digitalWrite(W5500_RST_PIN, HIGH);
|
|
delay(1000);
|
|
|
|
// Initialize Ethernet:
|
|
Ethernet.init(W5500_CS_PIN);
|
|
Ethernet.begin(mac, ip);
|
|
|
|
Serial.print("IP: ");
|
|
Serial.println(Ethernet.localIP());
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
pinMode(pin_5V, INPUT);
|
|
int state = digitalRead(pin_5V);
|
|
pinMode(pin_5V, OUTPUT);
|
|
|
|
if (state == HIGH) {
|
|
Serial.println("1");
|
|
} else {
|
|
Serial.println("0");
|
|
}
|
|
delay (250)
|
|
}
|