Advertisement
manvi_m

connecting 5 shift registers

Jun 29th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /*
  2. * Manvi Mittal
  3. * 5 shift registers
  4. */
  5.  
  6. const int ser = 17;
  7. const int latch = 18;
  8. const int clk = 19;
  9.  
  10. int lights [7] = {2, 4, 8, 16, 32, 64, 128};
  11. int bar [7] = {3, 7, 15, 31, 63, 127, 255};
  12.  
  13. void setup() {
  14. // put your setup code here, to run once:
  15. pinMode (ser, OUTPUT);
  16. pinMode (latch, OUTPUT);
  17. pinMode (clk, OUTPUT);
  18.  
  19. lightUp (B11111111, B11111111, B11111111, B11111111, B11111111); // scroll down for lightUp function
  20. delay (100);
  21.  
  22. }
  23.  
  24. void loop()
  25. {
  26. // put your main code here, to run repeatedly:
  27.  
  28. for (int i = 0; i < 7; i++)
  29. {
  30. lightUp (lights[i], B0000000, B0000000, B0000000, B0000000);
  31. delay (100);
  32. }
  33.  
  34. for (int i = 0; i < 7; i++)
  35. {
  36. lightUp (B0000000, lights[i], B0000000, B0000000, B0000000);
  37. delay (100);
  38. }
  39.  
  40. for (int i = 0; i < 7; i++)
  41. {
  42. lightUp (B0000000, B0000000, lights[i], B0000000, B0000000);
  43. delay (100);
  44. }
  45.  
  46. for (int i = 0; i < 7; i++)
  47. {
  48. lightUp (B0000000, B0000000, B0000000, lights[i], B0000000);
  49. delay (100);
  50. }
  51.  
  52. for (int i = 0; i < 7; i++)
  53. {
  54. lightUp (B0000000, B0000000, B0000000, B0000000, lights[i]);
  55. delay (100);
  56. }
  57.  
  58. for (int i = 0; i < 7; i++)
  59. {
  60. lightUp (bar[i], B0000000, B0000000, B0000000, B0000000);
  61. delay (100);
  62. }
  63.  
  64. for (int i = 0; i < 7; i++)
  65. {
  66. lightUp (B11111111, bar[i], B0000000, B0000000, B0000000);
  67. delay (100);
  68. }
  69.  
  70. for (int i = 0; i < 7; i++)
  71. {
  72. lightUp (B11111111, B11111111, bar[i], B0000000, B0000000);
  73. delay (100);
  74. }
  75.  
  76. for (int i = 0; i < 7; i++)
  77. {
  78. lightUp (B11111111, B11111111, B11111111, bar[i], B0000000);
  79. delay (100);
  80. }
  81.  
  82. for (int i = 0; i < 7; i++)
  83. {
  84. lightUp (B11111111, B11111111, B11111111, B11111111, bar[i]);
  85. delay (100);
  86. }
  87.  
  88. for (int i = 0; i < 66; i++)
  89. {
  90. lightUp (random (2, 255), random (2, 255), random (2, 255), random (2, 255), random (2, 255));
  91. delay (100);
  92. }
  93.  
  94.  
  95. }
  96.  
  97. void lightUp (int byte1, int byte2, int byte3, int byte4, int byte5)
  98. {
  99. digitalWrite (latch, LOW);
  100. shiftOut (ser, clk, MSBFIRST, byte1);
  101. shiftOut (ser, clk, MSBFIRST, byte2);
  102. shiftOut (ser, clk, MSBFIRST, byte3);
  103. shiftOut (ser, clk, MSBFIRST, byte4);
  104. shiftOut (ser, clk, MSBFIRST, byte5);
  105. digitalWrite (latch, HIGH);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement