Author Topic: Custom Gaming keypad  (Read 1183 times)

BaDjinn

  • Newbie
  • *
  • Posts: 2
Custom Gaming keypad
« on: March 20, 2018, 03:57:19 pm »
Hi to everyone!
I'm new of this forum so if i posted in the wrong section please let me know!
Now, my objective is to build a gaming keypad to use it for gaming (of course) and productivity by managing it through any of the various macro programs aviable. But since it's my first attempt i started small: a 5 button keypad, directly wired to the digispark, and using the DigiJoystick library.

The example script gives no problems and windows 10 pro sees the digispark as a joypad.
The problem came when i added the buttons. The code compile but the device it's not acknowledged as a joypad anymore and gives "unknown USB device".  :o

Here my code:
Code: [Select]
#include "DigiJoystick.h"

byte bStateL = 0x00;
byte bStateH = 0x00;

void setup() {
  // put your setup code here, to run once:
  byte bStateL = 0x00;
  byte bStateH = 0x00;
 for (int i =0; i < 5; ++i ){
  pinMode(i, INPUT_PULLUP);
  }
  //DigiJoystick.delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  for (int j=0; j<5; j++){
  byte bVar = readButton(j);
   bStateL |= (bVar<<j); 
  }
  DigiJoystick.setButtons(bStateL, bStateH);
  DigiJoystick.delay(10);
}

byte readButton(int pin){
  if(digitalRead(pin) == HIGH){
    DigiJoystick.delay(10);
    if(digitalRead(pin) == HIGH){
      return 0x01;
    }
  }
  return 0x00;
}

Is it a problem of timing(delay)? I can't find answers anywhere, so i'm asking to you gurus :'(

BaDjinn

  • Newbie
  • *
  • Posts: 2
Re: Custom Gaming keypad
« Reply #1 on: March 22, 2018, 08:51:36 am »
Ok, ok, ok...
After some more troubleshooting i found that not all of the digital pins of the digispark works well with the "INPUT_PULLUP" pinMode. Seems like i'll need some cd4021 after all...