After you have put all the pieves together for your Arduino Keypad Entry System Project, you need to define the setup. In the setup() section of your code, you prepare the Arduino to run this sketch.

Now you set up the Max Display Driver chip. The sendCommand() function toward the bottom of your code is used to make it a bit easier to send instructions to the chip using the SPI interface.

Every time you send an instruction, you have to set the slaveSelect pin to LOW, send the byte corresponding to the command you want to issue to the chip, send the byte with the value for the command, and then set slaveSelect back to HIGH. You don’t want to have to do these steps every time you talk to the Max chip, so the sendCommand() function packages these up nicely:

void sendCommand(int command, unsigned char value)

You merely send the command code you want and its value. For example, command 10 is for brightness. The following sets it to 8 (out of 15):

sendCommand(10, 8);

You set the chip to normal mode, turn off its test feature, set the brightness at medium, and tell it how many digits there are on your display (4). Then you set the chip to decode mode. This means it will automatically decode the byte sent to it and light up the corresponding segments of the LEDs: 0-9, the characters H, E, L, P, a dash, and a blank space.

You now set up the pin controlling your relay that powers the door mechanism. It’s set to output.

You also need to set up the pins that are used for reading the keypad. You use a special technique that takes advantage of “pull-up resistors” that are on your Arduino. These resistors are on the ATmega328 chip itself and can be set to hold a pin HIGH. Later, if it goes LOW for some reason (a keypress), your Arduino can respond appropriately.

You are setting all the rows to be used for input and writing these pins HIGH, which activates the pull-up resistors. All of the columns you’ll use for output. You set these pins HIGH for now, but will change this later on.

The last thing is to clear the display. Sometimes when powering up the system (and especially when uploading code), stray characters appear on the display. The clearDisplay() function at the bottom of your code sets all the digits to be blank:

void clearDisplay(){
 sendCommand(1, '_');
 sendCommand(2, '_');
 sendCommand(3, '_');
 sendCommand(4, '_');