Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit f4973e7

Browse files
committed
Update example to include fahrenheit.
1 parent 19a9d9e commit f4973e7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/simpletest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
import Adafruit_MCP9808.MCP9808 as MCP9808
3030

3131

32+
# Define a function to convert celsius to fahrenheit.
33+
def c_to_f(c):
34+
return c * 9.0 / 5.0 + 32.0
35+
3236
# Default constructor will use the default I2C address (0x18) and pick a default I2C bus.
3337
#
3438
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
@@ -48,5 +52,6 @@
4852
# Loop printing measurements every second.
4953
print 'Press Ctrl-C to quit.'
5054
while True:
51-
print 'Temperature: {0:0.4F} *C'.format(sensor.readTempC())
55+
temp = sensor.readTempC()
56+
print 'Temperature: {0:0.3F}*C / {1:0.3F}*F'.format(temp, c_to_f(temp))
5257
time.sleep(1.0)

0 commit comments

Comments
 (0)