void loop() {
Serial.println("USB Status: ");
while(1) {
if(USB_Status()==0) { Serial.println(" NONE"); }
if(USB_Status()==1) { Serial.println(" USB"); }
if(USB_Status()==2) { Serial.println(" USB + SERIAL"); }
delay(500);
}
}
byte USB_Status() {
// Checks for USB or USB Serial connection
// Returns :
// 0 = No USB data connection
// 1 = USB cable detected
// 2 = USB cable detected + USB Serial detected (for example, Serial Monitor was opened on assigned COM port)
// Note: Only identifies initial USB connection. Will NOT detect if USB is later disconnected.
// Will continue to return TRUE if USB cable is later unplugged
if(!usb_configuration) { return 0; } //usb_configured();
if(!Serial) { return 1; }
return 2;
}