// hobbyprojects.com // apa102_rgb_BLUE_LED_Blink.ino int apa102Clock = 7; int apa102Data = 8; int i; //--------------------------- void setup() { pinMode(apa102Data,OUTPUT); pinMode(apa102Clock,OUTPUT); } //--------------------------- void loop() { // Start Frame spiWrite(0x00); spiWrite(0x00); spiWrite(0x00); spiWrite(0x00); // LED frame spiWrite(0b11100011); // The first three bits(MSB) of the LED frame should be ‘1’. The next 5 bits(LSB) are brightness value (0–31) spiWrite(0b11111111); // blue LED ON) spiWrite(0b00000000); // green LED OFF) spiWrite(0b00000000); // red LED OFF) // End frame spiWrite(0b11111111); delay(500); // LED OFF // Start Frame spiWrite(0x00); spiWrite(0x00); spiWrite(0x00); spiWrite(0x00); //LED frame spiWrite(0b11100000); // The first three bits(MSB) of the LED frame should be ‘1’. The next 5 bits(LSB) are brightness value (0–31) spiWrite(0b00000000); // blue LED OFF) spiWrite(0b00000000); // green LED OFF) spiWrite(0b00000000); // red LED OFF) // End frame spiWrite(0b11111111); delay(500); } //=========================================================================== void spiWrite(uint8_t c) { uint8_t i; for (i=0; i<8 ;i++) { if (!(c&0x80)) { digitalWrite(apa102Data, LOW); } else { digitalWrite(apa102Data, HIGH); } digitalWrite(apa102Clock, HIGH); c <<= 1; digitalWrite(apa102Clock, LOW); } digitalWrite(apa102Data, HIGH); }