Adafruit Library
Adafruit_NeoTrellis.h
1 #ifndef _NEO_TRELLIS_H
2 #define _NEO_TRELLIS_H
3 
4 #include "Adafruit_seesaw.h"
5 #include "seesaw_neopixel.h"
6 #include <Arduino.h>
7 
8 #define NEO_TRELLIS_ADDR 0x2E
9 
10 #define NEO_TRELLIS_NEOPIX_PIN 3
11 
12 #define NEO_TRELLIS_NUM_ROWS 4
13 #define NEO_TRELLIS_NUM_COLS 4
14 #define NEO_TRELLIS_NUM_KEYS (NEO_TRELLIS_NUM_ROWS * NEO_TRELLIS_NUM_COLS)
15 
16 #define NEO_TRELLIS_MAX_CALLBACKS 32
17 
18 #define NEO_TRELLIS_KEY(x) (((x) / 4) * 8 + ((x) % 4))
19 #define NEO_TRELLIS_SEESAW_KEY(x) (((x) / 8) * 4 + ((x) % 8))
20 
21 #define NEO_TRELLIS_X(k) ((k) % 4)
22 #define NEO_TRELLIS_Y(k) ((k) / 4)
23 
24 #define NEO_TRELLIS_XY(x, y) ((y)*NEO_TRELLIS_NUM_ROWS + (x))
25 
26 typedef void (*TrellisCallback)(keyEvent evt);
27 
28 /**************************************************************************/
33 /**************************************************************************/
35 public:
36  Adafruit_NeoTrellis(uint8_t addr = NEO_TRELLIS_ADDR);
38 
39  bool begin(uint8_t addr = NEO_TRELLIS_ADDR, int8_t flow = -1);
40 
41  void registerCallback(uint8_t key, TrellisCallback (*cb)(keyEvent));
42  void unregisterCallback(uint8_t key);
43 
44  void activateKey(uint8_t key, uint8_t edge, bool enable = true);
45 
46  void read(bool polling = true);
47 
48  seesaw_NeoPixel pixels;
49 
50  friend class Adafruit_MultiTrellis;
51 
53 protected:
54  uint8_t _addr;
55  TrellisCallback (*_callbacks[NEO_TRELLIS_NUM_KEYS])(
56  keyEvent);
57 };
58 
59 /**************************************************************************/
64 /**************************************************************************/
66 public:
67  Adafruit_MultiTrellis(Adafruit_NeoTrellis *trelli, uint8_t rows,
68  uint8_t cols);
70 
71  bool begin();
72 
73  void registerCallback(uint16_t num, TrellisCallback (*cb)(keyEvent));
74  void registerCallback(uint8_t x, uint8_t y, TrellisCallback (*cb)(keyEvent));
75  void unregisterCallback(uint16_t num);
76  void unregisterCallback(uint8_t x, uint8_t y);
77 
78  void activateKey(uint16_t num, uint8_t edge, bool enable = true);
79  void activateKey(uint8_t x, uint8_t y, uint8_t edge, bool enable = true);
80 
81  void setPixelColor(uint8_t x, uint8_t y, uint32_t color);
82  void setPixelColor(uint16_t num, uint32_t color);
83  void show();
84 
85  void read();
86 
87 protected:
88  uint8_t _rows;
89  uint8_t _cols;
92 };
93 
94 #endif
bool begin(uint8_t addr=NEO_TRELLIS_ADDR, int8_t flow=-1)
Begin communication with the RGB trellis.
Definition: Adafruit_NeoTrellis.cpp:27
uint8_t _rows
the number of trellis boards in the Y direction
Definition: Adafruit_NeoTrellis.h:88
Class that stores state and functions for interacting with multiple neotrellis boards.
Definition: Adafruit_NeoTrellis.h:65
Adafruit_NeoTrellis(uint8_t addr=NEO_TRELLIS_ADDR)
Class constructor.
Definition: Adafruit_NeoTrellis.cpp:9
void unregisterCallback(uint8_t key)
unregister a callback on a given key
Definition: Adafruit_NeoTrellis.cpp:60
Class that stores state and functions for interacting with seesaw helper IC.
Definition: Adafruit_seesaw.h:220
Class that stores state and functions for interacting with the seesaw keypad module.
Definition: Adafruit_NeoTrellis.h:34
uint8_t _addr
the I2C address of this board
Definition: Adafruit_NeoTrellis.h:54
uint8_t _cols
the number of trellis boards in the X direction
Definition: Adafruit_NeoTrellis.h:89
void activateKey(uint8_t key, uint8_t edge, bool enable=true)
activate or deactivate a given key event
Definition: Adafruit_NeoTrellis.cpp:72
void read(bool polling=true)
read all events currently stored in the seesaw fifo and call any callbacks.
Definition: Adafruit_NeoTrellis.cpp:84
Definition: Adafruit_seesaw.h:197
Adafruit_NeoTrellis * _trelli
a multidimensional array of neotrellis objects
Definition: Adafruit_NeoTrellis.h:91
TrellisCallback(* _callbacks[NEO_TRELLIS_NUM_KEYS])(keyEvent)
the array of callback functions
Definition: Adafruit_NeoTrellis.h:55
friend class Adafruit_MultiTrellis
Definition: Adafruit_NeoTrellis.h:50
void registerCallback(uint8_t key, TrellisCallback(*cb)(keyEvent))
register a callback function on the passed key.
Definition: Adafruit_NeoTrellis.cpp:49
seesaw_NeoPixel pixels
the onboard neopixel matrix
Definition: Adafruit_NeoTrellis.h:48