Ambient Light Sample
This sample demonstrates reading the ambient light data.
- 1.Download the sample code from https://github.com/Turta-io/IoTHAT3/blob/master/Samples/Python/Ambient_Light.py
- 2.Copy the sample code to a folder on the Raspberry Pi.
- 3.Open terminal, and then go to the folder you copied the sample.
- 4.Run the sample with the following command:
python3 Ambient_Light.py
Ambient_Light.py
#!/usr/bin/env python3
#This sample demonstrates reading the ambient light data.
#Install IoT HAT 3 library with "pip3 install turta-iothat3"
from time import sleep
from turta_iothat3 import Turta_Light
#Initialize
light = Turta_Light.LightSensor()
try:
while True:
#Read ambient light
al = light.read_ambient_light()
#Print the reading
print("Ambient Light...: " + str(al))
#Wait
sleep(0.5)
#Exit on CTRL+C
except KeyboardInterrupt:
print('Bye.')
When you run the sample, it prints ambient light reading. The example output should be like this:
Ambient Light...: 123
Ambient Light...: 127
To stop the Python script, just press CTRL + C.
Last modified 3yr ago