#define LM35 A0
float temp, val;
int val1, val2, val3, val4, loopCount = 0;
int a = 13;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int dp = 8;
int d1 = 9;
int d2 = 10;
int d3 = 11;
int d4 = 12;
void setup() {
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dp, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (loopCount%1000==0)
{
val=analogRead(LM35);
temp=val*0.48876;
Serial.println(temp);
val1=int(temp)/10;
val2=int(temp)%10;
val3=int(temp*10)%10;
val4=int(temp*100)%10;
}
digitalWrite(dp,LOW);
showNumber(1,val1);
digitalWrite(dp,HIGH);
showNumber(2,val2);
digitalWrite(dp,LOW);
showNumber(3,val3);
digitalWrite(dp,LOW);
showNumber(4,val4);
loopCount++;
}
void showNumber(int pos, int num){
posit(pos);
setNum(num);
delay(1);
}
void posit(int pos){
switch(pos){
case 1:
digitalWrite(d1,LOW);
digitalWrite(d2,HIGH);
digitalWrite(d3,HIGH);
digitalWrite(d4,HIGH);
break;
case 2:
digitalWrite(d1,HIGH);
digitalWrite(d2,LOW);
digitalWrite(d3,HIGH);
digitalWrite(d4,HIGH);
break;
case 3:
digitalWrite(d1,HIGH);
digitalWrite(d2,HIGH);
digitalWrite(d3,LOW);
digitalWrite(d4,HIGH);
break;
case 4:
digitalWrite(d1,HIGH);
digitalWrite(d2,HIGH);
digitalWrite(d3,HIGH);
digitalWrite(d4,LOW);
break;
default:
digitalWrite(d1,HIGH);
digitalWrite(d2,HIGH);
digitalWrite(d3,HIGH);
digitalWrite(d4,HIGH);
}
}
void setNum(int num){
switch(num){
case 0:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
break;
case 1:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
case 2:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
break;
case 3:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
break;
case 4:
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
case 5:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
case 6:
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
case 7:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
break;
case 8:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
case 9:
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
break;
default:
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
}