2015-01-22 22:04:40 +01:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <Ethernet.h>
|
|
|
|
#include <EthernetUdp.h>
|
2015-01-18 19:43:50 +01:00
|
|
|
#include "Adafruit_NeoPixel.h"
|
2013-11-02 11:09:55 +01:00
|
|
|
|
|
|
|
#define PIN 6
|
2015-01-22 22:04:40 +01:00
|
|
|
#define WIDTH 16
|
|
|
|
#define HEIGHT 16
|
|
|
|
|
|
|
|
#define UDP_PACKET_MAX_SIZE 768
|
|
|
|
#define PIXEL_OFFSET 0x80
|
|
|
|
|
2013-11-02 11:09:55 +01:00
|
|
|
// Parameter 1 = number of pixels in strip
|
|
|
|
// Parameter 2 = pin number (most are valid)
|
|
|
|
// Parameter 3 = pixel type flags, add together as needed:
|
|
|
|
// NEO_RGB Pixels are wired for RGB bitstream
|
|
|
|
// NEO_GRB Pixels are wired for GRB bitstream
|
|
|
|
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
|
|
|
|
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
|
|
|
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(WIDTH * HEIGHT, PIN, NEO_GRB + NEO_KHZ800);
|
|
|
|
|
2015-01-22 22:04:40 +01:00
|
|
|
// Network configuration
|
2015-03-09 22:14:06 +01:00
|
|
|
byte mac[] = {0xFE, 0xED, 0x0D, 0xA0, 0x1E, 0xD5};
|
2015-01-22 22:04:40 +01:00
|
|
|
IPAddress ip(172, 22, 239, 182);
|
|
|
|
unsigned int localPort = 8888;
|
2013-11-02 11:09:55 +01:00
|
|
|
|
2015-01-22 22:04:40 +01:00
|
|
|
// buffers for receiving and sending data
|
|
|
|
char packetBuffer[UDP_PACKET_MAX_SIZE]; // buffer to hold incoming packet
|
2013-11-02 11:09:55 +01:00
|
|
|
|
2015-03-09 22:14:06 +01:00
|
|
|
// Create EthernetUDP instance to send and receive packets over UDP
|
2015-01-22 22:04:40 +01:00
|
|
|
EthernetUDP Udp;
|
2013-11-02 11:09:55 +01:00
|
|
|
|
2015-01-22 22:04:40 +01:00
|
|
|
void setup() {
|
|
|
|
// initialize ethernet device
|
|
|
|
Ethernet.begin(mac, ip);
|
|
|
|
// Start UDP
|
|
|
|
Udp.begin(localPort);
|
|
|
|
strip.begin();
|
|
|
|
// Initialize all pixels to 'off'
|
|
|
|
for (int i=0; i<256; i++) {
|
|
|
|
strip.setPixelColor(i, strip.Color(0, 0, 0));
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
}
|
|
|
|
|
2015-01-22 22:04:40 +01:00
|
|
|
void loop() {
|
|
|
|
// if there is data available, read a packet
|
|
|
|
int packetSize = Udp.parsePacket();
|
2013-11-02 11:09:55 +01:00
|
|
|
|
2015-01-22 22:04:40 +01:00
|
|
|
if (packetSize) {
|
|
|
|
// read the packet into packet buffer
|
|
|
|
Udp.read(packetBuffer, UDP_PACKET_MAX_SIZE);
|
|
|
|
|
|
|
|
for (int i = 0; i < packetSize; i = i + 3) {
|
2015-03-09 22:14:06 +01:00
|
|
|
strip.setPixelColor(i / 3, packetBuffer[i+2], packetBuffer[i+1], packetBuffer[i]);
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
|
|
|
strip.show();
|
2015-03-09 22:14:06 +01:00
|
|
|
}
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
|
|
|
|