In a simpler view seven segment led display have seven led's with their combination we can display decimal numerals.
when connecting a common cathode in a proteus i have no idea which pin is associated to the respective led in display so i write a little code to do that work for me.
Code :
/*
Arduino Sketch to find out which pin is Associated with corresponding LED in 7 segment display
Author : Kunchala Anil
It is a common cathode 7 Segment Display.
connect the common cathode to ground and all the remaining pins to the Arduino Digital pins 2 to 8
*/
int pin = 2;
int pin_dummy = 2;
void setup()
{
Serial.begin(9600);
Serial.println("Hello World");
for(int i = 2; i <= 8; i++)
{
pinMode(i,OUTPUT);
Serial.print("pin \t");
Serial.print(i);
Serial.println("\t is set as Output");
}//end of for loop
}//end of setup
void loop()
{
Serial.println("Please enter y");
while(!Serial.available())
{
//wait until user enters the data
}//end of while
if(Serial.available())
{
if(Serial.read() == 'y')
{
if(pin_dummy <= 8)
{
digitalWrite(pin_dummy,LOW);
Serial.println("you entered y");
digitalWrite(pin,HIGH);
Serial.print("pin ");
Serial.print(pin);
Serial.println(" is activated");
pin_dummy = pin; // pin_dummy is used to OFF the LED before ON next led in display
pin++;
}
else{
Serial.println("Maximum pin number is reached");
pin = 2;
pin_dummy =2;
Serial.println("Pin values are RESET");
}//end of If else
}
else{
Serial.println("you entered wrong character");
}//end of If Else
}//end of If
}//end of loop
after executing the above code i get the following combination
GFEDCBA for 2,3,4,5,6,7,8 pins respectively.
when connecting a common cathode in a proteus i have no idea which pin is associated to the respective led in display so i write a little code to do that work for me.
Code :
/*
Arduino Sketch to find out which pin is Associated with corresponding LED in 7 segment display
Author : Kunchala Anil
It is a common cathode 7 Segment Display.
connect the common cathode to ground and all the remaining pins to the Arduino Digital pins 2 to 8
*/
int pin = 2;
int pin_dummy = 2;
void setup()
{
Serial.begin(9600);
Serial.println("Hello World");
for(int i = 2; i <= 8; i++)
{
pinMode(i,OUTPUT);
Serial.print("pin \t");
Serial.print(i);
Serial.println("\t is set as Output");
}//end of for loop
}//end of setup
void loop()
{
Serial.println("Please enter y");
while(!Serial.available())
{
//wait until user enters the data
}//end of while
if(Serial.available())
{
if(Serial.read() == 'y')
{
if(pin_dummy <= 8)
{
digitalWrite(pin_dummy,LOW);
Serial.println("you entered y");
digitalWrite(pin,HIGH);
Serial.print("pin ");
Serial.print(pin);
Serial.println(" is activated");
pin_dummy = pin; // pin_dummy is used to OFF the LED before ON next led in display
pin++;
}
else{
Serial.println("Maximum pin number is reached");
pin = 2;
pin_dummy =2;
Serial.println("Pin values are RESET");
}//end of If else
}
else{
Serial.println("you entered wrong character");
}//end of If Else
}//end of If
}//end of loop
after executing the above code i get the following combination
GFEDCBA for 2,3,4,5,6,7,8 pins respectively.
The following code is used to display the 0-9 in common cathode seven segment display.
/*
hEXA DECIMAL ENCODING FOR DISPLAYING NUMBERS 0 TO 9
FOR COMBINATION - GFEDCBA to pins 2,3,4,5,6,7,8
*/
/*
Hex codes for displayiing respective values
*/
const int ZERO = 0X7E;
const int ONE = 0X30;
const int TWO = 0X6D;
const int THREE = 0X79;
const int FOUR = 0X33;
const int FIVE = 0X5B;
const int SIX = 0X5F;
const int SEVEN = 0X70;
const int EIGHT = 0X7F;
const int NINE = 0X7B;
//pins initialization
int pin[] = {
2,3,4,5,6,7,8};
//calculating the no of pins
int no_pins = sizeof(pin)/sizeof(pin[0]);
void setup(){
Serial.begin(9600);
//setting all pins as Outputs
for(int i = 0; i < no_pins;i++)
{
pinMode(pin[i],OUTPUT);
}//end of for loop
}//end of setup
void loop(){
for(int i=0;i<=9;i++)
{
switch(i)
{
case 0:
display_it(ZERO);
break;
case 1:
display_it(ONE);
break;
case 2:
display_it(TWO);
break;
case 3:
display_it(THREE);
break;
case 4:
display_it(FOUR);
break;
case 5:
display_it(FIVE);
break;
case 6:
display_it(SIX);
break;
case 7:
display_it(SEVEN);
break;
case 8:
display_it(EIGHT);
break;
case 9:
display_it(NINE);
break;
default :
Serial.println("something went wrong");
}//end of switch
}//end of for loop()
}//end of loop
void display_it(const int value)
{
for(int i=2,j=0;i<=8;i++,j++)
{
digitalWrite(i,bitRead(value,j));
}
delay(1000);
}
Proteus Schematic is :
No comments:
Post a Comment