Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2. /*
  3. * 8x8 LED array test1
  4. * display a line of lights moving around the perimeter of the 8x8 matrix
  5. */
  6.  
  7. // Arduino pin definitions - (ordered to keep wiring tidy)
  8. int row[] = {14,10,4,12,9,5,8,6}; //rows - driven HIGH for on
  9. int col[] = {17,16,13,2,15,3,7,11}; //columns - driven LOW for on
  10.  
  11. // give our moving light a tail?
  12. int tailLen = 10; //choose 1 to 28 to set length of tail
  13. int tail[28]; //number of each led currently being lit
  14. int tailPos = 0; //current position on leading light
  15.  
  16. int i, j; //general counters
  17. void setup()
  18. {
  19. for (i=0; i<8; i++) //set arduino pins to be outputs
  20. {
  21. pinMode(row[i], OUTPUT);
  22. pinMode(col[i], OUTPUT);
  23. }
  24. for (i=0; i<8; i++) //clear
  25. {
  26. digitalWrite(row[i], LOW);
  27. digitalWrite(col[i], HIGH);
  28. }
  29. for (i=0; i<=tailLen; i++) //initialise the tail
  30. {
  31. tail[i]=-1;
  32. }
  33. }
  34. void loop()
  35. {
  36. for (i=0; i<8; i++)
  37. {
  38. ledout(i);
  39. }
  40. for (i=15; i<56; i=i+8)
  41. {
  42. ledout(i);
  43. }
  44. for (i=63; i>55; i--)
  45. {
  46. ledout(i);
  47. }
  48. for (i=48; i>0; i=i-8)
  49. {
  50. ledout(i);
  51. }
  52. }
  53.  
  54. void ledout(int i)
  55. {
  56. tail[tailPos]=i;
  57. if (tailPos++ >= tailLen) tailPos=0;
  58.  
  59. for (j=0; j<tailLen; j++)
  60. {
  61. if (tail[j]>-1)
  62. {
  63. digitalWrite(row[tail[j]%8], HIGH);
  64. digitalWrite(col[tail[j]/8], LOW);
  65. delay(2);
  66. digitalWrite(row[tail[j]%8], LOW);
  67. digitalWrite(col[tail[j]/8], HIGH);
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement