Advertisement
Guest User

Untitled

a guest
Mar 25th, 2023
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.09 KB | Source Code | 0 0
  1. //Using ESP32 over WiFi with TouchDesigner
  2. #include <FastLED.h>
  3. #include "WiFi.h"
  4. #include "AsyncUDP.h"
  5.  
  6. //WiFi Auth
  7. const char* ssid = "****";
  8. const char* password = "***";
  9.  
  10. AsyncUDP udp;
  11.  
  12. // How many leds in your strip?
  13. #define NUM_LEDS 60
  14.  
  15. #define DATA_PIN 5
  16.  
  17. // Define the array of leds
  18. CRGB leds[NUM_LEDS];
  19. const int numOfBytes = NUM_LEDS * 3;
  20. char inputBuffer[numOfBytes];
  21.  
  22. void setup() {
  23.   FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical
  24.   delay(500);
  25.   Serial.begin(115200);
  26.   Serial.setTimeout(500);
  27.   WiFi.mode(WIFI_STA);
  28.   WiFi.begin(ssid, password);
  29.   Serial.println(WiFi.localIP());
  30. }
  31.  
  32. void loop() {
  33.   if (udp.listen(1234)) {
  34.     udp.onPacket([](AsyncUDPPacket packet) {
  35.       for (int i = 0;i<packet.length();i++){ //convert to a char array
  36.         inputBuffer[i] = (char)*(packet.data()+i);
  37.       }
  38.     });
  39.     Serial.readBytes(inputBuffer, numOfBytes);
  40.     for (int j = 0; j < NUM_LEDS; j++) {
  41.       leds[j] = CRGB(inputBuffer[(j * 3)], inputBuffer[(j * 3) + 1], inputBuffer[(j * 3) + 2]);
  42.     }
  43.     LEDS.show();
  44.   }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement