Skip to content

Commit 5b4058a

Browse files
author
Louis Bertrand
committed
Update ds18x20_asynctest.py
Fix newbie mistake s/if/while/ and neater output; also force 12 bit resolution to better demonstrate the operation.
1 parent f5c3f84 commit 5b4058a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/ds18x20_asynctest.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717

1818
# Scan for sensors and grab the first one found.
1919
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])
20+
ds18.resolution = 12
2021

2122
# Main loop to print the temperature every second.
2223
while True:
2324
conversion_delay = ds18.start_temperature_read()
2425
conversion_ready_at = time.monotonic() + conversion_delay
25-
if time.monotonic() < conversion_ready_at:
26-
print("waiting...")
27-
print('Temperature: {0:0.3f}C'.format(ds18.read_temperature()))
26+
print("waiting", end="")
27+
while time.monotonic() < conversion_ready_at:
28+
print(".", end="")
29+
time.sleep(0.1)
30+
print('\nTemperature: {0:0.3f}C\n'.format(ds18.read_temperature()))
2831
time.sleep(1.0)

0 commit comments

Comments
 (0)