This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
MAX7219_Base.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 #include <SPI.h>
7 
9 
17 class MAX7219_Base {
18  public:
26 
27  static constexpr uint8_t DECODEMODE = 9;
28  static constexpr uint8_t INTENSITY = 10;
29  static constexpr uint8_t SCANLIMIT = 11;
30  static constexpr uint8_t SHUTDOWN = 12;
31  static constexpr uint8_t DISPLAYTEST = 15;
32 
36  void init() {
39  SPI.begin();
40  sendRaw(DISPLAYTEST, 0); // Normal operation, no test mode
41  sendRaw(SCANLIMIT, 7); // Scan all 8 digits
42  sendRaw(DECODEMODE, 0); // Raw LED addressing
43  sendRaw(INTENSITY, 0xF); // Maximum intensity
44  clear();
45  sendRaw(SHUTDOWN, 1); // Enable the display
46  }
47 
51  void clear() {
52  for (uint8_t j = 1; j < 8 + 1; j++)
53  sendRaw(j, 0);
54  }
55 
64  void send(uint8_t digit, uint8_t value) {
65  sendRaw((digit & 0x7) + 1, value);
66  }
67 
76  void sendRaw(uint8_t opcode, uint8_t value) {
78  SPI.beginTransaction(settings);
79  SPI.transfer(opcode);
80  SPI.transfer(value);
82  SPI.endTransaction();
83  }
84 
91  void setIntensity(uint8_t intensity) {
92  sendRaw(INTENSITY, intensity & 0xF);
93  }
94 
95  private:
97  SPISettings settings = {SPI_MAX_SPEED, MSBFIRST, SPI_MODE0};
98 };
99 
MAX7219_Base
A base class for classes that control MAX7219 LED drivers.
Definition: MAX7219_Base.hpp:17
MAX7219_Base::clear
void clear()
Turn off all LEDs.
Definition: MAX7219_Base.hpp:51
MAX7219_Base::setIntensity
void setIntensity(uint8_t intensity)
Set the intensity of the LEDs.
Definition: MAX7219_Base.hpp:91
ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:34
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
MAX7219_Base::INTENSITY
static constexpr uint8_t INTENSITY
Definition: MAX7219_Base.hpp:28
ExtendedInputOutput.hpp
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:45
MAX7219_Base::MAX7219_Base
MAX7219_Base(pin_t loadPin)
Create a MAX7219_Base object.
Definition: MAX7219_Base.hpp:25
MAX7219_Base::SCANLIMIT
static constexpr uint8_t SCANLIMIT
Definition: MAX7219_Base.hpp:29
MAX7219_Base::SHUTDOWN
static constexpr uint8_t SHUTDOWN
Definition: MAX7219_Base.hpp:30
MAX7219_Base::settings
SPISettings settings
Definition: MAX7219_Base.hpp:97
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
SPI_MAX_SPEED
constexpr static Frequency SPI_MAX_SPEED
Definition: Settings.hpp:113
MAX7219_Base::loadPin
pin_t loadPin
Definition: MAX7219_Base.hpp:96
MAX7219_Base::DISPLAYTEST
static constexpr uint8_t DISPLAYTEST
Definition: MAX7219_Base.hpp:31
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:38
MAX7219_Base::init
void init()
Initialize the Arduino pins, SPI, and the MAX7219.
Definition: MAX7219_Base.hpp:36
MAX7219_Base::DECODEMODE
static constexpr uint8_t DECODEMODE
Definition: MAX7219_Base.hpp:27
MAX7219_Base::send
void send(uint8_t digit, uint8_t value)
Send the value to the given digit.
Definition: MAX7219_Base.hpp:64
MAX7219_Base::sendRaw
void sendRaw(uint8_t opcode, uint8_t value)
Send a raw opcode and value to the MAX7219.
Definition: MAX7219_Base.hpp:76