How to detect USB state changes - suspend/resume in particular?

FeuerSturm

Member
Hi,

is there a callback or function that I can use to keep
track of USB state changes?
I'd need to know when the USB state changes to suspended
and resume to turn off and on attached led strips.

I've looked through the source files but didn't see anything
ready to use, any ideas?

Thanks in advance!
 
I've tried that approach and it is working unreliable for me at most.

I'm using this simple test code:
Code:
unsigned long lastCheck;

void setup()
{
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
	unsigned long currentMillis = millis();
	if(currentMillis - lastCheck >= 1000)
	{
		lastCheck = currentMillis;
		if(!bitRead(USB1_PORTSC1,7))
		{
			digitalWrite(LED_BUILTIN, HIGH);
		} 
		else
		{
			digitalWrite(LED_BUILTIN, LOW);
		}
	}
}

The led does turn on, but randomly turns off for seconds and turns on again.
Am I doing something wrong?

Thanks!
 
Back
Top