daily pastebin goal
32%
SHARE
TWEET

Shift Register Mini Project

mianess Jun 22nd, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int seqNum [10] = { 252, 80, 186, 218, 86, 206, 238, 88, 254, 222 };
  2. int LedVals [9] = {0,1,2,4,8,16,32,64,128,};
  3. int BackLedVals[9] = {128, 64, 32, 16, 8, 4, 2, 1, 0};
  4. int newLED [8] = { 1, 3, 7, 15, 31, 63, 127, 255};
  5. int backLedVals [8] = {255, 127, 63, 31, 15, 7, 3, 1};
  6. bool lastButton = false;
  7. bool currentButton =false;
  8. int randNum;
  9. const int buttPin = 8;
  10. const int SER = 9;
  11. const int LATCH = 10;
  12. const int CLK = 11;
  13. const int SER2 = 2;
  14. const int LATCH2 = 3;
  15. const int CLK2 = 4;
  16. int count = 0;
  17. void setup() {
  18.   // put your setup code here, to run once:
  19.   pinMode (SER, OUTPUT);
  20.   pinMode (LATCH, OUTPUT);
  21.   pinMode (CLK, OUTPUT);
  22.   pinMode (SER2, OUTPUT);
  23.   pinMode (LATCH2, OUTPUT);
  24.   pinMode (CLK2, OUTPUT);
  25.   digitalWrite (LATCH, LOW);
  26.   shiftOut (SER, CLK, MSBFIRST, B11111111);
  27.   digitalWrite (LATCH, HIGH);
  28.   delay (200);
  29.   digitalWrite (LATCH, LOW);
  30.   shiftOut (SER, CLK, MSBFIRST, B00000000);
  31.   digitalWrite (LATCH, HIGH);
  32.   randomSeed(analogRead(0));
  33.   digitalWrite (LATCH2, LOW);
  34.   shiftOut (SER2, CLK2, MSBFIRST, B11111111);
  35.   digitalWrite (LATCH2, HIGH);
  36.   delay (200);
  37.   digitalWrite (LATCH2, LOW);
  38.   shiftOut (SER2, CLK2, MSBFIRST, B00000000);
  39.   digitalWrite (LATCH2, HIGH);
  40.   Serial.begin (9600);
  41.  
  42. }
  43.   boolean debounce (boolean last)
  44.   {
  45.   boolean current = digitalRead(buttPin);
  46.   if (last != current)
  47.   {
  48.     delay(5);
  49.     current = digitalRead(buttPin);
  50.   }
  51.   return current;
  52.     randomSeed(analogRead(0));
  53. }
  54. void effect (int seq [])
  55. {
  56. for (int i = 0; i < 10; i++)
  57.    {
  58.    digitalWrite (LATCH, LOW);
  59.   shiftOut (SER, CLK, MSBFIRST, seq[i]);
  60.   digitalWrite (LATCH, HIGH);
  61.   delay (100);
  62.    }
  63. }
  64. void loop()
  65. {
  66.   currentButton = debounce (lastButton);
  67.   if (lastButton == LOW && currentButton == HIGH)
  68.   {
  69.    randNum = random (1,11);
  70.    Serial.println (randNum);
  71.    digitalWrite(LATCH2, LOW);
  72.     shiftOut (SER2, CLK2, MSBFIRST, seqNum [randNum]);
  73.     digitalWrite (LATCH2, HIGH);
  74. //  }
  75. delay(500);
  76.   }
  77.   switch(randNum)
  78.   {
  79.    case 1 :
  80.    effect (BackLedVals);
  81.   break;
  82.  
  83.  
  84.  }
  85.   lastButton = currentButton;
  86. }
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