Erriez JY-LKM1638 board library for Arduino  1.1.0
This is an optimized JY-MCU JY-LKM1638 library for Arduino. It supports 8x 7-segment display, 8 dual color LEDs and 8 buttons with a simple API.
ErriezLKM1638Board.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2020 Erriez
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
34 #ifndef ERRIEZ_LKM1638_BOARD_H_
35 #define ERRIEZ_LKM1638_BOARD_H_
36 
37 #include <Arduino.h>
38 
39 #include <ErriezTM1638.h>
40 
41 #define NUM_COLOR_LEDS 8
42 #define NUM_DIGITS 8
43 
44 #define SEGMENTS_OFF 0b00000000
45 #define SEGMENTS_MINUS 0b01000000
46 #define SEGMENTS_DEGREE 0b01100011
47 #define SEGMENTS_C 0b00111001
48 
49 #if (NUM_COLOR_LEDS > 8)
50 #error "Too many LED's. This won't fit in a 8-bit variable"
51 #endif
52 
56 typedef enum {
57  LedOff = 0,
58  LedRed = 1,
59  LedGreen = 2
60 } LedColor;
61 
62 
66 class LKM1638Board : public TM1638
67 {
68 public:
69  // Constructor with 3 pins
70  LKM1638Board(uint8_t clkPin, uint8_t dioPin, uint8_t stbPin);
71 
72  // Get buttons
73  uint8_t getButtons();
74 
75  // Turn all LED's off
76  void clear();
77 
78  // Set dual color LED's
79  void setColorLED(uint8_t led, LedColor color);
80  void colorLEDsOn(uint8_t leds, LedColor color);
81  void colorLEDsOff(uint8_t leds);
82 
83  // Refresh 7-segment display
84  void refresh();
85 
86  // Control 7-segment dots
87  void dotOn(uint8_t pos);
88  void dotOff(uint8_t pos);
89  void setDots(uint8_t dots);
90 
91  // Set/get position for print functions
92  void setPrintPos(uint8_t pos);
93  uint8_t getPrintPos();
94 
95  // Write
96  void setSegmentsDigit(uint8_t pos, uint8_t leds);
97  void setDigit(uint8_t pos, uint8_t digit);
98 
99  // Notes: Overloaded functions with default arguments are not allowed, so
100  // create multiple functions with different number of arguments.
101 
102  // Display unsigned value 8, 16 or 32-bit with optional padding
103  void print(uint8_t value);
104  void print(uint8_t value, uint8_t radius);
105  void print(uint8_t value, uint8_t radius, uint8_t maxDigits);
106  void print(uint8_t value, uint8_t radius, uint8_t maxDigits, uint8_t pad);
107 
108  void print(uint16_t value);
109  void print(uint16_t value, uint8_t radius);
110  void print(uint16_t value, uint8_t radius, uint8_t maxDigits);
111  void print(uint16_t value, uint8_t radius, uint8_t maxDigits, uint8_t pad);
112 
113  void print(unsigned long value);
114  void print(unsigned long value, uint8_t radius);
115  void print(unsigned long value, uint8_t radius, uint8_t maxDigits);
116  void print(unsigned long value, uint8_t radius, uint8_t maxDigits, uint8_t pad);
117 
118  // Display signed value 8, 16 or 32-bit
119  void print(int8_t value);
120  void print(int8_t value, uint8_t radius);
121  void print(int8_t value, uint8_t radius, uint8_t maxDigits);
122 
123  void print(int16_t value);
124  void print(int16_t value, uint8_t radius);
125  void print(int16_t value, uint8_t radius, uint8_t maxDigits);
126 
127  void print(long value);
128  void print(long value, uint8_t radius);
129  void print(long value, uint8_t radius, uint8_t maxDigits);
130 
131 protected:
132  uint8_t _leds[NUM_DIGITS];
133  uint8_t _pos;
134  uint8_t _dots;
135 
136  void writeDigit(uint8_t pos);
137  void writeUnsignedValue(uint32_t value, uint8_t radius, uint8_t maxDigits,
138  uint8_t pad);
139  void writeSignedValue(int32_t value, uint8_t radius, uint8_t maxDigits);
140  uint8_t getNumDigits(uint32_t value, uint8_t radius);
141  void displayOverflow(uint8_t numDigits);
142 
143  // Swap bits and bytes
144  uint8_t swapBits(uint8_t data);
145  uint8_t swapPos(uint8_t pos);
146  uint8_t swapLeds(uint8_t led);
147 };
148 
149 #endif // ERRIEZ_LKM1638_BOARD_H_
uint8_t swapLeds(uint8_t led)
Swap dual color LED&#39;s.
uint8_t swapPos(uint8_t pos)
Swap digit position.
void dotOff(uint8_t pos)
Turn dot LED off.
void writeSignedValue(int32_t value, uint8_t radius, uint8_t maxDigits)
Write signed value to display.
LKM1638Board(uint8_t clkPin, uint8_t dioPin, uint8_t stbPin)
LKM1638 constructor.
uint8_t getButtons()
Read buttons.
void setDots(uint8_t dots)
Turn multiple dots on or off.
void clear()
Turn all LED&#39;s off.
uint8_t getPrintPos()
Get print position.
void setPrintPos(uint8_t pos)
Set print position.
void colorLEDsOff(uint8_t leds)
Turn multiple color LED&#39;s off.
void dotOn(uint8_t pos)
Turn dot LED on.
void setSegmentsDigit(uint8_t pos, uint8_t leds)
Write LED segments of a digit.
#define NUM_DIGITS
Number of digits.
void print(uint8_t value)
Print uint8_t value.
void setDigit(uint8_t pos, uint8_t digit)
Write digit.
uint8_t _dots
Dot LED&#39;s.
void writeDigit(uint8_t pos)
Write digit position.
uint8_t getNumDigits(uint32_t value, uint8_t radius)
Get number of digits of a signed 32-bit value.
uint8_t swapBits(uint8_t data)
Swap bits.
LKM1638Board class, derived from TM1638 library.
void displayOverflow(uint8_t numDigits)
Display overflow with - characters.
void refresh()
Refresh display.
LedColor
Dual color LED.
uint8_t _leds[NUM_DIGITS]
LED digits.
void setColorLED(uint8_t led, LedColor color)
Set dual color LED.
uint8_t _pos
Print position.
void colorLEDsOn(uint8_t leds, LedColor color)
Turn multiple color LED&#39;s on.
void writeUnsignedValue(uint32_t value, uint8_t radius, uint8_t maxDigits, uint8_t pad)
Write unsigned value to display.