Created
December 16, 2020 18:44
-
-
Save costyn/76a7438dac2fb31184dc98e01ce169fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <FastLED.h> | |
// Clock and data pins are whatever are SPI defaults for your board (SCK, MOSI) | |
// Arduino Mega 2560, Clock 52, Data 51 | |
struct CRGB16; | |
#define NUM_LEDS 30 | |
void oneFrame(uint16_t r, uint16_t g, uint16_t b); | |
void showLeds(); | |
struct CRGB16 { | |
uint16_t red; | |
uint16_t green; | |
uint16_t blue; | |
}; | |
CRGB leds[NUM_LEDS]; | |
uint16_t bpm = 15; | |
void setup() { | |
SPI.begin(); | |
} | |
void loop() { | |
showLeds(); | |
} | |
uint16_t maxB = 20000; | |
void showLeds() { | |
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); | |
// Start frame | |
for (int i = 0; i <= 4; i++) { | |
SPI.transfer16(0); | |
} | |
// LEDs | |
for (int i = 0; i <= NUM_LEDS; i++) { | |
uint16_t red = beatsin16(bpm+4,0,maxB + i * 1056); | |
uint16_t green = beatsin16(bpm,0,maxB+ i * 1056,0,120); | |
uint16_t blue = beatsin16(bpm+8,0,maxB+ i * 1056,0,210); | |
oneFrame(red, green, blue); | |
} | |
// End Frame | |
for (int i = 0; i <= 4; i++) {SPI.transfer16(0xFFFF);} | |
SPI.endTransaction(); | |
delay(5); | |
} | |
void oneFrame(uint16_t r, uint16_t g, uint16_t b) { | |
SPI.transfer(0xFF); // Start of LED Frame & Brightness | |
// SPI.transfer(0xFF); // as (1)(5bit)(5bit)(5bit) brightnesses | |
SPI.transfer(0x01); // as (1)(5bit)(5bit)(5bit) brightnesses | |
SPI.transfer16(r); // RED (16-bit) | |
SPI.transfer16(g); // GREEN (16-bit) | |
SPI.transfer16(b); // BLUE (16-bit) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment