Advertisement
Guest User

Untitled

a guest
Feb 13th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. // 2-dimensional array of row pin numbers:
  2. const int row[8] = {
  3. 2,3,4,5,6,7,8,9 };
  4.  
  5. // 2-dimensional array of column pin numbers:
  6. const int col[8] = {
  7. 10,11,12,13,16,17,18,19 };
  8.  
  9. // 2-dimensional array of pixels:
  10. int pixels[8][8];
  11.  
  12. // cursor position:
  13. int x = 5;
  14. int y = 5;
  15.  
  16. void setup() {
  17. Serial.begin(9600);
  18. // initialize the I/O pins as outputs:
  19.  
  20. // iterate over the pins:
  21. for (int thisPin = 0; thisPin < 8; thisPin++) {
  22. // initialize the output pins:
  23. pinMode(col[thisPin], OUTPUT);
  24. pinMode(row[thisPin], OUTPUT);
  25. // take the col pins (i.e. the cathodes) high to ensure that
  26. // the LEDS are off:
  27. digitalWrite(col[thisPin], HIGH);
  28. }
  29.  
  30. // initialize the pixel matrix:
  31. for (int x = 0; x < 8; x++) {
  32. for (int y = 0; y < 8; y++) {
  33. pixels[x][y] = HIGH;
  34. }
  35. }
  36. }
  37.  
  38. void loop() {
  39. // read input:
  40. readSensors();
  41.  
  42. // draw the screen:
  43. refreshScreen();
  44.  
  45. delay(500);
  46. }
  47.  
  48. void readSensors() {
  49. // turn off the last position:
  50. pixels[x][y] = HIGH;
  51. // read the sensors for X and Y values:
  52.  
  53. x++;
  54. x%=8;
  55.  
  56. if (x==0)
  57. {
  58. y ++;
  59. y%=8;
  60. }
  61.  
  62.  
  63. pixels[x][y] = LOW;
  64. }
  65.  
  66. void refreshScreen() {
  67. // iterate over the rows (anodes):
  68. for (int thisRow = 0; thisRow < 8; thisRow++) {
  69. // take the row pin (anode) high:
  70. digitalWrite(row[thisRow], HIGH);
  71. // iterate over the cols (cathodes):
  72. for (int thisCol = 0; thisCol < 8; thisCol++) {
  73. // get the state of the current pixel;
  74. int thisPixel = pixels[thisRow][thisCol];
  75. // when the row is HIGH and the col is LOW,
  76. // the LED where they meet turns on:
  77. digitalWrite(col[thisCol], thisPixel);
  78. // turn the pixel off:
  79. if (thisPixel == LOW) {
  80. digitalWrite(col[thisCol], HIGH);
  81. }
  82. }
  83. // take the row pin low to turn off the whole row:
  84. digitalWrite(row[thisRow], LOW);
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement