Keypad library works with Photon, but not Electron

Hi All,

I’ve got a 4x4 Matrix keypad that I’d like to use with my Electron but I’ve been getting a compile error even with the example sketch. If I swap the device I’m compiling for to a Photon there is no error.

The error is in Application.h related to usb keyboard

In file included from ../wiring/inc/spark_wiring_usbkeyboard.h:33:0,
                 from ./inc/application.h:47,
                 from Keypad/Key.h:35,
                 from Keypad/Key.cpp:30:
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected identifier before '=' token
   KEY_H                  = 0x0B,     // Keyboard h and H

../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected '}' before '=' token
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:15:26: error: expected unqualified-id before '=' token
../wiring/inc/spark_wiring_usbkeyboard_scancode.h:394:1: error: expected declaration before '}' token
 } UsbKeyboardScanCode;

make[1]: *** [../build/target/user/platform-10Keypad/Key.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

My issue is that I’m not exactly certain how to move past this? I tried to fork the library and remove application.h include to see what would happen but then I get undeclared types for the struct that includes “byte”, among many other errors. Using the SPARK_NO_PREPROCESSOR line doesn’t change anything.

Has anyone been able to get this working? I’d love to be able to just plug in a library with built in debounce, etc and not have to write my own.


What system firmware version are you compiling against? Are you compiling locally or using the WebIDE/Build/Dev?

Hi harrisonhjones,

I’m building against 0.6.0 for the Electron and I’m using whatever you call (WebIDE?).

For the moment I’ve worked around it by writing my own keypad reading functions, debouncer and latch; I’ll look at contributing to the community library later when I clean it up.


1 Like

I had a few minutes and took another look–

It seems like the Keypad library is conflicting with the Electron library–probably due to the the fact that the Electron can become an HID keyboard maybe?

In any case if I pull the Keypad library and rename every instance of “Key” to “MyKey” (case sensitive!) and update the KEY_H and KEYPAD_H def’s to be MYKEY_H and MYKEYPAD_H then everything is OK on the Electron, and my guess is OK on the Photon too.

I’ll probably submit a change/bug to the original Keypad author’s github requesting the renaming to stop the conflict, but in the meantime any users who run into the same issue can work this out by either forking the community Keypad library and renaming it, or simply create/copy the contents of Key.h, Key.cpp, Keypad.h, Keypad.cpp over to your own sketch and rename all the instances of Key to MyKey (including filenames) and the header guard defs (the caps ones listed above).

I’ll probably keep using the hacky polling code that I put together this morning because I wanted to latch and prevent repeating keys (it’s for an alarm panel) and it has been working so far today, so why change it :wink: