Afișaj 4 Digiți LED Display Verde catod comun
Afișaj 4 Digiți LED Display Verde catod comun
Afișaj digital de 4 x 7 segmente LED cu anod comun.
Foarte uşor de folosit în proiectele tip Arduino
Precauții : Atenție nu depășiți tensiunea dr 2,5v și nu inversaţi VCC și GND , altfel ardeți ledurile.
Exemplu de folosire :
/*
The segment A on the 4-digit 7-segment display connects to digital pin 9 on the arduino.
The segment B on the LED display connects to digital pin 2 on the arduino.
The segment C on the LED display connects to digital pin 3 on the arduino.
The segment D on the LED display connects to digital pin 5 on the arduino.
The segment E on the LED display connects to digital pin 6 on the arduino.
The segment F on the LED display connects to digital pin 8 on the arduino.
The segment G on the LED display connects to digital pin 7 on the arduino.
The decimal point (DP) segment on the LED display connects to digital pin 4 on the arduino.
Digit 1 on the LED display connects to digital pin 10 on the arduino.
Digit 2 on the LED display connects to digital pin 11 on the arduino.
Digit 3 on the LED display connects to digital pin 12 on the arduino.
Digit 4 on the LED display connects to digital pin 13 on the arduino.
*/
const int sensorPin= 0;//The analog sensor is connected to analog pin 0 of the arduino
//ABCDEFG,dp
const int numeral[10]= {
B11111100, //0
B01100000, //1
B11011010, //2
B11110010, //3
B01100110, //4
B10110110, //5
B00111110, //6
B11100000, //7
B11111110, //8
B11100110, //9
};
//pins for decimal point and each segment
//dp, G, F, E, D, C, B, A
const int segmentPins[]= { 4, 7, 8, 6, 5, 3, 2, 9};
const int numberofDigits=4;
const int digitPins[numberofDigits] = { 10,11,12, 13}; //digits 1, 2, 3, 4
void setup()
{
for (int i=0; i < 8; i++)
pinMode(segmentPins[i], OUTPUT); //set segment and DP pins to output
//sets the digit pins as outputs
for (int i=0; i < numberofDigits; i++)
pinMode(digitPins[i], OUTPUT);
}
void loop()
{
int value= analogRead(sensorPin);
showNumber(value);
}
void showNumber (int number)
{
if (number == 0)
showDigit (0, numberofDigits-1); //display 0 in the rightmost digit
else
{
for (int digit= numberofDigits-1; digit >=0; digit–)
{
if (number > 0)
{
showDigit(number % 10, digit);
number= number/10;
}
}
}
}
//Displays given number on a 7-segment display at the given digit position
void showDigit (int number, int digit)
{
digitalWrite(digitPins[digit], HIGH);
for (int segment= 1; segment < 8; segment++)
{
boolean isBitSet= bitRead(numeral[number], segment);
isBitSet= ! isBitSet; //remove this line if common cathode display
digitalWrite(segmentPins[segment], isBitSet);
}
delay(5);
digitalWrite(digitPins[digit], LOW);
}
Arduino projects.
Opinii
Nu există încă recenzii.