16x16 homemade led matris + 4x74HC595 shift register

Used Products:

1. Arduino UNO

Code:

int clockPin = 10; int dataPin = 9; int latchPin = 8; int clockPin2 = 6; int dataPin2 = 5; int latchPin2 = 4; long interval = 100; unsigned long previousTime = 0; void setup() { Serial.begin(9600); pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(latchPin2, OUTPUT); pinMode(clockPin2, OUTPUT); pinMode(dataPin2, OUTPUT); } unsigned int pattern1[8][2][2] = { {{0b1111111001111111,0b0000000110000000},{0b1111111111111111,0b1111111111111111}} ,{{0b1111110110111111,0b0000001111000000},{0b1111111001111111,0b0000001001000000}} ,{{0b1111101111011111,0b0000011111100000},{0b1111110000111111,0b0000010000100000}} ,{{0b1111011111101111,0b0000111111110000},{0b1111100000011111,0b0000100000010000}} ,{{0b1110111111110111,0b0001111111111000},{0b1111000000001111,0b0001000000001000}} ,{{0b1101111111111011,0b0011111111111100},{0b1110000000000111,0b0010000000000100}} ,{{0b1011111111111101,0b0111111111111110},{0b1100000000000011,0b0100000000000010}} ,{{0b0111111111111110,0b1111111111111111},{0b1000000000000001,0b1000000000000001}} }; int i = 0; byte b; void loop() { unsigned long currentTime = millis(); if (currentTime - previousTime > interval) { if (++i > 7) { i = 0; } previousTime = currentTime; } else { for (int j = 0; j < 2; j++) { b = B11111111; digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, b); shiftOut(dataPin, clockPin, b); digitalWrite(latchPin, 1); b = B00000000; digitalWrite(latchPin2, 0); shiftOut(dataPin2, clockPin2, b); shiftOut(dataPin2, clockPin2, b); digitalWrite(latchPin2, 1); b = highByte(pattern1[i][j][0]); digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, b); b = lowByte(pattern1[i][j][0]); shiftOut(dataPin, clockPin, b); digitalWrite(latchPin, 1); b = highByte(pattern1[i][j][1]); digitalWrite(latchPin2, 0); shiftOut(dataPin2, clockPin2, b); b = lowByte(pattern1[i][j][1]); shiftOut(dataPin2, clockPin2, b); digitalWrite(latchPin2, 1); } // for j } //if currentTime } // loop() // the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; //pinMode(myClockPin, OUTPUT); //pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut´┐Ż //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1<<i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); } //stop shifting digitalWrite(myClockPin, 0); }