LedControl Arduino Library
repository·master·Indexed 19 days ago
https://github.com/wayoda/ledcontrolAn Arduino library for controlling MAX7219 and MAX7221 LED display drivers, compatible with Arduino and Teensy 3.1 hardware. It provides functionality to manage power states, brightness, and scan limits, as well as methods to control individual LEDs, rows, columns, and render digits or characters on 7-segment displays.
What's inside ledcontrol
- LedControl is an Arduino library designed to interface with MAX7219 and MAX7221 LED display drivers. It is compatible with Arduino boards and Teensy (3.1).
Install the LedControl library
masterThe LedControl library can be installed following the standard Arduino library installation procedure. This allows you to use the library for controlling MAX7219 and MAX7221 LED display drivers on Arduino boards or Teensy (3.1) hardware.Configure display settings with LedControl
masterUse the following methods to manage the power state, brightness, and scan limits of your LED displays.
shutdown(int addr, bool status): Sets the power-saving mode. Passtrueto enter power-down mode, orfalsefor normal operation.setIntensity(int addr, int intensity): Sets the brightness level. Valid range is0to15.setScanLimit(int addr, int limit): Sets the number of digits (rows) to be displayed. Valid range is1to8. Note that changing the scan limit may affect display brightness.clearDisplay(int addr): Switches all LEDs on the specified display off.
Control individual LEDs or rows/columns
masterYou can manipulate the LED matrix using direct coordinate access or by setting entire rows/columns at once.
setLed(int addr, int row, int col, boolean state): Sets a single LED.rowandcolare both0..7.setRow(int addr, int row, byte value): Sets all 8 LEDs in a specific row (0..7). Thevalueis a byte where each bit corresponds to an LED.setColumn(int addr, int col, byte value): Sets all 8 LEDs in a specific column (0..7). Thevalueis a byte where each bit corresponds to an LED.
Initialize the LedControl class
masterTo control MAX7219 or MAX7221 LED drivers, instantiate the
LedControlclass by specifying the SPI pins and the number of devices in your chain.Parameters:
dataPin: The Arduino pin used for shifting out data (MOSI).clkPin: The Arduino pin used for the clock signal.csPin: The Arduino pin used for chip selection (driven LOW to select the device).numDevices: The maximum number of devices in the chain (defaults to 1).
// Example: 1 device, data on pin 11, clock on pin 13, CS on pin 10 LedControl lc(11, 13, 10, 1);Get the number of connected devices
masterThe
getDeviceCount()method returns the total number of devices configured in theLedControlinstance.int count = lc.getDeviceCount();Display digits and characters on 7-Segment displays
masterFor 7-segment displays, use these methods to render hexadecimal values or specific characters.
setDigit(int addr, int digit, byte value, boolean dp): Displays a hexadecimal digit (0x00to0x0F) at a specific position (0..7). Thedpparameter controls the decimal point.setChar(int addr, int digit, char value, boolean dp): Displays a character at a specific position (0..7). Supported characters include:'0'-'9','A','b','c','d','E','F','H','L','P','.','-','_', and' '. Thedpparameter controls the decimal point.