From 4c008d46a60e5daf3bd719e8c0d74de18ad0b6a5 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sun, 8 Nov 2020 12:37:00 +0900 Subject: [PATCH] add fastled example #10 --- .../receive_fastled/receive_fastled.ino | 46 ++++++++++++++++ .../WiFi/receive_fastled/receive_fastled.ino | 54 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 examples/Ethernet/receive_fastled/receive_fastled.ino create mode 100644 examples/WiFi/receive_fastled/receive_fastled.ino diff --git a/examples/Ethernet/receive_fastled/receive_fastled.ino b/examples/Ethernet/receive_fastled/receive_fastled.ino new file mode 100644 index 0000000..5dc30e4 --- /dev/null +++ b/examples/Ethernet/receive_fastled/receive_fastled.ino @@ -0,0 +1,46 @@ +#include +#include + +// Ethernet stuff +const IPAddress ip(192, 168, 0, 201); +uint8_t mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; + +ArtnetReceiver artnet; +uint32_t universe = 1; + +// FastLED +#define NUM_LEDS 1 +CRGB leds[NUM_LEDS]; +const uint8_t PIN_LED_DATA = 3; + +void setup() +{ + Serial.begin(115200); + delay(2000); + + FastLED.addLeds(leds, NUM_LEDS); + + Ethernet.begin(mac, ip); + artnet.begin(); + + // if Artnet packet comes to this universe, this function is called + artnet.subscribe(universe, [&](uint8_t* data, uint16_t size) + { + // set led + // artnet data size per packet is 512 max + // so there is max 170 pixel per packet (per universe) + for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) + { + size_t idx = pixel * 3; + leds[pixel].r = data[idx + 0]; + leds[pixel].g = data[idx + 1]; + leds[pixel].b = data[idx + 2]; + } + FastLED.show(); + }); +} + +void loop() +{ + artnet.parse(); // check if artnet packet has come and execute callback +} diff --git a/examples/WiFi/receive_fastled/receive_fastled.ino b/examples/WiFi/receive_fastled/receive_fastled.ino new file mode 100644 index 0000000..b7a8def --- /dev/null +++ b/examples/WiFi/receive_fastled/receive_fastled.ino @@ -0,0 +1,54 @@ +#include +#include + +// WiFi stuff +const char* ssid = "your-ssid"; +const char* pwd = "your-password"; +const IPAddress ip(192, 168, 1, 201); +const IPAddress gateway(192, 168, 1, 1); +const IPAddress subnet(255, 255, 255, 0); + +ArtnetWiFiReceiver artnet; +uint32_t universe = 1; + +// FastLED +#define NUM_LEDS 1 +CRGB leds[NUM_LEDS]; +const uint8_t PIN_LED_DATA = 3; + +void setup() +{ + Serial.begin(115200); + delay(2000); + + FastLED.addLeds(leds, NUM_LEDS); + + // WiFi stuff + WiFi.begin(ssid, pwd); + WiFi.config(ip, gateway, subnet); + while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } + Serial.print("WiFi connected, IP = "); Serial.println(WiFi.localIP()); + + artnet.begin(); + + // if Artnet packet comes to this universe, this function (lambda) is called + artnet.subscribe(universe, [&](uint8_t* data, uint16_t size) + { + // set led + // artnet data size per packet is 512 max + // so there is max 170 pixel per packet (per universe) + for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) + { + size_t idx = pixel * 3; + leds[pixel].r = data[idx + 0]; + leds[pixel].g = data[idx + 1]; + leds[pixel].b = data[idx + 2]; + } + FastLED.show(); + }); +} + +void loop() +{ + artnet.parse(); // check if artnet packet has come and execute callback +}