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!