Advertisement
pigg

Arduino控制七段顯示器

May 25th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. /*
  2. 範例5
  3. 每隔1秒鐘,在七段顯示器上顯示0~9,正數,依此循環。
  4.  
  5. 範例6
  6. 每隔1秒鐘,在七段顯示器上顯示9~0,倒數,依此循環。
  7.  
  8. 硬體接線a接0 b接1 c接2...以此類推
  9. */
  10.  
  11. void setup()
  12. {
  13. for(int i=0;i<=7;i++)  //將0~7腳設定為輸出
  14.   pinMode(i,OUTPUT);
  15. }
  16. int LED[]=
  17. {
  18. B0111111,//0
  19. B0000110,//1
  20. B1011011,//2
  21. B1001111,//3
  22. B1100110,//4
  23. B1101101,//5
  24. B1111101,//6
  25. B0100111,//7
  26. B1111111,//8
  27. B1100111 //9
  28. };
  29. void loop()
  30. {
  31.  for(int i=9;i>=0;i--)   //若要由0數到9則本行改為 for(int i=0;i<=9;i++)
  32. {
  33.   PORTD=LED[i];
  34.   delay(1000);
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement