USB Power Detection with WatchX

The code snippet below detects Power on the USB Port of WatchX.
An data connection to an computer is not needed.

Put in Setup:  
USBCON|=(1<<OTGPADE);  //enables VBUS pad

Use in Loop:  
if(USBSTA&(1<<VBUS)) {Code on USB Power is on}
or
bool usbConnected = (USBSTA&(1<<VBUS));
1 Like