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
|
|
|
|
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
|
|
|
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-01-22 22:04:40 +01:00
|
|
|
// Create EthernetUdp instance to send and receive packets over UDP
|
|
|
|
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
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Ready.");
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
Serial.println("Received packet:");
|
|
|
|
Serial.print("Length: ");
|
|
|
|
Serial.println(packetSize);
|
|
|
|
|
|
|
|
// assume an incoming uncompressed BMP image
|
|
|
|
// assume we know the pixels start at offset 54
|
|
|
|
for (int i = 0; i < packetSize; i = i + 3) {
|
|
|
|
Serial.print(packetBuffer[i], HEX);
|
|
|
|
Serial.print(packetBuffer[i+1], HEX);
|
|
|
|
Serial.print(packetBuffer[i+2], HEX);
|
|
|
|
Serial.print(" ");
|
|
|
|
strip.setPixelColor(i / 3, packetBuffer[i], packetBuffer[i+1], packetBuffer[i+2]);
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
2015-01-22 22:04:40 +01:00
|
|
|
Serial.print("\n");
|
2013-11-02 11:09:55 +01:00
|
|
|
strip.show();
|
2015-01-22 22:04:40 +01:00
|
|
|
}
|
2013-11-02 11:09:55 +01:00
|
|
|
}
|
|
|
|
|