That is not the smartest way to do it but it will work if you make changes
Let's start with just 2 buttons named button0 and button1
Declare 2 variables named buttonPin0 and buttonPin1 and give them values of 2 and 3 respectively
declare 2 variables named prevButtonState0 and prevButtonState1
use pinMode with INPUT_PULLUP as usual on the 2 button pins
In loop() test for a button press on buttonPin0 and if you find it has been pressed send the keystrokes
copy buttonState to previousButtonState0
test for a button press on buttonPin1 and if you find it has been pressed send the keystrokes
copy buttonState to previousButtonState1
Do you see how the previous states have been saved to separate variables ?
Get that working and we will move on to a much better way of doing it involving arrays which uses less code and is easily expandable to multiple inputs and outputs
I entirely agree and that is what I am working towards but do you think that @benimars is ready for them yet ? You and I may think that an array of structs is an easy solution but I doubt that @benimars would
Let him/her get the clumsy version working and I will lead him/her to a better solution. There is already a hint of it in the variable names that I deliberately suggested.
Did you try? It compiles error free. The object 'Keyboard' is created in keyboard.cpp and declared extern in keyboard.h .
The sketch in #3 contains other errors, but 'Keyboard' is ok.
Also this code can be significantly improved, and a lot can be learned in the process. E.g. store the characters to be transferred in tables, query the buttons by index in a loop and transfer the characters according to the table. Arrays and structs are keyvalues to be learnd
And getting rid of delay is always a good exercise.
@benimars There have been many suggestions for changing your approach, or improving upon the one you have taken..
Meanwhile, you are very close to making your original method work, just multiplied times five.
My suggestion is that you see through to success the simple replication of the original code block that handles one, to write five that handle five, with all the necessary additions as have been outlined.
There is no shame in using literal code when it is what you know how to do. The program will work just fine, and I believe it will help you see all of what might go into ways to do it that more experience coders won't be offended by.
The sheer gratification of getting this to work will be valuable.
And when you scale it up again to, say, 50 buttons, the sheep amount of cutting, pasting and editing that would take will be strong motivation to nake the next small step into programming and investigate some arguably better techniques.
So to @MicroBahner's "step by step" I would add "first things first".
You and I are thinking the same way. Even if there are better ways to do what @benimars wants to do, which there are, the primary objective should be to make the code work. Improvements can come later