Advertisement
sudoaptinstallname

Seven Segment With Decimal

Oct 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int SER = 8; // Serial Output to Shift Register
  2. const int LATCH = 9; // Shift Register Latch Pin
  3. const int CLK = 10; // Shift Register Clock Pin
  4.  
  5. int x;
  6.  
  7. int y;
  8.  
  9. int dly = 500;
  10.  
  11. int seq[]={130,217,211,178,115,123,194,507,242};
  12. void setup() {
  13.   // put your setup code here, to run once:
  14.  
  15.  
  16. pinMode(SER, OUTPUT);
  17. pinMode(LATCH, OUTPUT);
  18. pinMode(CLK, OUTPUT);
  19. digitalWrite(LATCH, LOW);
  20. digitalWrite(LATCH,HIGH);
  21. }
  22.  
  23. void dec()
  24. {
  25. digitalWrite(LATCH, LOW);
  26. shiftOut(SER, CLK, MSBFIRST, 4);
  27. digitalWrite(LATCH,HIGH);
  28. }
  29. void one()
  30. {
  31. digitalWrite(LATCH, LOW);
  32. shiftOut(SER, CLK, MSBFIRST, 130);
  33. digitalWrite(LATCH,HIGH);
  34. }
  35. void two()
  36. {
  37. digitalWrite(LATCH, LOW);
  38. shiftOut(SER, CLK, MSBFIRST, 217);
  39. digitalWrite(LATCH,HIGH);
  40. }
  41. void three()
  42. {
  43. digitalWrite(LATCH, LOW);
  44. shiftOut(SER, CLK, MSBFIRST, 211);
  45. digitalWrite(LATCH,HIGH);
  46. }
  47. void four()
  48. {
  49. digitalWrite(LATCH, LOW);
  50. shiftOut(SER, CLK, MSBFIRST, 178);
  51. digitalWrite(LATCH,HIGH);
  52. }
  53. void five()
  54. {
  55. digitalWrite(LATCH, LOW);
  56. shiftOut(SER, CLK, MSBFIRST, 115);
  57. digitalWrite(LATCH,HIGH);
  58. }
  59. void six()
  60. {
  61. digitalWrite(LATCH, LOW);
  62. shiftOut(SER, CLK, MSBFIRST, 123);
  63. digitalWrite(LATCH,HIGH);
  64. }
  65. void seven()
  66. {
  67. digitalWrite(LATCH, LOW);
  68. shiftOut(SER, CLK, MSBFIRST, 194);
  69. digitalWrite(LATCH,HIGH);
  70. }
  71. void eight()
  72. {
  73. digitalWrite(LATCH, LOW);
  74. shiftOut(SER, CLK, MSBFIRST, 507);
  75. digitalWrite(LATCH,HIGH);
  76. }
  77. void nine()
  78. {
  79. digitalWrite(LATCH, LOW);
  80. shiftOut(SER, CLK, MSBFIRST, 242);
  81. digitalWrite(LATCH,HIGH);
  82. }
  83. void loop() {
  84.   // put your main code here, to run repeatedly:
  85.  
  86. x = random(1,10);
  87.  
  88. for (y = 1; y <= 9; y++)
  89. {
  90.  
  91.  
  92. //seq[x];
  93. //delay(100);
  94.  
  95. switch (y)
  96. {
  97.   case 1:
  98.   one();
  99.   delay(dly);
  100.   break;
  101.  
  102.   case 2:
  103.   two();
  104.   delay(dly);
  105.   break;
  106.  
  107.   case 3:
  108.   three();
  109.   delay(dly);
  110.   break;
  111.  
  112.   case 4:
  113.   four();
  114.   delay(dly);
  115.   break;
  116.  
  117.   case 5:
  118.   five();
  119.   delay(dly);
  120.   break;
  121.  
  122.   case 6:
  123.   six();
  124.   delay(dly);
  125.   break;
  126.  
  127.   case 7:
  128.   seven();
  129.   delay(dly);
  130.   break;
  131.  
  132.   case 8:
  133.   eight();
  134.   delay(dly);
  135.   break;
  136.  
  137.   case 9:
  138.   nine();
  139.   delay(dly);
  140.   break;
  141.  
  142. }
  143. //
  144. //  case dec:
  145. //  dec();
  146. //  delay(dly);
  147. //  break;
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement