Moderator: igrr
sender code:
#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:
#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:
}