Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. /*****************************************************************
  2. PORT Command is used to change the state of pin i.e. On or OFF
  3. DDR is used to set the pinmode whether as input/output,
  4. thus DDR register instead of using pinMode().
  5. *****************************************************************/
  6. void setup()
  7. {
  8. DDRB = 0b00011111; //B0-B1(Set as output); DDR-Data Direvction Register is used to set the pin as input(0) or output(1)
  9. DDRD = 0b11111111; //D1-D7(Set as output)
  10. }
  11.  
  12. void loop()
  13. {
  14.  
  15. start();
  16. red();
  17. for (int i = 9; i >= 0; i--)
  18. {
  19. for ( int j = 9; j>=0; j--)
  20. {
  21. for (int del = 0; del < 15; del++)
  22. {
  23. disp(i, j,'r');
  24. }
  25. if(i==3 && j==0 ){
  26. yellow();
  27. }
  28. }
  29. }
  30. disp(0,0,'g');
  31. green();
  32. delay(5000);
  33. }
  34.  
  35. void start()
  36. { int i = 2;
  37. while (i != 0)
  38. {
  39. if (i == 2)
  40. {
  41. PORTB = 0b00000010; //Turn ON B1-pin and other pins of port B are OFF.
  42. }
  43. if (i == 1)
  44. {
  45. PORTB = 0b00000001;
  46. }
  47. PORTD = 0b00000010;
  48. PORTD = ~PORTD;
  49. delay(100);
  50. PORTD = 0b00000110;
  51. PORTD = ~PORTD;
  52. delay(100);
  53. PORTD = 0b00001110;
  54. PORTD = ~PORTD;
  55. delay(100);
  56. PORTD = 0b00011110;
  57. PORTD = ~PORTD;
  58. delay(100);
  59. PORTD = 0b00111110;
  60. PORTD = ~PORTD;
  61. delay(100);
  62. PORTD = 0b01111110;
  63. PORTD = ~PORTD;
  64. delay(100);
  65. PORTD = 0b11111110;
  66. PORTD = ~PORTD;
  67. delay(200);
  68. PORTD = 0b01111110;
  69. PORTD = ~PORTD;
  70. delay(100);
  71. PORTD = 0b00111110;
  72. PORTD = ~PORTD;
  73. delay(100);
  74. PORTD = 0b00011110;
  75. delay(100);
  76. PORTD = 0b00001110;
  77. delay(100);
  78. PORTD = 0b00000110;
  79. delay(100);
  80. PORTD = 0b00000010;
  81. delay(100);
  82. PORTD = 0b00000000;
  83. delay(200);
  84. i--;
  85. }
  86. }
  87.  
  88. void zero()
  89. {
  90. PORTD = 0b10000001;
  91. }
  92.  
  93. void one()
  94. {
  95. PORTD = 0b00001100;
  96. PORTD = ~PORTD;
  97. }
  98.  
  99. void two()
  100. {
  101. PORTD = 0b10110110;
  102. PORTD = ~PORTD;
  103. }
  104.  
  105. void three()
  106. {
  107. PORTD = 0b10011110;
  108. PORTD = ~PORTD;
  109. }
  110.  
  111. void four()
  112. {
  113. PORTD = 0b11001100;
  114. PORTD = ~PORTD;
  115. }
  116.  
  117. void five()
  118. {
  119. PORTD = 0b11011010;
  120. PORTD = ~PORTD;
  121. }
  122.  
  123. void six()
  124. {
  125. PORTD = 0b11111010;
  126. PORTD = ~PORTD;
  127. }
  128.  
  129. void seven()
  130. {
  131. PORTD = 0b00001110;
  132. PORTD = ~PORTD;
  133. }
  134.  
  135. void eight()
  136. {
  137. PORTD = 0b11111110;
  138. PORTD = ~PORTD;
  139. }
  140.  
  141. void nine()
  142. {
  143. PORTD = 0b11011110;
  144. PORTD = ~PORTD;
  145. }
  146.  
  147. void red(){
  148. PORTB = 0b00000100;
  149.  
  150. }
  151.  
  152. void yellow(){
  153. PORTB = 0b00001100;
  154. }
  155.  
  156. void green(){
  157. PORTB = (PORTB|0b00010000)&0b00010011;
  158. }
  159.  
  160. void digit1(int x)
  161. {
  162. PORTB = (PORTB|0b00000010)&0b11111110;
  163. switch (x) {
  164. case 1: one(); break;
  165. case 2: two(); break;
  166. case 3: three(); break;
  167. case 4: four(); break;
  168. case 5: five(); break;
  169. case 6: six(); break;
  170. case 7: seven(); break;
  171. case 8: eight(); break;
  172. case 9: nine(); break;
  173. case 10: zero(); break;
  174. case 0: zero(); break;
  175. }
  176. }
  177.  
  178. void digit2(int x)
  179. {
  180. PORTB = (PORTB|0b00000001)&0b11111101;
  181. switch (x) {
  182. case 1: one(); break;
  183. case 2: two(); break;
  184. case 3: three(); break;
  185. case 4: four(); break;
  186. case 5: five(); break;
  187. case 6: six(); break;
  188. case 7: seven(); break;
  189. case 8: eight(); break;
  190. case 9: nine(); break;
  191. case 0: zero(); break;
  192. case 10: zero(); break;
  193. }
  194. }
  195.  
  196. void disp(int i, int j,char x)
  197. {
  198. digit1(i);
  199. delay(10);
  200. digit2(j);
  201. delay(10);
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement