Adafruit LED Backpack Library
Adafruit_LEDBackpack.h
Go to the documentation of this file.
1 
22 #ifndef Adafruit_LEDBackpack_h
23 #define Adafruit_LEDBackpack_h
24 
25 #if (ARDUINO >= 100)
26 #include "Arduino.h"
27 #else
28 #include "WProgram.h"
29 #endif
30 
31 #include <Adafruit_I2CDevice.h>
32 
33 #include "Adafruit_GFX.h"
34 
35 #define LED_ON 1
36 #define LED_OFF 0
37 
38 #define LED_RED 1
39 #define LED_YELLOW 2
40 #define LED_GREEN 3
41 
42 #define HT16K33_BLINK_CMD 0x80
43 #define HT16K33_BLINK_DISPLAYON 0x01
44 #define HT16K33_BLINK_OFF 0
45 #define HT16K33_BLINK_2HZ 1
46 #define HT16K33_BLINK_1HZ 2
47 #define HT16K33_BLINK_HALFHZ 3
48 
49 #define HT16K33_CMD_BRIGHTNESS 0xE0
50 
51 #define SEVENSEG_DIGITS 5
52 
53 /*
54 Segment names for 14-segment alphanumeric displays.
55 See https://learn.adafruit.com/14-segment-alpha-numeric-led-featherwing/usage
56 
57  -------A-------
58  |\ | /|
59  | \ J / |
60  | H | K |
61  F \ | / B
62  | \|/ |
63  |--G1--|--G2--|
64  | /|\ |
65  E / | \ C
66  | L | N |
67  | / M \ |
68  |/ | \|
69  -------D------- DP
70 */
71 
72 #define ALPHANUM_SEG_A 0b0000000000000001
73 #define ALPHANUM_SEG_B 0b0000000000000010
74 #define ALPHANUM_SEG_C 0b0000000000000100
75 #define ALPHANUM_SEG_D 0b0000000000001000
76 #define ALPHANUM_SEG_E 0b0000000000010000
77 #define ALPHANUM_SEG_F 0b0000000000100000
78 #define ALPHANUM_SEG_G1 0b0000000001000000
79 #define ALPHANUM_SEG_G2 0b0000000010000000
80 #define ALPHANUM_SEG_H 0b0000000100000000
81 #define ALPHANUM_SEG_J 0b0000001000000000
82 #define ALPHANUM_SEG_K 0b0000010000000000
83 #define ALPHANUM_SEG_L 0b0000100000000000
84 #define ALPHANUM_SEG_M 0b0001000000000000
85 #define ALPHANUM_SEG_N 0b0010000000000000
86 #define ALPHANUM_SEG_DP 0b0100000000000000
87 
88 
92 public:
97 
106  bool begin(uint8_t _addr = 0x70, TwoWire *theWire = &Wire);
107 
112  void setDisplayState(bool state);
113 
118  void setBrightness(uint8_t b);
119 
128  void blinkRate(uint8_t b);
129 
133  void writeDisplay(void);
134 
138  void clear(void);
139 
140  uint16_t displaybuffer[8];
141 
142 protected:
143  Adafruit_I2CDevice *i2c_dev = NULL;
144 };
145 
150 public:
154  Adafruit_24bargraph(void);
155 
161  void setBar(uint8_t bar, uint8_t color);
162 };
163 
167 class Adafruit_8x16matrix : public Adafruit_LEDBackpack, public Adafruit_GFX {
168 public:
172  Adafruit_8x16matrix(void);
173 
182  void drawPixel(int16_t x, int16_t y, uint16_t color);
183 };
184 
189  public Adafruit_GFX {
190 public:
195 
204  void drawPixel(int16_t x, int16_t y, uint16_t color);
205 };
206 
210 class Adafruit_8x8matrix : public Adafruit_LEDBackpack, public Adafruit_GFX {
211 public:
215  Adafruit_8x8matrix(void);
216 
225  void drawPixel(int16_t x, int16_t y, uint16_t color);
226 };
227 
232  public Adafruit_GFX {
233 public:
238 
247  void drawPixel(int16_t x, int16_t y, uint16_t color);
248 };
249 
250 #define RAW_BITS 0
251 
252 
256 public:
260  Adafruit_7segment(void);
261 
267  size_t write(char c);
268 
275  size_t write(const char *buffer, size_t size);
276 
281  void print(char c);
282 
288  void print(unsigned char b, int base = RAW_BITS);
289 
295  void print(int n, int base = DEC);
296 
302  void print(unsigned int n, int base = DEC);
303 
309  void print(long n, int base = DEC);
310 
316  void print(unsigned long n, int base = DEC);
317 
323  void print(double n, int digits = 2);
324 
329  void print(const String &c);
330 
335  void print(const char c[]);
336 
341  void println(char c);
342 
349  void println(unsigned char b, int base = RAW_BITS);
350 
356  void println(int n, int base = DEC);
357 
363  void println(unsigned int n, int base = DEC);
364 
370  void println(long n, int base = DEC);
371 
377  void println(unsigned long n, int base = DEC);
378 
384  void println(double n, int digits = 2);
385 
390  void println(const String &c);
391 
396  void println(const char c[]);
397 
401  void println(void);
402 
408  void writeDigitRaw(uint8_t x, uint8_t bitmask);
409 
416  void writeDigitNum(uint8_t x, uint8_t num, bool dot = false);
417 
424  void writeDigitAscii(uint8_t x, uint8_t c, bool dot = false);
425 
430  void drawColon(bool state);
431 
438  void printNumber(long n, uint8_t base = 2);
439 
447  void printFloat(double n, uint8_t fracDigits = 2, uint8_t base = DEC);
448 
452  void printError(void);
453 
457  void writeColon(void);
458 
459 private:
460  uint8_t position;
461 };
462 
467 public:
471  Adafruit_AlphaNum4(void);
472 
479  void writeDigitRaw(uint8_t n, uint16_t bitmask);
480 
487  void writeDigitAscii(uint8_t n, uint8_t ascii, bool dot = false);
488 };
489 
490 #endif // Adafruit_LEDBackpack_h
Class for 8x16 pixel single-color mini matrices.
Definition: Adafruit_LEDBackpack.h:188
uint16_t displaybuffer[8]
Raw display data.
Definition: Adafruit_LEDBackpack.h:140
Adafruit_I2CDevice * i2c_dev
Pointer to I2C bus interface.
Definition: Adafruit_LEDBackpack.h:143
Class for 7-segment numeric displays.
Definition: Adafruit_LEDBackpack.h:255
Class for 24-element bargraph displays.
Definition: Adafruit_LEDBackpack.h:149
Class encapsulating the raw HT16K33 controller device.
Definition: Adafruit_LEDBackpack.h:91
void setBrightness(uint8_t b)
Set display brightness.
Definition: Adafruit_LEDBackpack.cpp:280
void clear(void)
Clear display.
Definition: Adafruit_LEDBackpack.cpp:334
void setDisplayState(bool state)
Turn display on or off.
Definition: Adafruit_LEDBackpack.cpp:271
Class for bi-color matrices.
Definition: Adafruit_LEDBackpack.h:231
#define RAW_BITS
Issue 7-segment data as raw bits.
Definition: Adafruit_LEDBackpack.h:250
void blinkRate(uint8_t b)
Set display blink rate.
Definition: Adafruit_LEDBackpack.cpp:287
Class for four-digit alphanumeric displays.
Definition: Adafruit_LEDBackpack.h:466
Adafruit_LEDBackpack(void)
Constructor for HT16K33 devices.
Definition: Adafruit_LEDBackpack.cpp:294
Class for 8x8 pixel single-color matrices.
Definition: Adafruit_LEDBackpack.h:210
void writeDisplay(void)
Issue buffered data in RAM to display.
Definition: Adafruit_LEDBackpack.cpp:321
bool begin(uint8_t _addr=0x70, TwoWire *theWire=&Wire)
Start I2C and initialize display state (blink off, full brightness).
Definition: Adafruit_LEDBackpack.cpp:296
Class for 8x16 pixel single-color matrices.
Definition: Adafruit_LEDBackpack.h:167