Skip to content

Instantly share code, notes, and snippets.

@chemdoc77
Last active March 26, 2017 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemdoc77/bf321544623ae3e63b65c57a09521b74 to your computer and use it in GitHub Desktop.
Save chemdoc77/bf321544623ae3e63b65c57a09521b74 to your computer and use it in GitHub Desktop.
Faux TV for DotStar Matrix
//Faux TV by Mark Kriegsman
//http://pastebin.com/RQCPVyXf
//https://plus.google.com/112916219338292742137/posts/Xg76A57iXV6
//Changed to APA102, i.e. DotStar by Chemdoc77
#include <FastLED.h>
#define LED_PIN 3
#define CLOCK_PIN 4
#define COLOR_ORDER BRG // or GBR
#define CHIPSET APA102
#define BRIGHTNESS 40
const uint8_t kMatrixWidth = 8;
const uint8_t kMatrixHeight = 8;
const bool kMatrixSerpentineLayout = false;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
CRGB leds[NUM_LEDS];
void setup() {
delay(2000); // safety delay
FastLED.addLeds<CHIPSET, LED_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop()
{
uint32_t ms = millis()*0.66;//CHANGE 0.4 TO AFFECT SPEED - LOWER SLOWER, HIGHER FASTER
int32_t yHueDelta32 = ((int32_t)cos16( ms * 27 ) * (350 / kMatrixWidth));
int32_t xHueDelta32 = ((int32_t)cos16( ms * 39 ) * (310 / kMatrixHeight));
DrawOneFrame( ms / 65536, yHueDelta32 / 32768, xHueDelta32 / 32768);
FastLED.show();
}
void DrawOneFrame( byte startHue8, int8_t yHueDelta8, int8_t xHueDelta8)
{
byte lineStartHue = startHue8;
for( byte y = 0; y < kMatrixHeight; y++) {
lineStartHue += yHueDelta8;
byte pixelHue = lineStartHue;
for( byte x = 0; x < kMatrixWidth; x++) {
pixelHue += xHueDelta8;
leds[ XY(x, y)] = CHSV( pixelHue, 255, 255);
}
}
}
// Helper function that translates from x, y into an index into the LED array
// Handles both 'row order' and 'serpentine' pixel layouts.
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
} else {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment