I've an Arduino micro, and I want to send a command to my pc of a key pressed by a %. To make the character of a generic game move at a % of his total speed (i want it to work with every key, like 'K' for example), how can I do it?
EXAMPLE:
Send the key 'A' with a 50% intensity
Send the key 'C' with a 25% intensity
Using potentiometers will certainly give you analogue signals but I can't imagine how you think this would work in practice. Please describe your vision in more detail
No, that's not what I'm suggesting. I'm trying to say that a single potentiometer is related to a single key on the keyboard, but it can send the command (for example 'a') with different intensities.
If the potentiometer gives a reading value of 10% the 'a' command will be sent at 10% intensity, resulting in the character of a generic game moving at 10% speed at left, but if the reading increases at 70% (for example) the character will then move at 70% speed, etc...
Please specify the encoding of such a command. The Serial port only can send characters, so the percentage has to be encoded somehow. It's up to you to find out how the pot value is converted into text and appended to the command.
So you will send a character code for "A", then a number?
Is one way to interpret your words. There is no such thing as sending a more or less intense character, like how hard you mash the key down or something.
Are you perhaps looking to send a character repeatedly, at a rate determined by a corresponding potentiometer?
i tried to implement a PWM way to send the 'a' command to my pc, but it isn't working (i've tried different duty cicles lenghts but none of them worked)
i used the Keyboard library with a function that (for example when the reading of the potentiometer is at 50%) it execute the function Keyboard.press('a') for 50 micros, and then the function Keyboard.release('a') for the remaining 50 micros (for a cycle duration of 100 micros).
As I already told, I don't know how to send and make the computer understend the format of the command sent, so I can't confirm it
How does this happen if you are just sending 'A's with whatever means you have, like by keyboard, no programming involved?
You speak of a generic game, please instead tell us about a real game, one that receives characters to make something go, and how that works.
Without knowing how the "generic game" interprets keystrokes, there's no way to help you.
Could it be… it moves as long as you hold the key down? Is that because the key went down, and never up, or because the keyboard is auto-repeating the character.
Or does it move with each 'A', and sending them periodically at an adjustable rate is what you think might work?