7 Segment Dislpay Arduino Code
int val0 = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
void setup()
{
for (int i = 0; i > 4; i++)
{
pinMode(i, INPUT);
}
for (int i = 4; i < 11; i++)
{
pinMode(i, OUTPUT);
}
}
void loop ()
{
val0 = digitalRead (11);
val1 = digitalRead (1);
val2 = digitalRead (2);
val3 = digitalRead (3);
if (val0 == LOW)
{
if(val1 == LOW)
{
if (val2 == LOW)
{
if (val3 == LOW)
{
dis0();
}
}
}
}
//code to show digit number 1
if(val3 == HIGH && val2 == LOW && val1 == LOW && val0 == LOW)
{
dis1();
}
//code to show digit number 2
if(val3 == LOW && val2 == HIGH && val1 == LOW && val0 == LOW){
dis2();
}
//code to show digit number 3
if (val3 == HIGH && val2 == HIGH && val1 == LOW && val0 == LOW)
{
dis3();
}
//code to show digit number 4
if (val3 == LOW && val2 == LOW && val1 == HIGH && val0 == LOW)
{
dis4();
}
//code to show digit number 4
if (val3 == HIGH && val2 == LOW && val1 == HIGH && val0 == LOW)
{
dis5();
}
//code to show digit number 4
if (val3 == LOW && val2 == HIGH && val1 == HIGH && val0 == LOW)
{
dis6();
}
//code to show digit number 4
if (val3 == HIGH && val2 == HIGH && val1 == HIGH && val0 == LOW)
{
dis7();
}
//code to show digit number 8
if (val3 == LOW && val2 == LOW && val1 == LOW && val0 == HIGH)
{
dis8();
}
//code to show digit number 9
if (val3 == HIGH && val2 == LOW && val1 == LOW && val0 == HIGH)
{
dis9();
}
//code to show Error
if (val3 == HIGH && val2 == HIGH && val1 == HIGH && val0 == HIGH)
{
disE();
}
}
void blank()
{
for (int i = 4; i < 11; i++)
{
digitalWrite (i, LOW);
}
}
//number combination acording to 7 segment display
void dis0(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
}
void dis1(){
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
void dis2(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
}
void dis3(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
}
void dis4(){
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10,HIGH);
}
void dis5(){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(10,HIGH);
digitalWrite(9, HIGH);
}
void dis6(){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(10, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
void dis7(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
void dis8(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
void dis9(){
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
void disE(){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
Comments
Post a Comment