Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <FastSPI_LED.h>
- #define NUM_LEDS 160
- struct CRGB { unsigned char r; unsigned char g; unsigned char b; };
- struct CRGB *leds;
- #define PIN 51
- int i = 0;
- long r;
- long g;
- long b;
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x4E, 0xEB };
- IPAddress ip(192, 168, 100, 40);
- unsigned int localPort = 41181; // local port to listen on
- // buffers for receiving and sending data
- char packetBuffer[250]; //buffer to hold incoming packet,
- char ReplyBuffer[] = "k"; // a string to send back to keep it synchronized
- // An EthernetUDP instance to let us send and receive packets over UDP
- EthernetUDP Udp;
- void setup() {
- Serial.begin(115200);
- // Leds:
- FastSPI_LED.setLeds(NUM_LEDS);
- FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);
- FastSPI_LED.setPin(PIN);
- FastSPI_LED.setDataRate(5);
- FastSPI_LED.init();
- FastSPI_LED.start();
- leds = (struct CRGB*)FastSPI_LED.getRGBData();
- // start the Ethernet and UDP:
- Ethernet.begin(mac,ip);
- Udp.begin(localPort);
- while (Udp.parsePacket()) {
- Udp.flush();
- }
- }
- void loop() {
- long packetSize = Udp.parsePacket();
- if(Udp.available() && packetSize > 0)
- {
- Serial.println("got package!");
- Udp.read(packetBuffer,250);
- memset(leds, 0, NUM_LEDS * 3);
- for(i = 0 ; i < NUM_LEDS; i++ ) {
- leds[i].r = 0;
- leds[i].g = 0;
- leds[i].b = 255;
- }
- noInterrupts();
- FastSPI_LED.show();
- delay(10);
- interrupts();
- Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
- Udp.write(ReplyBuffer);
- Udp.endPacket();
- }
- else
- {
- Serial.println("no no no!");
- memset(leds, 0, NUM_LEDS * 3);
- for (i = 0; i < NUM_LEDS; i++) {
- leds[i].r = 0;
- leds[i].g = 0;
- leds[i].b = 0;
- }
- noInterrupts();
- FastSPI_LED.show();
- delay(10);
- interrupts();
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement