Interfacing of 7 segment with Arduino:
Display 0-9 on 7 segment:
int segment_pins[8]={2,3,4,5,6,7,8,9};
int segment_digit[10]={0xc0,0xF9,0xA4,0x0B,0x99,0x92,0x82,0xF8,0x08,0x09};
void setup()
{
for(int i=0;i<8;i++)
pinMode(segment_pins[i],OUTPUT);
}
void loop()
{
for(int temp=0;temp<10;temp++)
{
char temp2=segment_digit[temp];
for(int k=0;k<8;k++)
{
char temp1=temp2&0x01;
temp2=temp2>>1;
digitalWrite(segment_pins[k],temp1);
}
delay(1000);
}
}
Simulation:
Display 0-99 on 7 segment:
int segment_pins[7]={0,1,2,3,4,5,6};
int segment_pinss[7]={7,8,9,10,11,12,13};
int segment_digit[10]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void setup()
{
for(int i=0;i<8;i++)
pinMode(segment_pins[i],OUTPUT);
for(int m=0;m<8;m++)
pinMode(segment_pinss[m],OUTPUT);
}
void loop()
{
for(int temp=0;temp<10;temp++)
{
char temp2=segment_digit[temp];
for(int k=0;k<7;k++)
{
char temp1=temp2&0x01;
digitalWrite(segment_pins[k],temp1);
temp2=temp2>>1;
}
for(int temp5=0;temp5<10;temp5++)
{
char temp6=segment_digit[temp5];
for(int n=0;n<7;n++)
{
char temp7=temp6&0x01;
digitalWrite(segment_pinss[n],temp7);
temp6=temp6>>1;
}
delay(1000);
}
}
}
Simulation:
Display 0-99 on 7 segment multiplexing:
int segment_pins[8]={0,1,2,3,4,5,6};
int segment_digit[10]={0xc0,0xF9,0xA4,0x0B,0x99,0x92,0x82,0xF8,0x08,0x09};
int seg1=7;
int seg2=8;
char temp1,temp2;
void setup()
{
for(int i=0;i<7;i++)
pinMode(segment_pins[i],OUTPUT);
pinMode(seg1, OUTPUT);
pinMode(seg2, OUTPUT);
}
void loop()
{
for(int dig1=0;dig1<10;dig1++)
{
for(int dig2=0;dig2<10;dig2++)
{
for(int m=0;m<30;m++)
{
temp1=segment_digit[dig1];
temp2=segment_digit[dig2];
for(int i=0;i<2;i++)
{
display1(i);
delay(1);
}
}
}
}
}
void display1(int i)
{
switch(i)
{
case 0:
digitalWrite(seg1, HIGH);
digitalWrite(seg2, LOW);
for(int k=0;k<8;k++)
{
char a=temp1&0x01;
temp1=temp1>>1;
digitalWrite(segment_pins[k],a);
delay(1);
}
digitalWrite(seg1, LOW);
digitalWrite(seg2, LOW);
temp1=0xff;
for(int k=0;k<8;k++)
{
char a=temp1&0x01;
temp1=temp1>>1;
digitalWrite(segment_pins[k],a);
//delay(5);
}
break;
case 1:
digitalWrite(seg1, LOW);
digitalWrite(seg2, HIGH);
for(int b=0;b<8;b++)
{
char temp4=temp2&0x01;
temp2=temp2>>1;
digitalWrite(segment_pins[b],temp4);
delay(1);
}
digitalWrite(seg1, LOW);
digitalWrite(seg2, LOW);
temp2=0xff;
for(int b=0;b<8;b++)
{
char temp4=temp2&0x01;
temp2=temp2>>1;
digitalWrite(segment_pins[b],temp4);
// delay(5);
}
break;
}
}
0 comments:
Post a Comment
if you have any doubt please let me know