Arduino GIGA R1 Wifi joy stick button issue ERROR code Compilation error: 'USBJoystick_' does not name a type; did you mean 'SysTick'?

Hello ,and regards to every one in this Forum, and it's my first post here.
i just bought Arduino GIGA R1 Wi-Fi, as I was trying to upgrade from Arduino Micro due to limited inputs, I am new with Arduino , but pushing through, the Reason I bought GiGA as Micro has limited input and I need more, and before I buy it said that it will support HID devices as Keyboard and Joystick, as my UNO will not but when i tried to run same codes from Micro all failed with GIGA R1, what I am looking for is a simple push button on A1 and GRD when pressed trigger joystick Button 1, with micro every thing working good , with GIGA fails even after adding Library.

Does GIGA support HID keyboard and joystick , or any guidance for a working code .

All help appreciated and thank you all

I usually look at the library properties file to see if the board I want to use is supported. But if it compiles, it will probably be ok.
If that doesn't help, post all code in code tags, also post the verbose compiler log in code tags.

thanks for answering back
this is code works with arduino micro

Code works with micro

#include <Joystick.h>

// Create an instance of the Joystick

Joystick_ Joystick;

const int button1Pin = 2; // Button 1

void setup()

{

Serial.begin(9600);

// Initialize the joystick

Joystick.begin();

// Set button pins as input with internal pull-up

pinMode(button1Pin, INPUT_PULLUP);

}

void loop()

{

// Read button states

bool button1State = digitalRead(button1Pin) == LOW; // Active LOW

// Update joystick state

Joystick.setButton(0, button1State); // Button 1

// Print values to the Serial Monitor for debugging

{

// Delay for a short time

delay(100);

}

}

====================================================================
FOR GIGA R1(included the Library )

#include <mbed.h>

#include <USBJoystick.h>

// Create an instance of the USBJoystick

Joystick  Joystick;

const int button1Pin = A1; // Button 1 pin

void setup()

{

// Initialize Serial communication for debugging

Serial.begin(9600);

// Initialize the joystick (Assuming `begin()` initializes the USB connection)

Joystick.begin();

// Set button pins as input with internal pull-up

pinMode(button1Pin, INPUT_PULLUP);

}

void loop()

{

// Read button states (Active LOW)

bool button1State = digitalRead(button1Pin) == LOW;

// Update joystick state

Joystick.setButton(0, button1State); // Button 1 mapped to button index 0

// Print button state to Serial Monitor for debugging

Serial.print("Button 1: ");

Serial.println(button1State ? "Pressed" : "Released");

// Delay for a short time to avoid excessive serial prints

delay(100);

}

ERROR CODE :Compilation error: 'Joystick' does not name a type; did you mean 'SysTick'?

and thanks for the help

Not enough info. See post #2.

Sorry as being new here and need to understand requirement , what more info required , as i mentioned before , a switch on bread board connected to pin A1 and ground when pressed will trigger Logitech USB button 1

Please tell me what more info required.
thank you for Your patience

I went through library all examples under HID is keyboard but none for joy stick.

And as the first code it worked with Arduino micro, not working with Arduino GIGA, trying to find out will it work with joystick buttons before I start Return Process as won't be needed

hello
this is the code trying with

#include <PluggableUSBHID.h>
//#include <USBKeyboard.h>
#include <USBJoystick.h>

USBJoystick_ Joystick;    // Correct instantiation of USBJoystick object
int buttonPin = A1;       // Button pin (can be any pin)

void setup() {
  Joystick.begin();  // Initialize joystick

  Serial.begin(9600);  // Start serial communication
  pinMode(buttonPin, INPUT_PULLUP);  // Button as input with pull-up resistor
}

void loop() {
  // Read button state (button is active LOW)
  int buttonState = digitalRead(buttonPin);

  // Print joystick values (this can be expanded later)
  Serial.print("Button: ");
  Serial.println(buttonState);

  // Send joystick button state to the host
  if (buttonState == LOW) {  // Button pressed (active low)
    Joystick.setButton(0, true);  // Button 0 is pressed
  } else {
    Joystick.setButton(0, false);  // Button 0 is released
  }

  // You can also add joystick axis movement here if needed
  // Example: Sending joystick axes (X, Y) values
  Joystick.setXAxis(512);  // 512 is the middle value for a 10-bit axis
  Joystick.setYAxis(512);  // Adjust as needed for your joystick range

  delay(100);  // Delay for readability and stability
}

what iam getting ERROR Code :slight_smile:
exit status 1

Compilation error: 'USBJoystick_' does not name a type; did you mean 'SysTick'?

I have deleted your other cross-post @hhkcontact2024 .

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi @hhkcontact2024.

You have an error in your code here:

Change it to this:

// Create an instance of the USBJoystick

USBJoystick Joystick;

The "USBJoystick" library does not have a begin function, so remove this code from your sketch.

The library does not have a setButton function. You must instead use its buttons function:

The buttons parameter is a 32-bit integer. Each bit in the integer controls the state of the button at that index. A bit can have a value of 0 or 1. If the bit is 0, then the button state will be set to off. If the bit is 1, then the button state will be on.

For someone not used to working with bitwise operators-,Bitwise%20Operators,-%3C%3C%20(bitshift%20left)), I think the easiest way to use this function will be to write the argument in binary literal notation-,binary%2Dliteral,-is%20the%20character). So if you want to set the state of the first button on, you would pass 0b00000000000000000000000000000001 to Joystick.buttons, and if you wanted to set the state of the button off, you would pass 0b00000000000000000000000000000000:

// Update joystick state
// Button 1 is mapped to button index 0
if(button1State == LOW) {
  Joystick.buttons(0b00000000000000000000000000000000);
} else {
  Joystick.buttons(0b00000000000000000000000000000001);
}

If you later want to make your code a bit more fancy, or if you have applications where the approach I described above is not suitable, you can use the bitWrite function in your code:

https://docs.arduino.cc/language-reference/en/functions/bits-and-bytes/bitWrite/

Or use C++ bitwise operators:

https://docs.arduino.cc/language-reference/#structure:~:text=not%20equal%20to)-,Bitwise%20Operators,-<<%20(bitshift%20left)

The library does not have setXAxis and setYAxis functions. You must instead use its move function: