update fastled examples to use forward method
This commit is contained in:
parent
fc962e5f15
commit
c5c2e7430c
@ -1,5 +1,5 @@
|
|||||||
|
#include <FastLED.h> // include FastLED *before* Artnet
|
||||||
#include <Artnet.h>
|
#include <Artnet.h>
|
||||||
#include <FastLED.h>
|
|
||||||
|
|
||||||
// Ethernet stuff
|
// Ethernet stuff
|
||||||
const IPAddress ip(192, 168, 0, 201);
|
const IPAddress ip(192, 168, 0, 201);
|
||||||
@ -13,8 +13,7 @@ uint32_t universe = 1;
|
|||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
const uint8_t PIN_LED_DATA = 3;
|
const uint8_t PIN_LED_DATA = 3;
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
@ -23,24 +22,26 @@ void setup()
|
|||||||
Ethernet.begin(mac, ip);
|
Ethernet.begin(mac, ip);
|
||||||
artnet.begin();
|
artnet.begin();
|
||||||
|
|
||||||
|
// if Artnet packet comes to this universe, forward them to fastled directly
|
||||||
|
artnet.forward(universe, leds, NUM_LEDS);
|
||||||
|
|
||||||
|
// this can be achieved manually as follows
|
||||||
// if Artnet packet comes to this universe, this function is called
|
// if Artnet packet comes to this universe, this function is called
|
||||||
artnet.subscribe(universe, [&](uint8_t* data, uint16_t size)
|
// artnet.subscribe(universe, [&](uint8_t* data, uint16_t size)
|
||||||
{
|
// {
|
||||||
// set led
|
// // set led
|
||||||
// artnet data size per packet is 512 max
|
// // artnet data size per packet is 512 max
|
||||||
// so there is max 170 pixel per packet (per universe)
|
// // so there is max 170 pixel per packet (per universe)
|
||||||
for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel)
|
// for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) {
|
||||||
{
|
// size_t idx = pixel * 3;
|
||||||
size_t idx = pixel * 3;
|
// leds[pixel].r = data[idx + 0];
|
||||||
leds[pixel].r = data[idx + 0];
|
// leds[pixel].g = data[idx + 1];
|
||||||
leds[pixel].g = data[idx + 1];
|
// leds[pixel].b = data[idx + 2];
|
||||||
leds[pixel].b = data[idx + 2];
|
// }
|
||||||
}
|
// });
|
||||||
FastLED.show();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
|
||||||
artnet.parse(); // check if artnet packet has come and execute callback
|
artnet.parse(); // check if artnet packet has come and execute callback
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
#include <FastLED.h> // include FastLED *before* Artnet
|
||||||
#include <Artnet.h>
|
#include <Artnet.h>
|
||||||
#include <FastLED.h>
|
|
||||||
|
|
||||||
// WiFi stuff
|
// WiFi stuff
|
||||||
const char* ssid = "your-ssid";
|
const char* ssid = "your-ssid";
|
||||||
@ -16,8 +16,7 @@ uint32_t universe = 1;
|
|||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
const uint8_t PIN_LED_DATA = 3;
|
const uint8_t PIN_LED_DATA = 3;
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
@ -26,29 +25,34 @@ void setup()
|
|||||||
// WiFi stuff
|
// WiFi stuff
|
||||||
WiFi.begin(ssid, pwd);
|
WiFi.begin(ssid, pwd);
|
||||||
WiFi.config(ip, gateway, subnet);
|
WiFi.config(ip, gateway, subnet);
|
||||||
while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); }
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print("WiFi connected, IP = "); Serial.println(WiFi.localIP());
|
Serial.print(".");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
Serial.print("WiFi connected, IP = ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
artnet.begin();
|
artnet.begin();
|
||||||
|
|
||||||
|
// if Artnet packet comes to this universe, forward them to fastled directly
|
||||||
|
artnet.forward(universe, leds, NUM_LEDS);
|
||||||
|
|
||||||
|
// this can be achieved manually as follows
|
||||||
// if Artnet packet comes to this universe, this function (lambda) is called
|
// if Artnet packet comes to this universe, this function (lambda) is called
|
||||||
artnet.subscribe(universe, [&](uint8_t* data, uint16_t size)
|
// artnet.subscribe(universe, [&](uint8_t* data, uint16_t size) {
|
||||||
{
|
// // set led
|
||||||
// set led
|
// // artnet data size per packet is 512 max
|
||||||
// artnet data size per packet is 512 max
|
// // so there is max 170 pixel per packet (per universe)
|
||||||
// so there is max 170 pixel per packet (per universe)
|
// for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) {
|
||||||
for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel)
|
// size_t idx = pixel * 3;
|
||||||
{
|
// leds[pixel].r = data[idx + 0];
|
||||||
size_t idx = pixel * 3;
|
// leds[pixel].g = data[idx + 1];
|
||||||
leds[pixel].r = data[idx + 0];
|
// leds[pixel].b = data[idx + 2];
|
||||||
leds[pixel].g = data[idx + 1];
|
// }
|
||||||
leds[pixel].b = data[idx + 2];
|
// });
|
||||||
}
|
|
||||||
FastLED.show();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
|
||||||
artnet.parse(); // check if artnet packet has come and execute callback
|
artnet.parse(); // check if artnet packet has come and execute callback
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user