Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By aortiz557
#34480 okay, i switched over to UDP and everything is working fine now. this code is in 2 parts. the first part runs on 1 esp-01 module and generates red, green, and blue values. it then sends them over udp to the other module. the second esp-01 module waits for 4 bytes to be received, first byte is led address, second byte red, third green, fourth blue. then writes those values to a strip of 60 neopixels connected on pin 2. the code is pretty ugly, i could wrap some things up nicely in arrays, and redundant code into loops. but I'm lazy. anyway, it works.

sender code:
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
byte remoteIp[] = {192,168,0,5};
WiFiUDP Udp;

  int reddegrees = 0;
  int bluedegrees = 120;
  int greendegrees = 240;
  int counter = 0;

void setup() {
  Serial.begin(115200);
  WiFi.begin("Router? I hardly know her!","******");
 
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }
    Serial.println("");
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    Udp.begin(8080);
}

void loop() {

if(reddegrees == 360)
  {
    reddegrees = 0;
  }
    if(greendegrees == 360)
  {
    greendegrees = 0;
  }
    if(bluedegrees == 360)
  {
    bluedegrees = 0;
  }
  float redradians = reddegrees*0.0174532925;
  float greenradians = greendegrees*0.0174532925;
  float blueradians = bluedegrees*0.0174532925;
 
  byte red = ((sin(redradians) + 1)/2)*255;
  byte green = ((sin(greenradians) + 1)/2)*255;
  byte blue = ((sin(blueradians) + 1)/2)*255;
   
Udp.beginPacket(remoteIp,8080);
byte temp = 0;
Udp.write(temp);
Udp.write(red);
Udp.write(green);
Udp.write(blue);
Udp.endPacket();
  reddegrees = reddegrees + 12;
  greendegrees = greendegrees + 12;
  bluedegrees = bluedegrees + 12;
  counter++;

delay(100);
}


receiver code:
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <Adafruit_NeoPixel.h>
WiFiUDP Udp;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60,2); //60 leds, pin 2

void setup()
{
strip.begin();
strip.show();
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin("Router? I hardly know her!","*****");
 
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }
    Serial.println("");
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    Udp.begin(8080);
    Serial.println("started server");
}

void loop() {
  int packetSize = Udp.parsePacket();
  if(packetSize >= 4)
  {
    strip.setPixelColor(Udp.read(),Udp.read(),Udp.read(),Udp.read());
  }
  strip.show();
  // put your main code here, to run repeatedly:

}