/* * This example works for ESP8266 & ESP32 and uses the NeoPixelBus library instead of the one bundle * Sketch written by Joey Babcock - https://joeybabcock.me/blog/, and Scott Lawson (Below) * Codebase created by ScottLawsonBC - https://github.com/scottlawsonbc */ #include #if defined(ESP8266) #include #include #elif defined(ESP32) #include #else #error "This is not a ESP8266 or ESP32!" #endif // Set to the number of LEDs in your LED strip #define NUM_LEDS 60 // Maximum number of packets to hold in the buffer. Don't change this. #define BUFFER_LEN 1024 // Toggles FPS output (1 = print FPS over serial, 0 = disable output) #define PRINT_FPS 1 //NeoPixelBus settings const uint8_t PixelPin = 3; // make sure to set this to the correct pin, ignored for Esp8266(set to 3 by default for DMA) // Wifi and socket settings const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; unsigned int localPort = 7777; char packetBuffer[BUFFER_LEN]; uint8_t N = 0; WiFiUDP port; // Network information // IP must match the IP in config.py IPAddress ip(192, 168, 0, 150); // Set gateway to your router's gateway IPAddress gateway(192, 168, 0, 1); IPAddress subnet(255, 255, 255, 0); NeoPixelBus ledstrip(NUM_LEDS, PixelPin); void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.config(ip, gateway, subnet); WiFi.begin(ssid, password); Serial.println(""); // Connect to wifi and print the IP address over serial while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); port.begin(localPort); ledstrip.Begin();//Begin output ledstrip.Show();//Clear the strip for use } #if PRINT_FPS uint16_t fpsCounter = 0; uint32_t secondTimer = 0; #endif void loop() { // Read data over socket int packetSize = port.parsePacket(); // If packets have been received, interpret the command if (packetSize) { int len = port.read(packetBuffer, BUFFER_LEN); for(int i = 0; i < len; i+=4) { packetBuffer[len] = 0; N = packetBuffer[i]; RgbColor pixel((uint8_t)packetBuffer[i+1], (uint8_t)packetBuffer[i+2], (uint8_t)packetBuffer[i+3]);//color ledstrip.SetPixelColor(N, pixel);//N is the pixel number } ledstrip.Show(); #if PRINT_FPS fpsCounter++; Serial.print("/");//Monitors connection(shows jumps/jitters in packets) #endif } #if PRINT_FPS if (millis() - secondTimer >= 1000U) { secondTimer = millis(); Serial.printf("FPS: %d\n", fpsCounter); fpsCounter = 0; } #endif }