void setup() {
pinMode(heaterPin_1, OUTPUT); // 設定 pin 8 為輸出
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
const int keyin[4]= {} ;
ds.reset();
}
unsigned int readBytes(int count)
{
unsigned int val = 0;
for (int i = 0; i < count; i++)
{
val |= (unsigned int)(ds.read() << i * 8);
}
return val;
}
int a = 0;
void loop() {
// 讀取 Keypad 的輸入
char key = keypad.getKey();
// NO_KEY 代表沒有按鍵被按下
ds.reset();
ds.write(0xEE); //Start Converting the temperatures
do {
delay(1);
configuration_register = 0;
ds.reset();
ds.write(0xAC);
// Read the configuration Register from the DS1821
configuration_register = readBytes(1);
} while ((configuration_register & (1 << 7)) == 0); // If Bit #8 is 1 then we are finished converting the temp
// Get Temp
ds.reset();
ds.write(0xAA);
temp_read = readBytes(1); ;
// Get Count Remaining
ds.reset();
ds.write(0xA0);
count_remain = readBytes(2);
// Load The Counter to populate the slope accumulator
ds.reset();
ds.write(0x41);
// Read Count Per Deg
ds.reset();
ds.write(0xA0);
count_per_c = readBytes(2);
// If we are reading above the 200 mark then we are below 0 and need to compensate the calculation
if (temp_read >= 200) temp_read -= 256;