Created
October 1, 2013 19:01
-
-
Save neckro/6783375 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
/* Runs a stochastic dither animation on an 8x8 LED matrix. | |
23 December 2011 - [email protected] - No license. Do what thou wilt. | |
Requires a Maxim MAX7221 or MAX7219 LED controller. | |
Also requires LedControl library: http://www.arduino.cc/playground/Main/LedControl | |
Fills a row's array proportional to its distance from origin, | |
then applies a Fisher-Yates shuffle to randomize the order. | |
*/ | |
#include <LedControl.h> | |
#define DATA_PIN 10 | |
#define CLOCK_PIN 11 | |
#define LOAD_PIN 12 | |
#define ADDRESS 0 | |
#define INTENSITY 15 | |
#define DIMX 8 | |
#define DIMY 8 | |
// ms to wait between frames | |
#define DELAY 0 | |
boolean row[DIMX]; | |
boolean preprow[DIMX]; | |
/* data, clock, load, number of devices */ | |
LedControl lc=LedControl(DATA_PIN,CLOCK_PIN,LOAD_PIN,1); | |
void setup() { | |
lc.shutdown(ADDRESS,false); | |
lc.setIntensity(ADDRESS,INTENSITY); | |
} | |
void loop() { | |
for(byte y=0;y<DIMY;y++) { | |
for(byte x=0;x<DIMX;x++) { | |
if (x<y+1) { | |
preprow[x] = true; | |
} else { | |
preprow[x] = false; | |
} | |
} | |
row[0] = preprow[0]; | |
for (byte n=1; n<DIMX; n++) { | |
int r = random(0, n); | |
row[n] = row[r]; | |
row[r] = preprow[n]; | |
} | |
int rowval = 0; | |
for(byte x=0;x<DIMX;x++) { | |
if (row[x] == true) { | |
bitSet(rowval, x); | |
} | |
} | |
lc.setRow(ADDRESS, y, rowval); | |
} | |
delay(DELAY); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment