Hey, I was trying to make a DIY handbrake a while back but it never really worked out and yesterday I remembered the project and wanted to finish it. I tried to find code for the Joystick.h library to simulate a joystick button press but I couldn't find anything so I'm here asking for help thanks in advance.
You could try putting bricks under the tires. Did not the joystick library come with example sketches? After you install most libraries, the example sketches are automatically available from the IDE menu.
This kind of reply is not helpful. What happened, or didn't happen? Where did you find the sketch? Also, please edit your post and place the code inside code tags, in accordance with the forum protocol.
the code was uploaded successfully but when I checked if the code was working and if the pc was recognizing the button nothing happened. I found the code in the joystick library under the name "Joystick button"
#include <Joystick.h>
Joystick_ Joystick;
void setup() {
// Initialize Button Pins
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
}
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;
// Last state of the button
int lastButtonState[4] = {0,0,0,0};
void loop() {
// Read pin values
for (int index = 0; index < 4; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(50);
}
(the axis and buttons available can be changed with the Joystick Library).
And from here you can test if the buttons are reporting, and else.
I have used the Joystick library myself and, well, didn't quite like it. It packed a lot of helpful stuff, but I feel like it's overly extraneous for a library that, well, is supposed to be the interface between code (or Arduino) and the computer. Mostly compounded by my own centering and calibrating code (plus some others).
I have been using the task manager and the buttons didn't work(they were always off)
I think that the Joystick library is just unnecacearly complicated therefore im here
i have tested it now as you suggested and the button works as expected with no problems therefore im trying to find out how to write the correct code for the appliance
no, the button doesn't work correctly cause I was responding to Mr Tom and he asked me to test it with the serial monitor and so I did but the joystick part still doesn't work
previously when I was working on another project which involved servos I understood a little more of the joystick library and made new code that worked just as I wanted it to. i found out i needed to make a joystick variable in this example its called joy1