Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.86 KB | None | 0 0
  1. #include "TimerOne.h"
  2.  
  3. //initializing and declaring led rows
  4.   int column[16]={13,12,11,10,9,8,7,6,5,4,3,2,1,0,A5,A4};
  5. //initializing and declaring led layers
  6.   int layer[4]={A0,A1,A2,A3};
  7. volatile  int mp_layer=0;
  8.   int mp_time = 1;
  9.   int irany = 0;
  10.   int tmp_counter=0;
  11.   unsigned long previousMillis = 0;        // will store last time LED was updated
  12.   byte pinMatrix[4][16] = {
  13.    
  14.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  15.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  16.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  17.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  18.    
  19.   };
  20.  
  21. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  22.    
  23. void setup()
  24. {
  25.   Timer1.initialize(2000);         // 2000 oké
  26.   Timer1.attachInterrupt(multiplex);  // attaches callback() as a timer overflow interrupt
  27.  
  28.   for(int i = 0; i<16; i++)
  29.   {
  30.     pinMode(column[i], OUTPUT);
  31.   }
  32.  
  33.   for(int i = 0; i<4; i++)
  34.   {
  35.     pinMode(layer[i], OUTPUT);
  36.   }
  37.   Serial.begin(9600);
  38. }//setup
  39.  
  40. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  41.  
  42. void multiplex()
  43. {
  44.   for(volatile int j = 0; j<16; j++)   //Kikapcsolok minden oszlopot az aktuális rétegen
  45.     {
  46.      digitalWrite(column[j], 0);
  47.     }  
  48.  
  49.   digitalWrite(layer[mp_layer], 0);    //Kikapcsolom az aktuális réteget  
  50.  
  51.   if (mp_layer<3) //Kiszámolom a soron következő réteget
  52.     mp_layer++;
  53.   else
  54.     mp_layer = 0;
  55.      
  56.   for(volatile int z = 0; z<16; z++)   //Bekapcsolok minden oszlopot amit kell
  57.      {
  58.       digitalWrite(column[z], pinMatrix[mp_layer][z]);
  59.      }
  60.  
  61.   digitalWrite(layer[mp_layer], 1);  //Bekapcsolom az soron következő réteget
  62.      
  63. }
  64.  
  65. //xxxxxxxxxxxxxxxxxxxxFUNCTION LOOPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  66. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  67.  
  68. void loop()
  69. {
  70.  
  71.       pinMatrix[0][0] = 0;     //réteg, olszlop
  72.       Serial.println(0);
  73.       myDelay(1000);
  74.      
  75.       pinMatrix[0][0] = 1;     //réteg, olszlop
  76.       Serial.println(1);
  77.       myDelay(1000);
  78.      
  79. }
  80.  
  81. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  82. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  83.  
  84. void myDelay(long interval)
  85. {
  86.   unsigned long currentMillis = millis();
  87.   while (currentMillis + interval >= millis()){}      
  88. }
  89.  
  90. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  91. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  92.  
  93. void testAllLed2(int mySpeed){
  94.    
  95.  for(int i = 0; i < 64; i++)
  96.     {
  97.       pinMatrix[0][i] = 1;     //réteg, olszlop
  98.       myDelay(mySpeed);
  99.     }
  100.  
  101.      
  102.  for(int i = 0; i < 64; i++)
  103.     {
  104.       pinMatrix[0][i] = 0;     //réteg, olszlop
  105.       myDelay(mySpeed);
  106.     }
  107. }
  108.  
  109. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  110. //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement