Advertisement
babyyoda_

74HC164 7 Segment

Feb 5th, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define data A5
  2. #define clock A4
  3.  
  4. int digit1 = 5;
  5. int digit2 = 6;
  6. int digit3 = 7;
  7.  
  8. int count = 0;
  9.  
  10. byte zero  = B00010010;
  11. byte one   = B11011110;
  12. byte two   = B00010101;
  13. byte three = B10010100;
  14. byte four  = B11011000;
  15. byte five  = B10110000;
  16. byte six   = B00110000;
  17. byte seven = B11010110;
  18. byte eight = B00010000;
  19. byte nine  = B11010000;
  20. byte clrs  = B11111111;
  21. byte night  = B00000001;
  22. byte timer  = B11111110;
  23.  
  24. byte Digit[] = {B00010010, B11011110, B00010101, B10010100, B11011000, B10110000, B00110000, B11010110, B00010000, B11010000};
  25. int i, j;
  26. int DELAY = 5;
  27.  
  28. void setup() {
  29.   pinMode(clock, OUTPUT);
  30.   pinMode(data , OUTPUT);
  31.   pinMode(digit1, OUTPUT);
  32.   pinMode(digit2, OUTPUT);
  33. }
  34.  
  35. void loop() {
  36.   setDigit_(25);
  37. }
  38.  
  39. int setDigit_(int D) {
  40.  
  41.   int unit, tens;
  42.   if (D > 9) {
  43.     unit = D % 10;
  44.     tens = D / 10;
  45.   }
  46.   else
  47.     unit = D;
  48.  
  49.   digitalWrite(digit2, LOW);
  50.   shiftOut(data, clock, LSBFIRST, Digit[tens]);
  51.   digitalWrite(digit1, HIGH);
  52.   delay(DELAY);
  53.   digitalWrite(digit1, LOW);
  54.   shiftOut(data, clock, LSBFIRST, Digit[unit]);
  55.   digitalWrite(digit2, HIGH);
  56.   delay(DELAY);
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement