SBK_MAX72xx library 2.0.5
Low-level driver for controlling multiple MAX7219/MAX7221 LED matrix chips via software SPI.
Loading...
Searching...
No Matches
SBK_MAX72xxSoft.h
Go to the documentation of this file.
1
28
29/*
30 * Adapted from the original Ledcontrol.h library by Eberhard Fahle:
31 * <https://github.com/wayoda/LedControl>
32 *
33 * Original library:
34 * LEdControl.h - A library for controlling LEDs with a MAX7219/MAX7221
35 * Copyright (c) 2007 Eberhard Fahle
36 *
37 * All credit for the original library goes to Eberhard Fahle.
38 */
39
40#pragma once
41
42#define SBK_MAX72xx_IS_DEFINED
43
44#include <Arduino.h>
45#include <SPI.h>
46
52{
53public:
67 SBK_MAX72xxSoft(uint8_t dataPin, uint8_t clkPin, uint8_t csPin, uint8_t devsNum = 1);
68
69 ~SBK_MAX72xxSoft(); // Destructor
70
83 uint8_t maxRows(uint8_t devIdx = 0) const
84 {
85 (void)devIdx;
86 return _defaultRowBufferSize;
87 }
88
97 uint8_t maxColumns() const { return _defaultColBufferSize; }
98
112 uint8_t maxSegments(uint8_t devIdx = 0) const { return maxRows(devIdx) * maxColumns(); }
113
117 void begin();
118
125 void setShutdown(uint8_t devIdx, bool status);
126
133 void setScanLimit(uint8_t devIdx, uint8_t limit);
134
141 void setBrightness(uint8_t devIdx, uint8_t brightness);
142
148 uint8_t devsNum() const { return _devsNum; }
149
155 void clear(uint8_t devIdx);
156
160 void clear();
161
177 void setLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx, bool state);
178
199 bool getLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx) const;
200
208 void setCol(uint8_t devIdx, uint8_t colIdx, uint8_t value);
209
219 void show();
220
231 void show(uint8_t devIdx);
232
233private:
234 void _spiTransfer(uint8_t targetDevice, uint8_t opcode, uint8_t data);
235 void _writeColToAllDevices(uint8_t targetDevice, uint8_t colIdx, uint8_t data);
236 inline uint8_t _bitMaskRow(uint8_t devIdx, uint8_t rowIdx) const;
237 inline uint8_t _colIndex(uint8_t devIdx, uint8_t colIdx) const;
238
239 const uint8_t _dataPin;
240 const uint8_t _clkPin;
241 const uint8_t _csPin;
242 const uint8_t _devsNum = 1;
243
244 static constexpr uint8_t _defaultRowBufferSize = 8;
245 static constexpr uint8_t _defaultColBufferSize = 8;
246 uint8_t *_buffer; // Internal display buffer
247 bool *_update; // Array to track if data has changed per device
248
249 uint32_t _spiClock = 1000000; // Default 1 MHz
250};
void begin()
Initialize SPI pins and all MAX72xx chips.
Definition SBK_MAX72xxSoft.cpp:60
uint8_t devsNum() const
Return the number of actives driver devices.
Definition SBK_MAX72xxSoft.h:148
uint8_t maxColumns() const
Returns the number of addressable columns (cathode outputs = DIGx).
Definition SBK_MAX72xxSoft.h:97
void setShutdown(uint8_t devIdx, bool status)
Enable or disable shutdown mode on a specific device.
Definition SBK_MAX72xxSoft.cpp:77
uint8_t maxRows(uint8_t devIdx=0) const
Returns the number of addressable row lines (anode outputs = SEGx).
Definition SBK_MAX72xxSoft.h:83
SBK_MAX72xxSoft(uint8_t dataPin, uint8_t clkPin, uint8_t csPin, uint8_t devsNum=1)
Construct a new Software SPI SBK_MAX72xxSoft object.
Definition SBK_MAX72xxSoft.cpp:39
void clear()
Clear display buffers and hardware for all devices.
Definition SBK_MAX72xxSoft.cpp:109
uint8_t maxSegments(uint8_t devIdx=0) const
Returns the total number of addressable LED segments for this device.
Definition SBK_MAX72xxSoft.h:112
void setBrightness(uint8_t devIdx, uint8_t brightness)
Set display brightness for a specific device.
Definition SBK_MAX72xxSoft.cpp:87
void setLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx, bool state)
Set the state of a specific LED in the device’s internal matrix buffer.
Definition SBK_MAX72xxSoft.cpp:117
void setScanLimit(uint8_t devIdx, uint8_t limit)
Set the scan limit (number of active digits) for a specific device.
Definition SBK_MAX72xxSoft.cpp:82
bool getLed(uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx) const
Get the state of a specific LED in the device’s internal matrix buffer.
Definition SBK_MAX72xxSoft.cpp:143
void show()
Push the internal display buffer to all connected devices.
Definition SBK_MAX72xxSoft.cpp:163
void setCol(uint8_t devIdx, uint8_t colIdx, uint8_t value)
Set the entire col value for a specific device (buffer only).
Definition SBK_MAX72xxSoft.cpp:151