Advertisement
Guest User

Untitled

a guest
May 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Arduino 7 segment display example software
  2. // http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
  3. // License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
  4.  
  5.  
  6.  
  7. // Define the LED digit patters, from 0 - 9
  8. // Note that these patterns are for common cathode displays
  9. // For common anode displays, change the 1's to 0's and 0's to 1's
  10. // 1 = LED on, 0 = LED off, in this order:
  11.  
  12. //                                    Arduino pin: 2,3,4,5,6,7,8
  13. byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0
  14.                                                            { 1,0,0,1,1,1,1 },  // = 1
  15.                                                            { 0,0,1,0,0,1,0 },  // = 2
  16.                                                            { 0,0,0,0,1,1,0 },  // = 3
  17.                                                            { 1,0,0,1,1,0,0 },  // = 4
  18.                                                            { 0,1,0,0,1,0,0 },  // = 5
  19.                                                            { 0,1,0,0,0,0,0 },  // = 6
  20.                                                            { 0,0,0,1,1,1,1 },  // = 7
  21.                                                            { 0,0,0,0,0,0,0 },  // = 8
  22.                                                            { 0,0,0,1,1,0,0 }   // = 9
  23.                                                            };
  24. void setup() {                
  25.   pinMode(2, OUTPUT);  
  26.   pinMode(3, OUTPUT);
  27.   pinMode(4, OUTPUT);
  28.   pinMode(5, OUTPUT);
  29.   pinMode(6, OUTPUT);
  30.   pinMode(7, OUTPUT);
  31.   pinMode(8, OUTPUT);
  32.   pinMode(9, OUTPUT);
  33.   writeDot(0);  // start with the "dot" off
  34. }
  35.  
  36. void writeDot(byte dot) {
  37.   digitalWrite(9, dot);
  38. }
  39.    
  40. void sevenSegWrite(byte digit) {
  41.   byte pin = 2;
  42.   for (byte segCount = 0; segCount < 7; ++segCount) {
  43.     digitalWrite(pin, seven_seg_digits[digit][segCount]);
  44.     ++pin;
  45.   }
  46. }
  47.  
  48. void loop() {
  49.   for (byte count = 10; count > 0; --count) {
  50.    delay(1000);
  51.    sevenSegWrite(count - 1);
  52.   }
  53.   delay(4000);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement