NetBurner 3.5.6
PDF Version
AlphaDisplay/src/SparkFun_Alphanumeric_Display.h
1/******************************************************************************
2SparkFun_Alphanumeric_Display.h
3SparkFun Alphanumeric Display Library Header File
4Priyanka Makin @ SparkFun Electronics
5Original Creation Date: July 25, 2019
6https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library
7
8Updated April 30, 2020 by Gaston Williams to add defineChar function
9
10Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391
11
12This file prototypes the HT16K33 class, implemented in SparkFun_Alphanumeric_Display.cpp.
13
14Development environment specifics:
15 IDE: Arduino 1.8.9
16 Hardware Platform: Arduino Uno
17 Alphanumeric Display Breakout Version: 1.0.0
18
19This code is beerware; if you see me (or any other SparkFun employee) at the
20local, and you've found our code helpful, please buy us a round!
21
22Distributed as-is; no warranty is given.
23******************************************************************************/
24#ifndef __SparkFun_Alphanumeric_Display_H__
25#define __SparkFun_Alphanumeric_Display_H__
26
27#include "Arduino.h"
28#include <Wire.h>
29#include <stdio.h>
30#include <stdlib.h>
31
32#define DEFAULT_ADDRESS 0x70 // Default I2C address when A0, A1 are floating
33#define DEFAULT_NOTHING_ATTACHED 0xFF
34
35// Define constants for segment bits
36#define SEG_A 0x0001
37#define SEG_B 0x0002
38#define SEG_C 0x0004
39#define SEG_D 0x0008
40#define SEG_E 0x0010
41#define SEG_F 0x0020
42#define SEG_G 0x0040
43#define SEG_H 0x0080
44#define SEG_I 0x0100
45#define SEG_J 0x0200
46#define SEG_K 0x0400
47#define SEG_L 0x0800
48#define SEG_M 0x1000
49#define SEG_N 0x2000
50
51
52typedef enum
53{
54 ALPHA_BLINK_RATE_NOBLINK = 0b00,
55 ALPHA_BLINK_RATE_2HZ = 0b01,
56 ALPHA_BLINK_RATE_1HZ = 0b10,
57 ALPHA_BLINK_RATE_0_5HZ = 0b11,
58} alpha_blink_rate_t;
59
60typedef enum
61{
62 ALPHA_DISPLAY_ON = 0b1,
63 ALPHA_DISPLAY_OFF = 0b0,
64} alpha_display_t;
65
66typedef enum
67{
68 ALPHA_DECIMAL_ON = 0b1,
69 ALPHA_DECIMAL_OFF = 0b0,
70} alpha_decimal_t;
71
72typedef enum
73{
74 ALPHA_COLON_ON = 0b1,
75 ALPHA_COLON_OFF = 0b0,
76} alpha_colon_t;
77
78typedef enum
79{
80 ALPHA_CMD_SYSTEM_SETUP = 0b00100000,
81 ALPHA_CMD_DISPLAY_SETUP = 0b10000000,
82 ALPHA_CMD_DIMMING_SETUP = 0b11100000,
83} alpha_command_t;
84
85// Structure for defining new character displays
86struct CharDef {
87 uint8_t position;
88 int16_t segments;
89 struct CharDef * next;
90};
91
92// class HT16K33
93class HT16K33 : public Print
94{
95private:
96 TwoWire *_i2cPort; // The generic connection to user's chosen I2C hardware
97 uint8_t _deviceAddressDisplayOne; // Address of primary alphanumeric display
98 uint8_t _deviceAddressDisplayTwo;
99 uint8_t _deviceAddressDisplayThree;
100 uint8_t _deviceAddressDisplayFour;
101 uint8_t digitPosition = 0;
102 uint8_t numberOfDisplays = 1;
103 bool displayOnOff = 0; // Tracks display on/off bit of display setup register
104 bool decimalOnOff = 0;
105 bool colonOnOff = 0;
106 uint8_t blinkRate = ALPHA_BLINK_RATE_NOBLINK; // Tracks blink bits in display setup register
107
108 // Enough RAM for up to 4 displays on same I2C bus
109 uint8_t displayRAM[16 * 4];
110 char displayContent[4 * 4 + 1] = "";
111
112 // Linked List of character definitions
113 struct CharDef * pCharDefList = NULL;
114
115public:
116 // Device status
117 bool begin(uint8_t addressDisplayOne = DEFAULT_ADDRESS,
118 uint8_t addressDisplayTwo = DEFAULT_NOTHING_ATTACHED,
119 uint8_t addressDisplayThree = DEFAULT_NOTHING_ATTACHED,
120 uint8_t addressDisplayFour = DEFAULT_NOTHING_ATTACHED,
121 TwoWire &wirePort = Wire); // Sets the address of the device and opens the Wire port for communication
122 bool isConnected(uint8_t displayNumber);
123 bool initialize();
124 uint8_t lookUpDisplayAddress(uint8_t displayNumber);
125
126 //Display configuration functions
127 bool clear();
128 bool setBrightness(uint8_t duty);
129 bool setBrightnessSingle(uint8_t displayNumber, uint8_t duty);
130 bool setBlinkRate(float rate);
131 bool setBlinkRateSingle(uint8_t displayNumber, float rate);
132 bool displayOn();
133 bool displayOff();
134 bool displayOnSingle(uint8_t displayNumber);
135 bool displayOffSingle(uint8_t displayNumber);
136 bool setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay);
137
138 bool enableSystemClock();
139 bool disableSystemClock();
140 bool enableSystemClockSingle(uint8_t displayNumber);
141 bool disableSystemClockSingle(uint8_t displayNumber);
142
143 // Light up functions
144 void illuminateSegment(uint8_t segment, uint8_t digit);
145 void illuminateChar(uint16_t disp, uint8_t digit);
146 void printChar(uint8_t displayChar, uint8_t digit);
147 bool updateDisplay();
148
149 // Define Character Segment Map
150 bool defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn);
151 uint16_t getSegmentsToTurnOn (uint8_t charPos);
152
153 // Decimal functions
154 bool decimalOn();
155 bool decimalOff();
156 bool decimalOnSingle(uint8_t displayNumber, bool updateNow = true);
157 bool decimalOffSingle(uint8_t displayNumber, bool updateNow = true);
158 bool setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal, bool updateNow = true);
159
160 // Colon functions
161 bool colonOn();
162 bool colonOff();
163 bool colonOnSingle(uint8_t displayNumber, bool updateNow = true);
164 bool colonOffSingle(uint8_t displayNumber, bool updateNow = true);
165 bool setColonOnOff(uint8_t displayNumber, bool turnOnColon, bool updateNow = true);
166
167 // Shifting
168 bool shiftRight(uint8_t shiftAmt = 1);
169 bool shiftLeft(uint8_t shiftAmt = 1);
170
171 // For overloading the print function
172 virtual size_t write(uint8_t);
173 virtual size_t write(const uint8_t *buffer, size_t size);
174 virtual size_t write(const char *str);
175
176 // I2C abstraction
177 bool readRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize);
178 bool writeRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize);
179 bool writeRAM(uint8_t reg, uint8_t data);
180};
181
182#endif
NetBurner Wire I2C Interface.
Wire interface class.
Definition Wire.h:42
int write(int fd, const char *buf, int nbytes)
Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio,...