This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

PCA9632

LED Driver
    This is the LED driver used in NOTICE PAL.

    Processing Flow

    1. Wire.begin(): Initialize the bus
    2. .setup(): Initialize the class object
    3. .reset(): Initialize the driver
    4. Execute various operations

    About PCA9632

    It is a 4-channel LED driver.

    • Each channel can be set to OFF, ON, PWM, or BLINK mode
    • Each channel supports independent brightness control via PWM
    • All channels set to blink will share the same blink pattern
    • Individual brightness control (via PWM) is available even in blink mode

    Required Procedures for Operation

    Wire Bus

    Ensure the Wire is initialized via Wire.begin() before calling the setup() method.

    Procedure Upon Wake from Sleep

    Ensure the Wire bus is active right before entering sleep (Wire will be automatically recovered after waking up).

    Code Example

    ##include <TWELITE>
    ##include <SNS_PCA9632>
    
    SNS_PCA9632 pca;

    Include #include <SNS_PCA9632> and declare an instance of the SNS_PCA9632 class.

    Initialization & Reset

    void setup() {
        Wire.begin();
        pca.setup();
        pca.reset();
    }

    Lighting Up

    ...
       pca.set_led_duty_all(
          127,
          127,
          127,
          127
       );
    
       pca.set_led_status(
          SNS_PCA9632::LED_PWM,
          SNS_PCA9632::LED_NOP,
          SNS_PCA9632::LED_PWM,
          SNS_PCA9632::LED_NOP);

    In the example above, LED1 and LED3 are lit using PWM control.

    Methods

    Constructor, setup()

    SnsPCA9632(uint8_t i2c_addr = DEFAULT_I2C_ADDRESS)
    void setup(uint8_t i2c_addr = DEFAULT_I2C_ADDRESS)

    The constructor allows specifying the i2c_addr.

    If the class object is defined globally, the constructor is not called automatically, so ensure to call setup().

    reset()

    bool reset()

    Initializes the device.

    Writes the following values to registers starting at address 0x0: {0x81, 0x35, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x0B, 0x00}

    set_mode2()

    bool set_mode2(uint8_t u8var = 0x35)

    Writes the specified value to the MODE2 register.

    set_power_mode()

    bool set_power_mode(bool b_pow_on)

    Set b_pow_on to true for normal operation, or false to enter sleep mode.

    bool set_blink_cycle(uint8_t u8var)
    bool set_blink_cycle_ms(uint16_t u16ms)

    Sets the blink (group PWM) cycle.

    If u8var is specified, the cycle is (u8var+1)/24 seconds.

    If u16ms is specified, it sets the cycle in milliseconds.

    bool set_blink_duty(uint8_t u8duty);

    Sets the duty ratio of the blink (group PWM). The lit duration becomes u8duty/256, where 0 is OFF and 255 is fully ON.

    set_led_duty()

    bool set_led_duty(uint8_t port, uint8_t duty)

    Sets the brightness (PWM duty ratio).

    port specifies the target LED (SNS_PCA9632::LED1..4).

    duty specifies a value from 0 to 255, with a brightness ratio of duty/256.

    set_led_duty_all()

    bool set_led_duty_all(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4)

    Sets the brightness (PWM duty ratio) for all LEDs.

    p1, p2, p3, p4 correspond to LED1..4. Each takes a value from 0 to 255, with a brightness ratio of duty/256.

    set_led_status()

    bool set_led_status(uint8_t u8led1, uint8_t u8led2, uint8_t u8led3, uint8_t u8led4)

    Sets the ON/OFF status for all LEDs.

    u8led1..4 specify the state of LED1 to LED4.

    Available states:

    Description
    SNS_PCA9632::LED_OFFOFF
    SNS_PCA9632::LED_ONON
    SNS_PCA9632::LED_PWMPWM brightness control
    SNS_PCA9632::LED_BLINKBlink control (group PWM)
    SNS_PCA9632::LED_NOPDo not change the current state

    probe()

    bool probe()

    Returns true if the device is present on the I2C bus.

    show_registers()

    void show_registers()

    Displays values of registers (0x0–0x8).