Adafruit Library
Adafruit_NeoKey_1x4.h
1 #ifndef _NEOKEY_1X4_H
2 #define _NEOKEY_1X4_H
3 
4 #include "Adafruit_seesaw.h"
5 #include "seesaw_neopixel.h"
6 #include <Arduino.h>
7 
8 #define NEOKEY_1X4_ADDR 0x30
9 
10 #define NEOKEY_1X4_NEOPIN 3
11 #define NEOKEY_1X4_BUTTONA 4
12 #define NEOKEY_1X4_BUTTONB 5
13 #define NEOKEY_1X4_BUTTONC 6
14 #define NEOKEY_1X4_BUTTOND 7
15 #define NEOKEY_1X4_BUTTONMASK ((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7))
16 
17 #define NEOKEY_1X4_ROWS 1
18 #define NEOKEY_1X4_COLS 4
19 #define NEOKEY_1X4_KEYS (NEOKEY_1X4_ROWS * NEOKEY_1X4_COLS)
20 
21 #define NEOKEY_1X4_MAX_CALLBACKS 32
22 
23 /* NEOKEY_1X4_KEY depends on PCB routing */
24 // #define NEOKEY_1X4_KEY(x) (((x) / 4) * 8 + ((x) % 4))
25 #define NEOKEY_1X4_KEY(x) (((x) / 8) * 4 + ((x) % 8))
26 
27 #define NEOKEY_1X4_X(k) ((k) % 4)
28 #define NEOKEY_1X4_Y(k) ((k) / 4)
29 
30 #define NEOKEY_1X4_XY(x, y) ((y)*NEOKEY_1X4_ROWS + (x))
31 
32 typedef void (*NeoKey1x4Callback)(keyEvent evt);
33 
34 /**************************************************************************/
39 /**************************************************************************/
41 public:
42  Adafruit_NeoKey_1x4(uint8_t addr = NEOKEY_1X4_ADDR, TwoWire *i2c_bus = &Wire);
44 
45  bool begin(uint8_t addr = NEOKEY_1X4_ADDR, int8_t flow = -1);
46 
47  void registerCallback(uint8_t key, NeoKey1x4Callback (*cb)(keyEvent));
48  void unregisterCallback(uint8_t key);
49 
50  uint8_t read(void);
51 
52  seesaw_NeoPixel pixels;
53 
54  friend class Adafruit_MultiNeoKey1x4;
55 
57 protected:
58  uint8_t last_buttons = 0;
59  uint8_t _addr;
60  NeoKey1x4Callback (*_callbacks[NEOKEY_1X4_KEYS])(
61  keyEvent);
62 };
63 
64 /**************************************************************************/
69 /**************************************************************************/
71 public:
72  Adafruit_MultiNeoKey1x4(Adafruit_NeoKey_1x4 *neokeys, uint8_t rows,
73  uint8_t cols);
75 
76  bool begin();
77 
78  void registerCallback(uint16_t num, NeoKey1x4Callback (*cb)(keyEvent));
79  void registerCallback(uint8_t x, uint8_t y,
80  NeoKey1x4Callback (*cb)(keyEvent));
81  void unregisterCallback(uint16_t num);
82  void unregisterCallback(uint8_t x, uint8_t y);
83 
84  void setPixelColor(uint8_t x, uint8_t y, uint32_t color);
85  void setPixelColor(uint16_t num, uint32_t color);
86  void show();
87 
88  void read();
89 
90 protected:
91  uint8_t _rows;
92  uint8_t _cols;
94 };
95 
96 #endif
uint8_t _rows
the number of trellis boards in the Y direction
Definition: Adafruit_NeoKey_1x4.h:91
uint8_t _addr
the I2C address of this board
Definition: Adafruit_NeoKey_1x4.h:59
uint8_t last_buttons
The last reading for the buttons.
Definition: Adafruit_NeoKey_1x4.h:58
Class that stores state and functions for interacting with the seesaw NeoKey module.
Definition: Adafruit_NeoKey_1x4.h:40
uint8_t _cols
the number of trellis boards in the X direction
Definition: Adafruit_NeoKey_1x4.h:92
Class that stores state and functions for interacting with seesaw helper IC.
Definition: Adafruit_seesaw.h:234
NeoKey1x4Callback(* _callbacks[NEOKEY_1X4_KEYS])(keyEvent)
the array of callback functions
Definition: Adafruit_NeoKey_1x4.h:60
void unregisterCallback(uint8_t key)
unregister a callback on a given key
Definition: Adafruit_NeoKey_1x4.cpp:67
Definition: Adafruit_seesaw.h:211
Class that stores state and functions for interacting with multiple neotrellis boards.
Definition: Adafruit_NeoKey_1x4.h:70
Adafruit_NeoKey_1x4 * _neokeys
a multidimensional array of neokey objects
Definition: Adafruit_NeoKey_1x4.h:93
friend class Adafruit_MultiNeoKey1x4
Definition: Adafruit_NeoKey_1x4.h:54
bool begin(uint8_t addr=NEOKEY_1X4_ADDR, int8_t flow=-1)
Begin communication with the RGB trellis.
Definition: Adafruit_NeoKey_1x4.cpp:28
seesaw_NeoPixel pixels
the onboard neopixel matrix
Definition: Adafruit_NeoKey_1x4.h:52
Adafruit_NeoKey_1x4(uint8_t addr=NEOKEY_1X4_ADDR, TwoWire *i2c_bus=&Wire)
Class constructor.
Definition: Adafruit_NeoKey_1x4.cpp:10
void registerCallback(uint8_t key, NeoKey1x4Callback(*cb)(keyEvent))
register a callback function on the passed key.
Definition: Adafruit_NeoKey_1x4.cpp:56
uint8_t read(void)
Read key GPIO pins, possibly generating callback events.
Definition: Adafruit_NeoKey_1x4.cpp:77