Advertisement
computermuseo

matrix 8X8 matrice led arduino

Apr 16th, 2015
2,692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. const int row[8] = {
  2. 2,7,19,5,13,18,12,16 };// 2-dimensional array of column pin numbers:
  3. const int col[8] = {
  4. 6,11,10,3,17,4,8,9 };// 2-dimensional array of pixels:
  5. int pixels[8][8];
  6. // cursor position:
  7. int x = 5;
  8. int y = 5;
  9. void setup() {
  10. // initialize the I/O pins as outputs
  11. // iterate over the pins:
  12. for (int thisPin = 0; thisPin < 8; thisPin++) {
  13. // initialize the output pins:
  14. pinMode(col[thisPin], OUTPUT);
  15. pinMode(row[thisPin], OUTPUT);
  16. // take the col pins (i.e. the cathodes) high to ensure that
  17. // the LEDS are off:
  18. digitalWrite(col[thisPin], HIGH);
  19. }
  20.  
  21. // initialize the pixel matrix:
  22. for (int x = 0; x < 8; x++) {
  23. for (int y = 0; y < 8; y++) {
  24. pixels[x][y] = HIGH;
  25. }
  26. }
  27. }void loop() {
  28. // read input:
  29. readSensors();
  30.  
  31. // draw the screen:
  32. refreshScreen();
  33. }void readSensors() {
  34. // turn off the last position:
  35. pixels[x][y] = HIGH;
  36. // read the sensors for X and Y values:
  37. x = 7 - map(analogRead(A0), 0, 1023, 0, 7);
  38. y = map(analogRead(A1), 0, 1023, 0, 7);
  39. // set the new pixel position low so that the LED will turn on
  40. // in the next screen refresh:
  41. pixels[x][y] = LOW;
  42.  
  43. }void refreshScreen() {
  44. // iterate over the rows (anodes):
  45. for (int thisRow = 0; thisRow < 8; thisRow++) {
  46. // take the row pin (anode) high:
  47. digitalWrite(row[thisRow], HIGH);
  48. // iterate over the cols (cathodes):
  49. for (int thisCol = 0; thisCol < 8; thisCol++) {
  50. // get the state of the current pixel;
  51. int thisPixel = pixels[thisRow][thisCol];
  52. // when the row is HIGH and the col is LOW,
  53. // the LED where they meet turns on:
  54. digitalWrite(col[thisCol], thisPixel);
  55. // turn the pixel off:
  56. if (thisPixel == LOW) {
  57. digitalWrite(col[thisCol], HIGH);
  58. }
  59. }
  60. // take the row pin low to turn off the whole row:
  61. digitalWrite(row[thisRow], LOW);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement