SHARE
TWEET

Using the Shift Register with 2 Breadboards

jmyean May 2nd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Jung Min Yean
  3.  * Learning How to Use a Shift Register
  4.  * 04/30/2019
  5.  */
  6.  
  7.  const int Data = 8; // The output
  8.  const int Latch = 9;
  9.  const int Clock = 10; // Goes around the Shift Register
  10.  int sequence[] = {0,1,2,4,8,16,32,64,128};
  11.  int sequence2[] = {0,1,3,7,15,31,63,127,255};
  12.  int sequence3[] = {255,127,63,31,15,7,3,1,0};
  13.  int sequence4[] = {0,24,36,66,129};
  14.  int sequence5[] = {129,66,36,24,0};
  15.  int sequence6[] = {0,24,60,126,255};
  16.  
  17. void setup()
  18. {
  19.   pinMode(Data, OUTPUT);
  20.   pinMode(Latch, OUTPUT);
  21.   pinMode(Clock, OUTPUT);
  22.  
  23.    digitalWrite(Latch, LOW);
  24.   shiftOut(Data, Clock, MSBFIRST, B11111111); // B means Binary - 1 is on and 0 is off
  25.   digitalWrite(Latch, HIGH);
  26.   delay(200);
  27.  
  28.   digitalWrite(Latch, LOW);
  29.   shiftOut(Data, Clock, MSBFIRST, B00000000); // B means Binary - 1 is on and 0 is off
  30.   digitalWrite(Latch, HIGH);
  31.   delay(200);
  32. }
  33. void lightUp()
  34. {
  35.   for(int i = 0; i < 8; i++)
  36.     {
  37.     digitalWrite(Latch, LOW);
  38.     shiftOut(Data, Clock, MSBFIRST, sequence[i]);
  39.     shiftOut(Data, Clock, MSBFIRST, B00000000);
  40.     digitalWrite(Latch, HIGH);
  41.     delay(200);
  42.   }
  43.     for(int i = 0; i < 8; i++)
  44.     {
  45.     digitalWrite(Latch, LOW);
  46.     shiftOut(Data, Clock, MSBFIRST, B00000000);  
  47.     shiftOut(Data, Clock, MSBFIRST, sequence[i]);
  48.     digitalWrite(Latch, HIGH);
  49.     delay(200);
  50.   }
  51. }
  52.  
  53. void addingUp()
  54. {
  55.   for (int i = 0; i < 8; i++)
  56.   {
  57.     digitalWrite(Latch, LOW);
  58.     shiftOut(Data, Clock, MSBFIRST, sequence2[i]);
  59.     shiftOut(Data, Clock, MSBFIRST, B00000000);
  60.     digitalWrite(Latch, HIGH);
  61.     delay(200);
  62.   }
  63.     for(int i = 0; i < 8; i++)
  64.     {
  65.     digitalWrite(Latch, LOW);    
  66.     shiftOut(Data, Clock, MSBFIRST, B11111111);
  67.     shiftOut(Data, Clock, MSBFIRST, sequence2[i]);
  68.     digitalWrite(Latch, HIGH);
  69.     delay(200);
  70.   }
  71. }
  72.  
  73. void subtractingDown()
  74. {
  75.   for (int i = 0; i < 8; i++)
  76.   {
  77.     digitalWrite(Latch, LOW);
  78.     shiftOut(Data, Clock, MSBFIRST, B11111111);
  79.     shiftOut(Data, Clock, MSBFIRST, sequence3[i]);
  80.     digitalWrite(Latch, HIGH);
  81.     delay(200);
  82.   }
  83.     for(int i = 0; i < 8; i++)
  84.     {
  85.     digitalWrite(Latch, LOW);
  86.     shiftOut(Data, Clock, MSBFIRST, sequence3[i]);
  87.     shiftOut(Data, Clock, MSBFIRST,B00000000);
  88.     digitalWrite(Latch, HIGH);
  89.     delay(200);
  90.   }
  91. }
  92.  
  93. void chopsticksOut()
  94. {
  95.   for (int i = 0; i < 5; i++)
  96.   {
  97.     digitalWrite(Latch, LOW);
  98.     shiftOut(Data, Clock, MSBFIRST, sequence4[i]);
  99.     shiftOut(Data, Clock, MSBFIRST, sequence4[i]);
  100.     digitalWrite(Latch, HIGH);
  101.     delay(200);
  102.   }
  103. }
  104.  
  105. void chopsticksIn()
  106. {
  107.   for (int i = 0; i < 5; i++)
  108.   {
  109.     digitalWrite(Latch, LOW);
  110.     shiftOut(Data, Clock, MSBFIRST, sequence5[i]);
  111.     shiftOut(Data, Clock, MSBFIRST, sequence5[i]);
  112.     digitalWrite(Latch, HIGH);
  113.     delay(200);
  114.   }
  115. }
  116.  
  117. void addingOut()
  118. {
  119.   for (int i = 0; i < 5; i++)
  120.   {
  121.     digitalWrite(Latch, LOW);
  122.     shiftOut(Data, Clock, MSBFIRST, sequence6[i]);
  123.     shiftOut(Data, Clock, MSBFIRST, sequence6[i]);
  124.     digitalWrite(Latch, HIGH);
  125.     delay(200);
  126.   }
  127. }
  128.  
  129. void loop()
  130. {
  131. lightUp();
  132. addingUp();
  133. subtractingDown();
  134. chopsticksIn();
  135. chopsticksOut();
  136. addingOut();
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top