Skip to content

Instantly share code, notes, and snippets.

@spinogrizz
Created November 17, 2012 13:47
Show Gist options
  • Save spinogrizz/4096090 to your computer and use it in GitHub Desktop.
Save spinogrizz/4096090 to your computer and use it in GitHub Desktop.
Blink LED on every UDP packet
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);
unsigned int localPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
pinMode(7, OUTPUT);
}
void loop() {
int bytesAvailable = Udp.parsePacket();
if( bytesAvailable )
{
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment