I would like to make a button that is programmed to do a series of inputs when pressed, like this:
1, Turn a joystick 180°
2, Press a button
3, Press another button
4, Turn the joystick again
So like I am doing these inputs but with only 1 button press.
Is it possible somehow?
i will assume that you are using an IC with a native USB like the MEGA32U4 with a proper software loaded to be detected as a HID (human interface device) which is basically a joystick or keyboard or mouse. right?
if your IC doesn't have the native USB you cant program it do do macros trough the virtual serial COM port, or at least you could but you'll need some kind of software on the PC to open the port and wait for a command, and then execute a series of virtual button presses directly on the PC....
much easier to make it use a button like F9 instead of an external input
EDIT: if you are just after a macro, windows offers for his mouses and keyboards, trough their program "manage windows mouse and keyboard" (or something like that) to create macros for some button presses.
also your "turn joystick 180°" is vague and difficult to make.
also there are other "cheating" programs online to generate macros for games and the likes.
I am using a leonardo, so it has a built in HID. I want to make fake signal(s) for the PC and I have to make it in the hardware not in an external software. By fake I mean a signal that will say I am pressing multiple buttons and making position changes on the joystick while I am doing nothing just pressing that programmed button once. Also, I don't want to cheat in games (although it is for games), it is a personal project
ok so, the leonardo has the MEGA32U4 i mentioned before, and it doesn't "have the HID built in", you have to program it youself, now i'm not very well versed in arduino IDE but i can almost assure you that there are numerous examples and libraries to make the board act as a joystick.
what you have to do in your case is simply something like this
while(! button_pressed); //wait for button press
macro(); //do macro
while(button_pressed); //wait for button release to avoid double macro
the thing is that you have to find a library for the leonardo that can emulate those actions.
Sorry for the bad explanation. I wanted to say I'm using a leonardo and already made the communication between the borad and the PC, it registers every input nicely so I'm already have 'my controller'. But thank you for the link.
However, I don't understand that 3 row of code, can you explain it? Where I have to put it, what should I do with the input, what is it doing exactly?
I am curious why would you want to do it. Not sure if understand you correctly, but you could have different variables that could normally contain the 'states' you want to control from their default sources (the joysticks, buttons, etc.) and your 'super button' would have the authority to affect them in your code.
the pseudo-code i wrote was intended for a "single button joystick", because it waits for the one and only button present on the joystick, i guess that in your case you want a fully functional joystick with added buttons for macro functions, right?
the code is more complex in your case, because i don't know what type of inputs are we dealing with... are they interrupt based or polling based?
do you have a routine that loads all the button presses and another that sends the commands to the pc? or do you have an empty while(1); in you main code and the button presses are detected by external interrupts?
in either of this cases you just need to add a functions that reads the state of your macro button, and instead of just sending a single button press, it calls a function that executes timed events, like:
set joystick full left
wait 2 sec
set joystick dead center
press button A
release button A
press button B
release button B
set joystick full right
wait 2 sec
set joystick dead center
the thing is.... without knowing what type of code we are dealing with i cannot help you more than by giving you a general idea.
also you strike me like you dont know what is going on exactly inside you code, hence why you dont know where and how to add a macro button