Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "TimerOne.h"
- //initializing and declaring led rows
- int column[16]={13,12,11,10,9,8,7,6,5,4,3,2,1,0,A5,A4};
- //initializing and declaring led layers
- int layer[4]={A0,A1,A2,A3};
- volatile int mp_layer=0;
- int mp_time = 1;
- int irany = 0;
- int tmp_counter=0;
- unsigned long previousMillis = 0; // will store last time LED was updated
- byte pinMatrix[4][16] = {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- };
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- void setup()
- {
- Timer1.initialize(2000); // 2000 oké
- Timer1.attachInterrupt(multiplex); // attaches callback() as a timer overflow interrupt
- for(int i = 0; i<16; i++)
- {
- pinMode(column[i], OUTPUT);
- }
- for(int i = 0; i<4; i++)
- {
- pinMode(layer[i], OUTPUT);
- }
- Serial.begin(9600);
- }//setup
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- void multiplex()
- {
- for(volatile int j = 0; j<16; j++) //Kikapcsolok minden oszlopot az aktuális rétegen
- {
- digitalWrite(column[j], 0);
- }
- digitalWrite(layer[mp_layer], 0); //Kikapcsolom az aktuális réteget
- if (mp_layer<3) //Kiszámolom a soron következő réteget
- mp_layer++;
- else
- mp_layer = 0;
- for(volatile int z = 0; z<16; z++) //Bekapcsolok minden oszlopot amit kell
- {
- digitalWrite(column[z], pinMatrix[mp_layer][z]);
- }
- digitalWrite(layer[mp_layer], 1); //Bekapcsolom az soron következő réteget
- }
- //xxxxxxxxxxxxxxxxxxxxFUNCTION LOOPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- void loop()
- {
- pinMatrix[0][0] = 0; //réteg, olszlop
- Serial.println(0);
- myDelay(1000);
- pinMatrix[0][0] = 1; //réteg, olszlop
- Serial.println(1);
- myDelay(1000);
- }
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- void myDelay(long interval)
- {
- unsigned long currentMillis = millis();
- while (currentMillis + interval >= millis()){}
- }
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- void testAllLed2(int mySpeed){
- for(int i = 0; i < 64; i++)
- {
- pinMatrix[0][i] = 1; //réteg, olszlop
- myDelay(mySpeed);
- }
- for(int i = 0; i < 64; i++)
- {
- pinMatrix[0][i] = 0; //réteg, olszlop
- myDelay(mySpeed);
- }
- }
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement