AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
LedMatrix.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
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 
25 #ifndef ACE_SEGMENT_LED_MATRIX_H
26 #define ACE_SEGMENT_LED_MATRIX_H
27 
28 #include <Arduino.h> // LOW and HIGH
29 
30 #if LOW != 0 || HIGH != 1
31  #error LOW is not 0 or HIGH is not 1
32 #endif
33 
34 namespace ace_segment {
35 
36 class Hardware;
37 
49 class LedMatrix {
50  public:
51  LedMatrix(Hardware* hardware, uint8_t numGroups, uint8_t numElements):
52  mHardware(hardware),
53  mNumGroups(numGroups),
54  mNumElements(numElements)
55  {}
56 
57  virtual ~LedMatrix() {}
58 
61  mGroupOn = LOW;
62  mGroupOff = HIGH;
63  mElementOn = HIGH;
64  mElementOff = LOW;
65  }
66 
68  void setAnodeOnGroup() {
69  mGroupOn = HIGH;
70  mGroupOff = LOW;
71  mElementOn = LOW;
72  mElementOff = HIGH;
73  }
74 
77  mGroupOn = 1 - mGroupOn;
78  mGroupOff = 1 - mGroupOff;
79  }
80 
82  virtual void configure() {}
83 
85  virtual void finish() {}
86 
87  virtual void enableGroup(uint8_t group) = 0;
88 
89  virtual void disableGroup(uint8_t group) = 0;
90 
91  virtual void drawElements(uint8_t pattern) = 0;
92 
93  protected:
94  Hardware* const mHardware;
95  const uint8_t mNumGroups;
96  const uint8_t mNumElements;
97 
98  uint8_t mGroupOn;
99  uint8_t mGroupOff;
100  uint8_t mElementOn;
101  uint8_t mElementOff;
102 };
103 
104 }
105 
106 #endif
virtual void finish()
Turn off the pins by doing the opposite of configure().
Definition: LedMatrix.h:85
virtual void configure()
Configure the pins for the given LED wiring.
Definition: LedMatrix.h:82
void setAnodeOnGroup()
LED positive terminals are on the group line.
Definition: LedMatrix.h:68
void invertGroupLevels()
If a transistor drives the group, invert the logic levels.
Definition: LedMatrix.h:76
Class that represents the abstraction of a particular LED display wiring.
Definition: LedMatrix.h:49
void setCathodeOnGroup()
LED negative terminals are on the group line.
Definition: LedMatrix.h:60