MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.1k stars 409 forks source link

Code stopped if I remove the USB #188

Open esportsim opened 3 years ago

esportsim commented 3 years ago

Hi, my simple code stops if I remove the USB from the PC. Why?

include

unsigned long previousMillis = 0; unsigned long currentMillis;

unsigned long serialCurrentMillis; unsigned long serialPreviousMillis; boolean is_working_led_on = true; int led_interval = 200; int working_led = 3;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 128, 0, true, true, false, false, false, false, false, false, false, false, false);

void setup() { pinMode(working_led, OUTPUT); Joystick.begin(); }

void loop() {

// WORKING LED ---------------------------------------------------------------- currentMillis = millis();

if (currentMillis - previousMillis >= led_interval) { previousMillis = currentMillis; if (is_working_led_on) { digitalWrite(working_led, LOW); is_working_led_on = false; } else { digitalWrite(working_led, HIGH); is_working_led_on = true; } }

Joystick.setButton(0, 1);
Joystick.setButton(1, 1);

}

82ndab-Bravo17 commented 3 years ago

Probably because the sketch doesn't receive a response from the computer to the Joystick.setButton statements.