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.06k stars 403 forks source link

Adding this line in setup causes updates to stop #203

Open paulwrath1223 opened 3 years ago

paulwrath1223 commented 3 years ago

Description of Issue

Adding these lines after "serial begin" in setup causes updates to stop, despite "set axis" being executed while (!Serial) delay(10); It is part of the example sketch for the mpu 6050 gyro. joystick INO.zip

Technical Details

IDK I'm a noob

Sketch File that Reproduces Issue

#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 4, 0, false, false, false, false, false, false, false, false, true, true, true); 

void setup() {
  Joystick.setAcceleratorRange(0, 1023);
  Joystick.setBrakeRange(0, 1023);
  Joystick.setSteeringRange(0, 720);
  Serial.begin(115200);
//  while (!Serial)                                                    // GITHUB ISSUE HERE
//    delay(10);                                                       // uncomment those two lines and the joysticks will not move. the rest of the code is hot garbage, but thats my fault.

  Joystick.begin();

}

void loop() 
{

  Joystick.setSteering(10);
  Joystick.setBrake(10);
  Joystick.setAccelerator(10); 

}

Wiring Details

You can test this with just a board

Additional context

this might be really obvious to everyone else, but it seems to me that if the loop is running, (which can be confirmed with a debug print), the lines should be executed regardless of if it waited in setup. I fixed the problem by just waiting 1 second every power up and removing the problem lines.

Pomax commented 1 year ago

Can confirm that this indeed (still) prevents the joystick library from ever actually doing anything, even if the rest of the code runs just fine.