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.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
7 #include <Helpers/BitArray.hpp>
8 
10 
18 class MAX7219 : public MAX7219_Base, public StaticSizeExtendedIOElement<8 * 8> {
19  public:
27 
30  void begin() override { init(); }
31 
36  void pinMode(UNUSED_PARAM pin_t pin, UNUSED_PARAM uint8_t mode) override
37  __attribute__((deprecated)) {}
38 
48  void digitalWrite(pin_t pin, uint8_t val) override {
49  buffer.set(pin, val);
50  update();
51  }
52 
63  int digitalRead(pin_t pin) override { return buffer.get(pin); }
64 
75  analog_t analogRead(pin_t pin) override __attribute__((deprecated)) {
76  return 1023 * digitalRead(pin);
77  }
78 
92  void analogWrite(pin_t pin, analog_t val) override
93  __attribute__((deprecated)) {
94  digitalWrite(pin, val >= 0x80);
95  }
96 
102  void update() override {
103  for (uint8_t i = 0; i < buffer.getBufferLength(); i++)
104  sendRaw(i + 1, buffer.getByte(i));
105  }
106 
107  private:
109 };
110 
MAX7219_Base
A base class for classes that control MAX7219 LED drivers.
Definition: MAX7219_Base.hpp:17
MAX7219::pinMode
void pinMode(UNUSED_PARAM pin_t pin, UNUSED_PARAM uint8_t mode) override __attribute__((deprecated))
The pinMode function is not implemented because the mode is OUTPUT by definition.
Definition: MAX7219.hpp:36
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
MAX7219::analogRead
analog_t analogRead(pin_t pin) override __attribute__((deprecated))
The analogRead function is deprecated because a MAX7219 is always digital.
Definition: MAX7219.hpp:75
BitArray::getByte
uint8_t getByte(uint8_t byteIndex) const
Get the byte at the given index.
Definition: BitArray.hpp:92
StaticSizeExtendedIOElement
A class for ExtendedIOElements with a fixed size.
Definition: StaticSizeExtendedIOElement.hpp:16
BitArray.hpp
MAX7219::buffer
BitArray< 8 *8 > buffer
Definition: MAX7219.hpp:108
MAX7219::digitalRead
int digitalRead(pin_t pin) override
Get the current state of a given output.
Definition: MAX7219.hpp:63
UNUSED_PARAM
#define UNUSED_PARAM
Definition: Def.hpp:79
MAX7219::begin
void begin() override
Initialize.
Definition: MAX7219.hpp:30
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
analog_t
uint16_t analog_t
The type returned from analogRead and similar functions.
Definition: Def.hpp:15
ExtendedIOElement::pin
pin_t pin(pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition: ExtendedIOElement.cpp:26
StaticSizeExtendedIOElement.hpp
BitArray::set
void set(uint8_t bitIndex)
Set the value of the given bit to 1.
Definition: BitArray.hpp:36
MAX7219::digitalWrite
void digitalWrite(pin_t pin, uint8_t val) override
Set the state of a given output pin.
Definition: MAX7219.hpp:48
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
MAX7219_Base::loadPin
pin_t loadPin
Definition: MAX7219_Base.hpp:96
MAX7219::MAX7219
MAX7219(pin_t loadPin)
Create a MAX7219 ExtendedIOElement.
Definition: MAX7219.hpp:26
BitArray::getBufferLength
uint8_t getBufferLength() const
Get the buffer length in bytes.
Definition: BitArray.hpp:100
BitArray::get
bool get(uint8_t bitIndex)
Get the value of the given bit.
Definition: BitArray.hpp:26
MAX7219::analogWrite
void analogWrite(pin_t pin, analog_t val) override __attribute__((deprecated))
The analogWrite function is deprecated because a MAX7219 is always digital.
Definition: MAX7219.hpp:92
MAX7219_Base.hpp
MAX7219_Base::init
void init()
Initialize the Arduino pins, SPI, and the MAX7219.
Definition: MAX7219_Base.hpp:36
MAX7219::update
void update() override
Write the buffer to the display.
Definition: MAX7219.hpp:102
BitArray< 8 *8 >
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
MAX7219
A class for LED outputs using the MAX7219 LED display driver.
Definition: MAX7219.hpp:18