document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. * matrixMpxAnimation sketch
  3. * animates two heart images to show a beating heart
  4. */
  5. // the heart images are stored as bitmaps - each bit corresponds to an LED
  6. // a 0 indicates the LED is off, 1 is on
  7. byte P[] = {
  8. B11111111,
  9. B10000001,
  10. B10000001,
  11. B11111111,
  12. B10000000,
  13. B10000000,
  14. B10000000,
  15. B10000000};
  16. byte E[] = {
  17. B11111111,
  18. B10000000,
  19. B10000000,
  20. B10000000,
  21. B11111111,
  22. B10000000,
  23. B10000000,
  24. B11111111};
  25.  
  26. byte M[] = {
  27. B10000001,
  28. B11000101,
  29. B11001001,
  30. B10010001,
  31. B10000001,
  32. B10000001,
  33. B10000001,
  34. B10000001};
  35.  
  36. byte A[] = {
  37. B00011000,
  38. B00100100,
  39. B01000010,
  40. B10000001,
  41. B11111111,
  42. B10000001,
  43. B10000001,
  44. B10000001};
  45.  
  46. byte L[] = {
  47. B10000000,
  48. B10000000,
  49. B10000000,
  50. B10000000,
  51. B10000000,
  52. B10000000,
  53. B10000000,
  54. B11111111};
  55.  
  56.  
  57.  
  58. const int columnPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
  59. const int rowPins[] = { 10,11,12,15,16,17,18,19};
  60. void setup() {
  61. for (int i = 0; i < 8; i++)
  62. {
  63. pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
  64. pinMode(columnPins[i], OUTPUT);
  65. digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
  66. }
  67. }
  68. void loop() {
  69. int pulseDelay = 800 ; // milliseconds to wait between beats
  70. show(P, 160);
  71. show(A, 160); // followed by the big heart for 200ms
  72. show(M, 160);
  73. show(E, 160);
  74. show(L, 160);
  75. show(A, 160);
  76.  
  77. delay(pulseDelay); // show nothing between beats
  78. }
  79.  
  80. // routine to show a frame of an image stored in the array pointed to by the image parameter.
  81. // the frame is repeated for the given duration in milliseconds
  82. void show( byte * image, unsigned long duration)
  83. {
  84. unsigned long start = millis(); // begin timing the animation
  85. while (start + duration > millis()) // loop until the duration period has passed
  86. {
  87. for(int row = 0; row < 8; row++)
  88. {
  89. digitalWrite(rowPins[row], HIGH); // connect row to +5 volts
  90. for(int column = 0; column < 8; column++)
  91. {
  92. boolean pixel = bitRead(image[row],column);
  93. if(pixel == 1)
  94. {
  95. digitalWrite(columnPins[column], LOW); // connect column to Gnd
  96. }
  97. delayMicroseconds(300); // a small delay for each LED
  98. digitalWrite(columnPins[column], HIGH); // disconnect column from Gnd
  99. }
  100. digitalWrite(rowPins[row], LOW); // disconnect LEDs
  101. }
  102. }
  103. }
');