[Arduino] Using 74LS48 decoder and 7 -segment to display number
#################################################
Document :
PDF file 74LS48 Spec
XL-SD105602 - 0.56-inch Single Digit LED 7-Segment Display
According to PDF (74LS48 -- common cathode) and Single Digit LED 7-segment Display.
Connect Output a to LED a. LED a pin location is 7. 74LS48 output a is pin 13.
Connect Output b to LED b. LED b pin location is 6. 74LS48 output b is pin 12.
Connect Output c to LED c. LED c pin location is 4. 74LS48 output c is pin 11.
Connect Output d to LED d. LED d pin location is 2. 74LS48 output d is pin 10.
Connect Output e to LED e. LED e pin location is 1. 74LS48 output e is pin 9.
Connect Output f to LED f. LED f pin location is 9. 74LS48 output f is pin 15.
Connect Output g to LED g. LED g pin location is 10. 74LS48 output g is pin 14.
Connect Input A to Arduino Digital pin 2.
Connect Input B to Arduino Digital pin 3.
Connect Input C to Arduino Digital pin 4.
Connect Input D to Arduino Digital pin 5
Because my Digit LED 7-segment Display is common cathode.
So 74LS48 GND is pin 8. Let the pin 8 connect to GND of arduino. That will make the LED blink, other connect to VCC won't blink.
#################################################
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
#define led2 2
#define led3 3
#define led4 4
#define led5 5
// Pins for A B C D E F G, in sequence
const int segs[4] = { led2, led3, led4, led5};
// Segments that make each number
const byte numbers[10] = {0b0000, 0b0001, 0b0010, 0b0011, 0b0100, 0b0101, 0b0110, 0b0111, 0b1000, 0b1001};
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
for ( int i = 1 ; i <= 9 ; i++)
{
lightSegments(numbers[0]);
NolightSegments(numbers[0]);
}
}
void lightSegments(byte number) {
for (int i = 0; i < 4; i++) {
int bit = bitRead(number, i);
digitalWrite(segs[i], bit);
}
}
void NolightSegments(byte number) {
for (int i = 0; i < 4; i++) {
digitalWrite(segs[i], LOW);
}
}
// digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
// delay(1000); // wait for a second
// digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
// delay(1000);
0 意見:
張貼留言