I am attempting to use an arduino leonardo to send keyboard inputs for gaming. For example, when I bend one of the flex sensors more than a certain limit, the arduino then uses the "Keyboard.press('w')" command to send the letter 'w' as an input. this has worked perfectly for 1 sensor, but when I try to read 2 at once, it doesn't recognize the second one and does nothing.
this is the code that i used
#include <Keyboard.h>
void setup()
{
pinMode(A0, INPUT);
pinMode(A1, INPUT);
Keyboard.begin();
}
void loop()
{
while (analogRead(A0) < 150){
Keyboard.press('w');
delay(10);
}
while (analogRead(A0) > 150) {
Keyboard.release('w');
}
while (analogRead(A1) < 150) {
Keyboard.press('e');
delay(10);
}
while (analogRead(A1) > 150) {
Keyboard.release('e');
}
}
I then found out that you can not use both inputs at the same time and that they have to be delayed in order for it to read only one pin at a time, so my final question is: how do i implement this delay in the code?