Fork me on GitHub!

Type APA102

struct APA102; /* Opaque */

Description

This type is used for many functions that need to write to the LED strip. It is obtained useing APA102_Init.

Type APA102_Animation

struct APA102_Animation; /* Opaque */

Description

This type is used to terminate any running animation using APA102_KillAnimation. It is the return value of every animation function.s

Type APA102_Frame

struct APA102 {
  uint8_t r, g, b, brightness;
};

Description

This type is used for every function that writes to the LED strip and contains the color and brightness for a single LED. It is obtained using APA102_CreateFrame.

Function APA102_Begin

void APA102_Begin(void);

Arguments

This function has no arguments

Return value

This function has no return value

Description

After calling this function, one can use APA102_WriteLED to send individual LED frames to the LED strip.

Function APA102_BlinkAnimation

struct APA102_Animation* APA102_BlinkAnimation(
  struct APA102* strip,
  struct APA102_Frame* led,
  int interval
);

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
led struct APA102_Frame* Color and brightness to use
interval int The blinking interval in milliseconds

Return value

The returned value contains a reference to the running animation. This reference can later be used to stop the animation from running using APA102_KillAnimation.

Description

Runs a monochrome blinking (on-and-off) animation on the LED strip using a separate thread using the given interval.

Function APA102_CreateFrame

struct APA102_Frame* APA102_CreateFrame(
  uint8_t brightness,
  uint8_t r,
  uint8_t g,
  uint8_t b
);

Arguments

Name Type Description
brightness uint8_t 5-bit integer (0-31) containing the brightness of the led
r uint8_t The red component of the color
g uint8_t The green component of the color
b uint8_t The blue component of the color

Return value

A LED frame containing color and brightness information. This type is required for every function that write to the LED strip.

Description

Creates a LED frame which is needed for every function that writes to the LED strip.

Function APA102_End

void APA102_End(void);

Arguments

This function has no arguments

Return value

This function has no return value

Description

This function must be called after APA102_Begin and multiple APA102_WriteLED calls to end the led-by-led write to the strip.

Function APA102_FadeAnimation

struct APA102_Animation* APA102_FadeAnimation(
  struct APA102* strip,
  struct APA102_Frame** leds,
  int interval
)

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
leds struct APA102_Frame** Array containing colors and brightnesses to use
interval int The animation interval in milliseconds, dividable by 10

Return value

The returned value contains a reference to the running animation. This reference can later be used to stop the animation from running using APA102_KillAnimation.

Description

Creates a cycling color fade which fades through the colors and brightnesses provided in the leds argument. A new color is reached every interval milliseconds. interval must be dividable by 10

Function APA102_Fill

void APA102_Fill(
  struct APA102* strip,
  struct APA102_Frame* led
);

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
led struct APA102_Frame* Color and brightness to use

Return value

This function has no return value

Description

This function sets all LEDs in the LED strip to the given LED frame value.

Function APA102_Init

struct APA102* APA102_Init(
  int n_leds
);

Arguments

Name Type Description
n_leds int The number of LEDs the LED strip contains

Return value

This function returns a reference to the LED strip, which is needed for many functions that write to it.

Function APA102_KillAnimation

void APA102_KillAnimation(
  struct APA102_Animation* anim
);

Arguments

Name Type Description
anim struct APA102_Animation* The animation to kill

Return value

This function has no return value

Description

Stops a running animation. This might take some time as these animations need to quit from their loops and they only check when they are active (not when they are waiting), so the maximum time is the specified interval to the animation.

Function APA102_MultiStripes

void APA102_MultiStripes(
  struct APA102* strip,
  struct APA102_Frame** leds,
  int stripe_size,
  int gap_size,
  int offset,
  int coffset
);

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
leds struct APA102_Frame** Array containing colors and brightnesses to use
stripe_size int The size of each stripe
gap_size int The size of the gaps between the stripes
offset int The offset of the stripes from the start of the strip
coffset int The offset of the colors from the first stripe

Return value

This function has no return value

Description

This function writes multi-colored stripes to the LED strip in the color pattern contained in leds, which is a NULL-terminated array of APA102_Frames. offset and coffset are mainly used for animation purposes.

Function APA102_MultiStripesAnimation

struct APA102_Animation* APA102_MultiStripesAnimation(
  struct APA102* strip,
  struct APA102_Frame** leds,
  int interval,
  int stripe_size,
  int gap_size,
  int direction
)

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
leds struct APA102_Frame** Array containing colors and brightnesses to use
interval int The animation interval in milliseconds
stripe_size int The size of each stripe
gap_size int The size of the gaps between the stripes
direction int The direction of the animation (-1: outwards, 1: inwards)

Return value

The returned value contains a reference to the running animation. This reference can later be used to stop the animation from running using APA102_KillAnimation.

Description

Creates an animation of multistripes with changing offsets, creating a ‘walking’-illusion. A direction of -1 means that the ‘walking’ will happen from the first to the last LED, a value of 1 will have the reverse effect.

Function APA102_PulseAnimation

struct APA102_Animation* APA102_PulseAnimation(
  struct APA102* strip,
  struct APA102_Frame* led,
  int interval
);

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
led struct APA102_Frame* Color to use (brightness is ignored)
interval int The interval of brightness changes

Return value

The returned value contains a reference to the running animation. This reference can later be used to stop the animation from running using APA102_KillAnimation.

Description

Runs a monochrome pulsing (brightness) animation on the LED strip using a separate thread using the given interval.

Function APA102_Stripes

void APA102_Stripes(
  struct APA102* strip,
  struct APA102_Frame* led,
  int stripe_size,
  int gap_size,
  int offset,
);

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
led struct APA102_Frame* Color and brightness to use
stripe_size int The size of each stripe
gap_size int The size of the gaps between the stripes
offset int The offset of the stripes from the start of the strip

Return value

This function has no return value

Description

This function writes monochrome stripes to the LED strip in the color and brightness provided. offset and coffset are mainly used for animation purposes.

Function APA102_StripesAnimation

struct APA102_Animation* APA102_StripesAnimation(
  struct APA102* strip,
  struct APA102_Frame* led,
  int interval,
  int stripe_size,
  int gap_size,
  direction
)

Arguments

Name Type Description
strip struct APA102* Reference to the strip object to use
leds struct APA102_Frame* Color and brightness to use
interval int The animation interval in milliseconds
stripe_size int The size of each stripe
gap_size int The size of the gaps between the stripes
direction int The direction of the animation (-1: outwards, 1: inwards)

Return value

The returned value contains a reference to the running animation. This reference can later be used to stop the animation from running using APA102_KillAnimation.

Description

Creates an animation of stripes with changing offsets, creating a ‘walking’-illusion. A direction of -1 means that the ‘walking’ will happen from the first to the last LED, a value of 1 will have the reverse effect.

Function APA102_WriteLED

void APA102_WriteLED(
  struct APA102_Frame* led
);

Arguments

Name Type Description
led struct APA102_Frame* The color and brightness to write

Return value

This function has no return value

Description

Writes a single LED to the strip. This function must be used in conjunction with APA102_Begin and APA102_End.