Arduino joystick doesnt work

hello i am writing here because my head is about to explode. i donwload the library from the youtube Video but i get the error joystick. h no such file or directory even if i install it. i use hall sensor ky 035 arduino pro Micro Windows 10 x64. when i use the hallsensor code to get a signal works fine. Has anyone the same problem? i double checked the writing over 40 times before i post here. why doesnt recognize the library? and at some point i tried to open the Analog_ebrake folder first it said it didnt find the library and on the next line said multible libraries joystick.h (my nerves are getting worse after that hahaha)

What library?

Where? - can we see your code?

You need to provide more information... or your head is doomed.

goodmorning here are what i use.
1)that's the one that works

int hallSensorPin = A0;
int hallSensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(hallSensorPin,INPUT) ;
}
void loop (){
hallSensorValue = digitalRead(hallSensorPin);
Serial.print("hallSensorValue: ");
Serial.println(hallSensorValue);
}

with this one i get 1 when the magnet is away from the hallsensor 0 when i get the magnet close to the hall sensor

2)here is the error
#include <Joystick.h>




void setup()

{pinMode(A0, INPUT);
Joystick.begin();}

const int pinToButtonMap = A0;

void loop()

{int pot = analogRead(A0);
int mapped = map(pot,0,1023,0,255);
{Joystick.setThrottle(mapped);}}

on this one i get the error joystick.h no such file or directory.

the joystick library inside has this code
*
Joystick.h

Copyright (c) 2015, Matthew Heironimus

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/



#ifndef JOYSTICK_h
#define JOYSTICK_h

#include "HID.h"

#if ARDUINO < 10606
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
#endif

#if !defined(USBCON)
#error The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
#endif

#if !defined(_USING_HID)

#warning "Using legacy HID core (non pluggable)"

#else

//================================================================================
//================================================================================
//  Joystick (Gamepad)

class Joystick_
{
private:
	bool     autoSendState;
	int8_t	 xAxis;
	int8_t	 yAxis;
	int8_t	 zAxis;
	int16_t	 xAxisRotation;
	int16_t	 yAxisRotation;
	int16_t	 zAxisRotation;
	uint32_t buttons;
	uint8_t  throttle;
	uint8_t  rudder;
	int16_t	 hatSwitch[2];

public:
	Joystick_();

	void begin(bool initAutoSendState = true);
	void end();

	void setXAxis(int8_t value);
	void setYAxis(int8_t value);
	void setZAxis(int8_t value);

	void setXAxisRotation(int16_t value);
	void setYAxisRotation(int16_t value);
	void setZAxisRotation(int16_t value);

	void setButton(uint8_t button, uint8_t value);
	void pressButton(uint8_t button);
	void releaseButton(uint8_t button);

	void setThrottle(uint8_t value);
	void setRudder(uint8_t value);

	void setHatSwitch(int8_t hatSwitch, int16_t value);

	void sendState();
};
extern Joystick_ Joystick;

#endif
#endif

Please post the full error message.

Please remember to use code tags when posting code

1 Like

Hi, @thatgamingchannelyoutube
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

1 Like

C:\Users\thodw\OneDrive\Desktop\Analog-E-Brake-master\Analog-E-Brake-master\ANALOG_EBRAKE\ANALOG_EBRAKE.ino:8:10: fatal error: Joystick.h: No such file or directory
#include <Joystick.h>
^~~~~~~~~~~~
compilation terminated.
Compilation error: exit status 1}

That's what i get , and i copied the joystick.h into libraries


the second include was by accident i tried it with one include only.
my arduino is the pro micro but how the ide recognizes it correctly?
Since the hallSensorPin works what do i do wrong?

Hi,
To add code please click this link;

Tom... :grinning: :+1: :coffee: :australia:

ok i made it work. but it works reverse. i copied the code from the joystick.h library i put it on arduino IDE and works. now i have this last problem. When the handbrake is released is like i am pressing it, and when i press it goes to 0. has to do from where it begins?? how i fix that?

Simple arithmetic.
(Hint: post your code)

void setup()

{
  pinMode(A0, INPUT);
  Joystick.begin();
}



void loop()

{
  int pot = analogRead(A0);
  int mapped = map(pot, 0, 1023, 0, 255);
  { Joystick.setThrottle(mapped); }
}

what values should i use? i tried 0 , 1023, 0, 255) but i had to invert the input on assetto corsa to work corectly. i mean it shows 1when the magnet is not close, 0 when magnet is close to hallsensor. it works upside down let's say

void setup()
{
  Joystick.begin();
}

void loop()
{
  int pot = analogRead(A0);
  int mapped = 255 - (pot / 4);
  Joystick.setThrottle(mapped); 
}

Simple. Arithmetic.

works perfect!!! thanks a lot!!!

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