Hey all!
So, I have two Arduino Megas both equipped with an ethernet shield 2. With that code I want to send a UDP Packet over the ethernet from the first Arduino, to tell the other Arduino it should or shouldn
t switch on an LED if I push a button (I need to keep it pushed).
That works, but the problem I have is that it takes very very long...
When I upload the code and push the button it takes about a minute for the first Arduino to even register that I pushed the button. And it takes another thirty seconds or so to switch on or switch on the LED.
How can I speed that up?
Thank you very much!
Here`s the code:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
byte taster = A4;
byte power = 44;
byte tasterWert;
byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED}; //dest mac address
IPAddress ip(); //Local
IPAddress destIp(); //dest
unsigned int localPort = 5000; //Local Port to listen on
unsigned int destPort = 5005; //dest port
EthernetUDP Udp; //Instance
char high [] = "H";
char low [] = "L";
void setup(){
pinMode(taster,INPUT);
pinMode(power,OUTPUT);
Ethernet.begin(9600);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
digitalWrite(power,HIGH);
int tasterWert = digitalRead(taster);
Serial.println(tasterWert);
Udp.beginPacket(destIp, destPort);
if(tasterWert == 1){
Udp.write(high);
}
Udp.endPacket();
Udp.beginPacket(destIp, destPort);
if(tasterWert == 0){
Udp.write(low);
}
Udp.endPacket();
}