Hello guys
I've just upload/checked the code below for sending UDP packets over ethernet when 2 contacts are closed.
The arduino works and the code is uploaded but i think he doesn't sen UDP packets.
Please can somebody check my code?
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
// the media access control (ethernet hardware) address for the shield:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 192, 168, 1, 1 };
unsigned int localPort = 6553; // local port to listen on
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup()
{
Ethernet.begin(mac, ip); //Start the Ethernet and UDP
Udp.begin(localPort);
Serial.begin(9600);
pinMode(22, INPUT); // Sets the digital pin as input
pinMode(23, INPUT); // Sets the digital pin as input
pinMode(24, INPUT); // Sets the digital pin as input
pinMode(25, INPUT); // Sets the digital pin as input
}
void loop()
{
if (digitalRead(22) && digitalRead(23))
sendPacket("g1");
if (digitalRead(24) && digitalRead(25))
sendPacket("g2");
}
void sendPacket(char *contents)
{
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(contents);
Udp.endPacket();
}
Thanks in advance
Leon