LED adressables
Content
LED Neopixel alimentées par une alimentation 5VDC à dimmensionner en fonction du nombre total de LED (par exemple ruban RGB de 40 led : 3 x 0.05 x 40 = 6A)
variante avec LED alimentées par le 3,3V de la carte de l'ESP8266
exemple de programme avec LED Neopixel :
// pour LOLIN D1 mini pro ESP8266
#include <FastLED.h>
#include <ArtnetWifi.h>
#include <Arduino.h>
// WiFi stuff
//const char* ssid = "HUAWEI-B715-AED4";//"Canard";
//const char* password = "KERGOMARD";//"canarder";
const char* ssid = "travel_lab";
const char* password = "olivarpremier";
const IPAddress ip(192, 168, 0, 116);
const IPAddress gateway(192, 168, 0, 253);
const IPAddress subnet(255, 255, 255, 0);
// LED settings
const int numLeds = 2; // CHANGE FOR YOUR SETUP
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
const byte dataPin = D5;
CRGB leds[numLeds];
// Art-Net settings
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;
// connect to wifi – returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
//Serial.println("");
//Serial.println("Connecting to WiFi");
// Wait for connection
//Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
leds[0] = CRGB(10, 0, 10);//debug : check if fastled OK
FastLED.show(); // Envoyer les couleurs aux LED
delay(50);
leds[0] = CRGB(0, 0, 0);//debug : check if fastled OK
FastLED.show(); // Envoyer les couleurs aux LED
//Serial.print(".");
delay(50);
if (i > 200)
{
state = false;
leds[0] = CRGB(10,0, 0);//debug : check if fastled OK
FastLED.show(); // Envoyer les couleurs aux LED
ESP.restart();
break;
}
i++;
}
if (state)
{
leds[0] = CRGB(0,10, 0);//debug : check if fastled OK
FastLED.show(); // Envoyer les couleurs aux LED
//Serial.println("");
//Serial.print("Connected to ");
//Serial.println(ssid);
//Serial.print("IP address: ");
//Serial.println(WiFi.localIP());
}
else
{
leds[0] = CRGB(10, 0, 0);//debug : check if fastled OK
FastLED.show(); // Envoyer les couleurs aux LED
//Serial.println("");
//Serial.println("Connection failed.");
}
return state;
}
void initTest()
{
//delay(1000);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(127, 0, 0);
FastLED.show();
delay(1);
}
FastLED.show();
delay(1000);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 127, 0);
}
FastLED.show();
delay(1000);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 0, 127);
}
FastLED.show();
delay(1000);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show();
}
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)
{
FastLED.setBrightness(data[0]);
FastLED.show();
}
// range check
if (universe < startUniverse)
{
return;
}
uint8_t index = universe - startUniverse;
if (index >= maxUniverses)
{
return;
}
// Store which universe has got in
universesReceived[index] = true;
//Serial.println(index);
for (int i = 0 ; i < maxUniverses ; i++)
{
if (!universesReceived[i])
{
sendFrame = 0;
break;
}
}
// read universe and put into the right part of the display buffer
for (int i = 0; i < length / 3; i++)
{
int led = i + (index * 170);
if (led < numLeds)
{
leds[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
}
}
if (sendFrame)
{
FastLED.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
}
}
void setup()
{
//Serial.begin(115200);
FastLED.addLeds<NEOPIXEL, dataPin>(leds, numLeds);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
ConnectWifi();
delay(1000);
artnet.begin();
//initTest();
memset(universesReceived, 0, maxUniverses);
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
}
void loop()
{
// we call the read function inside the loop
while (WiFi.status() == WL_CONNECTED)
{
artnet.read();
FastLED.show(); //mise a jour des LED's à chaque cycle
}
ESP.restart();
}