Go Down

Topic: Due, key mapping trouble (Read 405 times) previous topic - next topic

uitaek91

I bought Due for keyboard(keypad) key mapping. And attached mini keypad to Due, tested 'USBHost' - 'KeyboardController'. But it doesn't working(NumLock LED is ON).
I tried other HID : mini keyboard, mouse, another keypad. Everything is working! Very well.
I don't understand. Why doesn't working, only one keypad? What reason?

+
So... first, i tried key mapping that working keypad. Code is...

Code: [Select]
#include <KeyboardController.h>

USBHost usb;

KeyboardController keyboard(usb);

int pressedKey, releasedKey;
 // Keypad buttons.
boolean SLASH = false, MULTI = false, MINUS = false, PLUS = false, NUM7 = false, NUM8 = false, NUM9 = false, BS = false, NUM4 = false, NUM5 = false, NUM6 = false, TAP = false, NUM1 = false, NUM2 = false, NUM3 = false, NUM0 = false, DOT = false, ENTER = false;

void keyPressed() {
  pressedKey = keyboard.getOemKey();
 
  if (pressedKey == 84) {SLASH = true;}
  if (pressedKey == 85) {MULTI = true;}
  if (pressedKey == 86) {MINUS = true;}
  if (pressedKey == 87) {PLUS = true;}
  if (pressedKey == 36) {NUM7 = true;}
  if (pressedKey == 37) {NUM8 = true;}
  if (pressedKey == 38) {NUM9 = true;}
  if (pressedKey == 42) {BS = true;}
  if (pressedKey == 33) {NUM4 = true;}
  if (pressedKey == 34) {NUM5 = true;}
  if (pressedKey == 35) {NUM6 = true;}
  if (pressedKey == 43) {TAP = true;}
  if (pressedKey == 30) {NUM1 = true;}
  if (pressedKey == 31) {NUM2 = true;}
  if (pressedKey == 32) {NUM3 = true;}
  if (pressedKey == 39) {NUM0 = true;}
  if (pressedKey == 55) {DOT = true;}
  if (pressedKey == 88) {ENTER = true;}
}

void keyReleased() {
  releasedKey = keyboard.getOemKey();
 
  if (releasedKey == 84 && SLASH == true) {SLASH = false;}
  if (releasedKey == 85 && MULTI == true) {MULTI = false;}
  if (releasedKey == 86 && MINUS == true) {MINUS = false;}
  if (releasedKey == 87 && PLUS == true) {PLUS = false;}
  if (releasedKey == 36 && NUM7 == true) {NUM7 = false;}
  if (releasedKey == 37 && NUM8 == true) {NUM8 = false;}
  if (releasedKey == 38 && NUM9 == true) {NUM9 = false;}
  if (releasedKey == 42 && BS == true) {BS = false;}
  if (releasedKey == 33 && NUM4 == true) {NUM4 = false;}
  if (releasedKey == 34 && NUM5 == true) {NUM5 = false;}
  if (releasedKey == 35 && NUM6 == true) {NUM6 = false;}
  if (releasedKey == 43 && TAP == true) {TAP = false;}
  if (releasedKey == 30 && NUM1 == true) {NUM1 = false;}
  if (releasedKey == 31 && NUM2 == true) {NUM2 = false;}
  if (releasedKey == 32 && NUM3 == true) {NUM3 = false;}
  if (releasedKey == 39 && NUM0 == true) {NUM0 = false;}
  if (releasedKey == 55 && DOT == true) {DOT = false;}
  if (releasedKey == 88 && ENTER == true) {ENTER = false;}
}

void setup()
{
  Serial.begin(9600);
  Keyboard.begin();
  Mouse.begin();
}

void loop()
{
  usb.Task();
 
  if (NUM0 == true) {Mouse.press(); Serial.println("MOUSE_LEFT_PRESSED");} else {Mouse.release(); Serial.println("MOUSE_LEFT_RELEASED");} // Only 'Serial.println' worked.
}


I have been make keypad by Leonardo. So i know keyboard, mouse library little. But this time... OMG. What i do? Plz, help me!
(Sorry to baby English level...)

Go Up