Example 02 - ProjectUNION DCC
===================================

Purpose
-------
A small reference project demonstrating the ProjectUNION_DCC library.

Hardware
--------
ESP32 DevKit
SSD1306 OLED 128x64 I2C
Green LED with 330 ohm resistor on GPIO16
Red LED with 330 ohm resistor on GPIO17
Push button between GPIO0 and GND
DCC input with 6N137 on GPIO26

Connections
-----------
OLED SDA      -> GPIO21
OLED SCL      -> GPIO22
Green LED     -> GPIO16
Red LED       -> GPIO17
Button        -> GPIO0 to GND
6N137 output  -> GPIO26

Operation
---------
- Default DCC address: 101
- DCC direction A selects the green LED.
- DCC direction B selects the red LED.
- The DCC address can be changed on the DCC web page.
- Web test buttons simulate both directions without a DCC signal.
- OLED pages show address, signal, last command and LED states.
- Short button press changes OLED page.
- Long button press switches the OLED on or off.

Required libraries
------------------
ProjectUNION Core 0.3.3 or newer
ProjectUNION DCC 0.3.1 or newer
NmraDcc
Adafruit GFX Library
Adafruit SSD1306

Important
---------
GPIO0 is an ESP32 boot strap pin. Do not hold the button while powering on or resetting the ESP32.

The DCC input must be electrically isolated through the 6N137 circuit.


OLED network page
-----------------
Use a short press on the push button to cycle through the OLED pages.
The fourth page shows:

- Current IP address
- DNS / mDNS name: union-dcc-demo.local

Open the web interface using either:

http://union-dcc-demo.local

or the IP address shown on the OLED.


Version 1.2
-----------
The DCC signal indicator now uses changes in the received packet counter.
This fixes a compatibility issue where received packets increased correctly,
but the internal lastPacketMs value was not updated by some NmraDcc versions.

DCC signal status:
- OK: packets have been received within the last 2 seconds.
- Missing: no packet activity has been detected for 2 seconds.


Version 1.3
-----------
The DCC status indicator is now latched:

- Missing: no valid DCC packet has been received since startup.
- OK: at least one valid DCC packet has been received since startup.

Reason:
The packet counter in this example increases mainly when relevant accessory
commands are decoded. It is not a reliable continuous detector of the raw
DCC track signal between commands.
