p26_74HC595Drivea7SegmentalLED.ino 705 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. Demo code for Project 26 - 74HC595 Drive a 7 Segmental LED
  3. */
  4. int latchPin = 8;
  5. int clockPin = 12;
  6. int dataPin = 11; //pins 74HC595 are connected to
  7. void setup ()
  8. {
  9. pinMode(latchPin,OUTPUT);
  10. pinMode(clockPin,OUTPUT);
  11. pinMode(dataPin,OUTPUT); //set the pins OUTPUT
  12. }
  13. void loop()
  14. {
  15. int a[]={
  16. 249,164,176,153,146,130,248,128,144,//0~9 decimal of octet
  17. 136,131,167,161,134,142
  18. //a~f
  19. }; //QO,Q1,Q2,Q3,Q4,Q5,Q6,Q7 - - a,b,c,d,e,f,g,dp
  20. for(int x=0; x<16 ;x++ )
  21. {
  22. digitalWrite(latchPin,LOW);
  23. shiftOut(dataPin,clockPin,MSBFIRST,a[x]);
  24. // display a[] by function shiftOut(), MSB_First
  25. digitalWrite(latchPin,HIGH);
  26. delay(1000);
  27. }
  28. }