Display numbers in big bright red LEDs use only 3 micro-controller pins and the 74HC595 shift register
byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b,0b10011000 };
Here a zero corresponds to an LED being ON and a 1 corresponds to an LED being OFF. Maybe a little counter-intuitive, but it is this way because the seven segment Display we are using is a common anode device so you toggle the different LEDs on and off by connecting ground to the LED pins. This array contains the LED settings to display the ten decimal digits (thanks
arabic numerals
! Roman numerals are lame...) So, now that we know which bytes we want to send to the shift registers the code just boils down to looping over the byte array and sending out a new byte every so often. This is the code to do that:
for (int numberToDisplay = 0; numberToDisplay < 10; numberToDisplay++) { // take the latchPin low so // the LEDs don't change while you're sending in bits: digitalWrite(latchPin, LOW); // shift out the bits: shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]); //take the latch pin high so the LEDs will light up: digitalWrite(latchPin, HIGH); // pause before next value: delay(300); }
Note that in the line:
shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]);We grab the LED segment settings from the dec_digits array. We cannot just write the number out to the shift register. For example, if you shift out an 8 you are sending the shift register the byte 00001000, this means light up all of the segment of the 7-Segment LEDs except the third one. This would look like A not an 8. If you want to see an 8 you have to write out the byte: 128 (decimal) = 0x80(hex) = (binary), which means every LED segment on except the decimal point.
/* LucidTronix 7 Segment LED * and 74HC595 shift register * Tutorial at: * http://www.lucidtronix.com/tutorials/41 */int dataPin = 2;int latchPin = 3;int clockPin = 4;byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b,0b10011000 };void setup() { //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT);}void loop() { for (int numberToDisplay = 0; numberToDisplay < 10; numberToDisplay++) { // take the latchPin low so // the LEDs don't change while you're sending in bits: digitalWrite(latchPin, LOW); // shift out the bits: shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]); //take the latch pin high so the LEDs will light up: digitalWrite(latchPin, HIGH); // pause before next value: delay(300); }}
| Title | Description | # | Cost | Link | Picture |
| PCB 7 Segment LED Display and 74HC595 Shift Register | 74HC595 Shift Register breakout board for 7 Segment LED numeric display | 1 | $4.0 | Link |
|
| LED Display | 7 Segment numeric LED Display REDValue:7 Red LEDs | 1 | $0.95 | Link |
|
| Shift Register | IC 8-BIT SHIFT REGISTER 16-DIP Serial to Parallel Tri-State 2 V ~ 6 VValue:74HC | 1 | $0.63 | Link |
|
| Capacitor | Ceramic Capacitors CAP CER 0.1UF 50V 20% RADIALValue: 0.1µF | 2 | $0.24 | Link |
|
| Resistor | RES 300 OHM 1/4W 5% CARBON FILMValue:300 | 8 | $0.08 | Link |
|
Comments: