I was trying to accomplish the same goal.
A keypad connected to the NanoARM to send shortcuts to the PC.
Here is the code:
Code: Select all
#include <Keypad.h>
#include "HID-Project.h"
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {8, 7, 6, 5};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
while(!SerialUSB);
SerialUSB.begin(9600);
Consumer.begin();
}
void OpenApp(char appAddress)
{
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_ESC);
delay(100);
Keyboard.releaseAll();
Keyboard.write('run');
Keyboard.write(appAddress);
}
void loop(){
char customKey = customKeypad.getKey();
switch (customKey)
{
case '1':
Consumer.write(MEDIA_PREVIOUS);
SerialUSB.println("Button 1 pressed");
break;
case '2':
Consumer.write(MEDIA_PLAY_PAUSE);
SerialUSB.println("Button 2 pressed");
break;
case '3':
Consumer.write(MEDIA_NEXT);
SerialUSB.println("Button 3 pressed");
break;
case 'A':
OpenApp('C:\Program Files (x86)\Steam\Steam.exe');
break;
case '4':
// statements
break;
case '5':
// statements
break;
case '6':
// statements
break;
case 'B':
// statements
break;
case '7':
// statements
break;
case '8':
// statements
break;
case '9':
// statements
break;
case 'C':
// statements
break;
case '*':
// statements
break;
case '0':
// statements
break;
case '#':
// statements
break;
case 'D':
// statements
break;
}
}
I can see the keys being pressed via Serial Monitor but the shortcut is not executed by the PC.
I was wondering if do I need to change the keypad.h and HID-Project.h libraries to use the SerialUSB instead of the Serial function?
Or should I try to use an FTDI module with the NanoARM D0/D1 to provide a new USB to connect to the PC?
Thanks for the help.