Adafruit IS31FL3741 Library
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Adafruit_IS31FL3741 Class Reference

Class for Lumissil IS31FL3741 LED driver. This is the base class upon which the rest of this code builds. It focuses on lowest- level I2C operations and the chip registers, and has no concept of a 2D graphics coordinate system, nor of RGB colors. It is linear and monochromatic. More...

#include <Adafruit_IS31FL3741.h>

Inheritance diagram for Adafruit_IS31FL3741:
Adafruit_IS31FL3741_buffered Adafruit_IS31FL3741_colorGFX Adafruit_IS31FL3741_colorGFX_buffered Adafruit_EyeLights Adafruit_IS31FL3741_EVB Adafruit_IS31FL3741_QT Adafruit_EyeLights_buffered Adafruit_IS31FL3741_EVB_buffered Adafruit_IS31FL3741_QT_buffered

Public Member Functions

 Adafruit_IS31FL3741 ()
 Constructor for IS31FL3741 LED driver.
 
bool begin (uint8_t addr=IS3741_ADDR_DEFAULT, TwoWire *theWire=&Wire)
 Initialize I2C and IS31FL3741 hardware. More...
 
bool reset (void)
 Perform software reset, update all registers to POR values. More...
 
bool enable (bool en)
 Enable/disable output via the shutdown register bit. More...
 
bool unlock (void)
 Allows changing of command register by writing 0xC5 to 0xFE. More...
 
bool setGlobalCurrent (uint8_t current)
 Set global current-mirror from 0 (off) to 255 (brightest). More...
 
uint8_t getGlobalCurrent (void)
 Get the global current-mirror register setting. More...
 
bool setLEDscaling (uint16_t lednum, uint8_t scale)
 Set the scaling level for a single LED. More...
 
bool setLEDscaling (uint8_t scale)
 Set the scaling level for all LEDs. Optimized for fewer I2C transfers vs. setting each individually. More...
 
bool setLEDPWM (uint16_t lednum, uint8_t pwm)
 Set the PWM level for a single LED. More...
 
bool fill (uint8_t fillpwm=0)
 Set the PWM value for all LEDs - great for clearing the whole display at once. Optimized for fewer I2C transfers vs. setting each individually. More...
 
void show (void)
 Empty function makes direct & buffered code more interchangeable. Direct classes have an immediate effect when setting LED states, only buffered ones need an explicit call to show(), but it gets annoying when moving code back and forth. So this does nothing in the direct case. For code that you KNOW will always be strictly unbuffered, don't call this, it sets a bad precedent.
 

Static Public Member Functions

static uint16_t color565 (uint8_t red, uint8_t green, uint8_t blue)
 Converter for RGB888-format color (separate) to RGB565-format. More...
 
static uint16_t color565 (uint32_t color)
 Converter for RGB888-format color (packed) to RGB565-format. More...
 
static uint32_t Color (uint8_t r, uint8_t g, uint8_t b)
 Convert separate red, green and blue values into a single "packed" 24-bit RGB color. More...
 
static uint8_t gamma8 (uint8_t x)
 An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions appear more perceptially correct. More...
 
static uint32_t gamma32 (uint32_t x)
 A gamma-correction function for 32-bit packed RGB colors. Makes color transitions appear more perceptially correct. More...
 
static uint32_t ColorHSV (uint16_t hue, uint8_t sat=255, uint8_t val=255)
 Convert hue, saturation and value into a packed 32-bit RGB color that can be passed to setPixelColor() or Color565(). Swiped directly from Adafruit_NeoPixel. More...
 

Protected Member Functions

bool selectPage (uint8_t page)
 Select a given bank/page in the chip memory for subsequent reads/writes. More...
 
bool setLEDvalue (uint8_t first_page, uint16_t lednum, uint8_t value)
 Set either the PWM or scaling level for a single LED; used by the setLEDPWM() and setLEDscaling() functions, not directly. More...
 
bool fillTwoPages (uint8_t first_page, uint8_t value)
 Fill two pages of IS31FL3741 registers related to PWM levels or scaling; used by the fill() and setLEDscaling() functions, not directly. More...
 

Protected Attributes

int8_t _page = -1
 Cached value of the page we're currently addressing.
 
Adafruit_I2CDevice * _i2c_dev = NULL
 Pointer to I2C device.
 

Detailed Description

