Advertisement
zer044

ledcube_read_from_array

Aug 28th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. /**
  2. * by zer044 arduino account holder
  3. * 25/08/2011
  4. * 3by3 Led cube read from array
  5. **/
  6.  
  7.  
  8. int levelPins[] = {22,23,24};
  9. int colPins[] = {30,31,32,33,34,35,36,37,38};
  10. int x=0;
  11. int x=y;
  12.  
  13.  
  14. int first[3][9] = {
  15. {1, 1, 1, 0, 0, 0, 0, 0, 0},
  16. {1, 1, 1, 0, 0, 0, 0, 0, 0},
  17. {1, 1, 1, 0, 0, 0, 0, 0, 0},
  18. };
  19. int second[3][9] = {
  20.  {0, 0, 0, 1, 1, 1, 0, 0, 0},
  21.  {0, 0, 0, 1, 1, 1, 0, 0, 0},
  22.  {0, 0, 0, 1, 1, 1, 0, 0, 0},
  23. };
  24. int third[3][9] = {
  25. {0, 0, 0, 0, 0, 0, 1, 1, 1},
  26. {0, 0, 0, 0, 0, 0, 1, 1, 1},
  27. {0, 0, 0, 0, 0, 0, 1, 1, 1},
  28. };
  29.  
  30. int all[3][9] = {
  31. {1, 1, 1, 1, 1, 1, 1, 1, 1},
  32. {1, 1, 1, 1, 1, 1, 1, 1, 1},
  33. {1, 1, 1, 1, 1, 1, 1, 1, 1},
  34. };
  35.  
  36. void setup () {
  37.  
  38.   //set all output
  39.   for (int i=0; i<3; i++) {
  40.     pinMode(levelPins[i], OUTPUT);
  41.   }
  42.   for (int j=0; j<9; j++) {
  43.     pinMode(colPins[j], OUTPUT);
  44.  
  45.   }
  46. }
  47.  
  48. void show (int image[3][9]) {
  49.  
  50.  
  51.    for (int level=0; level<3; level++) {
  52.   digitalWrite(levelPins[level], LOW);
  53.    
  54.    for (int col=0; col < 9; col++) {
  55.     int pixel = image[level][col];
  56.    
  57.   if (pixel == 1) {digitalWrite(colPins[col], HIGH);}
  58.    
  59.    delayMicroseconds(30);
  60.  digitalWrite(colPins[col], LOW);
  61.        } // col for
  62.    digitalWrite(levelPins[level], HIGH);
  63.    } // level for
  64.  
  65.  
  66.  } // end of show
  67.  
  68.  
  69.  
  70. void loop()
  71. {
  72. show(first);
  73. show(second);
  74. show(third);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement