Materiais
- 1 Arduino;
- Display de 7 segmentos;
- 1 LM35 (sensor de temperatura);
- 16 resistores 220 ohms.
Circuito eletrônico
Código fonte
int sensor=A5;
int leitura=A5;
int temperatura=A5;
void setup(){
for(byte x=2; x<16; x++){
pinMode(x,OUTPUT);
}
Serial.begin(9600);
}
void loop(){
leitura=analogRead(sensor);
temperatura=(leitura*500)/1023;
Serial.print("Temperatura: ");
Serial.print(temperatura);
Serial.println(" C");
if(temperatura==15){
um1(),cinco();
}
if(temperatura==16){
um1(),seis();
}
if(temperatura==17){
um1(),sete();
}
if(temperatura==18){
um1(),oito();
}
if(temperatura==19){
um1(),nove();
}
if(temperatura==20){
dois1(),zero();
}
if(temperatura==21){
dois1(),um();
}
if(temperatura==22){
dois1(),dois();
}
if(temperatura==23){
dois1(),tres();
}
if(temperatura==24){
dois1(),quatro();
}
if(temperatura==25){
dois1(),cinco();
delay(1000);
}
if(temperatura==26){
dois1(),seis();
delay(1000);
}
if(temperatura==27){
dois1(),sete();
delay(1000);
}
if(temperatura==28){
dois1(),oito();
delay(1000);
}
if(temperatura==29){
dois1(),nove();
delay(1000);
}
if(temperatura==30){
tres1(),zero();
delay(1000);
}
if(temperatura==31){
tres1(),um();
delay(1000);
}
if(temperatura==32){
tres1(),dois();
delay(1000);
}
if(temperatura==33){
tres1(),tres();
delay(1000);
}
if(temperatura==34){
tres1(),quatro();
delay(1000);
}
if(temperatura==35){
tres1(),cinco();
delay(1000);
}
delay(1000);
}
void zero(){
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
}
void um(){
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
}
void um1(){
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
digitalWrite(12,1);
digitalWrite(13,1);
digitalWrite(14,0);
digitalWrite(15,0);
}
void dois(){
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,0);
digitalWrite(7,1);
digitalWrite(8,1);
}
void dois1(){
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,1);
digitalWrite(12,1);
digitalWrite(13,0);
digitalWrite(14,1);
digitalWrite(15,1);
}
void tres(){
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,0);
}
void tres1(){
digitalWrite(9,1);
digitalWrite(10,0);
digitalWrite(11,1);
digitalWrite(12,1);
digitalWrite(13,1);
digitalWrite(14,1);
digitalWrite(15,0);
}
void quatro(){
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
}
void cinco(){
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,0);
}
void seis(){
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
}
void sete(){
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
}
void oito(){
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
}
void nove(){
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
}
0 comentários:
Postar um comentário