American truck simulator shifter. HELP NEEDED!

Hi everyone. I have found a arduino sketch for my Arduino Nano but I am an absolute NOOB when it comes to programing. This sketch is for an American truck simulator 18 speed shifter that I built but I keep running in to this error code.

Compilation error: 'Joystick' was not declared in this scope

Like I said, I am a complete noob and if anyone could help, that would be very appreciated!

Here is the entire code


void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  
}

void loop() {
  // put your main code here, to run repeatedly:
    
  //Range Selector Pin 2
  if(digitalRead(2) == LOW)
  {
    Joystick.button(2,1);
  }
  else
  {
    Joystick.button(2,0);
  }

  //Splitter Pin 3
  if(digitalRead(3) == LOW)
  {
    Joystick.button(3,1);
  }
  else
  {
    Joystick.button(3,0);
  }

Sorry, it is NOT the entire code. If you had the entire code, you would not have the error. Go back to where you found the code and find the missing code lines.

Hi @supertrucker7 :raised_back_of_hand:

You are welcome in our comunity :hearts:

The error is due to a misunderstanding of what Joystick is.

If you need to use Joystic you need to declare it in program yourself for example "int N=3;" , or try to check libraries if you use them :white_check_mark: otherwise, it looks like you didn't copy the entire code of the sketch, but rather the top part.

Thank you so much for your help! I'll give it a try

Exactly what model of Nano? Unfortunately, the name "Nano" is now overused and several models with very different specs and capabilities are all called "Nano". Some are capable of doing what you want, and others are not.

this is the full code but I still run into the error? Would the example like "int N=3" go above void setup?


void setup() {
  // put your setup code here, to run once:
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:

  //Range Selector Pin 1
  if(digitalRead(1) == LOW)
  {
    Joystick.button(1,1);
  }
  else
  {
    Joystick.button(1,0);
  }

  //Splitter Pin 2
  if(digitalRead(2) == LOW)
  {
    Joystick.button(2,1);
  }
  else
  {
    Joystick.button(2,0);
  }

  
  //Splitter UK/Easy-Jake Pin 4
  if(digitalRead(4) == LOW)
  {
    Joystick.button(3,1);
  }
  else
  {
    Joystick.button(3,0);
  }

}

These are them https://www.amazon.ca/dp/B0816SGKHH?psc=1&ref=ppx_yo2ov_dt_b_product_details

These are "classic" Nano V3. Unfortunately it will never do what you want.

You need something like a Pro Micro (don't confuse with Pro Mini).

It may be all the code you have, but only because you lost part of it when you copied it. But even if you find the missing part, your Nano can't run it.

Joystick is NOT declared anywhere in your supposed complete program. You seem to be missing some type of library .

The guy I downloaded the sketch from showed it working on a teensy 2.0 but I thought since the Nano's were cheaper that I would give these a go. What joystick library should I use and how would I declare Joystick?

Use the library manager in the IDE and search for "Joystick". It will probably be the first, possibly the only match.

Take a look at the example sketches that get installed with the library to see what is missing from your code.

Then select Nano from the boards menu and click to upload your code. You will get a different error message this time.

?
Even that would have needed the joystick library. Wonder what else is missing?

Motorbikes are typically cheaper than tractors, but I know which one I'd want when ploughing a field

I downloaded the library and I got different codes. All that I need is to have one code to put on several shifters. There is just 2 buttons, which is why I only added the top part of the code thinking it would work, and these buttons are normally open and one normally closed. If you think of a way some other time to fix this delema PLEASE share. Thanks A LOT!

We want to help you further. But the frustrating thing for us is that you seem to be forgetting that we are not there in the room with you and we cannot see your updated code, or the error messages you are now seeing or the circuit you are building. You say you are following our suggestions but we can't tell if you have done them right or even understood what we were suggesting.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.