A library for SPI control of adafruit's neopixel ring and addressable LEDs.

Dependencies:   PixelArray

Dependents:   TI_NEOPIXEL_SPI_SAMPLE

Committer:
tichise
Date:
Thu Jan 02 14:22:55 2020 +0000
Revision:
4:70bc3528e07e
Parent:
3:f0859c280204
add LED pattern

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tichise 0:c28aa7d4f97e 1 #include "TI_NEOPIXEL_SPI.h"
tichise 0:c28aa7d4f97e 2 #include "mbed.h"
tichise 0:c28aa7d4f97e 3
tichise 3:f0859c280204 4 TI_NEOPIXEL_SPI::TI_NEOPIXEL_SPI(PinName input) : _neoPixel(input)
tichise 0:c28aa7d4f97e 5 {
tichise 0:c28aa7d4f97e 6 }
tichise 0:c28aa7d4f97e 7
tichise 0:c28aa7d4f97e 8 void TI_NEOPIXEL_SPI::switchLightOff(int count)
tichise 0:c28aa7d4f97e 9 {
tichise 0:c28aa7d4f97e 10
tichise 3:f0859c280204 11 Pixel pixels[count];
tichise 0:c28aa7d4f97e 12
tichise 0:c28aa7d4f97e 13 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 14 {
tichise 3:f0859c280204 15 pixels[i].r = 0;
tichise 3:f0859c280204 16 pixels[i].g = 0;
tichise 3:f0859c280204 17 pixels[i].b = 0;
tichise 0:c28aa7d4f97e 18 }
tichise 0:c28aa7d4f97e 19
tichise 3:f0859c280204 20 _neoPixel.send(pixels, count);
tichise 0:c28aa7d4f97e 21 }
tichise 0:c28aa7d4f97e 22
tichise 3:f0859c280204 23 void TI_NEOPIXEL_SPI::switchLightOn(int count, int startCount, int endCount, rgbColor rgbColor)
tichise 0:c28aa7d4f97e 24 {
tichise 3:f0859c280204 25 Pixel pixels[count];
tichise 0:c28aa7d4f97e 26
tichise 0:c28aa7d4f97e 27 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 28 {
tichise 3:f0859c280204 29 if (startCount <= i && i < endCount)
tichise 3:f0859c280204 30 {
tichise 3:f0859c280204 31 pixels[i].r = rgbColor.red;
tichise 3:f0859c280204 32 pixels[i].g = rgbColor.green;
tichise 3:f0859c280204 33 pixels[i].b = rgbColor.blue;
tichise 3:f0859c280204 34 }
tichise 3:f0859c280204 35 else
tichise 3:f0859c280204 36 {
tichise 3:f0859c280204 37 pixels[i].r = 0;
tichise 3:f0859c280204 38 pixels[i].g = 0;
tichise 3:f0859c280204 39 pixels[i].b = 0;
tichise 2:0148ac5c90fa 40 }
tichise 0:c28aa7d4f97e 41 }
tichise 0:c28aa7d4f97e 42
tichise 3:f0859c280204 43 _neoPixel.send(pixels, count);
tichise 0:c28aa7d4f97e 44 }
tichise 0:c28aa7d4f97e 45
tichise 2:0148ac5c90fa 46 void TI_NEOPIXEL_SPI::changeColor(int count, int startCount, int endCount, rgbColor rgbColor)
tichise 0:c28aa7d4f97e 47 {
tichise 3:f0859c280204 48 Pixel pixels[count];
tichise 0:c28aa7d4f97e 49
tichise 0:c28aa7d4f97e 50 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 51 {
tichise 3:f0859c280204 52 if (startCount <= i && i < endCount)
tichise 3:f0859c280204 53 {
tichise 3:f0859c280204 54 pixels[i].r = rgbColor.red;
tichise 3:f0859c280204 55 pixels[i].g = rgbColor.green;
tichise 3:f0859c280204 56 pixels[i].b = rgbColor.blue;
tichise 3:f0859c280204 57 }
tichise 3:f0859c280204 58 else
tichise 3:f0859c280204 59 {
tichise 3:f0859c280204 60 pixels[i].r = 0;
tichise 3:f0859c280204 61 pixels[i].g = 0;
tichise 3:f0859c280204 62 pixels[i].b = 0;
tichise 2:0148ac5c90fa 63 }
tichise 0:c28aa7d4f97e 64 }
tichise 0:c28aa7d4f97e 65
tichise 3:f0859c280204 66 _neoPixel.send(pixels, count);
tichise 0:c28aa7d4f97e 67 }
tichise 0:c28aa7d4f97e 68
tichise 2:0148ac5c90fa 69 void TI_NEOPIXEL_SPI::changePointColor(int count, int topIndex, int endIndex, rgbColor topColor, rgbColor bottomColor)
tichise 0:c28aa7d4f97e 70 {
tichise 3:f0859c280204 71 Pixel pixels[count];
tichise 0:c28aa7d4f97e 72
tichise 0:c28aa7d4f97e 73 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 74 {
tichise 2:0148ac5c90fa 75 if (i == topIndex)
tichise 0:c28aa7d4f97e 76 {
tichise 3:f0859c280204 77 pixels[i].r = topColor.red;
tichise 3:f0859c280204 78 pixels[i].g = topColor.green;
tichise 3:f0859c280204 79 pixels[i].b = topColor.blue;
tichise 0:c28aa7d4f97e 80 }
tichise 2:0148ac5c90fa 81 else if (i == endIndex)
tichise 0:c28aa7d4f97e 82 {
tichise 3:f0859c280204 83 pixels[i].r = bottomColor.red;
tichise 3:f0859c280204 84 pixels[i].g = bottomColor.green;
tichise 3:f0859c280204 85 pixels[i].b = bottomColor.blue;
tichise 0:c28aa7d4f97e 86 }
tichise 0:c28aa7d4f97e 87 else
tichise 0:c28aa7d4f97e 88 {
tichise 3:f0859c280204 89 pixels[i].r = 0;
tichise 3:f0859c280204 90 pixels[i].g = 0;
tichise 3:f0859c280204 91 pixels[i].b = 0;
tichise 0:c28aa7d4f97e 92 }
tichise 0:c28aa7d4f97e 93 }
tichise 0:c28aa7d4f97e 94
tichise 3:f0859c280204 95 _neoPixel.send(pixels, count);
tichise 0:c28aa7d4f97e 96 }
tichise 0:c28aa7d4f97e 97
tichise 2:0148ac5c90fa 98 void TI_NEOPIXEL_SPI::circle(int count, int startCount, int endCount, rgbColor rgbColor)
tichise 0:c28aa7d4f97e 99 {
tichise 0:c28aa7d4f97e 100 for (int j = 0; j < count; j++)
tichise 0:c28aa7d4f97e 101 {
tichise 3:f0859c280204 102 Pixel pixels[count];
tichise 0:c28aa7d4f97e 103
tichise 0:c28aa7d4f97e 104 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 105 {
tichise 2:0148ac5c90fa 106 if (i <= j)
tichise 0:c28aa7d4f97e 107 {
tichise 3:f0859c280204 108 if (startCount <= i && i < endCount)
tichise 3:f0859c280204 109 {
tichise 3:f0859c280204 110 pixels[i].r = rgbColor.red;
tichise 3:f0859c280204 111 pixels[i].g = rgbColor.green;
tichise 3:f0859c280204 112 pixels[i].b = rgbColor.blue;
tichise 3:f0859c280204 113 }
tichise 3:f0859c280204 114 else
tichise 3:f0859c280204 115 {
tichise 3:f0859c280204 116 pixels[i].r = 0;
tichise 3:f0859c280204 117 pixels[i].g = 0;
tichise 3:f0859c280204 118 pixels[i].b = 0;
tichise 2:0148ac5c90fa 119 }
tichise 0:c28aa7d4f97e 120 }
tichise 0:c28aa7d4f97e 121 else
tichise 0:c28aa7d4f97e 122 {
tichise 3:f0859c280204 123 pixels[i].r = 0;
tichise 3:f0859c280204 124 pixels[i].g = 0;
tichise 3:f0859c280204 125 pixels[i].b = 0;
tichise 0:c28aa7d4f97e 126 }
tichise 0:c28aa7d4f97e 127 }
tichise 0:c28aa7d4f97e 128
tichise 3:f0859c280204 129 _neoPixel.send(pixels, count);
tichise 2:0148ac5c90fa 130
tichise 3:f0859c280204 131 if (startCount <= j && j < endCount)
tichise 3:f0859c280204 132 {
tichise 4:70bc3528e07e 133 if (count == 16)
tichise 4:70bc3528e07e 134 {
tichise 4:70bc3528e07e 135 wait(0.05);
tichise 4:70bc3528e07e 136 }
tichise 4:70bc3528e07e 137 else
tichise 4:70bc3528e07e 138 {
tichise 4:70bc3528e07e 139 wait(0.015);
tichise 4:70bc3528e07e 140 }
tichise 2:0148ac5c90fa 141 }
tichise 0:c28aa7d4f97e 142 }
tichise 0:c28aa7d4f97e 143 }
tichise 0:c28aa7d4f97e 144
tichise 0:c28aa7d4f97e 145 void TI_NEOPIXEL_SPI::chase(int count, int bufferCount, rgbColor c1, rgbColor c2)
tichise 0:c28aa7d4f97e 146 {
tichise 0:c28aa7d4f97e 147 int virtualCount = count + bufferCount;
tichise 3:f0859c280204 148 Pixel pixels[virtualCount];
tichise 0:c28aa7d4f97e 149
tichise 0:c28aa7d4f97e 150 for (int j = 0; j < virtualCount; j++)
tichise 0:c28aa7d4f97e 151 {
tichise 3:f0859c280204 152 pixels[j].r = c2.red;
tichise 3:f0859c280204 153 pixels[j].g = c2.green;
tichise 3:f0859c280204 154 pixels[j].b = c2.blue;
tichise 0:c28aa7d4f97e 155 }
tichise 0:c28aa7d4f97e 156
tichise 4:70bc3528e07e 157 for (int j = 0; j < count; j++)
tichise 0:c28aa7d4f97e 158 {
tichise 3:f0859c280204 159 pixels[j].r = c1.red;
tichise 3:f0859c280204 160 pixels[j].g = c1.green;
tichise 3:f0859c280204 161 pixels[j].b = c1.blue;
tichise 0:c28aa7d4f97e 162
tichise 3:f0859c280204 163 pixels[j - bufferCount].r = c2.red;
tichise 3:f0859c280204 164 pixels[j - bufferCount].g = c2.green;
tichise 3:f0859c280204 165 pixels[j - bufferCount].b = c2.blue;
tichise 0:c28aa7d4f97e 166
tichise 3:f0859c280204 167 _neoPixel.send(pixels, virtualCount);
tichise 4:70bc3528e07e 168
tichise 4:70bc3528e07e 169 if (count == 16)
tichise 4:70bc3528e07e 170 {
tichise 4:70bc3528e07e 171 wait(0.05);
tichise 4:70bc3528e07e 172 }
tichise 4:70bc3528e07e 173 else
tichise 4:70bc3528e07e 174 {
tichise 4:70bc3528e07e 175 wait(0.015);
tichise 4:70bc3528e07e 176 }
tichise 0:c28aa7d4f97e 177 }
tichise 0:c28aa7d4f97e 178 }
tichise 0:c28aa7d4f97e 179
tichise 4:70bc3528e07e 180 void TI_NEOPIXEL_SPI::chase2(int count, int bufferCount, rgbColor c1, rgbColor c2)
tichise 4:70bc3528e07e 181 {
tichise 4:70bc3528e07e 182 for (int j = 0; j < count; j++)
tichise 4:70bc3528e07e 183 {
tichise 4:70bc3528e07e 184 Pixel pixels[count];
tichise 4:70bc3528e07e 185
tichise 4:70bc3528e07e 186 for (int i = 0; i < count; i++)
tichise 4:70bc3528e07e 187 {
tichise 4:70bc3528e07e 188 if (i <= j)
tichise 4:70bc3528e07e 189 {
tichise 4:70bc3528e07e 190 pixels[i].r = c1.red;
tichise 4:70bc3528e07e 191 pixels[i].g = c1.green;
tichise 4:70bc3528e07e 192 pixels[i].b = c1.blue;
tichise 4:70bc3528e07e 193
tichise 4:70bc3528e07e 194 // LEDを節約
tichise 4:70bc3528e07e 195 pixels[i - bufferCount].r = c2.red;
tichise 4:70bc3528e07e 196 pixels[i - bufferCount].g = c2.green;
tichise 4:70bc3528e07e 197 pixels[i - bufferCount].b = c2.blue;
tichise 4:70bc3528e07e 198 }
tichise 4:70bc3528e07e 199 else
tichise 4:70bc3528e07e 200 {
tichise 4:70bc3528e07e 201 pixels[i].r = c2.red;
tichise 4:70bc3528e07e 202 pixels[i].g = c2.green;
tichise 4:70bc3528e07e 203 pixels[i].b = c2.blue;
tichise 4:70bc3528e07e 204 }
tichise 4:70bc3528e07e 205 }
tichise 4:70bc3528e07e 206
tichise 4:70bc3528e07e 207 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 208
tichise 4:70bc3528e07e 209 if (count == 16)
tichise 4:70bc3528e07e 210 {
tichise 4:70bc3528e07e 211 wait(0.05);
tichise 4:70bc3528e07e 212 }
tichise 4:70bc3528e07e 213 else
tichise 4:70bc3528e07e 214 {
tichise 4:70bc3528e07e 215 wait(0.015);
tichise 4:70bc3528e07e 216 }
tichise 4:70bc3528e07e 217 }
tichise 4:70bc3528e07e 218 }
tichise 4:70bc3528e07e 219
tichise 4:70bc3528e07e 220 void TI_NEOPIXEL_SPI::chaseReverse(int count, int bufferCount, rgbColor c1, rgbColor c2)
tichise 4:70bc3528e07e 221 {
tichise 4:70bc3528e07e 222 printf("chaseReverse \n");
tichise 4:70bc3528e07e 223
tichise 4:70bc3528e07e 224 Pixel pixels[count];
tichise 4:70bc3528e07e 225
tichise 4:70bc3528e07e 226 for (int j = 0; j <= count; j++)
tichise 4:70bc3528e07e 227 {
tichise 4:70bc3528e07e 228 pixels[j].r = c2.red;
tichise 4:70bc3528e07e 229 pixels[j].g = c2.green;
tichise 4:70bc3528e07e 230 pixels[j].b = c2.blue;
tichise 4:70bc3528e07e 231 }
tichise 4:70bc3528e07e 232
tichise 4:70bc3528e07e 233 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 234
tichise 4:70bc3528e07e 235 for (int j = 0; j <= count; j++)
tichise 4:70bc3528e07e 236 {
tichise 4:70bc3528e07e 237 if (0 <= (count - j))
tichise 4:70bc3528e07e 238 {
tichise 4:70bc3528e07e 239 pixels[count - j].r = c1.red;
tichise 4:70bc3528e07e 240 pixels[count - j].g = c1.green;
tichise 4:70bc3528e07e 241 pixels[count - j].b = c1.blue;
tichise 4:70bc3528e07e 242 }
tichise 4:70bc3528e07e 243
tichise 4:70bc3528e07e 244 if (bufferCount <= j)
tichise 4:70bc3528e07e 245 {
tichise 4:70bc3528e07e 246 pixels[count + bufferCount - j].r = c2.red;
tichise 4:70bc3528e07e 247 pixels[count + bufferCount - j].g = c2.green;
tichise 4:70bc3528e07e 248 pixels[count + bufferCount - j].b = c2.blue;
tichise 4:70bc3528e07e 249 }
tichise 4:70bc3528e07e 250
tichise 4:70bc3528e07e 251 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 252
tichise 4:70bc3528e07e 253 if (count == 16)
tichise 4:70bc3528e07e 254 {
tichise 4:70bc3528e07e 255 wait(0.05);
tichise 4:70bc3528e07e 256 }
tichise 4:70bc3528e07e 257 else
tichise 4:70bc3528e07e 258 {
tichise 4:70bc3528e07e 259 wait(0.015);
tichise 4:70bc3528e07e 260 }
tichise 4:70bc3528e07e 261 }
tichise 4:70bc3528e07e 262 }
tichise 4:70bc3528e07e 263
tichise 4:70bc3528e07e 264 void TI_NEOPIXEL_SPI::chaseRainbow(int count, int bufferCount)
tichise 2:0148ac5c90fa 265 {
tichise 2:0148ac5c90fa 266 for (int j = 0; j < count; j++)
tichise 2:0148ac5c90fa 267 {
tichise 3:f0859c280204 268 Pixel pixels[count];
tichise 2:0148ac5c90fa 269
tichise 2:0148ac5c90fa 270 for (int i = 0; i < count; i++)
tichise 2:0148ac5c90fa 271 {
tichise 2:0148ac5c90fa 272 if (i <= j)
tichise 2:0148ac5c90fa 273 {
tichise 2:0148ac5c90fa 274 uint8_t phase = 256 / count * i;
tichise 2:0148ac5c90fa 275 rgbColor rgbColor = convertHsvToRgb(phase / 256.0, 1.0, 1.0);
tichise 3:f0859c280204 276 pixels[i].r = rgbColor.red;
tichise 3:f0859c280204 277 pixels[i].g = rgbColor.green;
tichise 3:f0859c280204 278 pixels[i].b = rgbColor.blue;
tichise 2:0148ac5c90fa 279
tichise 2:0148ac5c90fa 280 // LEDを節約
tichise 4:70bc3528e07e 281 pixels[i - bufferCount].r = 0;
tichise 4:70bc3528e07e 282 pixels[i - bufferCount].g = 0;
tichise 4:70bc3528e07e 283 pixels[i - bufferCount].b = 0;
tichise 2:0148ac5c90fa 284 }
tichise 2:0148ac5c90fa 285 else
tichise 2:0148ac5c90fa 286 {
tichise 3:f0859c280204 287 pixels[i].r = 0;
tichise 3:f0859c280204 288 pixels[i].g = 0;
tichise 3:f0859c280204 289 pixels[i].b = 0;
tichise 2:0148ac5c90fa 290 }
tichise 2:0148ac5c90fa 291 }
tichise 2:0148ac5c90fa 292
tichise 3:f0859c280204 293 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 294
tichise 4:70bc3528e07e 295 if (count == 16)
tichise 4:70bc3528e07e 296 {
tichise 4:70bc3528e07e 297 wait(0.05);
tichise 4:70bc3528e07e 298 }
tichise 4:70bc3528e07e 299 else
tichise 4:70bc3528e07e 300 {
tichise 4:70bc3528e07e 301 wait(0.015);
tichise 4:70bc3528e07e 302 }
tichise 2:0148ac5c90fa 303 }
tichise 2:0148ac5c90fa 304 }
tichise 2:0148ac5c90fa 305
tichise 0:c28aa7d4f97e 306 void TI_NEOPIXEL_SPI::circleRainbow(int count)
tichise 0:c28aa7d4f97e 307 {
tichise 0:c28aa7d4f97e 308 for (int j = 0; j < count; j++)
tichise 0:c28aa7d4f97e 309 {
tichise 3:f0859c280204 310 Pixel pixels[count];
tichise 0:c28aa7d4f97e 311
tichise 0:c28aa7d4f97e 312 for (int i = 0; i < count; i++)
tichise 0:c28aa7d4f97e 313 {
tichise 0:c28aa7d4f97e 314 if (i <= j)
tichise 0:c28aa7d4f97e 315 {
tichise 0:c28aa7d4f97e 316 uint8_t phase = 256 / count * i;
tichise 0:c28aa7d4f97e 317 rgbColor rgbColor = convertHsvToRgb(phase / 256.0, 1.0, 1.0);
tichise 3:f0859c280204 318 pixels[i].r = rgbColor.red;
tichise 3:f0859c280204 319 pixels[i].g = rgbColor.green;
tichise 3:f0859c280204 320 pixels[i].b = rgbColor.blue;
tichise 0:c28aa7d4f97e 321 }
tichise 0:c28aa7d4f97e 322 else
tichise 0:c28aa7d4f97e 323 {
tichise 3:f0859c280204 324 pixels[i].r = 0;
tichise 3:f0859c280204 325 pixels[i].g = 0;
tichise 3:f0859c280204 326 pixels[i].b = 0;
tichise 0:c28aa7d4f97e 327 }
tichise 0:c28aa7d4f97e 328 }
tichise 0:c28aa7d4f97e 329
tichise 3:f0859c280204 330 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 331
tichise 4:70bc3528e07e 332 if (count == 16)
tichise 4:70bc3528e07e 333 {
tichise 4:70bc3528e07e 334 wait(0.05);
tichise 4:70bc3528e07e 335 }
tichise 4:70bc3528e07e 336 else
tichise 4:70bc3528e07e 337 {
tichise 4:70bc3528e07e 338 wait(0.015);
tichise 4:70bc3528e07e 339 }
tichise 4:70bc3528e07e 340 }
tichise 4:70bc3528e07e 341 }
tichise 4:70bc3528e07e 342
tichise 4:70bc3528e07e 343 void TI_NEOPIXEL_SPI::moon(int count, int startIndex, int stopIndex, rgbColor c1, rgbColor c2)
tichise 4:70bc3528e07e 344 {
tichise 4:70bc3528e07e 345
tichise 4:70bc3528e07e 346 Pixel pixels[count];
tichise 4:70bc3528e07e 347
tichise 4:70bc3528e07e 348 for (int j = 0; j < count; j++)
tichise 4:70bc3528e07e 349 {
tichise 4:70bc3528e07e 350 if (0 <= j && j <= count)
tichise 4:70bc3528e07e 351 {
tichise 4:70bc3528e07e 352 pixels[j].r = c2.red;
tichise 4:70bc3528e07e 353 pixels[j].g = c2.green;
tichise 4:70bc3528e07e 354 pixels[j].b = c2.blue;
tichise 4:70bc3528e07e 355 }
tichise 4:70bc3528e07e 356 }
tichise 4:70bc3528e07e 357
tichise 4:70bc3528e07e 358 int loopCount = (stopIndex - startIndex) / 2;
tichise 4:70bc3528e07e 359 int middlePoint = startIndex + loopCount;
tichise 4:70bc3528e07e 360
tichise 4:70bc3528e07e 361 for (int i = 0; i <= loopCount - 1; i++)
tichise 4:70bc3528e07e 362 {
tichise 4:70bc3528e07e 363 pixels[middlePoint + i].r = c1.red;
tichise 4:70bc3528e07e 364 pixels[middlePoint + i].g = c1.green;
tichise 4:70bc3528e07e 365 pixels[middlePoint + i].b = c1.blue;
tichise 4:70bc3528e07e 366
tichise 4:70bc3528e07e 367 pixels[middlePoint - i].r = c1.red;
tichise 4:70bc3528e07e 368 pixels[middlePoint - i].g = c1.green;
tichise 4:70bc3528e07e 369 pixels[middlePoint - i].b = c1.blue;
tichise 4:70bc3528e07e 370
tichise 4:70bc3528e07e 371 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 372
tichise 4:70bc3528e07e 373 if (count == 16)
tichise 4:70bc3528e07e 374 {
tichise 4:70bc3528e07e 375 wait(0.05);
tichise 4:70bc3528e07e 376 }
tichise 4:70bc3528e07e 377 else
tichise 4:70bc3528e07e 378 {
tichise 4:70bc3528e07e 379 wait(0.04);
tichise 4:70bc3528e07e 380 }
tichise 4:70bc3528e07e 381 }
tichise 4:70bc3528e07e 382
tichise 4:70bc3528e07e 383 for (int i = 0; i <= loopCount - 1; i++)
tichise 4:70bc3528e07e 384 {
tichise 4:70bc3528e07e 385 pixels[startIndex + i].r = c2.red;
tichise 4:70bc3528e07e 386 pixels[startIndex + i].g = c2.green;
tichise 4:70bc3528e07e 387 pixels[startIndex + i].b = c2.blue;
tichise 4:70bc3528e07e 388
tichise 4:70bc3528e07e 389 pixels[stopIndex - i].r = c2.red;
tichise 4:70bc3528e07e 390 pixels[stopIndex - i].g = c2.green;
tichise 4:70bc3528e07e 391 pixels[stopIndex - i].b = c2.blue;
tichise 4:70bc3528e07e 392
tichise 4:70bc3528e07e 393 _neoPixel.send(pixels, count);
tichise 4:70bc3528e07e 394
tichise 4:70bc3528e07e 395 if (count == 16)
tichise 4:70bc3528e07e 396 {
tichise 4:70bc3528e07e 397 wait(0.05);
tichise 4:70bc3528e07e 398 }
tichise 4:70bc3528e07e 399 else
tichise 4:70bc3528e07e 400 {
tichise 4:70bc3528e07e 401 wait(0.04);
tichise 4:70bc3528e07e 402 }
tichise 0:c28aa7d4f97e 403 }
tichise 0:c28aa7d4f97e 404 }
tichise 0:c28aa7d4f97e 405
tichise 0:c28aa7d4f97e 406 rgbColor TI_NEOPIXEL_SPI::convertHsvToRgb(float h, float s, float v)
tichise 0:c28aa7d4f97e 407 {
tichise 0:c28aa7d4f97e 408 int i = floor(h * 6);
tichise 0:c28aa7d4f97e 409 float f = h * 6 - i;
tichise 0:c28aa7d4f97e 410 float p = v * (1 - s);
tichise 0:c28aa7d4f97e 411 float q = v * (1 - f * s);
tichise 0:c28aa7d4f97e 412 float t = v * (1 - (1 - f) * s);
tichise 0:c28aa7d4f97e 413 float r = 0, g = 0, b = 0;
tichise 0:c28aa7d4f97e 414
tichise 0:c28aa7d4f97e 415 switch (i % 6)
tichise 0:c28aa7d4f97e 416 {
tichise 0:c28aa7d4f97e 417 case 0:
tichise 0:c28aa7d4f97e 418 r = v;
tichise 0:c28aa7d4f97e 419 g = t;
tichise 0:c28aa7d4f97e 420 b = p;
tichise 0:c28aa7d4f97e 421 break;
tichise 0:c28aa7d4f97e 422 case 1:
tichise 0:c28aa7d4f97e 423 r = q;
tichise 0:c28aa7d4f97e 424 g = v;
tichise 0:c28aa7d4f97e 425 b = p;
tichise 0:c28aa7d4f97e 426 break;
tichise 0:c28aa7d4f97e 427 case 2:
tichise 0:c28aa7d4f97e 428 r = p;
tichise 0:c28aa7d4f97e 429 g = v;
tichise 0:c28aa7d4f97e 430 b = t;
tichise 0:c28aa7d4f97e 431 break;
tichise 0:c28aa7d4f97e 432 case 3:
tichise 0:c28aa7d4f97e 433 r = p;
tichise 0:c28aa7d4f97e 434 g = q;
tichise 0:c28aa7d4f97e 435 b = v;
tichise 0:c28aa7d4f97e 436 break;
tichise 0:c28aa7d4f97e 437 case 4:
tichise 0:c28aa7d4f97e 438 r = t;
tichise 0:c28aa7d4f97e 439 g = p;
tichise 0:c28aa7d4f97e 440 b = v;
tichise 0:c28aa7d4f97e 441 break;
tichise 0:c28aa7d4f97e 442 case 5:
tichise 0:c28aa7d4f97e 443 r = v;
tichise 0:c28aa7d4f97e 444 g = p;
tichise 0:c28aa7d4f97e 445 b = q;
tichise 0:c28aa7d4f97e 446 break;
tichise 0:c28aa7d4f97e 447 }
tichise 0:c28aa7d4f97e 448
tichise 0:c28aa7d4f97e 449 return (rgbColor){r * 255, g * 255, b * 255};
tichise 0:c28aa7d4f97e 450 }