Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/opt4048_oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
# ok we finished the reading!
try:
CIEx, CIEy, lux = sensor.cie
except RuntimeError:
print("Error reading sensor data")

print("\nCIE Coordinates:")
print(f"CIE x:{CIEx}, y:{CIEy}, lux: {lux}", end=" ")
print("\nCIE Coordinates:")
print(f"CIE x:{CIEx}, y:{CIEy}, lux: {lux}", end=" ")

# Calculate and display color temperature
color_temp = sensor.calculate_color_temperature(CIEx, CIEy)
print(f"Color Temperature: {color_temp} K")
print(f"Time since last read: {time.monotonic() - timestamp} sec")
timestamp = time.monotonic()
# Calculate and display color temperature
color_temp = sensor.calculate_color_temperature(CIEx, CIEy)
print(f"Color Temperature: {color_temp} K")
print(f"Time since last read: {time.monotonic() - timestamp} sec")
timestamp = time.monotonic()
except RuntimeError:
print("Error reading sensor data")

sensor.mode = Mode.AUTO_ONESHOT
12 changes: 8 additions & 4 deletions examples/opt4048_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
sensor.conversion_time = ConversionTime.TIME_100MS
sensor.mode = Mode.CONTINUOUS
while True:
x, y, lux = sensor.cie
print(f"CIE x:{x}, y:{y}, lux: {lux}", end=" ")
print(f"K: {sensor.calculate_color_temperature(x,y)}")
time.sleep(1)
try:
x, y, lux = sensor.cie
print(f"CIE x:{x}, y:{y}, lux: {lux}", end=" ")
print(f"K: {sensor.calculate_color_temperature(x,y)}")
time.sleep(1)
except RuntimeError:
# CRC check failed while reading data
pass
20 changes: 12 additions & 8 deletions examples/opt4048_webserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
last_read_time = 0
while True:
if time.monotonic() > last_read_time + READ_INTERVAL:
last_read_time = time.monotonic()
x, y, lux = sensor.cie
print("---CIE Data---")
print(f"CIE x: {x}")
print(f"CIE y: {y}")
print(f"Lux: {lux}")
print(f"Color Temperature: {sensor.calculate_color_temperature(x,y)} K")
print("-------------")
try:
last_read_time = time.monotonic()
x, y, lux = sensor.cie
print("---CIE Data---")
print(f"CIE x: {x}")
print(f"CIE y: {y}")
print(f"Lux: {lux}")
print(f"Color Temperature: {sensor.calculate_color_temperature(x,y)} K")
print("-------------")
except RuntimeError:
# CRC check failed while reading data
pass