added hold button for new key
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
Convert DDR control panel to buttons.
|
||||
DDR control panel uses a JST YLR-12V connector
|
||||
Pins 1-6 are used for buttons, pin 7 and 8 are GRD
|
||||
Hold down L1+R1+S1 for 5 seconds (hold_time) for different key
|
||||
|
||||
Button to keyboard mappings
|
||||
Left 1 : A
|
||||
@@ -11,6 +12,8 @@ Right 1 : D
|
||||
Right 2 : L
|
||||
Start 1 : S
|
||||
Start 2 : K
|
||||
L1+R1+S1 (hold_time) : Q
|
||||
L2+R2+S2 (hold_time) : P
|
||||
|
||||
*/
|
||||
|
||||
@@ -22,6 +25,11 @@ Start 2 : K
|
||||
#define BT_S1 5
|
||||
#define BT_S2 6
|
||||
|
||||
// Timer preperation for ESC (back)
|
||||
bool L1_held = false, L2_held = false, R1_held = false, R2_held = false, S1_held = false, S2_held = false, E1_held = false, E2_held = false;
|
||||
bool P1_held = false, P2_held = false;
|
||||
unsigned long P1_time = 0, P2_time = 0;
|
||||
const long hold_time = 5000; // how long to hold for
|
||||
|
||||
#include <Keyboard.h>
|
||||
|
||||
@@ -51,55 +59,152 @@ void loop()
|
||||
// Check button inputs
|
||||
if(digitalRead(BT_L1) == LOW)
|
||||
{
|
||||
Keyboard.press('a');
|
||||
if(!E1_held) // make sure we're not trying to use back
|
||||
{
|
||||
Keyboard.press('a');
|
||||
L1_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('a');
|
||||
L1_held = false;
|
||||
}
|
||||
|
||||
if(digitalRead(BT_L2) == LOW)
|
||||
{
|
||||
Keyboard.press('j');
|
||||
if(!E2_held)
|
||||
{
|
||||
Keyboard.press('j');
|
||||
L2_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('j');
|
||||
L2_held = false;
|
||||
}
|
||||
|
||||
if(digitalRead(BT_R1) == LOW)
|
||||
{
|
||||
Keyboard.press('d');
|
||||
if(!E1_held)
|
||||
{
|
||||
Keyboard.press('d');
|
||||
R1_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('d');
|
||||
R1_held = false;
|
||||
}
|
||||
|
||||
if(digitalRead(BT_R2) == LOW)
|
||||
{
|
||||
Keyboard.press('l');
|
||||
if(!E2_held)
|
||||
{
|
||||
Keyboard.press('l');
|
||||
R2_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('l');
|
||||
R2_held = false;
|
||||
}
|
||||
|
||||
if(digitalRead(BT_S1) == LOW)
|
||||
{
|
||||
Keyboard.press('s');
|
||||
if(!E1_held)
|
||||
{
|
||||
Keyboard.press('s');
|
||||
S1_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('s');
|
||||
S1_held = false;
|
||||
}
|
||||
|
||||
if(digitalRead(BT_S2) == LOW)
|
||||
{
|
||||
Keyboard.press('k');
|
||||
if(!E2_held)
|
||||
{
|
||||
Keyboard.press('k');
|
||||
S2_held = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('k');
|
||||
S2_held = false;
|
||||
}
|
||||
|
||||
// check hold status to determine ESC keys
|
||||
if(!L1_held || !R1_held || !S1_held)
|
||||
{
|
||||
E1_held = false;
|
||||
P1_held = false;
|
||||
P1_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine time held
|
||||
if(!P1_held)
|
||||
{
|
||||
P1_held = true;
|
||||
P1_time = millis(); // start timer
|
||||
}
|
||||
else
|
||||
{
|
||||
if(millis() - P1_time >= hold_time)
|
||||
{
|
||||
E1_held = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!L2_held || !R2_held || !S2_held)
|
||||
{
|
||||
E2_held = false;
|
||||
P2_held = false;
|
||||
P2_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine time held
|
||||
if(!P2_held)
|
||||
{
|
||||
P2_held = true;
|
||||
P2_time = millis(); // start timer
|
||||
}
|
||||
else
|
||||
{
|
||||
if(millis() - P2_time >= hold_time)
|
||||
{
|
||||
E2_held = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ESC (back) keys
|
||||
if(E1_held)
|
||||
{
|
||||
Keyboard.press('q');
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('q');
|
||||
}
|
||||
|
||||
if(E2_held)
|
||||
{
|
||||
Keyboard.press('p');
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.release('p');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user