44// All Rights Reserved 2025
55// Licensed under the GNU GPL License.
66
7- #define DEBUG 1 // 1: DEBUG at 115200, 0: No DEBUG
8-
9- // Required libraries
10- #include < SPI.h>
11- #include < Ethernet.h>
12- #include < EthernetUdp.h>
13- #include < ArtnetEther.h>
14- #include < FastLED.h>
15-
16- // Defined constants
17- #define LED_PIN 6
18- #define NUM_LEDS 33
19- #define ARTNET_PORT 6454
20- #define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed)
21- #define LEDS_PER_UNIVERSE 170
22- #define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3 )
23-
24- // Tracking for smart refresh
7+ #include " main.h"
8+
9+ // Global variable definitions
2510const uint8_t NUM_UNIVERSES = (NUM_LEDS + LEDS_PER_UNIVERSE - 1 ) / LEDS_PER_UNIVERSE ;
2611const uint8_t ALL_UNI_MASK = (1 << NUM_UNIVERSES ) - 1 ;
2712
28-
29- // Static IP and MAC address
3013byte mac[] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
31- IPAddress ip (192 , 168 , 1 , 50 ); // Set your desired static IP here
14+ IPAddress ip (192 , 168 , 1 , 50 );
3215ArtnetEtherReceiver artnet;
3316
34- // / @brief Array to hold the LED data
3517CRGB leds[NUM_LEDS ];
3618uint8_t universesReceived = 0 ;
3719unsigned long lastShowTime = 0 ;
3820const unsigned long MIN_SHOW_INTERVAL = 8 ; // ~125fps max
3921
40- void artnet_callback (
41- const uint8_t *data, uint16_t size,
42- const ArtDmxMetadata &metadata,
43- const ArtNetRemoteInfo &remote
44- ) {
22+ void led_status (String led, bool state) {
23+ #if DEBUG
24+ Serial.print (led);
25+ Serial.print (" LED is now " );
26+ Serial.println (state ? " ON" : " OFF" );
27+ #endif
28+
29+ if (led == " network" ) {
30+ digitalWrite (NETWORK_STATUS_PIN , state ? HIGH : LOW );
31+ } else if (led == " led_write" ) {
32+ digitalWrite (LED_WRITE_STATUS_PIN , state ? HIGH : LOW );
33+ }
34+ }
35+
36+ void artnet_callback ( const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote ) {
4537 uint8_t rel = metadata.universe - START_UNIVERSE ;
4638 if (rel >= NUM_UNIVERSES ) return ;
4739
@@ -62,27 +54,115 @@ void artnet_callback(
6254 Serial.println (universesReceived, HEX );
6355 #endif
6456
65- if (universesReceived == ALL_UNI_MASK &&
66- now - lastShowTime >= MIN_SHOW_INTERVAL ) {
67-
57+ if (universesReceived == ALL_UNI_MASK && now - lastShowTime >= MIN_SHOW_INTERVAL ) {
58+ led_status (" led_write" , true );
6859 FastLED.show ();
6960 lastShowTime = now;
7061 universesReceived = 0 ;
62+ led_status (" led_write" , false );
7163 }
7264}
7365
66+ void led_hello () {
67+ // do a little dance to say hello
68+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
69+ delay (200 );
70+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
71+ delay (200 );
72+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
73+ delay (200 );
74+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
75+ delay (200 );
76+
77+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
78+ delay (200 );
79+ digitalWrite (NETWORK_STATUS_PIN , LOW );
80+ delay (200 );
81+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
82+ delay (200 );
83+ digitalWrite (NETWORK_STATUS_PIN , LOW );
84+ delay (200 );
85+
86+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
87+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
88+ delay (200 );
89+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
90+ digitalWrite (NETWORK_STATUS_PIN , LOW );
91+ delay (200 );
92+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
93+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
94+ delay (200 );
95+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
96+ digitalWrite (NETWORK_STATUS_PIN , LOW );
97+ delay (200 );
98+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
99+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
100+ delay (200 );
101+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
102+ digitalWrite (NETWORK_STATUS_PIN , LOW );
103+ delay (200 );
104+ digitalWrite (LED_WRITE_STATUS_PIN , HIGH );
105+ digitalWrite (NETWORK_STATUS_PIN , HIGH );
106+ delay (200 );
107+ digitalWrite (LED_WRITE_STATUS_PIN , LOW );
108+ digitalWrite (NETWORK_STATUS_PIN , LOW );
109+ delay (200 );
110+ }
111+
112+ void led_oh_shit (int led_pin) {
113+ while (1 ) {
114+ digitalWrite (led_pin, HIGH );
115+ delay (250 );
116+ digitalWrite (led_pin, LOW );
117+ delay (250 );
118+ }
119+ }
74120
75121void init_leds () {
76- FastLED.addLeds <WS2812B , LED_PIN , GRB >(leds, NUM_LEDS );
122+ // initialize FastLED
123+ FastLED.addLeds <WS2812B , WS2812_DATA_PIN , GRB >(leds, NUM_LEDS );
77124 FastLED.setMaxRefreshRate (0 ); // Remove artificial frame rate limit
78125 FastLED.setDither (false );
79126 FastLED.setCorrection (UncorrectedColor);
80127 FastLED.clear ();
81128 FastLED.show ();
129+
130+ // initialize status pins
131+ pinMode (NETWORK_STATUS_PIN , OUTPUT );
132+ pinMode (LED_WRITE_STATUS_PIN , OUTPUT );
133+
134+ led_hello ();
82135}
83136
84137void init_networking () {
85- Ethernet.begin (mac, ip);
138+ if (DHCP ) {
139+ if (Ethernet.begin (mac)) {
140+ // DHCP configured successfully :)
141+ } else {
142+ // shit shit shit shit shit
143+ led_oh_shit (NETWORK_STATUS_PIN );
144+ }
145+ } else {
146+ Ethernet.begin (mac, ip);
147+ }
148+
149+ if (Ethernet.linkStatus () == LinkON) {
150+ led_status (" network" , true );
151+ } else {
152+ led_oh_shit (NETWORK_STATUS_PIN );
153+ }
154+
155+ #if DEBUG
156+ Serial.print (" Ethernet initialized with IP: " );
157+ Serial.println (Ethernet.localIP ());
158+ Serial.print (" Subnet Mask: " );
159+ Serial.println (Ethernet.subnetMask ());
160+ Serial.print (" Gateway IP: " );
161+ Serial.println (Ethernet.gatewayIP ());
162+ Serial.print (" Link Status: " );
163+ Serial.println (Ethernet.linkStatus () == LinkON ? " LinkON" : " LinkOFF" );
164+ #endif
165+
86166 delay (100 );
87167 artnet.begin (ARTNET_PORT );
88168 artnet.subscribeArtDmx (artnet_callback);
@@ -106,5 +186,15 @@ void setup() {
106186}
107187
108188void loop () {
109- artnet.parse ();
189+ if (TEST_MODE ) {
190+ for (int i = 0 ; i < NUM_LEDS ; i++) {
191+ leds[i] = CRGB ::Red;
192+ }
193+
194+ FastLED.show ();
195+ while (1 ); // halt!
196+
197+ } else {
198+ artnet.parse ();
199+ }
110200}
0 commit comments