Last active
November 9, 2019 19:04
-
-
Save drews256/d1c6eecbcfd4f5639f3ccb4cc1ec4553 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* 8x8 LED array test1 | |
* display a line of lights moving around the perimeter of the 8x8 matrix | |
*/ | |
// Arduino pin definitions - (ordered to keep wiring tidy) | |
int row[] = {14,10,4,12,9,5,8,6}; //rows - driven LOW for on | |
int col[] = {17,16,13,2,15,3,7,11}; //columns - driven HIGH for on | |
// give our moving light a tail? | |
int tailLen = 10; //choose 1 to 28 to set length of tail | |
int tail[28]; //number of each led currently being lit | |
int tailPos = 0; //current position on leading light | |
int i, j; //general counters | |
void setup() | |
{ | |
for (i=0; i<8; i++) //set arduino pins to be outputs | |
{ | |
pinMode(row[i], OUTPUT); | |
pinMode(col[i], OUTPUT); | |
} | |
for (i=0; i<8; i++) //clear | |
{ | |
digitalWrite(row[i], HIGH); | |
digitalWrite(col[i], LOW); | |
} | |
for (i=0; i<=tailLen; i++) //initialise the tail | |
{ | |
tail[i]=-1; | |
} | |
} | |
void loop() | |
{ | |
for (i=0; i<8; i++) | |
{ | |
ledout(i); | |
} | |
for (i=15; i<56; i=i+8) | |
{ | |
ledout(i); | |
} | |
for (i=63; i>55; i--) | |
{ | |
ledout(i); | |
} | |
for (i=48; i>0; i=i-8) | |
{ | |
ledout(i); | |
} | |
} | |
void ledout(int i) | |
{ | |
tail[tailPos]=i; | |
if (tailPos++ >= tailLen) tailPos=0; | |
for (j=0; j<tailLen; j++) | |
{ | |
if (tail[j]>-1) | |
{ | |
digitalWrite(row[tail[j]%8], LOW); | |
digitalWrite(col[tail[j]/8], HIGH); | |
delay(2); | |
digitalWrite(row[tail[j]%8], HIGH); | |
digitalWrite(col[tail[j]/8], LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment