Hi I'm new here, sry if I'm doing something wrong.
What I have: Arduino Pro Micro, a 5x5 button matrix (with diodes and pullup).
Question:
I want to achieve the following: when you press the button 19, the arduino should send 2 keystrokes after each other, so that the pc sees it like I'm pressing the button twice in a row.
Code explanation:
So I wrote a scan function that basically scans the matrix, debounces it and then stores all the buttonstates in an array(it's called "bs"). I tried to set the variable "button" to high whenever the button is pressed and then after 1 second it sets the variable to high again. But all I get is a constant low on the serial monitor. If the problem is easy to fix I'm sorry to waste your time, but I'm just really bad at programming.
unsigned long storedtime;
int button;
int buttonstate;
void loop() {
scan(); //the scan function that puts the buttonstates into the array "bs"
buttonstate=bs[19]; //a random pushbutton for testing
if(buttonstate==HIGH){ //if pressed set button to 1
button=1;
storedtime=millis();
}
if(button==0 && millis()-storedtime>1000){ //after 1 sec, it will set button to 1 again
button=1;
}
Serial.print(button);
button=0;
}