diff --git a/doc/api/pupdevices/colordistancesensor.rst b/doc/api/pupdevices/colordistancesensor.rst index 328b423..2360942 100644 --- a/doc/api/pupdevices/colordistancesensor.rst +++ b/doc/api/pupdevices/colordistancesensor.rst @@ -67,7 +67,7 @@ Changing the detectable colors ****************************** By default, the sensor is configured to detect red, yellow, green, -blue, white, or ``None``, which suits many applications. +blue, white, or no color, which suits many applications. For better results in your application, you can measure your desired colors in advance, and tell the sensor to look only for those colors. diff --git a/doc/api/pupdevices/colorsensor.rst b/doc/api/pupdevices/colorsensor.rst index 577558a..4b30cdb 100644 --- a/doc/api/pupdevices/colorsensor.rst +++ b/doc/api/pupdevices/colorsensor.rst @@ -58,7 +58,7 @@ Changing the detectable colors ****************************** By default, the sensor is configured to detect red, yellow, green, -blue, white, or ``None``, which suits many applications. +blue, white, or no color, which suits many applications. For better results in your application, you can measure your desired colors in advance, and tell the sensor to look only for those colors. diff --git a/examples/pup/sensor_color/detectable_colors.py b/examples/pup/sensor_color/detectable_colors.py index 413c817..a3e9e70 100644 --- a/examples/pup/sensor_color/detectable_colors.py +++ b/examples/pup/sensor_color/detectable_colors.py @@ -5,26 +5,22 @@ from pybricks.tools import wait # Initialize the sensor. sensor = ColorSensor(Port.A) -# First, decide which objects you want to detect. -# Then measure their color with the hsv() method, -# as shown in the previous example. Write them down -# as shown below. The name is optional, but it is -# useful when you print the color value. -green = Color(h=132, s=94, v=26, name='GREEN_BRICK') -magenta = Color(h=348, s=96, v=40, name='MAGENTA_BRICK') -brown = Color(h=17, s=78, v=15, name='BROWN_BRICK') -red = Color(h=359, s=97, v=39, name='RED_BRICK') +# First, decide which objects you want to detect, and measure their HSV values. +# You can do that with the hsv() method as shown in the previous example. +# +# Use your measurements to override the default colors, or add new colors: +Color.GREEN = Color(h=132, s=94, v=26) +Color.MAGENTA = Color(h=348, s=96, v=40) +Color.BROWN = Color(h=17, s=78, v=15) +Color.RED = Color(h=359, s=97, v=39) # Put your colors in a list or tuple. -# Including None is optional. Just omit it if -# you always want to get one of your colors. -my_colors = (green, magenta, brown, red, None) +my_colors = (Color.GREEN, Color.MAGENTA, Color.BROWN, Color.RED, Color.NONE) # Save your colors. sensor.detectable_colors(my_colors) -# color() works as usual, but it only -# returns one of your specified colors. +# color() works as usual, but now it returns one of your specified colors. while True: color = sensor.color() @@ -32,7 +28,7 @@ while True: print(color) # Check which one it is. - if color == magenta: + if color == Color.MAGENTA: print("It works!") # Wait so we can read it. diff --git a/examples/pup/sensor_color_distance/detectable_colors.py b/examples/pup/sensor_color_distance/detectable_colors.py index 51f5bd7..e2fa422 100644 --- a/examples/pup/sensor_color_distance/detectable_colors.py +++ b/examples/pup/sensor_color_distance/detectable_colors.py @@ -5,26 +5,22 @@ from pybricks.tools import wait # Initialize the sensor. sensor = ColorDistanceSensor(Port.A) -# First, decide which objects you want to detect. -# Then measure their color with the hsv() method, -# as shown in the previous example. Write them down -# as shown below. The name is optional, but it is -# useful when you print the color value. -green = Color(h=132, s=94, v=26, name='GREEN_BRICK') -magenta = Color(h=348, s=96, v=40, name='MAGENTA_BRICK') -brown = Color(h=17, s=78, v=15, name='BROWN_BRICK') -red = Color(h=359, s=97, v=39, name='RED_BRICK') +# First, decide which objects you want to detect, and measure their HSV values. +# You can do that with the hsv() method as shown in the previous example. +# +# Use your measurements to override the default colors, or add new colors: +Color.GREEN = Color(h=132, s=94, v=26) +Color.MAGENTA = Color(h=348, s=96, v=40) +Color.BROWN = Color(h=17, s=78, v=15) +Color.RED = Color(h=359, s=97, v=39) # Put your colors in a list or tuple. -# Including None is optional. Just omit it if -# you always want to get one of your colors. -my_colors = (green, magenta, brown, red, None) +my_colors = (Color.GREEN, Color.MAGENTA, Color.BROWN, Color.RED, Color.NONE) # Save your colors. sensor.detectable_colors(my_colors) -# color() works as usual, but it only -# returns one of your specified colors. +# color() works as usual, but now it returns one of your specified colors. while True: color = sensor.color() @@ -32,7 +28,7 @@ while True: print(color) # Check which one it is. - if color == magenta: + if color == Color.MAGENTA: print("It works!") # Wait so we can read it.