I have been trying to get a button matrix to work but im not experienced enough in programming.
I Have tried to read up but i don't know how to execute so some help would be greatly appreciated.
I want the keypad to function as a game controller of sorts. when i pres the 1 key on the keypad i want the read light to light up and only go out when i release the button. code was copied from "mstanley" on arduino forum.
Q: How do i use the Keypad.h library to get my keypad press to run one line of code when i press a button and another line when i release the button.
I Was testing with leds now, the code is identical, digitalWrite(1, HIGH); then digitalWrite(1, LOW); this can easily get exchanged for joystic.PressButton 1 and Joystick.ReleaseButton 1
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3,2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char holdKey;
unsigned long t_hold;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
char key = keypad.getKey();
if (key){
holdKey = key;
Serial.println(key);
}
if (keypad.getState() == HOLD) {
if ((millis() - t_hold) > 100 ) {
switch (holdKey) {
case '1':
digitalWrite(11, HIGH);
delay(200);
digitalWrite(11, LOW);
break;
case '2':
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12, LOW);
break;
case '3':
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
}
t_hold = millis();
}
}
}

