Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

LED Strip HAL

Data Private to this module:

LED_t LeftDrum_Strip[NUMDrum]: buffer for left drum LEDs

LED_t RightDrum_Strip[NUMDrum]: buffer for right drum LEDs

LED_t BottomDrum_Strip[NUMDrum]: buffer for bottom drum LEDs

LED_t Clock_Strip[NUMClock]: buffer for clock LEDs

LED_t * pLEDStrip: pointer to the LED strip array

uint8_t NumLEDs: pointer to the number of LEDs in the array

uint32_t ZEROS = 0: start frame

uint32_t EndFrame = 0x11111111: end frame

// --------------------------------------------------------------------

This function clears the buffer of the chosen LED strip

Input: WhichStrip: Which LED strip to clear

Output: True if this function successfully clears the strip

// --------------------------------------------------------------------

bool Clear_Strip(WhichStrip)

select the proper LED array

create the default cleared LEDs

loop through selected strip

set LED to cleared LED with minimum brightness

// --------------------------------------------------------------------
This function sets the color of a single LED in an LED strip

Input: WhichStrip: Which LED strip to set the color of

WhichColor: Which color to set to

WhichLED: LED number in the strip

Output: True if this function successfully sets the color

// --------------------------------------------------------------------

bool Set_Single_Color(WhichStrip, WhichColor, WhichLED) {

if No Drum is passed as the strip

return false

select the proper LED array

if the LED number is less than 1 or greater than the number of LEDs

return false

red = place holder for red value

green = place holder for green value

blue = place holder for blue value

switch on Color

case Red:

set red, green, blue to appropriate values

break;

case Green:

set red, green, blue to appropriate values

break;
case Blue:

set red, green, blue to appropriate values

break;

case Purple:

set red, green, blue to appropriate values

break;

case White:

set red, green, blue to appropriate values

break;

case Yellow:

set red, green, blue to appropriate values

break;

case Turquoise:

set red, green, blue to appropriate values

break;

case Pink:

set red, green, blue to appropriate values

break;

case Gold:

set red, green, blue to appropriate values

break;

default:
set red, green, blue to 0

break;

set red byte on chosen LED to red

set green byte on chosen LED to green

set blue byte on chosen LED to blue

// --------------------------------------------------------------------

This function sets the color of all the LEDs in an LED strip

Input: WhichStrip: Which LED strip to set the color of

WhichColor: Which color to set to

Output: True if this function successfully sets the color

// --------------------------------------------------------------------

bool Set_All_Color(WhichStrip, WhichColor){

if No Drum is passed as the strip

return false

select the proper LED array

red = place holder for red value

green = place holder for green value

blue = place holder for blue value

switch on Color

case Red:
set red, green, blue to appropriate values

break;

case Green:

set red, green, blue to appropriate values

break;

case Blue:

set red, green, blue to appropriate values

break;

case Purple:

set red, green, blue to appropriate values

break;

case White:

set red, green, blue to appropriate values

break;

case Yellow:

set red, green, blue to appropriate values

break;

case Turquoise:

set red, green, blue to appropriate values

break;

case Pink:

set red, green, blue to appropriate values


break;

case Gold:

set red, green, blue to appropriate values

break;

default:

set red, green, blue to 0

break;

loop through all LEDs in chosen strip

set red byte to red

set green byte to green

set blue byte to blue

// --------------------------------------------------------------------

This function sets the intensity of all the LEDs in a strip

Input: WhichStrip: Which LED strip to set the intensity of

WhichIntensity: What intensity to set the strip to

Output: True if this function successfully sets the intensity

// --------------------------------------------------------------------

bool Set_Intensity(WhichStrip, intensity) {

select the proper LED array

if intensity is less than 0 or greater than 31

return false
loop through selected strip

set each LED in the strip to passed brightness value

return true;

// --------------------------------------------------------------------

This function writes the contents of the buffer to the LED strip

Input: WhichStrip: Which LED strip to write to

Output: True once this function is done writing to the LEDs

False if this function still has to write to the LEDs

// --------------------------------------------------------------------

bool TakeDisplayUpdateStep(WhichStrip)

return value is false

LED index = 0

select the proper LED array

if first index send the zero frame

SPI send 32 zero frame

SPI send 32 the first LED

increment LED index

if we have sent the last LED value to the strip

SPI send 32 end frame

return value is true


reset LED index

short for loop delay to give LEDs time to update

return the return value

// --------------------------------------------------------------------

This function sets internal pointers to the appropriate LED strip values

Input: WhichStrip: Which LED strip to point to

Output: N/A

// --------------------------------------------------------------------

static void selectLEDStrip(WhichLED) {

if left drum

set LED strip pointer to left drum array

number of LEDs = number of left drum LEDs

else if right drum

set LED strip pointer to right drum array

number of LEDs = number of right drum LEDs

else if bottom drum

set LED strip pointer to bottom drum array

number of LEDs = number of bottom drum LEDs

else if clock LEDs

set LED strip pointer to clock array


number of LEDs = number of clock LEDs

You might also like