I can't get ExtremeJoystickTest to compile

Status
Not open for further replies.

philip61

New member
I can't get ExtremeJoystickTest to compile, I may not have placed
sub_desc, usb_desc.c, usb_joystick, usb_joystick.c in the correct W10 folder.


Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"



ExtremeJoystickTest: In function 'void setup()':

ExtremeJoystickTest:24: error: 'Joystick' was not declared in this scope

To make a USB Joystick, use the Tools > USB Type menu

* *Joystick.useManualSend(true);

* *^

ExtremeJoystickTest: In function 'void loop()':

ExtremeJoystickTest:40: error: 'Joystick' was not declared in this scope

To make a USB Joystick, use the Tools > USB Type menu

* *Joystick.X(analogRead(A0) * 64);

* *^

'Joystick' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
/* Complete USB Joystick Example* *Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input

* *You must select Joystick from the "Tools > USB Type" menu

* *Pushbuttons should be connected between the digital pins and ground.
* *Potentiometers should be connected to analog inputs 0 to 5.

* *This example code is in the public domain.
*/

// Configure the number of buttons. *Be careful not
// to use a pin for both a digital button and analog
// axis. *The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 14; *// 16 for Teensy, 32 for Teensy++

void setup() {
* // you can print to the serial monitor while the joystick is active!
* Serial.begin(9600);
* // configure the joystick to manual send mode. *This gives precise
* // control over when the computer receives updates, but it does
* // require you to manually call Joystick.send_now().
* Joystick.useManualSend(true);//**********************************error here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* for (int i=0; i<numButtons; i++) {
* * pinMode(i, INPUT_PULLUP);
* }
* Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;

void loop() {
*
* //Serial.println("test");
*
* // read 6 analog inputs and use them for the joystick axis
* Joystick.X(analogRead(A0) * 64);
* Joystick.Y(analogRead(A1) * 64);
* Joystick.Z(analogRead(A2) * 64);
* Joystick.Xrotate(analogRead(A3) * 64);
* Joystick.Yrotate(analogRead(A4) * 64);
* Joystick.Zrotate(analogRead(A5) * 64);
*
* Joystick.slider(1, analogRead(A6) * 64);
* Joystick.slider(2, analogRead(A7) * 64);
* Joystick.slider(3, analogRead(A8) * 64);
* Joystick.slider(4, analogRead(A9) * 64);
* Joystick.slider(5, analogRead(A10) * 64);
* Joystick.slider(6, analogRead(A11) * 64);
* Joystick.slider(7, analogRead(A12) * 64);
* Joystick.slider(8, analogRead(A13) * 64);

*
* //Joystick.sliderLeft(analogRead(4));
* //Joystick.sliderRight(analogRead(5));
*
* // read digital pins and use them for the buttons
* for (int i=0; i<numButtons; i++) {
* * if (digitalRead(i)) {
* * * // when a pin reads high, the button is not pressed
* * * // the pullup resistor creates the "on" signal
* * * allButtons = 0;
* * } else {
* * * // when a pin reads low, the button is connecting to ground.
* * * allButtons = 1;
* * }
* * Joystick.button(i + 1, allButtons);
* }

* // make the hat switch automatically move in a circle
* angle = angle + 1;
* if (angle >= 360) angle = 0;
* Joystick.hat(1, angle);
* Joystick.hat(2, angle);
* Joystick.hat(3, angle);
* Joystick.hat(4, angle);
*
* // Because setup configured the Joystick manual send,
* // the computer does not see any of the changes yet.
* // This send_now() transmits everything all at once.
* Joystick.send_now();
*
* // check to see if any button changed since last time
* boolean anyChange = false;
* for (int i=0; i<numButtons; i++) {
* * if (allButtons != prevButtons) anyChange = true;
* * prevButtons = allButtons;
* }
*
* // if any button changed, print them to the serial monitor
* if (anyChange) {
* * Serial.print("Buttons: ");
* * for (int i=0; i<numButtons; i++) {
* * * Serial.print(allButtons, DEC);
* * }
* * Serial.println();
* }
*
* // a brief delay, so this runs "only" 200 times per second
* delay(10);
}
 
First, you have to select a Joystick entry from the Tools/USB type menu, not the Serial entry:

tools-usb.png

Second: Joystick.Xrotate and Joystick.Yrotate are not supported for "JOYSTICK_SIZE == 12" as far as I understand C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\usb_joystick.h.

Third: Joystick.slider only takes 1 argument, not 2 arguments.

BTW, here is your code using "CODE" tags:
Code:
/* Complete USB Joystick Example* *Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input

* *You must select Joystick from the "Tools > USB Type" menu

* *Pushbuttons should be connected between the digital pins and ground.
* *Potentiometers should be connected to analog inputs 0 to 5.

* *This example code is in the public domain.
*/

// Configure the number of buttons. *Be careful not
// to use a pin for both a digital button and analog
// axis. *The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 14; // 16 for Teensy, 32 for Teensy++

void setup() {
  // you can print to the serial monitor while the joystick is active!
  Serial.begin(9600);
  // configure the joystick to manual send mode. *This gives precise
  // control over when the computer receives updates, but it does
  // require you to manually call Joystick.send_now().
  Joystick.useManualSend(true);//**********************************error here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!
  for (int i = 0; i < numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
  Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle = 0;

void loop() {

  //Serial.println("test");

  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(analogRead(A0) * 64);
  Joystick.Y(analogRead(A1) * 64);
  Joystick.Z(analogRead(A2) * 64);
  Joystick.Xrotate(analogRead(A3) * 64);
  Joystick.Yrotate(analogRead(A4) * 64);
  Joystick.Zrotate(analogRead(A5) * 64);

  Joystick.slider(1, analogRead(A6) * 64);
  Joystick.slider(2, analogRead(A7) * 64);
  Joystick.slider(3, analogRead(A8) * 64);
  Joystick.slider(4, analogRead(A9) * 64);
  Joystick.slider(5, analogRead(A10) * 64);
  Joystick.slider(6, analogRead(A11) * 64);
  Joystick.slider(7, analogRead(A12) * 64);
  Joystick.slider(8, analogRead(A13) * 64);


  //Joystick.sliderLeft(analogRead(4));
  //Joystick.sliderRight(analogRead(5));

  // read digital pins and use them for the buttons
  for (int i = 0; i < numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }

  // make the hat switch automatically move in a circle
  angle = angle + 1;
  if (angle >= 360) angle = 0;
  Joystick.hat(1, angle);
  Joystick.hat(2, angle);
  Joystick.hat(3, angle);
  Joystick.hat(4, angle);

  // Because setup configured the Joystick manual send,
  // the computer does not see any of the changes yet.
  // This send_now() transmits everything all at once.
  Joystick.send_now();

  // check to see if any button changed since last time
  boolean anyChange = false;
  for (int i = 0; i < numButtons; i++) {
    if (allButtons[i] != prevButtons[i]) anyChange = true;
    prevButtons[i] = allButtons[i];
  }

  // if any button changed, print them to the serial monitor
  if (anyChange) {
    Serial.print("Buttons: ");
    for (int i = 0; i < numButtons; i++) {
      Serial.print(allButtons[i], DEC);
    }
    Serial.println();
  }

  // a brief delay, so this runs "only" 200 times per second
  delay(10);
}

Hope this helps,
Paul
 
Sorry for the long text, I tried to condense it to 2 sliders,only and as I am using the Trustmaster HOTAS (left/right JS), I only want to get 2 sliders working first.

I tried all the tool setup that contain joystick. failed each time.
I don't know where the "JOYSTICK_SIZE == 12" came from
on the 2 arguments, how do you differentiate the 12 sliders?

I reduced the sample code to this and it did not compile:


void setup() {
Joystick.useManualSend(true);
}

void loop() {
Joystick.slider(1, analogRead(A6));
Joystick.slider(2, analogRead(A7));
Joystick.send_now();
delay(10);
}


this did compile:

void setup() {
Joystick.useManualSend(true);
}

void loop() {
Joystick.slider(100);
Joystick.send_now();
delay(10);
}

how would you do 10 sliders?
am I using the correct LIB?
I am not deep C++ coder, so I get one of the Engineers and work to help me this the deep code issues.
Thanks for helping me.
P
 
Hi P,
Sorry, I won't be able to help you a lot since I never played with joysticks.
What I understand sofar is that the default setting is JOYSTICK = 12, set in usb_desc.h, line 699. That setting allows Joystick.slider() to take only 1 argument. And that's why your second piece of code does compile.
Probably best to study this thread for more info.

Regards,
Paul

PS: you may want to embed your code in CODE tags (using the '#' option) for better readability:

Capture.PNG
 
Status
Not open for further replies.
Back
Top