muwerk mupplet Display Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
Loading...
Searching...
No Matches
max72xx.h
1// max72xx.h - MAX72XX driver class
2
3#pragma once
4
5#include <SPI.h>
6
7namespace ustd {
14class Max72XX {
15 protected:
16 // hardware configuration
17 uint8_t csPin;
18 uint8_t chainLen;
19
20 public:
22 enum OP {
23 noop = 0,
24 digit0 = 1,
25 digit1 = 2,
26 digit2 = 3,
27 digit3 = 4,
28 digit4 = 5,
29 digit5 = 6,
30 digit6 = 7,
31 digit7 = 8,
33 intensity = 10,
34 scanlimit = 11,
35 shutdown = 12,
36 displaytest = 15
37 };
38
44 Max72XX(uint8_t csPin, uint8_t chainLen) : csPin(csPin), chainLen(chainLen) {
45 if (chainLen > 16) {
46 chainLen = 16;
47 }
48 }
49
52 void begin() {
53 // initialize chip select
54 pinMode(csPin, OUTPUT);
55 digitalWrite(csPin, HIGH);
56
57 // multiple init management is done inside the SPI library
58 SPI.begin();
59 }
60
64 inline uint8_t getChainLen() const {
65 return chainLen;
66 }
67
71 inline void setDecodeMode(uint8_t mode) {
73 }
74
78 inline void setIntensity(uint8_t intensity) {
80 }
81
85 inline void setScanLimit(uint8_t scanlimit) {
87 }
88
93 inline void setPowerSave(bool powersave) {
94 sendCommand(OP::shutdown, powersave ? 0 : 1);
95 }
96
104 inline void setTestMode(bool testmode) {
105 sendCommand(OP::displaytest, testmode ? 1 : 0);
106 }
107
113 void sendCommand(OP opcode, uint8_t data) {
114 digitalWrite(csPin, LOW);
115 for (uint8_t count = 0; count < chainLen; count++) {
116 SPI.transfer(opcode);
117 SPI.transfer(data);
118 }
119 digitalWrite(csPin, HIGH);
120 }
121
126 void sendBlock(uint8_t *buffer, uint8_t size) {
127 digitalWrite(csPin, LOW);
128 SPI.transfer(buffer, size);
129 digitalWrite(csPin, HIGH);
130 }
131};
132} // namespace ustd
The MAX72XX Controller Class.
Definition: max72xx.h:14
void begin()
Definition: max72xx.h:52
OP
Definition: max72xx.h:22
@ digit6
Digit 6.
Definition: max72xx.h:30
@ digit3
Digit 3.
Definition: max72xx.h:27
@ shutdown
Shutdown Mode (0 or 1)
Definition: max72xx.h:35
@ decodemode
Decode Mode (0,1,15,255)
Definition: max72xx.h:32
@ digit5
Digit 5.
Definition: max72xx.h:29
@ digit0
Digit 0.
Definition: max72xx.h:24
@ digit7
Digit 7.
Definition: max72xx.h:31
@ displaytest
Display Test (0 or 1)
Definition: max72xx.h:36
@ scanlimit
Scan-Limit (0-7)
Definition: max72xx.h:34
@ noop
No operation.
Definition: max72xx.h:23
@ digit2
Digit 2.
Definition: max72xx.h:26
@ digit4
Digit 4.
Definition: max72xx.h:28
@ intensity
Intensity (0-15)
Definition: max72xx.h:33
@ digit1
Digit 1.
Definition: max72xx.h:25
void setPowerSave(bool powersave)
Definition: max72xx.h:93
void setIntensity(uint8_t intensity)
Definition: max72xx.h:78
void sendCommand(OP opcode, uint8_t data)
Definition: max72xx.h:113
uint8_t getChainLen() const
Definition: max72xx.h:64
void setTestMode(bool testmode)
Definition: max72xx.h:104
void sendBlock(uint8_t *buffer, uint8_t size)
Definition: max72xx.h:126
void setScanLimit(uint8_t scanlimit)
Definition: max72xx.h:85
Max72XX(uint8_t csPin, uint8_t chainLen)
Definition: max72xx.h:44
void setDecodeMode(uint8_t mode)
Definition: max72xx.h:71
The muwerk namespace.
Definition: display_digits_max72xx.h:10