Arduino Leonardo(Atmega32u4) - Detecting if USB is connected to a computer?
ADDEN of UDADDR is set if the '32U4 has been assigned a USB address by the host and the firmware wants to enable USB connectivity.

UDADDR &amp; _BV(ADDEN)