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.
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 otherwise, it looks like you didn't copy the entire code of the sketch, but rather the top part.
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.
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.
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?
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.