LedControl Arduino Library

repository·master·Indexed 19 days ago

https://github.com/wayoda/ledcontrol

An 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.

Tokens
737
Snippets
2
Records
7
Agent score
18%

What's inside ledcontrol

  1. Install the LedControl library

    master
    The 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.
  2. Configure display settings with LedControl

    master

    Use 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. Pass true to enter power-down mode, or false for normal operation.
    • setIntensity(int addr, int intensity): Sets the brightness level. Valid range is 0 to 15.
    • setScanLimit(int addr, int limit): Sets the number of digits (rows) to be displayed. Valid range is 1 to 8. Note that changing the scan limit may affect display brightness.
    • clearDisplay(int addr): Switches all LEDs on the specified display off.
  3. Control individual LEDs or rows/columns

    master

    You 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. row and col are both 0..7.
    • setRow(int addr, int row, byte value): Sets all 8 LEDs in a specific row (0..7). The value is 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). The value is a byte where each bit corresponds to an LED.
  4. Initialize the LedControl class

    master

    To control MAX7219 or MAX7221 LED drivers, instantiate the LedControl class 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);
  5. Display digits and characters on 7-Segment displays

    master

    For 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 (0x00 to 0x0F) at a specific position (0..7). The dp parameter 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 ' '. The dp parameter controls the decimal point.