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_COLS + (x))
25 
26 typedef void (*TrellisCallback)(keyEvent evt);
27 
28 /**************************************************************************/
33 /**************************************************************************/
35 public:
36  Adafruit_NeoTrellis(uint8_t addr = NEO_TRELLIS_ADDR,
37  TwoWire *i2c_bus = &Wire);
39 
40  bool begin(uint8_t addr = NEO_TRELLIS_ADDR, int8_t flow = -1);
41 
42  void registerCallback(uint8_t key, TrellisCallback (*cb)(keyEvent));
43  void unregisterCallback(uint8_t key);
44 
45  void activateKey(uint8_t key, uint8_t edge, bool enable = true);
46 
47  void read(bool polling = true);
48 
49  seesaw_NeoPixel pixels;
50 
51  friend class Adafruit_MultiTrellis;
52 
54 protected:
55  uint8_t _addr;
56  TrellisCallback (*_callbacks[NEO_TRELLIS_NUM_KEYS])(
57  keyEvent);
58 };
59 
60 /**************************************************************************/
65 /**************************************************************************/
67 public:
68  Adafruit_MultiTrellis(Adafruit_NeoTrellis *trelli, uint8_t rows,
69  uint8_t cols);
71 
72  bool begin();
73 
74  void registerCallback(uint16_t num, TrellisCallback (*cb)(keyEvent));
75  void registerCallback(uint8_t x, uint8_t y, TrellisCallback (*cb)(keyEvent));
76  void unregisterCallback(uint16_t num);
77  void unregisterCallback(uint8_t x, uint8_t y);
78 
79  void activateKey(uint16_t num, uint8_t edge, bool enable = true);
80  void activateKey(uint8_t x, uint8_t y, uint8_t edge, bool enable = true);
81 
82  void setPixelColor(uint8_t x, uint8_t y, uint32_t color);
83  void setPixelColor(uint16_t num, uint32_t color);
84  void show();
85 
86  void read();
87 
88 protected:
89  uint8_t _rows;
90  uint8_t _cols;
93 };
94 
95 #endif
bool begin(uint8_t addr=NEO_TRELLIS_ADDR, int8_t flow=-1)
Begin communication with the RGB trellis.
Definition: Adafruit_NeoTrellis.cpp:29
Adafruit_NeoTrellis(uint8_t addr=NEO_TRELLIS_ADDR, TwoWire *i2c_bus=&Wire)
Class constructor.
Definition: Adafruit_NeoTrellis.cpp:10
uint8_t _rows
the number of trellis boards in the Y direction
Definition: Adafruit_NeoTrellis.h:89
Class that stores state and functions for interacting with multiple neotrellis boards.
Definition: Adafruit_NeoTrellis.h:66
void unregisterCallback(uint8_t key)
unregister a callback on a given key
Definition: Adafruit_NeoTrellis.cpp:62
Class that stores state and functions for interacting with seesaw helper IC.
Definition: Adafruit_seesaw.h:235
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:55
uint8_t _cols
the number of trellis boards in the X direction
Definition: Adafruit_NeoTrellis.h:90
void activateKey(uint8_t key, uint8_t edge, bool enable=true)
activate or deactivate a given key event
Definition: Adafruit_NeoTrellis.cpp:74
void read(bool polling=true)
read all events currently stored in the seesaw fifo and call any callbacks.
Definition: Adafruit_NeoTrellis.cpp:86
Definition: Adafruit_seesaw.h:212
Adafruit_NeoTrellis * _trelli
a multidimensional array of neotrellis objects
Definition: Adafruit_NeoTrellis.h:92
TrellisCallback(* _callbacks[NEO_TRELLIS_NUM_KEYS])(keyEvent)
the array of callback functions
Definition: Adafruit_NeoTrellis.h:56
friend class Adafruit_MultiTrellis
Definition: Adafruit_NeoTrellis.h:51
void registerCallback(uint8_t key, TrellisCallback(*cb)(keyEvent))
register a callback function on the passed key.
Definition: Adafruit_NeoTrellis.cpp:51
seesaw_NeoPixel pixels
the onboard neopixel matrix
Definition: Adafruit_NeoTrellis.h:49