from machine import *
from time import *
# --- Sensor setup ---
ldr = ADC(26) # LDR connected to GP26 (ADC0)
# --- List to store readings ---
ldr_values = [] # start with empty list
TOTAL_SAMPLES = 10 # how many readings to take
INTERVAL_SEC = 2 # time gap between readings (seconds)
print("Taking", TOTAL_SAMPLES, "LDR readings...")
# --- Collect readings into the list ---
for i in range(TOTAL_SAMPLES):
value = ldr.read_u16() # read sensor value
ldr_values.append(value) # store in the list
print("Reading", i + 1, "=", value)
sleep(INTERVAL_SEC)
print("\nAll readings:", ldr_values)
# --- Analyse the readings using list functions ---
highest = max(ldr_values)
lowest = min(ldr_values)
total = sum(ldr_values)
average = total / len(ldr_values)
print("\nAnalysis of LDR readings:")
print("Maximum value :", highest)
print("Minimum value :", lowest)
print("Average value :", average)
# --- Sort the readings (low to high) using list.sort() ---
ldr_values.sort()
print("\nReadings sorted (low to high):")
print(ldr_values)