Created
June 4, 2019 09:28
-
-
Save MindstormFan/2fc338bd979c97f201ac676460097067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte seven_seg_digits[10] = { B11111100, // = 0 | |
B01100000, // = 1 | |
B11011010, // = 2 | |
B11110010, // = 3 | |
B01100110, // = 4 | |
B10110110, // = 5 | |
B10111110, // = 6 | |
B11100000, // = 7 | |
B11111110, // = 8 | |
B11100110 // = 9 | |
}; | |
// connect to the ST_CP of 74HC595 (pin 3,latch pin, pin 5 of IC) | |
int latchPin = 3;//12; //3; | |
// connect to the SH_CP of 74HC595 (pin 4, clock pin, pin 6 of IC) | |
int clockPin = 4;//13; //4; | |
// connect to the DS of 74HC595 (pin 2 pin 3 of IC) | |
int dataPin =2; //11; //2; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(13, OUTPUT); | |
pinMode(12, OUTPUT); | |
pinMode(11, OUTPUT); | |
pinMode(latchPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
pinMode(dataPin, OUTPUT); | |
} | |
// display a number on the digital segment display | |
void sevenSegWrite(byte digit) { | |
// set the latchPin to low potential, before sending data | |
digitalWrite(latchPin, LOW); | |
// the original data (bit pattern) | |
shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]); | |
// set the latchPin to high potential, after sending data | |
digitalWrite(latchPin, HIGH); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
digitalWrite(11, HIGH); | |
for (byte digit = 10; digit > 0; --digit) { | |
delay(1000); | |
sevenSegWrite(digit - 1); | |
} | |
digitalWrite(11, LOW); | |
digitalWrite(12, HIGH); | |
for (byte digit = 10; digit > 0; --digit) { | |
delay(1000); | |
sevenSegWrite(digit - 1); | |
} | |
digitalWrite(12, LOW); | |
digitalWrite(13, HIGH); | |
for (byte digit = 10; digit > 0; --digit) { | |
delay(1000); | |
sevenSegWrite(digit - 1); | |
} | |
digitalWrite(13, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment