Beispiel #1
0
#FAHRENHEIT CALCULATION
def read_temp_f():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_f = (int(temp_string) / 1000.0) * 9.0 / 5.0 + 32.0 # TEMP_STRING IS THE SENSOR OUTPUT, MAKE SURE IT'S AN INTEGER TO DO THE MATH
        temp_f = str(round(temp_f, 1)) # ROUND THE RESULT TO 1 PLACE AFTER THE DECIMAL, THEN CONVERT IT TO A STRING
        return temp_f

void setup(void)
{
  lcd.init();                       // initialize the lcd
  lcd.backlight();
  Serial.begin(9600)
  sensors.begin();                  // turn on sensors for DS18b20
  pinMode(buttonUp, INPUT);         // Set INCREASE button to input
  pinMode(buttonDown, INPUT);       // Set DECREASE button to input
  lcd.setCursor(0,0);               // Set LCD cursor to first cursor spot
  lcd.print("Temperature");         // Print "Temperature" to cursor spot on LCD
}
void loop(void)
{

  sensors.requestTemperatures();    // Get temperature readings

  lcd.setCursor(2,1);
  lcd.print(sensors.getTempFByIndex(0));  // Print actual temperature