|
| 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) |
0 commit comments