Skip to content

Instantly share code, notes, and snippets.

@keshavsaharia
Created April 13, 2014 02:24
Show Gist options
  • Save keshavsaharia/10566292 to your computer and use it in GitHub Desktop.
Save keshavsaharia/10566292 to your computer and use it in GitHub Desktop.
LEDarray
boolean view[7][7];
void setup() {
for (int i = 0 ; i < 14 ; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
view[x][y] = false;
}
}
}
void on(int x, int y) {
view[x][y] = true;
}
void off(int x, int y) {
view[x][y] = false;
}
void allOn() {
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
view[x][y] = true;
}
}
}
void allOff() {
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
view[x][y] = false;
}
}
}
void output(int times) {
output(20, times);
}
void output(int ledDelay, int times) {
for (int i = 0 ; i < times ; i++) {
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
if(view[x][y]) {
digitalWrite(y, LOW);
digitalWrite(x + 7, HIGH);
delayMicroseconds(ledDelay);
digitalWrite(x + 7, LOW);
} else {
digitalWrite(y, HIGH);
delayMicroseconds(ledDelay);
}
}
}
}
}
void loop() {
for (int i = 3 ; i >= 0 ; i--) {
allOff();
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
if (abs(x - 3) == i && abs(y - 3) == i) {
on(x, y);
}
}
}
output(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment