This library provides a single class Keypad, which represents an array of Open Airbus Cockpit Keypad Expansion cards.

Open Airbus Cockpit Keypad Expansion Cards comprises two MM74C922 controllers, each one handling 16 keys. These controllers are connected in a common 4-bits data bus with independent control lines. Each card have up-link connectors for data bus and power line, which makes possible to chain several cards sharing the same data bus. The control line comprises two connections: DAV (Data Available), which is HIGH when the controller wants to send data, and OE (Output Enabled), which is LOW when the Arduino board authorizes the controller to use the bus.

The complexity of the array this array of expansion cards is hidden by this class. The user code only have to deal with the following primitives.

  • Bus configuration. Using configBus() function, the user indicates what pins correspond to the shared data bus.
  • Controller configuration. For each connected controller, the user indicates what pins correspond to the DAV and the OE signals using the configController() function.
  • Read key. Using readKey() function, the user code can interrogate what’s the currenty pressed key.
  • Read key type. Using readKeyType() function, the user code can interrogate what’s the last key type (key pressed and then released).

The following example shows how to use this library to manage a Keypad Expansion card.

Important note: the keys are numbered in consecutive ranges respect the index of its controller. I.e., CONTROLLER_0 keys goes from 0 to 15, CONTROLLER_1 goes from 16 to 31, and so.

#include <oackb.h>

#define BUS_A_PIN 2
#define BUS_B_PIN 3
#define BUS_C_PIN 4
#define BUS_D_PIN 5

#define CARD0_DAV_PIN 6
#define CARD0_OE_PIN 7
#define CARD1_DAV_PIN 8
#define CARD1_OE_PIN 9

OAC::Keypad keys;

void setup() {
  keys.configBus(BUS_A_PIN, BUS_B_PIN, BUS_C_PIN, BUS_D_PIN);
  keys.configController(OAC::Keypad::CONTROLLER_0, CARD0_DAV_PIN, CARD0_OE_PIN);
  keys.configController(OAC::Keypad::CONTROLLER_1, CARD1_DAV_PIN, CARD1_OE_PIN);
}

In this fragment, we have declared some constants for our pins and the Keypad object we will use. In setup() function we configure the pins of the card. configBus() method sets the pins used by the common data bus (from A to D). configController method may be used to configure the DAV and OE pins of each controller. In this example we are gonna use a single card with two controllers (up to 32 keys).

Now we can use the card in our setup() function as follows:

void loop() {
  short key = keys.readKey();
  switch (key) {
    case 0:
      // Action while key 0 is pressed
      break;
    case 1:
      // Action while key 1 is pressed
      break;
    // And so on...
  }
}

The readKey() function reads the status of the keypad and returns the key that is pressed, or -1 if none. The returned value is the key number that is pressed in that moment. Then we can use that value to execute some action.

Nevertheless, this is not what we usually want. Since loop() is executed continuously, the action associated with each key will be executed continuously while the key is pressed. We use to be interested in key typing: the process of pressing and then releasing the key. Fortunately, this library provides a convenience function for that:

void loop() {
  short key = keys.readKeyType();
  switch (key) {
    case 0:
      // Action when key 0 is typed
      break;
    case 1:
      // Action when key 1 is typed
      break;
    // And so on...
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *