LedController
2.0.2
A library for the MAX7219 and the MAX7221 Led display drivers.
|
Check the sakurajin::LedController for more infomation about its functions or look for the Examples.
This page shows you the basic usage of the sakurajin::LedController and what you can do with it.
You can initilize the library in two ways: with hardware SPI or with software SPI.
The Serial Peripheral Interface (SPI) is a synchronous serial communication interface specification used for short-distance communication, primarily in embedded systems. In this case your microcontroller is the master which controls the slave (at least one 7-Segment display or led matrix).
The master has three significant pins: SCLK(Serial Clock), MOSI(Master Out Slave In), SS(Slave Select). The slave also has tree needed pins (and two for power(GND and VCC)): CLK(Clock), DIN(Data In), CS(Ship Select). SCLK has to be connected to CLK and MOSI to DIN. These signals can be shared by multiple SPI slaves even if they have nothing to do with each other. SS has to be connected to CS and each Slave has its own SS pin(which can be any free pin).
To get started you need to first create a new sakurajin::controller_configuration object. This is used to configure the setup of the sakurajin::LedController which can get complex. sakurajin::controller_configuration has no constructor and is more like an struct with methods than it is a 'real' class. Because it is a template you need to know the dimension of your Matrix which causes the type to be sakurajin::controller_configuration<sements_x,segments_y>
. To see how you can use more than one row with the sakurajin::LedController go here. The rest of the example will use sakurajin::controller_configuration<4,1>
like in the rocket example.
If you want to use Hardware Spi set useHardwareSpi to true, otherwise set it to false. If you use hardware SPI you only need to specify the CS pin, if not you also need to CLK and MOSI pins. Just assign the wanted values to SPI_CS, SPI_CLK and SPI_MOSI.
Now you can check if the configuration is Valid by calling the sakurajin::controller_configuration.isValid() method. If it returns true, you can continue with the next step, if not try setting debug_output and figure out what went wrong.
Now that you have a valid configuration, you can pass it to the init function of a sakurajin::LedController object. You can use the sakurajin::LedController.setRow and sakurajin::LedController.setSegment to send data to the LedMatrix.
sakurajin::LedController.setRow sets a specific Row of a given segment to a given byte. It needs the segment index which can be calculated from the segment coordinates by calling lc.getConfig().getSegmentNumber(x,y)
.
sakurajin::LedController.setSegment sets a whole segment but the segment can be specified through coordinates or the index.
The following snippet is (probably working) sample code that initilizes a sakurajin::LedController using Hardware spi and sets some segments using sakurajin::LedController.setRow and sakurajin::LedController.setSegment.
Now that you know how to use the sakurajin::LedController you can check the more advanced features like using multiple rows or moving the displayed data.