The Arduino board will be connected to the seven segment display using the circu
ID: 2081613 • Letter: T
Question
The Arduino board will be connected to the seven segment display using the circuit shown in Figure-1. Following are the specifications for the lab: The program must prompt the user to enter two numbers, then wait for input. Once input is received the program must read in two characters (numbers) from the serial monitor (in one input buffer). Echo (print) the two values back to the serial monitor. The data for the LEDs must be stored in a 1-dimensional 10-element array of unsigned integers (or char types), with each array element corresponding to one digit. The "on" or "off" information for the LEDs will be stored in the bits of each integer. On the seven segment display, the first digit entered should be displayed for 1 second, then the second digit for 1 second, and then the display should turn off and wait for new input. The program must use a loop to set the output values for the LEDs. In the loop, you must use bitwise operators to extract the correct '1' or '0' values for each LED from the array integer.Explanation / Answer
The connections which are done for 7 segment display are given below:
PIN1 or E to PIN 6 of ARDUINO UNO
PIN2 or D to PIN 5
PIN4 or C to PIN 4
PIN5 or H or DP to PIN 9 ///not needed as we are not using decimal point
PIN6 or B to PIN 3
PIN7 or A to PIN 2
PIN9 or F to PIN 7
PIN10 or G to PIN 8
PIN3 or PIN8 or CC to ground through 100 resistor.
Now to understand the working, consider a seven segment display is connected to a port, so say we have connected “A segment of display to PIN0”, “B segment of display to PIN1”, “A segment of display to PIN3”, “A segment of display to PIN4”, “A segment of display to PIN5”, “A segment of display to PIN6”.
Here the common ground has to be connected to ground for the display to work. One can check each segment of display by using multimeter in diode mode. Each segment should not be power with a voltage greater than 4v, if did the display will be damaged permanently. For avoiding this a common resistor can be provider at common terminal, as shown in circuit diagram.
Now, if we want to display a “0” in this display.
We need to turn the LEDs of segments “A, B, C, D, E F”, so we need to power PIN0, PIN1, PIN2, PIN3, PIN4 and PIN5. So every time we need a “0”, we need to power all the pins mentioned.
Now, if we want “1” on display.
We need to power segments “B, C”, for segment B, C to turn ON we need to power PIN1, PIN2. With both the pins high we get “1” on display. So as seen above we are going to power pins corresponding to the digit that to be shown on display.Here we are going to write a program turning each segment ON and OFF for a count 0-9. The working of 0-9 counter is best explained step by step in C code given below.
#define segA 2//connecting segment A to PIN2
#define segB 3// connecting segment B to PIN3
#define segC 4// connecting segment C to PIN4
#define segD 5// connecting segment D to PIN5
#define segE 6// connecting segment E to PIN6
#define segF 7// connecting segment F to PIN7
#define segG 8// connecting segment G to PIN8
int COUNT=0;//count integer for 0-9 increment
void setup()
{
for (int i=2;i<9;i++)
{
pinMode(i, OUTPUT);// taking all pins from 2-8 as output
}
}
void loop()
{
switch (COUNT)
{
case 0://when count value is zero show”0” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
case 1:// when count value is 1 show”1” on disp
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 2:// when count value is 2 show”2” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 3:// when count value is 3 show”3” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 4:// when count value is 4 show”4” on disp
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 5:// when count value is 5 show”5” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 6:// when count value is 6 show”6” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 7:// when count value is 7 show”7” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 8:// when count value is 8 show”8” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 9:// when count value is 9 show”9” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
break;
}
if (COUNT<10)
{
COUNT++;
delay(1000);///increment count integer for every second
}
if (COUNT==10)
{
COUNT=0;// if count integer value is equal to 10, reset it to zero.
delay(1000);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.