Paso 11: El código
#include < OneWire.h >Cable de datos esté conectado en el pin 3 en el Arduino
int DS18S20_Pin = 3; Pin señal DS18S20 digital 2
Configuración de una instancia de oneWire para comunicarse con dispositivos OneWire
OneWire ds(DS18S20_Pin);
int digit1;
int digit2;
int digit3;
int x;
int num;
int comienzo;
oneA int = 0; PINES de ARDUINO no Atmega
oneB int = 1;
int veces = 2;
oneD int = 4;
int oneE = 5;
oneF int = 6;
int oneG = 7;
twoA int = 8;
int twoB = 9;
PSS int = 10;
twoD int = 11;
twoE INT = 12;
twoF int = 13;
twoG int = A0;
threeA int = A1;
int threeB = A2;
void setup(void)
{
pinMode (oneA, salida); //digit1
pinMode(oneB,OUTPUT);
pinMode(oneC,OUTPUT);
pinMode(oneD,OUTPUT);
pinMode(oneE,OUTPUT);
pinMode(oneF,OUTPUT);
pinMode(oneG,OUTPUT);
pinMode (twoA, salida); //digit2
pinMode(twoB,OUTPUT);
pinMode(twoC,OUTPUT);
pinMode(twoD,OUTPUT);
pinMode(twoE,OUTPUT);
pinMode(twoF,OUTPUT);
pinMode(twoG,OUTPUT);
pinMode (threeA, salida); //digit3
pinMode(threeB,OUTPUT);
}
void loop(void)
{
Float temperatura = getTemp();
flotador tempf = (((temperature*(9))/5)+32);
Num = (int) tempf;
Si (x > = 0)
{
Num = (int) tempf;
x = 0;
Num = tempf;
digit1 = num % 10;
Num = num/10;
digit2 = num % 10;
Num = num/10;
digit3 = num % 10;
Num = num/10;
}
{Switch(digit1)}
caso 0:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,LOW);
rotura;
caso 1:
digitalWrite(oneA,LOW);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,LOW);
rotura;
caso 2:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,LOW);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,LOW);
digitalWrite(oneG,HIGH);
rotura;
caso 3:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,HIGH);
rotura;
caso 4:
digitalWrite(oneA,LOW);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
rotura;
caso 5:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,LOW);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
rotura;
caso 6:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,LOW);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
rotura;
caso 7:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,LOW);
rotura;
caso 8:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
rotura;
caso 9:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
rotura;
}
{Switch(digit2)}
caso 0:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,LOW);
rotura;
caso 1:
digitalWrite(twoA,LOW);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,LOW);
rotura;
caso 2:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,LOW);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,LOW);
digitalWrite(twoG,HIGH);
rotura;
caso 3:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,HIGH);
rotura;
caso 4:
digitalWrite(twoA,LOW);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
rotura;
caso 5:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,LOW);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
rotura;
caso 6:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,LOW);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
rotura;
caso 7:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,LOW);
rotura;
caso 8:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
rotura;
caso 9:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
rotura;
}
if(digit3 == 1) {}
digitalWrite(threeA,HIGH);
digitalWrite(threeB,HIGH);
}
Else {}
digitalWrite(threeA,LOW);
digitalWrite(threeB,LOW);
}
}
Float getTemp() {//Code partir es de Bildr.org
Devuelve la temperatura de un DS18S20 en grados Celsius
datos del octeto [12];
addr Byte [8];
Si (! {ds.search(addr))}
no hay más sensores en cadena, de la búsqueda reset
DS.reset_search();
volver -1000;
}
Si (OneWire::crc8 (addr, 7)! = {addr[7])}
Serial.Print ("CRC no es válido! \n");
volver -1000;
}
Si (addr [0]! = 0 x 10 & & addr [0]! = 0x28) {}
Serial.Print ("dispositivo no se reconoce");
volver -1000;
}
DS.Reset();
DS.Select(ADDR);
DS.Write(0X44,1); iniciar la conversión, con la energía del parásito en el final
byte actual = ds.reset();
DS.Select(ADDR);
DS.Write(0xBE); Bloc de notas de lectura
para (int i = 0; i < 9; i ++) {/ / necesitamos 9 bytes
datos [i] = ds.read();
}
DS.reset_search();
el byte MSB = datos [1];
octeto LSB = datos [0];
Float tempRead = ((MSB << 8) | LSB); utilizando el complemento de dos
Float TemperatureSum = tempRead / 16;
volver TemperatureSum;
}