so my keyboard sketch is running pretty "solid" the only thing i miss is that if i press/hold a button, it'll give me just one single stroke.....which is actually pretty good for most of the buttons! only two of the 25 i would like to have a press/hold function.
so i searched a bit an found a pretty good start sketch (IMO). the only thing i'm not sure about is how to modify it to work with my already running sketch.
this is the code i want to implement:
void loop(){
delay(50);
keypadLoop();
}
void keypadLoop() {
// Keypad related
char key = keypad.getKey('o');
KeyState state = keypad.getState('o');
if (state == PRESSED && key != NO_KEY) {
previousPressedKey = key;
hasReleasedKey = false;
Keyboard.print('o');
}
else if (state == RELEASED && !hasReleasedKey) {
// Multiple RELEASED events occur when there had not been HOLD
Keyboard.print('o');
hasReleasedKey = true;
}
else if (state == HOLD) {
Keyboard.print('o');
Keyboard.println(previousPressedKey);
}
}
i know there is more stuff above void loop, that's not the problem to add to my sketch!
can someone tell me if this is the way to add the hold function for just the 'o' key ? or do i need to change more?
the last line of my already existing sketch is:
case 'n':
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
break;
case 'o':
Keyboard.press('o');
delay(100);
Keyboard.releaseAll();
break;
default:
Serial.println(key);
}
}
}
of course not.....must have a mistake there as i was doing this sketch in my 15 min. break at work.
i'll put some leds with the according buttons and some other functions....and IMO that's the easiest way to add them later....i'm really not into getting in to deep with the programming thing, since it's just a small winter project, with that said i might not even use this stuff after my box works as i want it to.
would this work better?
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
switch (key){
case '#': digitalWrite(ledPin,!digitalRead(ledPin)); break;
case '*':
digitalWrite(ledPin,!digitalRead(ledPin));
break;
}
break;
case RELEASED:
switch (key){
case '*':
digitalWrite(ledPin,!digitalRead(ledPin));
blink = false;
break;
}
break;
case HOLD:
switch (key){
case '*': blink = true; break;
}
break;