Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
apa102 Class Reference
APA102 class, controlling LED strips or arrays like this http://www.sparkfun.com/products/10312. More...
#include <apa102.h>
Public Member Functions | |
| apa102 (PinName CKI, PinName SDI, int STRIP_LENGTH=32, int reset_delay=800) | |
| Create a new apa102 object. | |
| void | post (int *strip_colors) |
| write RGB color data to strip or array | |
| void | clear (void) |
| clears the array or strip (all off) | |
| int | level (int level=0) |
| set level of the entire array 0-100% | |
| int | delay (uint32_t reset_delay=100) |
| get/set reset/write delay | |
Detailed Description
APA102 class, controlling LED strips or arrays like this http://www.sparkfun.com/products/10312.
the APA102 IC's are 5V but works well connected directly to mbed IO pins.
You need a 5V power supply capable of about 2A to light up a 32 led strip, do NOT power from mbed(usb).
the required reset delay is a blocking wait(), it can be lowered (or set to 0) if you want to use the time for executing code instead, data sheet says 500us but i found it need at least 800us.
Example:
#include "mbed.h" #include "apa102.h" #define STRIP_LENGTH 32 apa102 mystrip(p9, p10, STRIP_LENGTH); int dir=1, level=10; int rainbow[] = {0xff00ff,0xff00cc,0xff0099,0xff0066,0xff0033,0xff0000,0xff3300,0xff6600, 0xff9900,0xffcc00,0xffff00,0xccff00,0x99ff00,0x66ff00,0x33ff00,0x00ff00, 0x00ff33,0x00ff66,0x00ff99,0x00ffcc,0x00ffff,0x00ccff,0x0099ff,0x0066ff, 0x0033ff,0x0000ff,0x3300ff,0x6600ff,0x9900ff,0xcc00ff,0x9900ff,0x6600ff }; void move(void){ int temp = rainbow[31]; for (int x = (STRIP_LENGTH - 1) ; x > 0 ; x--) rainbow[x] = rainbow[x - 1]; rainbow[0] = temp; } void pulse(void){ if(dir) { mystrip.level(level+=2); if(level >= 100)dir = 0; } else if(!dir) { mystrip.level(level--); if(level <= 5)dir = 1; } } int main() { mystrip.level(level); while(1) { move(); pulse(); mystrip.post(rainbow); wait_ms(100); } }
Definition at line 87 of file apa102.h.
Constructor & Destructor Documentation
| apa102 | ( | PinName | CKI, |
| PinName | SDI, | ||
| int | STRIP_LENGTH = 32, |
||
| int | reset_delay = 800 |
||
| ) |
Create a new apa102 object.
- Parameters:
-
CKI clock pin SDI data pin STRIP_LENGTH number of apa102 IC's i strip or array defaults to 32 reset_delay delay in us to allow latching data defaults to 800
- Returns:
- nothing
Definition at line 7 of file apa102.cpp.
Member Function Documentation
| void clear | ( | void | ) |
clears the array or strip (all off)
Definition at line 29 of file apa102.cpp.
| int delay | ( | uint32_t | reset_delay = 100 ) |
get/set reset/write delay
mainly for experimenting with reset values without recompiling, leave at default to begin with & then lower to get faster execution.
- Parameters:
-
delay delay in us
- Returns:
- delay in us
Definition at line 46 of file apa102.cpp.
| int level | ( | int | level = 0 ) |
set level of the entire array 0-100%
at low levels the colors may change because R,G or B reaches 0.
- Parameters:
-
level level in percent
- Returns:
- current level
Definition at line 35 of file apa102.cpp.
| void post | ( | int * | strip_colors ) |
write RGB color data to strip or array
color data for each LED is 3 bytes int the order of rrggbb. array must have STRIP_LENGTH number of elements
- Parameters:
-
strip_colors array of color data
Definition at line 15 of file apa102.cpp.
Generated on Thu Jul 14 2022 22:02:19 by
1.7.2