AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
LedMatrixSerial.cpp
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 #include "Hardware.h"
26 #include "LedMatrixSerial.h"
27 
28 namespace ace_segment {
29 
32 
33  // Actual values of latchPin, dataPin and clockPin don't matter because the
34  // functions are triggered on a rising edge, not on the level.
35  mHardware->pinMode(mLatchPin, OUTPUT);
36  mHardware->pinMode(mDataPin, OUTPUT);
37  mHardware->pinMode(mClockPin, OUTPUT);
38 
39  for (uint8_t group = 0; group < mNumGroups; group++) {
40  uint8_t pin = mGroupPins[group];
41  mHardware->pinMode(pin, OUTPUT);
42  mHardware->digitalWrite(pin, mGroupOff);
43  }
44 }
45 
47  mHardware->pinMode(mLatchPin, INPUT);
48  mHardware->pinMode(mDataPin, INPUT);
49  mHardware->pinMode(mClockPin, INPUT);
50 
51  for (uint8_t group = 0; group < mNumGroups; group++) {
52  uint8_t pin = mGroupPins[group];
53  mHardware->pinMode(pin, INPUT);
54  }
55 }
56 
57 void LedMatrixSerial::enableGroup(uint8_t group) {
58  writeGroupPin(group, mGroupOn);
59 }
60 
61 void LedMatrixSerial::disableGroup(uint8_t group) {
62  writeGroupPin(group, mGroupOff);
63 }
64 
65 void LedMatrixSerial::drawElements(uint8_t pattern) {
66  mHardware->digitalWrite(mLatchPin, LOW);
67  uint8_t actualPattern = (mElementOn == HIGH) ? pattern : ~pattern;
68  mHardware->shiftOut(mDataPin, mClockPin, MSBFIRST, actualPattern);
69  mHardware->digitalWrite(mLatchPin, HIGH);
70 }
71 
72 void LedMatrixSerial::writeGroupPin(uint8_t group, uint8_t output) {
73  uint8_t groupPin = mGroupPins[group];
74  mHardware->digitalWrite(groupPin, output);
75 }
76 
77 }
virtual void configure() override
Configure the pins for the given LED wiring.
virtual void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value)
Shift out.
Definition: Hardware.h:53
virtual void pinMode(uint8_t pin, uint8_t mode)
Set pin mode.
Definition: Hardware.h:48
virtual void configure()
Configure the pins for the given LED wiring.
Definition: LedMatrix.h:82
virtual void digitalWrite(uint8_t pin, uint8_t value)
Write value to pin.
Definition: Hardware.h:43
virtual void finish() override
Turn off the pins by doing the opposite of configure().
void writeGroupPin(uint8_t group, uint8_t output)
Write to group pin identified by &#39;group&#39;.