GeldenGolem

3Shift code

Oct 24th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. const int serial=8; //serial output to shift register
  2. const int latch=9; //shift register latch pin
  3. const int clck=10; //shift register clock pin
  4. int sequence[15 ] = {1, 2, 4, 8, 16, 32, 64, 128, 64, 32, 16, 8, 4, 2, 1};
  5. int sequence2 [15] = {1,3,7,15,31,63,127,255,127,63,31,15,7,3,1};
  6. int sequence3 [7]= {129, 66, 36, 24, 36, 66, 129};
  7. int sequence4 [11 ]={17, 34, 68, 136, 80, 64, 80, 136, 68, 34, 17};
  8. void setup()
  9. {
  10. pinMode (serial, OUTPUT);
  11. pinMode (latch, OUTPUT);
  12. pinMode (clck,OUTPUT);
  13.  
  14. digitalWrite (latch, LOW); //latch low
  15. shiftOut (serial, clck, MSBFIRST, B00000000); //shift most significant bit first
  16. digitalWrite (latch, HIGH); //latch high-show pattern
  17.  
  18. }
  19.  
  20. void loop()
  21. {
  22. for (int i=0; i<15; i++)
  23. {
  24. digitalWrite (latch, LOW); //latch low
  25. shiftOut (serial, clck, MSBFIRST, sequence[i]); //shift most significant bit first
  26. digitalWrite (latch, HIGH); //latch high-show pattern
  27. delay (200);
  28. }
  29. for (int i=0; i<15; i++)
  30. {
  31. digitalWrite (latch, LOW); //latch low
  32. shiftOut (serial, clck, MSBFIRST, sequence2[i]); //shift most significant bit first
  33. digitalWrite (latch, HIGH); //latch high-show pattern
  34. delay (200);
  35. }
  36. for (int i=0; i<15; i++)
  37. {
  38. digitalWrite (latch, LOW); //latch low
  39. shiftOut (serial, clck, MSBFIRST, sequence3[i]); //shift most significant bit first
  40. digitalWrite (latch, HIGH); //latch high-show pattern
  41. delay (200);
  42. }
  43. for (int i=0; i<15; i++)
  44. {
  45. digitalWrite (latch, LOW); //latch low
  46. shiftOut (serial, clck, MSBFIRST, sequence4[i]); //shift most significant bit first
  47. digitalWrite (latch, HIGH); //latch high-show pattern
  48. delay (200);
  49. }
  50. }
Add Comment
Please, Sign In to add comment