Writing the driver
As we want to have reusable code, we are going to write a driver package for the keypad. The driver will provide an easy-to-use interface while hiding the more complicated implementation logic. Doing it this way, we can simply reuse the package in later projects even beyond the book. The official TinyGo drivers typically provide a constructor-like function that creates a new instance of the driver and a Configure
function that takes care of initialization. We are also going to provide a similar API.
Just like in our previous projects, we are going to start by creating a new folder named controlling-keypad
inside the Chapter03
folder. Then, we are going to create a main.go
file with an empty main
function. Also, we need to create a new folder named keypad
and create a new file named driver.go
, and then name the package keypad
. Your project structure should now look like the following: