### Initialize TLC591x with Hardware SPI Source: https://context7.com/andy4495/tlc591x/llms.txt Demonstrates how to instantiate the TLC591x class using the microcontroller's hardware SPI interface for faster performance. Requires SPI.begin() in the setup function. ```cpp #include // Constructor parameters for HW SPI: num_chips, LE_pin, OE_pin TLC591x myLED(2, 5, 9); // Hardware SPI with OE control void setup() { myLED.displayEnable(); SPI.begin(); // Initialize hardware SPI } void loop() { myLED.print("OK"); delay(1000); } ``` ```cpp #include // Constructor parameters for HW SPI: num_chips, LE_pin TLC591x myLED(2, 7); // Hardware SPI, OE tied low void setup() { SPI.begin(); } void loop() { myLED.print("Go"); delay(1000); } ``` -------------------------------- ### Initialize TLC591x with Software SPI Source: https://context7.com/andy4495/tlc591x/llms.txt Demonstrates how to instantiate the TLC591x class using software SPI. Includes examples for both configurations where the Output Enable (OE) pin is managed by the library or hard-wired low. ```cpp #include // Constructor parameters: num_chips, SDI_pin, CLK_pin, LE_pin, OE_pin TLC591x myLED(2, 5, 6, 7, 9); // 2 chips cascaded, OE pin enables brightness control void setup() { myLED.displayEnable(); // Turn on display (OE pin defaults to disabled) } void loop() { myLED.print("Hi"); delay(1000); } ``` ```cpp #include // Constructor parameters: num_chips, SDI_pin, CLK_pin, LE_pin TLC591x myLED(2, 7, 8, 9); // OE pin tied low externally void setup() { // No displayEnable() needed - display is always on } void loop() { myLED.print("88"); delay(1000); } ``` -------------------------------- ### Control TLC591x LED Display with Arduino Source: https://context7.com/andy4495/tlc591x/llms.txt This example demonstrates initializing the TLC591x library with cascaded chips, performing text scrolling, numeric counting with brightness modulation, direct LED bit-masking, and display toggling. ```cpp #include TLC591x display(2, 5, 6, 7, 9); void setup() { display.displayEnable(); } void loop() { char text[9]; uint8_t leds[2]; memcpy(text, "HELLO ", 8); for (int i = 0; i < 6; i++) { display.print(&text[i]); delay(400); } for (int count = 0; count <= 99; count++) { sprintf(text, "%02d", count); display.print(text); display.displayBrightness(count * 2); delay(50); } display.displayBrightness(0); for (int i = 0; i < 16; i++) { leds[0] = (i < 8) ? (1 << i) : 0xFF; leds[1] = (i >= 8) ? (1 << (i - 8)) : 0x00; display.printDirect(leds); delay(150); } display.print("Go"); for (int i = 0; i < 5; i++) { display.displayDisable(); delay(200); display.displayEnable(); delay(200); } delay(1000); } ``` -------------------------------- ### Enable Display Output Source: https://github.com/andy4495/tlc591x/blob/main/README.md Set the Output Enable (/OE) signal low to turn on the display. This method is only effective if the OE pin was defined during object initialization. ```cpp void displayEnable(); ``` -------------------------------- ### Display Methods Source: https://context7.com/andy4495/tlc591x/llms.txt Methods for outputting data to the LED drivers, including ASCII-to-segment mapping for displays and raw bit manipulation for individual LEDs. ```APIDOC ## Method: print(const char* s) ### Description Prints ASCII characters to 7-segment displays using built-in segment mapping. Element 0 of the array is the most significant digit. ### Parameters - **s** (const char*) - Required - The string or character array to display. ## Method: print(unsigned int n) ### Description Shifts out raw bit values to control individual LEDs or bar graphs. Supports up to 2 chips (16 bits). ### Parameters - **n** (unsigned int) - Required - The 16-bit value representing the state of the LEDs. ``` -------------------------------- ### TLC591x Library Constructors Source: https://context7.com/andy4495/tlc591x/llms.txt Initializes the TLC591x driver instance using either software bit-bang or hardware SPI, with optional support for Output Enable (OE) pin control. ```APIDOC ## Constructor: Software SPI ### Description Creates a TLC591x instance using software SPI (bit-bang) for flexible pin assignment. ### Parameters - **num_chips** (int) - Required - Number of cascaded chips - **SDI_pin** (int) - Required - Serial Data In pin - **CLK_pin** (int) - Required - Clock pin - **LE_pin** (int) - Required - Latch Enable pin - **OE_pin** (int) - Optional - Output Enable pin for brightness control ## Constructor: Hardware SPI ### Description Creates a TLC591x instance using the microcontroller's hardware SPI peripheral for high-speed data transfer. ### Parameters - **num_chips** (int) - Required - Number of cascaded chips - **LE_pin** (int) - Required - Latch Enable pin - **OE_pin** (int) - Optional - Output Enable pin for brightness control ``` -------------------------------- ### Initialize TLC591x Object with Hardware SPI Source: https://github.com/andy4495/tlc591x/blob/main/README.md Create a TLC591x object using hardware SPI. Supports controlling the Output Enable (OE) pin or hard-wiring it low. ```cpp TLC591x myLED(num_chips, LE_pin, OE_pin); // OE pin controlled by library TLC591x myLED(num_chips, LE_pin); // OE pin hard-wired low (always enabled) ``` -------------------------------- ### System and Brightness Control Source: https://github.com/andy4495/tlc591x/blob/main/README.md Methods for managing display state, operating modes, and PWM-based brightness. ```APIDOC ## void displayBrightness(byte b) ### Description Sets display brightness using PWM on the /OE pin. Note: 0 is brightest, 255 is dimmest. ### Parameters - **b** (byte) - Required - Brightness value (0-255). --- ## void displayEnable() / displayDisable() ### Description Turns the display on or off by setting the /OE signal. --- ## void normalMode() / specialMode() ### Description Switches the chip between Normal and Special operating modes as defined in the datasheet. ``` -------------------------------- ### Initialize TLC591x Object with Software SPI Source: https://github.com/andy4495/tlc591x/blob/main/README.md Create a TLC591x object using software SPI. Supports controlling the Output Enable (OE) pin or hard-wiring it low. ```cpp TLC591x myLED(num_chips, SDI_pin, CLK_pin, LE_pin, OE_pin); // OE pin controlled by library TLC591x myLED(num_chips, SDI_pin, CLK_pin, LE_pin); // OE pin hard-wired low (always enabled) ``` -------------------------------- ### TLC591x Initialization Source: https://github.com/andy4495/tlc591x/blob/main/README.md Methods for initializing the TLC591x object using either software or hardware SPI configurations. ```APIDOC ## Constructor Initialization ### Description Creates a TLC591x object to manage cascaded LED driver chips. Supports both software and hardware SPI. ### Parameters - **num_chips** (int) - Required - Number of cascaded chips (max 254). - **SDI_pin** (int) - Required (Software SPI) - Serial Data Input pin. - **CLK_pin** (int) - Required (Software SPI) - Clock pin. - **LE_pin** (int) - Required - Latch Enable pin. - **OE_pin** (int) - Optional - Output Enable pin. ### Request Example // Software SPI with OE control TLC591x myLED(num_chips, SDI_pin, CLK_pin, LE_pin, OE_pin); // Hardware SPI without OE control TLC591x myLED(num_chips, LE_pin); ``` -------------------------------- ### Adjusting Display Brightness with displayBrightness() Source: https://context7.com/andy4495/tlc591x/llms.txt Controls display brightness using PWM on the OE pin. This method requires the OE pin to be PWM-capable. A value of 0 represents the brightest setting, while 255 is the dimmest due to active-low logic. ```cpp #include TLC591x myLED(2, 5, 6, 7, 9); // OE pin 9 must be PWM-capable void setup() { myLED.displayEnable(); } void loop() { char s[3]; // Fade from bright to dim for (int brightness = 0; brightness <= 255; brightness += 16) { sprintf(s, "%2x", brightness); myLED.print(s); myLED.displayBrightness(brightness); // 0=brightest, 255=dimmest delay(500); } // Reset to maximum brightness myLED.displayBrightness(0); delay(1000); // Breathing effect for (int i = 0; i < 3; i++) { for (int b = 0; b < 255; b += 5) { myLED.displayBrightness(b); delay(20); } for (int b = 255; b > 0; b -= 5) { myLED.displayBrightness(b); delay(20); } } } ``` -------------------------------- ### Display Control Methods Source: https://github.com/andy4495/tlc591x/blob/main/README.md Methods for printing data to the displays and controlling individual LED segments. ```APIDOC ## void print(char* s) ### Description Prints ASCII characters to 7-segment displays. Assumes a specific mapping for segments A-G and DP. ### Parameters - **s** (char*) - Required - Array of characters to display. --- ## void printDirect(const uint8_t* b) ### Description Directly controls individual LED segments by shifting out raw byte data. ### Parameters - **b** (uint8_t*) - Required - Array of bytes to shift out. ``` -------------------------------- ### Include TLC591x Library Header Source: https://github.com/andy4495/tlc591x/blob/main/README.md Include the necessary header file to use the TLC591x library functions in your Arduino sketch. ```cpp #include ``` -------------------------------- ### Control Individual LEDs with Bitwise Output Source: https://context7.com/andy4495/tlc591x/llms.txt Uses the print(unsigned int n) method to shift raw bit values to the driver. This is ideal for controlling individual LEDs or bar graphs connected to the TLC591x outputs. ```cpp #include TLC591x myLED(2, 5, 6, 7, 9); // 2 chips = 16 LEDs void setup() { myLED.displayEnable(); } void loop() { for (unsigned int i = 0; i < 1024; i++) { myLED.print(i); delay(100); } myLED.print(0b0000000100000001); delay(1000); myLED.print(0xFF); delay(1000); myLED.print(0xFFFF); delay(1000); } ``` -------------------------------- ### Control Individual LEDs (Legacy) Source: https://github.com/andy4495/tlc591x/blob/main/README.md Shift a value bit-by-bit to control individual LEDs. This method is for backward compatibility and supports only one or two TLC591x chips. ```cpp void print(unsigned int n) ``` -------------------------------- ### Print ASCII Characters to 7-Segment Displays Source: https://github.com/andy4495/tlc591x/blob/main/README.md Control LEDs to display ASCII characters on 7-segment displays. The input is a char array representing characters for each chip. Assumes a specific pin-to-segment mapping. ```cpp void print(char* s) ``` -------------------------------- ### Direct LED Control with printDirect() Source: https://context7.com/andy4495/tlc591x/llms.txt Directly controls LED segments or individual LEDs by shifting out raw byte values. This method supports any number of cascaded TLC591x chips. The array element 0 is shifted out last. ```cpp #include TLC591x myLED(4, 5, 6, 7, 9); // 4 cascaded chips void setup() { myLED.displayEnable(); } void loop() { uint8_t data[4]; // Control 32 individual LEDs (4 chips x 8 outputs) data[0] = 0xFF; // Chip 4 - all LEDs on data[1] = 0x0F; // Chip 3 - lower 4 LEDs on data[2] = 0xF0; // Chip 2 - upper 4 LEDs on data[3] = 0xAA; // Chip 1 - alternating pattern myLED.printDirect(data); delay(1000); // Custom segment patterns for 7-segment display // Segment mapping: OUT0=DP, OUT1=A, OUT2=B, OUT3=C, OUT4=E, OUT5=G, OUT6=F, OUT7=D data[0] = 0x7B; // Display "0" data[1] = 0x30; // Display "1" data[2] = 0x6D; // Display "2" data[3] = 0x75; // Display "3" myLED.printDirect(data); delay(2000); } ``` -------------------------------- ### Disable Display Output Source: https://github.com/andy4495/tlc591x/blob/main/README.md Set the Output Enable (/OE) signal high to turn off the display. This method is only effective if the OE pin was defined during object initialization. ```cpp void displayDisable(); ``` -------------------------------- ### Control Display Brightness with PWM Source: https://github.com/andy4495/tlc591x/blob/main/README.md Control display brightness using PWM on the /OE pin. Requires a PWM-capable OE pin. A value of 0 is brightest, 255 is dimmest. This method enables the display. ```cpp void displayBrightness(byte b); ``` -------------------------------- ### Display ASCII Text on 7-Segment Displays Source: https://context7.com/andy4495/tlc591x/llms.txt Uses the print(const char* s) method to display ASCII characters. The library handles segment mapping automatically, allowing for static text, scrolling, and formatted numerical output. ```cpp #include TLC591x myLED(2, 5, 6, 7, 9); void setup() { myLED.displayEnable(); } void loop() { char text[9]; myLED.print("Hi"); delay(2000); memcpy(text, "Arduino ", 8); for (int i = 0; i < 7; i++) { myLED.print(&text[i]); delay(500); } int value = 42; sprintf(text, "%2d", value); myLED.print(text); delay(2000); } ``` -------------------------------- ### Display Enable/Disable Control Source: https://context7.com/andy4495/tlc591x/llms.txt Controls the output enable signal to turn the display on or off. This function is only effective when the OE pin is defined in the constructor. It allows for basic display power management. ```cpp #include TLC591x myLED(2, 5, 6, 7, 9); void setup() { // Display starts disabled when OE pin is used myLED.displayEnable(); // Turn on display } void loop() { myLED.print("On"); delay(2000); myLED.displayDisable(); // Turn off display delay(1000); myLED.displayEnable(); // Turn on display delay(1000); } ``` -------------------------------- ### Directly Control LEDs or Segments Source: https://github.com/andy4495/tlc591x/blob/main/README.md Directly control individual LEDs or segments of a 7-segment display by shifting an array of byte values. Values are shifted from right to left. ```cpp void printDirect(const uint8_t* b) ``` -------------------------------- ### Set TLC591x to Normal Mode Source: https://github.com/andy4495/tlc591x/blob/main/README.md Puts the TLC591x chip into Normal Mode. This is the default mode upon power-on. This method overrides brightness settings. ```cpp void normalMode(); ``` -------------------------------- ### Special Mode for Configuration Source: https://context7.com/andy4495/tlc591x/llms.txt Switches the TLC591x between Special Mode and Normal Mode. Special Mode allows writing to the Configuration Latch to adjust current gain. This requires the OE pin to be connected. Use `normalMode()` to return to standard operation. ```cpp #include TLC591x myLED(2, 5, 6, 7, 9); void setup() { myLED.displayEnable(); } void loop() { uint8_t config[2]; // Configure current gain using Special Mode // MSB must be 1, remaining 7 bits set brightness (0x80-0xFF) // Low brightness setting (0xA0 = 10100000) myLED.print("Lo"); delay(500); myLED.specialMode(); // Enter special mode (display disabled) config[0] = 0xA0; // ~25% brightness config[1] = 0xA0; myLED.printDirect(config); // Write to configuration latch myLED.normalMode(); // Return to normal mode (re-enables display) delay(2000); // Medium brightness setting (0xC0 = 11000000) myLED.print("Md"); delay(500); myLED.specialMode(); config[0] = 0xC0; // ~50% brightness config[1] = 0xC0; myLED.printDirect(config); myLED.normalMode(); delay(2000); // High brightness setting (0xE0 = 11100000) myLED.print("Hi"); delay(500); myLED.specialMode(); config[0] = 0xE0; // ~75% brightness config[1] = 0xE0; myLED.printDirect(config); myLED.normalMode(); delay(2000); // Maximum brightness setting (0xFF = 11111111) myLED.print("FF"); delay(500); myLED.specialMode(); config[0] = 0xFF; // 100% brightness (default) config[1] = 0xFF; myLED.printDirect(config); myLED.normalMode(); delay(2000); } ``` -------------------------------- ### Set TLC591x to Special Mode Source: https://github.com/andy4495/tlc591x/blob/main/README.md Puts the TLC591x chip into Special Mode. Requires the /OE signal to be connected and defined. The display is disabled in this mode, and the Configuration Latch can be written using printDirect(). ```cpp void specialMode(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.