Advertisement
pimBE

fastled esp8266 artnet ws2801

May 11th, 2016
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #define FASTLED_ESP8266_RAW_PIN_ORDER
  2. #include "FastLED.h"
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiUdp.h>
  5.  
  6. #define ARTNET_ARTDMX 0x5000 //20480 as a decimal ArtNet OP Code
  7. #define DATA_PIN 0
  8. #define CLOCK_PIN 2
  9. #define CHIPSET WS2801
  10. #define COLOR_ORDER RGB
  11. #define NUM_LEDS 96
  12. #define BRIGHTNESS 255
  13. CRGB leds[NUM_LEDS];
  14.  
  15. //WiFi Setup
  16. char ssid[] = "VOO-738695";
  17. char pass[] = "PASSWORD";
  18. IPAddress local_ip(192, 168, 0, 20);
  19. IPAddress gateway(192, 168, 0, 1);
  20. IPAddress subnet(255, 255, 255, 0);
  21. #define ART_NET_PORT 6454
  22. WiFiUDP Audp; //UDP socket for ArtNet
  23. #define BUFFER_SIZE 640
  24. unsigned char PacketBuffer[BUFFER_SIZE]; //buffer to hold incoming packet data
  25.  
  26. void setup() {
  27. WiFi.begin(ssid, pass); //Connect to Network
  28. WiFi.config(local_ip, gateway, subnet); //Set static IP information
  29. while (WiFi.status() != WL_CONNECTED) //wait until we are connected
  30. {
  31. delay(500);
  32. }
  33. Audp.begin(ART_NET_PORT); //Open ArtNet port
  34. FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  35. FastLED.setBrightness( BRIGHTNESS );
  36. }
  37.  
  38. // the loop function runs over and over again forever
  39. void loop() {
  40. int packetSize = Audp.parsePacket(); //Parse Packet
  41. if ( packetSize ) //ArtNet packet size is 530
  42. {
  43. Audp.read(PacketBuffer, BUFFER_SIZE); //Read packet into buffer
  44. int opcode = artNetOpCode(PacketBuffer); //Check to see if packet is ArtNet
  45. if ( opcode == ARTNET_ARTDMX ) //If code returned is correct
  46. {
  47. for(int i=0; i<NUM_LEDS; i++) {
  48. int d = i*3+18;
  49. leds[i].r = PacketBuffer[d];
  50. leds[i].g = PacketBuffer[d+1];
  51. leds[i].b = PacketBuffer[d+2];
  52. }
  53. FastLED.show();
  54. }
  55. }
  56. }
  57. int artNetOpCode(unsigned char* pbuff) {
  58. String test = String((char*)pbuff);
  59. if ( test.equals("Art-Net") )
  60. {
  61. if ( pbuff[11] >= 14 )
  62. { //protocol version [10] hi byte [11] lo byte
  63. return pbuff[9] *256 + pbuff[8]; //opcode lo byte first
  64. }
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement