Minimal library to work with APA102-based LED strips. Uses code from FastLED library.

Dependents:   MobileArcade

Committer:
abraha2d
Date:
Tue Dec 11 06:29:34 2018 +0000
Revision:
0:c223864b981f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abraha2d 0:c223864b981f 1 #include "mbed.h"
abraha2d 0:c223864b981f 2 #include "APA102.h"
abraha2d 0:c223864b981f 3
abraha2d 0:c223864b981f 4 void fill_solid( struct CRGB * leds, int numToFill, const struct CRGB& color) {
abraha2d 0:c223864b981f 5 for(int i = 0; i < numToFill; i++) {
abraha2d 0:c223864b981f 6 leds[i] = color;
abraha2d 0:c223864b981f 7 }
abraha2d 0:c223864b981f 8 }
abraha2d 0:c223864b981f 9
abraha2d 0:c223864b981f 10 void APA102_write(mbed::SPI& mSPI, struct CRGB * leds, int numToFill) {
abraha2d 0:c223864b981f 11
abraha2d 0:c223864b981f 12 mSPI.write(0);
abraha2d 0:c223864b981f 13 mSPI.write(0);
abraha2d 0:c223864b981f 14 mSPI.write(0);
abraha2d 0:c223864b981f 15 mSPI.write(0);
abraha2d 0:c223864b981f 16
abraha2d 0:c223864b981f 17 for (int i = 0; i < numToFill; ++i) {
abraha2d 0:c223864b981f 18 mSPI.write(0xE0 | 31);
abraha2d 0:c223864b981f 19 mSPI.write(leds[i].b);
abraha2d 0:c223864b981f 20 mSPI.write(leds[i].g);
abraha2d 0:c223864b981f 21 mSPI.write(leds[i].r);
abraha2d 0:c223864b981f 22 }
abraha2d 0:c223864b981f 23
abraha2d 0:c223864b981f 24 int nDWords = numToFill / 32;
abraha2d 0:c223864b981f 25 do {
abraha2d 0:c223864b981f 26 mSPI.write(0xFF);
abraha2d 0:c223864b981f 27 mSPI.write(0x00);
abraha2d 0:c223864b981f 28 mSPI.write(0x00);
abraha2d 0:c223864b981f 29 mSPI.write(0x00);
abraha2d 0:c223864b981f 30 } while(nDWords--);
abraha2d 0:c223864b981f 31
abraha2d 0:c223864b981f 32 }