Stap 11: De Code
#include < OneWire.h >Data aansluiting is 3 pin op de Arduino aangesloten
int DS18S20_Pin = 3; DS18S20 signaal pin op digitale 2
Opstelling van een exemplaar van de privacy om te communiceren met alle apparaten privacy
Privacy ds(DS18S20_Pin);
int digit1;
int digit2;
int digit3;
int x;
int num;
int begin;
int oneA = 0; ARDUINO PINNEN niet Atmega
int oneB = 1;
int oneC = 2;
int oneD = 4;
int oneE = 5;
int oneF = 6;
int oneG = 7;
int twoA = 8;
int twoB = 9;
int twoC = 10;
int twoD = 11;
int twoE = 12;
int twoF = 13;
int twoG = A0;
int threeA = a1 worden verkregen;
int threeB = A2;
void setup(void)
{
pinMode (oneA, OUTPUT); //digit1
pinMode(oneB,OUTPUT);
pinMode(oneC,OUTPUT);
pinMode(oneD,OUTPUT);
pinMode(oneE,OUTPUT);
pinMode(oneF,OUTPUT);
pinMode(oneG,OUTPUT);
pinMode (twoA, OUTPUT); //digit2
pinMode(twoB,OUTPUT);
pinMode(twoC,OUTPUT);
pinMode(twoD,OUTPUT);
pinMode(twoE,OUTPUT);
pinMode(twoF,OUTPUT);
pinMode(twoG,OUTPUT);
pinMode (threeA, OUTPUT); //digit3
pinMode(threeB,OUTPUT);
}
void loop(void)
{
zweven temperatuur = getTemp();
zweven tempf = (((temperature*(9))/5)+32);
num = tempf (int);
Als (x > = 0)
{
num = tempf (int);
x = 0;
num = tempf;
digit1 = num % 10;
num = num/10;
digit2 = num % 10;
num = num/10;
digit3 = num % 10;
num = num/10;
}
switch(digit1) {}
Case 0:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,LOW);
breken;
Case 1:
digitalWrite(oneA,LOW);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,LOW);
breken;
Case 2:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,LOW);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,LOW);
digitalWrite(oneG,HIGH);
breken;
Case 3:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,HIGH);
breken;
Case 4:
digitalWrite(oneA,LOW);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
breken;
Case 5:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,LOW);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
breken;
Case 6:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,LOW);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
breken;
Case 7:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,LOW);
digitalWrite(oneG,LOW);
breken;
zaak 8:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,HIGH);
digitalWrite(oneE,HIGH);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
breken;
Case 9:
digitalWrite(oneA,HIGH);
digitalWrite(oneB,HIGH);
digitalWrite(oneC,HIGH);
digitalWrite(oneD,LOW);
digitalWrite(oneE,LOW);
digitalWrite(oneF,HIGH);
digitalWrite(oneG,HIGH);
breken;
}
switch(digit2) {}
Case 0:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,LOW);
breken;
Case 1:
digitalWrite(twoA,LOW);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,LOW);
breken;
Case 2:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,LOW);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,LOW);
digitalWrite(twoG,HIGH);
breken;
Case 3:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,HIGH);
breken;
Case 4:
digitalWrite(twoA,LOW);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
breken;
Case 5:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,LOW);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
breken;
Case 6:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,LOW);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
breken;
Case 7:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,LOW);
digitalWrite(twoG,LOW);
breken;
zaak 8:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,HIGH);
digitalWrite(twoE,HIGH);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
breken;
Case 9:
digitalWrite(twoA,HIGH);
digitalWrite(twoB,HIGH);
digitalWrite(twoC,HIGH);
digitalWrite(twoD,LOW);
digitalWrite(twoE,LOW);
digitalWrite(twoF,HIGH);
digitalWrite(twoG,HIGH);
breken;
}
if(digit3 == 1) {}
digitalWrite(threeA,HIGH);
digitalWrite(threeB,HIGH);
}
else {}
digitalWrite(threeA,LOW);
digitalWrite(threeB,LOW);
}
}
zweven getTemp() {//Code ingang is van Bildr.org
geeft als resultaat de temperatuur van een DS18S20 in graden Celsius
bytegegevens [12];
byte addr [8];
Als (! ds.search(addr)) {}
geen meer sensoren op de keten, reset zoeken
DS.reset_search();
Return-1000;
}
Als (OneWire::crc8 (addr, 7)! = addr[7]) {}
Serial.Print ("CRC is niet geldig! \n");
Return-1000;
}
Als (addr [0]! = 0x10 & & addr [0]! = 0x28) {}
Serial.Print ('apparaat wordt niet herkend');
Return-1000;
}
DS.reset();
DS.Select(addr);
DS.write(0x44,1); Start conversie, met kracht van de parasiet op eind
byte aanwezig = ds.reset();
DS.Select(addr);
DS.write(0xBE); Lees Kladblok
voor (int i = 0; ik < 9; i ++) {/ / moeten we 9 bytes
gegevens [i] = ds.read();
}
DS.reset_search();
byte MSB = data [1];
byte LSB = data [0];
zweven tempRead = ((MSB << 8) | LSB); met behulp van twee compliment
zweven TemperatureSum = tempRead / 16;
Return TemperatureSum;
}