Skip to content

Commit 1b7b376

Browse files
committed
Initial commit
0 parents  commit 1b7b376

File tree

10 files changed

+714
-0
lines changed

10 files changed

+714
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Arduino_APA102
2+
Drive rgb LEDs **APA102**, Serial LEDs connected with 2 pins.
3+
4+
# License
5+
6+
Copyright (c) 2020 Arduino SA. All rights reserved.
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2.1 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General Public
19+
License along with this library; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

docs/api.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# APA102 library
2+
3+
## Methods
4+
5+
### `Arduino_APA102(numLEDs, newDataPin , newClockPin)`
6+
7+
Attach the LEDs to the pins, and save the number of total LEDs.
8+
9+
#### Syntax
10+
11+
```
12+
Arduino_APA102 leds(totalLEDs, dataPin, clockPin);
13+
```
14+
15+
#### Parameters
16+
17+
* numLEDs : Amount of the LEDs to control
18+
* dataPin : Pin connected to SDI (DATA)
19+
* clockPin : Pîn connected to CKI (CLOCK)
20+
21+
22+
#### Example
23+
24+
```
25+
#include <Arduino_APA102.h>
26+
27+
Arduino_APA102 leds(5, 5, 4);
28+
29+
void setup() {}
30+
void loop() {}
31+
```
32+
33+
#### See also
34+
35+
* [begin()](#attached)
36+
* [setPixelColor()](#setPixelColor)
37+
* [show()](#show)
38+
39+
### `begin()`
40+
41+
Initialize the pins to control the devices attached.
42+
43+
#### Syntax
44+
45+
```
46+
leds.begin()
47+
```
48+
49+
#### Example
50+
51+
```
52+
#include <Arduino_APA102.h>
53+
54+
Arduino_APA102 leds(5, 5, 4);
55+
56+
void setup() {
57+
leds.begin();
58+
}
59+
void loop() {}
60+
```
61+
#### See also
62+
63+
* [setPixelColor()](#setPixelColor)
64+
* [show()](#show)
65+
* [end()](#end)
66+
67+
### `end()`
68+
69+
Disable the lines
70+
71+
#### Syntax
72+
73+
```
74+
leds.end()
75+
```
76+
77+
#### See also
78+
79+
* [begin()](#setPixelColor)
80+
81+
82+
### `setPixelColor()`
83+
84+
Saves the color value
85+
86+
#### Syntax
87+
88+
````
89+
leds.setPixelColor(indexLed, newColor)
90+
````
91+
92+
#### Parameters
93+
94+
* indexLed: LED index number
95+
* newColor: the value of the R G and B togetger i.e 0xFFFFFF(white) or 255,255,255 (int)
96+
97+
#### Example
98+
99+
```
100+
#include <Arduino_APA102.h>
101+
102+
Arduino_APA102 leds(5, 5, 4);
103+
104+
void setup() {
105+
leds.begin();
106+
}
107+
void loop() {
108+
leds.setPixelColor(0, 0xFF00FF);
109+
leds.setPixelColor(1, 255, 0, 255);
110+
leds.setPixelColor(2, 0, 0, 255);
111+
leds.show();
112+
}
113+
```
114+
115+
#### See also
116+
117+
* [fill()](#fill)
118+
* [setBrightness()](#setBrightness)
119+
* [show()](#show)
120+
121+
122+
### `fill()`
123+
124+
Write the color to a consecutive chain of LEDs, i.e from 4th count 5 then LEDs 4 to 9 will be saved with the same color.
125+
126+
#### Syntax
127+
128+
````
129+
leds.fill(newColor, startLed, count)
130+
````
131+
132+
#### Parameters
133+
134+
* newColor: color value see[Color](#Color)
135+
* startLed: Index to start counting
136+
* count: Forwarding LEDs that are going to be set.
137+
138+
#### See also
139+
140+
* [setPixelColor()](#setPixelColor)
141+
* [setBrightness()](#show)
142+
* [show()](#show)
143+
144+
### `setBrightness()`
145+
146+
Set the brightness of the LEDs, this scales the values that have been set by [setPixelColor()](#setPixelColor) and scale them by the percentage used in the parameter.
147+
148+
#### Syntax
149+
150+
```
151+
led.setBrightness(50)
152+
```
153+
154+
#### Parameters
155+
156+
* (optional) IndexLed: Choose one LED to change its value
157+
* newBrightness: Percentage amount to scale the color's values of the LEDs (0% - 100%)
158+
159+
160+
#### Example
161+
162+
```
163+
#include <Arduino_APA102.h>
164+
165+
Arduino_APA102 leds(5, 5, 4);
166+
167+
void setup() {
168+
leds.begin();
169+
170+
leds.setPixelColor(0, 0xFFFFFF);
171+
leds.setPixelColor(1, 0xFFFFFF);
172+
leds.show();
173+
delay(1000);
174+
}
175+
176+
void loop() {
177+
leds.setBrightness(50); //Set global brightness
178+
leds.show();
179+
delay(1000);
180+
181+
leds.setBrightness(0, 10); //Change LED 0 's brightness
182+
leds.show();
183+
delay(1000);
184+
}
185+
```
186+
187+
#### See also
188+
189+
* [setPixelColor()](#setPixelColor)
190+
* [setBrightness()](#show)
191+
* [show()](#show)
192+
193+
### `setCurrent()`
194+
195+
Control the internal PWM duty cycle of the LEDs, remember that this is not the same as brightness, with the same duty cycle you can have different brightness depending on the colors used.
196+
197+
Value from 0(min) to 31(max)
198+
199+
#### Syntax
200+
201+
```
202+
leds.setCurrent(31) //Global
203+
leds.setCurrent(0,31) //Individual
204+
```
205+
206+
#### Parameters
207+
* (optional)indexLed: LED to set
208+
* newCurrent: PWM duty cycle, from 0 to 31
209+
210+
#### See also
211+
212+
* [setPixelColor()](#setPixelColor)
213+
* [setBrightness()](#show)
214+
* [show()](#show)

docs/readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# APA102 RBG LEDs library
2+
3+
4+
This library allows an Arduino board to control the **APA102** RGB LEDs. This RGB devices can be controlled with 2 lines and the wiring is serial.
5+
6+
To use this library:
7+
8+
```
9+
#include <Arduino_APA102.h>
10+
11+
Arduino_APA102(totalLEDs, dataLine, ClockLine);
12+
```
13+
14+
## Circuit
15+
16+
Connect both SCK and SDA pins to a digital pin in your Arduino.
17+
18+
## Examples

examples/Fade/Fade.ino

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "Arduino_APA102.h"
2+
3+
int dataPin = 5;
4+
int clockPin = 4;
5+
int totalLEDs = 5;
6+
7+
// Construct object, Arduino_APA102(nLEDS, data line, clock line)
8+
Arduino_APA102 leds(totalLEDs, dataPin, clockPin);
9+
10+
uint32_t color = random(0, 0xFFFFFF); // 0x[R][G][B]
11+
//uint32_t color_white = leds.Color( 255 , 255 , 255); // Save yor color
12+
13+
void setup() {
14+
// put your setup code here, to run once:
15+
leds.begin();
16+
17+
leds.fill(color, 0, totalLEDs);
18+
leds.show();
19+
}
20+
21+
void loop() {
22+
// put your main code here, to run repeatedly:
23+
24+
int brightness = 0;
25+
26+
// ALL FADE
27+
// FADE IN
28+
for (brightness = 0; brightness < 101; brightness++ ) {
29+
leds.setBrightness(brightness);
30+
leds.show();
31+
delay(10);
32+
}
33+
// FADE OUT
34+
for (brightness = 100; brightness > -1; brightness-- ) {
35+
leds.setBrightness(brightness);
36+
leds.show();
37+
delay(10);
38+
}
39+
40+
//Change color
41+
color = random(0, 0xFFFFFF);
42+
leds.fill(color, 0, totalLEDs);
43+
44+
// INDIVIDUAL FADE
45+
for (int i = 0; i < totalLEDs; i++) {
46+
// FADE IN
47+
for (int brightness = 0; brightness < 101; brightness++) {
48+
leds.setBrightness(i , brightness);
49+
leds.show();
50+
}
51+
}
52+
53+
// INDIVIDUAL FADE
54+
for (int i = 0; i < totalLEDs; i++) {
55+
// FADE OUT
56+
for (int brightness = 100; brightness > -1; brightness--) {
57+
leds.setBrightness(i , brightness);
58+
leds.show();
59+
}
60+
}
61+
}

examples/Low_Power/Low_Power.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "Arduino_APA102.h"
2+
3+
int dataPin = 5;
4+
int clockPin = 4;
5+
int totalLEDs = 5;
6+
7+
// Construct object, Arduino_APA102(nLEDS, data line, clock line)
8+
Arduino_APA102 leds(totalLEDs, dataPin, clockPin);
9+
10+
//uint32_t color = random(0, 0xFFFFFF); // 0x[R][G][B]
11+
uint32_t color_red = leds.Color( 255 , 0 , 0); // Save yor color
12+
uint32_t color_blue = leds.Color( 0 , 255 , 0); // Save yor color
13+
uint32_t color_green = leds.Color( 0 , 0 , 255); // Save yor color
14+
15+
16+
int r = 0;
17+
int g = 100;
18+
int b = 250;
19+
20+
void setup() {
21+
// put your setup code here, to run once:
22+
leds.begin();
23+
24+
leds.setPixelColor(0 , color_red);
25+
leds.setPixelColor(1 , color_red);
26+
leds.setPixelColor(2 , color_green);
27+
leds.setPixelColor(3 , color_green);
28+
leds.setPixelColor(4 , color_blue);
29+
leds.show();
30+
31+
delay(2500);
32+
// Brigtness doesnt change the Max Current, you controll the PWM duty cycle of the APA102
33+
// With the same Max current set in 2 LEDs, you can see different phyisical brightness
34+
// depending on the use of each or combination of the internal rgb LEDs wich each APA102 component has
35+
// You can see the effect:
36+
//
37+
// Current can be set from 0-31
38+
// Brightness from 0% - 100%
39+
40+
leds.setCurrent(0,5);
41+
leds.setCurrent(1,31);
42+
leds.setCurrent(2,0);
43+
leds.setCurrent(3,1);
44+
leds.setCurrent(4,20);
45+
leds.show();
46+
}
47+
48+
void loop() {
49+
// put your main code here, to run repeatedly:
50+
51+
}

0 commit comments

Comments
 (0)