Guest User

7-Segment Display Counter

a guest
Oct 1st, 2017
436
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. byte pins[8] = {2,3,4,6,7,8,9}; // The digital pins that we are using
  2. int duration = 1000; // The delay between the number changes
  3.  
  4. byte num0 = 0x3F;
  5. byte num1 = 0x0C;
  6. byte num2 = 0x5B;
  7. byte num3 = 0x5E;
  8. byte num4 = 0x6C;
  9. byte num5 = 0x76;
  10. byte num6 = 0x77;
  11. byte num7 = 0x1C;
  12. byte num8 = 0x7F;
  13. byte num9 = 0x7E;
  14.  
  15. void printN(byte _digit) { // The function that prints the numbers
  16.   for (int i = 0; i < 8; i++) {
  17.     digitalWrite(pins[i], bitRead(_digit, i ));
  18.   }    
  19. }
  20.  
  21. void setup() { // Our setup function, in which we initialise the above-mentioned pins
  22.   for(int i = 0; i <= 9; i++) {
  23.     pinMode(pins[i], OUTPUT);
  24.   }
  25. }
  26.  
  27. void loop() {
  28.   printN(num0); delay(duration); // Basicly, what this line does: print 0 on the display then wait 1 second
  29.   printN(num1); delay(duration);
  30.   printN(num2); delay(duration);
  31.   printN(num3); delay(duration);
  32.   printN(num4); delay(duration);
  33.   printN(num5); delay(duration);
  34.   printN(num6); delay(duration);
  35.   printN(num7); delay(duration);
  36.   printN(num8); delay(duration);
  37.   printN(num9); delay(duration);
  38. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×