Class for Lumissil IS31FL3741 LED driver. This is the base class upon which the rest of this code builds. It focuses on lowest- level I2C operations and the chip registers, and has no concept of a 2D graphics coordinate system, nor of RGB colors. It is linear and monochromatic.

Member Function Documentation

◆ begin()

bool Adafruit_IS31FL3741::begin ( uint8_t  addr = IS3741_ADDR_DEFAULT,
TwoWire *  theWire = &Wire 
)

Initialize I2C and IS31FL3741 hardware.

Parameters
addrI2C address where we expect to find the chip.
theWirePointer to TwoWire I2C bus to use, defaults to &Wire.
Returns
true on success, false if chip isn't found.

◆ reset()

bool Adafruit_IS31FL3741::reset ( void  )

Perform software reset, update all registers to POR values.

Returns
true if I2C command acknowledged, false on error.

◆ enable()

bool Adafruit_IS31FL3741::enable ( bool  en)

Enable/disable output via the shutdown register bit.

Parameters
entrue to enable, false to disable.
Returns
true if I2C command acknowledged, false on error.

◆ unlock()

bool Adafruit_IS31FL3741::unlock ( void  )

Allows changing of command register by writing 0xC5 to 0xFE.

Returns
true if I2C command acknowledged, false on error.

◆ setGlobalCurrent()

bool Adafruit_IS31FL3741::setGlobalCurrent ( uint8_t  current)

Set global current-mirror from 0 (off) to 255 (brightest).

Parameters
current8-bit level, 0 to 255.
Returns
true if I2C command acknowledged, false on error.

◆ getGlobalCurrent()

uint8_t Adafruit_IS31FL3741::getGlobalCurrent ( void  )

Get the global current-mirror register setting.

Returns
0 (off) to 255 (brightest)

◆ setLEDscaling() [1/2]

bool Adafruit_IS31FL3741::setLEDscaling ( uint16_t  lednum,
uint8_t  scale 
)

Set the scaling level for a single LED.

Parameters
lednumThe individual LED to set: 0 to 350.
scaleLevel from 0 to 255.
Returns
true if I2C command acknowledged, false if LED index is out of range or if I2C error.
Note
This refers to individual LED registers as controlled by the driver, not RGB pixels – that's a different thing handled in subclasses as needed.

◆ setLEDscaling() [2/2]

bool Adafruit_IS31FL3741::setLEDscaling ( uint8_t  scale)

Set the scaling level for all LEDs. Optimized for fewer I2C transfers vs. setting each individually.

Parameters
scaleLevel from 0 to 255.
Returns
true if I2C transfers completed successfully, false on error.

◆ setLEDPWM()

bool Adafruit_IS31FL3741::setLEDPWM ( uint16_t  lednum,
uint8_t  pwm 
)

Set the PWM level for a single LED.

Parameters
lednumThe individual LED to set: 0 to 350.
pwmLevel from 0 to 255.
Returns
true if I2C command acknowledged, false if LED index is out of range or if I2C error.
Note
This refers to individual LED registers as controlled by the driver, not RGB pixels – that's a different thing handled in subclasses as needed.

◆ fill()

bool Adafruit_IS31FL3741::fill ( uint8_t  fillpwm = 0)

Set the PWM value for all LEDs - great for clearing the whole display at once. Optimized for fewer I2C transfers vs. setting each individually.

Parameters
fillpwmPWM level from 0 to 255, default is 0 (off).
Returns
true if I2C transfers completed successfully, false on error.

◆ color565() [1/2]

static uint16_t Adafruit_IS31FL3741::color565 ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)
inlinestatic

Converter for RGB888-format color (separate) to RGB565-format.

Parameters
red8-bit red value.
green8-bit green value.
blue8-bit blue value.
Returns
Packed 16-bit RGB565 color.
Note
Yes, the name is unfortunate – have lowercase color565() here, and uppercase Color and ColorHSV() later. This is for compatibility with existing code from Adafruit_GFX and Adafruit_NeoPixel, which were separately developed and used differing cases. The idea here is to help re-use existing Arduino sketch code from other projects, so don't "fix" this.

◆ color565() [2/2]

static uint16_t Adafruit_IS31FL3741::color565 ( uint32_t  color)
inlinestatic

Converter for RGB888-format color (packed) to RGB565-format.

Parameters
color24-bit value (0x00RRGGBB)
Returns
Packed 16-bit RGB565 color (0bRRRRRGGGGGGBBBBB)
Note
See notes above re: naming.

◆ Color()

static uint32_t Adafruit_IS31FL3741::Color ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inlinestatic

Convert separate red, green and blue values into a single "packed" 24-bit RGB color.

Parameters
rRed brightness, 0 to 255.
gGreen brightness, 0 to 255.
bBlue brightness, 0 to 255.
Returns
Packed RGB value, which can then be assigned to a variable for later use or passed to the setPixelColor() function in some subclasses. Packed RGB format is predictable (0x00RRGGBB), regardless of LED color order.

◆ gamma8()

static uint8_t Adafruit_IS31FL3741::gamma8 ( uint8_t  x)
inlinestatic

An 8-bit gamma-correction function for basic pixel brightness adjustment. Makes color transitions appear more perceptially correct.

Parameters
xInput brightness, 0 (minimum or off/black) to 255 (maximum).
Returns
Gamma-adjusted brightness, can then be passed to one of the setPixelColor() functions. This uses a fixed gamma correction exponent of 2.6, which seems reasonably okay for average RGB LEDs in average tasks. If you need finer control you'll need to provide your own gamma-correction function instead.
Note
Copied from Adafruit_NeoPixel, only the table name changed.

◆ gamma32()

uint32_t Adafruit_IS31FL3741::gamma32 ( uint32_t  x)
static

A gamma-correction function for 32-bit packed RGB colors. Makes color transitions appear more perceptially correct.

Parameters
xPacked RGB color.
Returns
Gamma-adjusted packed color, can then be passed in one of the setPixelColor() functions. Like gamma8(), this uses a fixed gamma correction exponent of 2.6, which seems reasonably okay for average NeoPixels in average tasks. If you need finer control you'll need to provide your own gamma-correction function instead.

◆ ColorHSV()

uint32_t Adafruit_IS31FL3741::ColorHSV ( uint16_t  hue,
uint8_t  sat = 255,
uint8_t  val = 255 
)
static

Convert hue, saturation and value into a packed 32-bit RGB color that can be passed to setPixelColor() or Color565(). Swiped directly from Adafruit_NeoPixel.

Parameters
hueAn unsigned 16-bit value, 0 to 65535, representing one full loop of the color wheel, which allows 16-bit hues to "roll over" while still doing the expected thing (and allowing more precision than the wheel() function that was common to prior NeoPixel examples).
satSaturation, 8-bit value, 0 (min or pure grayscale) to 255 (max or pure hue). Default of 255 if unspecified.
valValue (brightness), 8-bit value, 0 (min / black / off) to 255 (max or full brightness). Default of 255 if unspecified.
Returns
Packed 32-bit RGB with the most significant byte set to 0. Result is linearly but not perceptually correct, so you may want to pass the result through a gamma function.
Note
Yes, the name is unfortunate – have uppercase ColorHSV() here, and lowercase color565() elsewhere. This is for compatibility with existing code from Adafruit_NeoPixel amd Adafruit_GFX, which were separately developed and used differing cases. The idea here is to help re-use existing Arduino sketch code, so don't "fix."

◆ selectPage()

bool Adafruit_IS31FL3741::selectPage ( uint8_t  page)
protected

Select a given bank/page in the chip memory for subsequent reads/writes.

Parameters
pageThe IS41 page to switch to (0 to 4).
Returns
true if I2C command acknowledged, false on invalid page or I2C error.

◆ setLEDvalue()

bool Adafruit_IS31FL3741::setLEDvalue ( uint8_t  first_page,
uint16_t  lednum,
uint8_t  value 
)
protected

Set either the PWM or scaling level for a single LED; used by the setLEDPWM() and setLEDscaling() functions, not directly.

Parameters
first_pageDetermines whether scaling or PWM will be set: 0 for PWM, 2 for scaling.
lednumThe individual LED to set: 0 to 350.
valuePWM or scaling value from 0 to 255.
Returns
true if I2C command acknowledged, false if LED index is out of range or if I2C error.
Note
This refers to individual LED registers as controlled by the driver, not RGB pixels – that's a different thing handled in subclasses as needed.

◆ fillTwoPages()

bool Adafruit_IS31FL3741::fillTwoPages ( uint8_t  first_page,
uint8_t  value 
)
protected

Fill two pages of IS31FL3741 registers related to PWM levels or scaling; used by the fill() and setLEDscaling() functions, not directly.

Parameters
first_pageFirst of two successive pages to fill; usually 0 or 2.
valueSetting from 0 to 255.
Returns
true if I2C transfers completed successfully, false on error.

The documentation for this class was generated from the following files: