arnet wifi
Content
microprogramme
// pour LOLIN D1 mini pro ESP8266
// first DMX start address
#define DMXSTART 0//canal de départ -1
//#include <FastLED.h> // include FastLED *before* Artnet
// Please include ArtnetWiFi.h to use Artnet on the platform
// which can use both WiFi and Ethernet
#include <ArtnetWifi.h>
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
// this is also valid for other platforms which can use only WiFi
//#include <Artnet.h>
// WiFi stuff
const char* ssid = "xxxxxxxxxxxxxx";
const char* pwd = "xxxxxxxxxxxxx";
const IPAddress ip(192, 168, 0, 114);
const IPAddress gateway(192, 168, 0, 253);
const IPAddress subnet(255, 255, 255, 0);
const uint8_t PIN_LED_DATA = D5;
#define NUM_LEDS 45
const int numberOfChannels = NUM_LEDS * 4;
Adafruit_NeoPixel strip(NUM_LEDS, PIN_LED_DATA, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
uint8_t decalage;
ArtnetWifi artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
sendFrame = 1;
// set brightness of the whole strip
if (universe == 15)
{
strip.setBrightness(data[0]);
strip.show();
}
// Store which universe has got in
if ((universe - startUniverse) < maxUniverses)
{
universesReceived[universe - startUniverse] = 1;
}
for (int i = 0 ; i < maxUniverses ; i++)
{
if (universesReceived[i] == 0)
{
//Serial.println("Broke");
sendFrame = 0;
break;
}
}
// read universe and put into the right part of the display buffer
for (int i = 0; i < length / 4; i++)
{
int led = i + (universe - startUniverse) * (previousDataLength / 4);
if (led < NUM_LEDS)
decalage = i * 4; //optimisation
strip.setPixelColor(led, data[decalage], data[decalage + 1], data[decalage + 2], data[decalage+ 3]);
}
previousDataLength = length;
if (sendFrame)
{
strip.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
}
}
void setup() {
Serial.begin(115200);
delay(2000);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
//strip.setMaxPowerInVoltsAndMilliamps(5, 1000); //diode de protection sur D1 1A max ????
// WiFi stuff
WiFi.begin(ssid, pwd);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
Serial.println(".");
strip.setPixelColor(0, 100, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(10);
strip.setPixelColor(0, 0, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(40);
}
Serial.print("WiFi connected, IP = ");
Serial.println(WiFi.localIP());
strip.setPixelColor(0, 100,0 , 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(1000);
strip.setPixelColor(0, 0, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(10);
strip.setPixelColor(0, 0, 100, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(1000);
strip.setPixelColor(0, 0, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(10);
strip.setPixelColor(0, 0, 0, 100, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(1000);
strip.setPixelColor(0, 0, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
delay(10);
strip.setPixelColor(0, 0, 0, 0, 100);
strip.show(); // Envoyer les couleurs aux LED
delay(1000);
strip.setPixelColor(0, 0, 0, 0, 0);
strip.show(); // Envoyer les couleurs aux LED
//delay(1000);
artnet.begin();
// artnet.subscribe_net(0); // optionally you can change
// artnet.subscribe_subnet(0); // optionally you can change
//artnet.shortname("45 RGBW strip 1");//keep < 18 char
//artnet.longname("45 RGBW strip 1 ");//keep <64 char
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
}
void loop() {
artnet.read(); // check if artnet packet has come and execute callback
//strip.show(); // Envoyer les couleurs aux LED
}