mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-14 18:44:20 +00:00
snippets/pup/sensor_color: add ambient sample
ambient color sensor is unique to this sensor
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user