Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using ESP32 over WiFi with TouchDesigner
- #include <FastLED.h>
- #include "WiFi.h"
- #include "AsyncUDP.h"
- //WiFi Auth
- const char* ssid = "****";
- const char* password = "***";
- AsyncUDP udp;
- // How many leds in your strip?
- #define NUM_LEDS 60
- #define DATA_PIN 5
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- const int numOfBytes = NUM_LEDS * 3;
- char inputBuffer[numOfBytes];
- void setup() {
- FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
- delay(500);
- Serial.begin(115200);
- Serial.setTimeout(500);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- Serial.println(WiFi.localIP());
- }
- void loop() {
- if (udp.listen(1234)) {
- udp.onPacket([](AsyncUDPPacket packet) {
- for (int i = 0;i<packet.length();i++){ //convert to a char array
- inputBuffer[i] = (char)*(packet.data()+i);
- }
- });
- Serial.readBytes(inputBuffer, numOfBytes);
- for (int j = 0; j < NUM_LEDS; j++) {
- leds[j] = CRGB(inputBuffer[(j * 3)], inputBuffer[(j * 3) + 1], inputBuffer[(j * 3) + 2]);
- }
- LEDS.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement