snippets/pup/sensor_color: add ambient sample

ambient color sensor is unique to this sensor
This commit is contained in:
Laurens Valk
2020-07-13 14:13:21 +02:00
parent caa4012b2a
commit ee05a6686e
@@ -0,0 +1,26 @@
from pybricks.pupdevices import ColorSensor
from pybricks.parameters import Port
from pybricks.tools import wait
# Initialize the sensor.
sensor = ColorSensor(Port.A)
# Repeat forever.
while True:
# Get the ambient color values. Instead of scanning the color of a surface,
# this lets you scan the color of light sources like lamps or screens.
h, s, v = sensor.hsv(surface=False)
color = sensor.color(surface=False)
# Get the ambient light intensity.
ambient = sensor.ambient()
# Print the measurements.
print("Hue:", h, "Sat:", s, "Val:", v, "Col:", color, "Amb:", ambient)
# Point the sensor at a computer screen or colored light. Watch the color.
# Also, cover the sensor with your hands and watch the ambient value.
# Wait so we can read the printed line
wait(100)