iluz/Arduino/Interlock/interrupt_sequence/interrupt_sequence.ino
2025-06-20 14:47:05 +02:00

63 lines
1.3 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); // Static IP
// Change when connecting to the internet
IPAddress serverIP(192, 168, 1, 100); // computer
// Don't change
unsigned int port = 5005;
// Define CS and RST pins:
#define W5500_CS_PIN 10
#define W5500_RST_PIN 9
// Definitions for interrupt sequence
int interrupt_pin = 2; // Wired
volatile int interrupt_flag;
EthernetClient client;
//client.connect ()
void setup() {
// put your setup code here, to run once:
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);
Serial.print("Sending a message");
// Initialize Ethernet:
Ethernet.init(W5500_CS_PIN);
Ethernet.begin(mac, ip);
// Try to send a message through socket
//client.write("hey", 3);
// Initialize interrupt
pinMode(interrupt_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interrupt_pin), ISR_button, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
if (interrupt_flag) {
interrupt_flag = 0;
}
}
void ISR_button () {
interrupt_flag = 1;
}