From ee05a6686eda6194f5828a4757484f2bc5be58ef Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 13 Jul 2020 14:13:21 +0200 Subject: [PATCH] snippets/pup/sensor_color: add ambient sample ambient color sensor is unique to this sensor --- snippets/pup/sensor_color/color_ambient.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 snippets/pup/sensor_color/color_ambient.py diff --git a/snippets/pup/sensor_color/color_ambient.py b/snippets/pup/sensor_color/color_ambient.py new file mode 100644 index 0000000..076453f --- /dev/null +++ b/snippets/pup/sensor_color/color_ambient.py @@ -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)