Advertisement
Riz1Ahmed

ShiftRegisterMatrixDisplay_8x16

Feb 16th, 2022 (edited)
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <ShiftRegister74HC595.h>
  2.  
  3. //My display matrix connection image: https://imgur.com/a/v81w42t
  4.  
  5. //Please change this two value with total Shift Register no in row and column.
  6. const int rowRegNo=1;
  7. const int columnRegNo=2;
  8.  
  9. //In my Matrix Display
  10. //DataPin  = Blue cable
  11. //LatchPin = Green cable
  12. //ClockPin = White cable
  13. int v5=2;
  14. int dpC=2,lpC=3,cpC=4;//Pins of Column
  15. int dpR=5,lpR=6,cpR=7;//Pins of Row
  16.  
  17. const int rowSize=rowRegNo*8;
  18. const int columnSize=columnRegNo*8;
  19. ShiftRegister74HC595<rowRegNo> rReg(dpR,cpR,lpR);
  20. ShiftRegister74HC595<columnRegNo> cReg(dpC,cpC,lpC);
  21.  
  22. int* alphaMt;
  23.  
  24. bool mt[rowSize][columnSize] = {
  25.   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  26.   {0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
  27.   {0,1,0,0,1,0,1,0,0,0,0,0,0,0,1,0},
  28.   {0,1,0,0,1,0,0,0,1,1,1,1,0,1,1,0},
  29.   {0,1,1,1,1,0,1,0,0,0,1,0,0,0,1,0},
  30.   {0,1,0,1,0,0,1,0,0,1,0,0,0,0,1,0},
  31.   {0,1,0,0,1,0,1,0,1,1,1,1,0,1,1,1},
  32.   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  33. };
  34. uint8_t mtB[][2]={{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
  35.  
  36. void setup() {
  37.   Serial.begin(9600);
  38.   pinMode(v5, OUTPUT);
  39.  
  40.   setupBoolDisp();
  41.   initAlpha();
  42. }
  43.  
  44. void loop(){
  45.   showDisplay();
  46. }
  47.  
  48. int pos=15,tm=0;
  49. void showDisplay() {
  50.   tm++;
  51.   if (!(tm%20)) {
  52.     pos--;
  53.     if(pos<0) pos=15;
  54.   }
  55.  
  56.   rReg.setAllHigh();//Reverse
  57.   cReg.setAllLow();//Reverse
  58.  
  59.   for (int r=0; r<rowSize; r++){
  60.     rReg.set(r, LOW);
  61.     for (int c=0; c<columnSize; c++){
  62.       int x=(c+pos)%16;
  63.       if (mt[r][c])
  64.         cReg.setNoUpdate(x,HIGH);//p2
  65.         //cReg.set(x, HIGH);//p1
  66.     }
  67.     cReg.updateRegisters();//p2
  68.     delay(1);
  69.  
  70.     //cReg.setAll(mtB[r]);
  71.     delay(1);
  72.     cReg.setAllLow();//Reverse
  73.     rReg.set(r, HIGH);//Reverse
  74.   }
  75. }
  76.  
  77. void setupBoolDisp(){
  78.   for (int i=0; i<8;i++){
  79.     int y=0;
  80.     for (int j=0; j<16; j++){
  81.       int idx=j/8 , p=j%8;
  82.       mtB[i][idx]|=(1<<p) *mt[i][j];
  83.     }
  84. //    Serial.print(mtB[i][0]);
  85. //    Serial.print(",");
  86. //    Serial.println(mtB[i][1]);
  87.   }
  88. }
  89.  
  90. void initAlpha(){
  91.   int x[rowSize][columnSize]={{0,9}};
  92.   //alphaMt = x;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement