NicoHood/HID

Cant figure out what the issue is

Closed this issue · 1 comments

I'm trying to use an encoder to press buttons on a gamepad but cant figure out what the problem is. I was previously using Keyboard.press when the encoder turns, and simply replaced that with Gamepad.press(1); but nothing seems to happen? Any ideas? My code is;

#include "HID-Project.h"
#include <Encoder.h>

Encoder myEnc(2, 3);

void setup() {
  Gamepad.begin();
  
}

long oldPosition  = 0;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {       
    if (newPosition <= oldPosition) {    
    //Keyboard.press('u');
    Gamepad.press(1);
    delay(100);
    //Keyboard.release('u');
    Gamepad.release(1);
  
    
    
    }  
    if (newPosition >= oldPosition) {    
    //Keyboard.press(',');
    Gamepad.press(2);
    delay(100);
    //Keyboard.release(',');
    Gamepad.release(2);
  
  
        }   
  oldPosition = newPosition;
  }
  delay(300);

}

Any ideas on what could be going wrong? I uploaded the example code to the board and that worked fine, but in my code nothing happens, tx LED doesnt illuminate, and gamepad shows nothing is happening.

I guess this has nothing to do with HID Lib. If you use encoder you shouldn't have a delay in the main loop. Its most likely that every time you turn the encoder, your board is in "delay-mode" so the turn can't b recognised.