Browse Source

Get it actually working

main
fluffy 8 months ago
parent
commit
139ff68123
1 changed files with 33 additions and 8 deletions
  1. +33
    -8
      DDRuino.ino

+ 33
- 8
DDRuino.ino View File

@@ -1,5 +1,15 @@
/*@ file DDRunino.ino
*
* Simple Arduino sketch to run a DDR pad as a keyboard
*
* https://git.beesbuzz.biz/fluffy/DDRuino/
*/

#include <Keyboard.h>

// Uncomment this to enable the serial debugger to determine the pin mappings
//#define DEBUG

struct Input {
int pin;
int keyCode;
@@ -7,19 +17,27 @@ struct Input {
};

Input mapping[] = {
{ 1, KEY_RETURN },
{ 2, KEY_ESC },
{ 3, KEY_UP_ARROW },
{ 4, KEY_DOWN_ARROW },
{ 5, KEY_RIGHT_ARROW },
{ 6, KEY_LEFT_ARROW },
{ 4, KEY_RETURN },
{ 5, KEY_ESC },
{ 6, KEY_UP_ARROW },
{ 7, KEY_DOWN_ARROW },
{ 8, KEY_RIGHT_ARROW },
{ 9, KEY_LEFT_ARROW },
};

void setup()
{
Serial.begin(9600);

#ifdef DEBUG
for (int i = 0; i < 12; i++) {
pinMode(i, INPUT_PULLUP);
}
#endif

for (auto i : mapping) {
pinMode(i.pin, INPUT_PULLUP);
i.state = false;
i.state = HIGH;
}

Keyboard.begin();
@@ -27,8 +45,15 @@ void setup()

void loop()
{
#ifdef DEBUG
for (int i = 0; i < 12; i++) {
Serial.print(!digitalRead(i) ? "0123456789abcdef"[i] : ' ');
}
Serial.print('\n');
#endif
for (auto& i : mapping) {
bool val = digitalRead(i.pin);
bool val = !digitalRead(i.pin);
if (val != i.state) {
if (val) {
// TODO debounce


Loading…
Cancel
Save