Below is my code

The code doesn't work because have this error:

:NameError: name 'processKey' is not defined

How do I fix this?

  • Please don't post a picture of your code next time. It's much more helpful if you copy and paste it here – Unsigned_Arduino Sep 8 '20 at 13:11

This isn't so much a question related to the Pi but is more of software based problem, so this question might be better suited on Stack Overflow. However, I'll give you a quick explanation here.

Your problem is when the code is compiled the compiler gets to the line keypad.registerKeyPressHander(processKey) and it can't find the the function processKey. The reason is you have defined the function after you try to call it. To fix this just move the function to the top of the program.

A good practice in software development is to define all of your functions at the top of the program and your main code should be located under the functions. This prevents the issue you have encountered where the program can't find the function because it hasn't yet been defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.