I have a bit of a technical question related to coding the Optical Sensor in VEXcode EXP.
The last couple of days I’ve been preparing to have my students do the Color Sensing EXP activity (EXP Activity - Color Sensing - Google Docs). As I tried the activity out myself, I noticed that the [optical detects blue] block doesn’t work very well. I’m pretty sure this is because of the lighting in my classroom, but even when I turned on the LED light on the sensor to 100%, it would still not execute the turn in the code most of the time.
I figured out a pretty good solution by instead using the [optical hue in degrees] reporter block and using a range of numbers for “blue”. I would like to give my students some hints and suggestions to do something similar if they come across the same problem I did.
However, I’m not totally satisfied with this solution. I wanted to know more details about the Optical Sensor and found this article: https://kb.vex.com/hc/en-us/articles/4415762989332-Using-Optical-Sensor-with-VEX-EXP
There is a useful graphic of the color wheel with the different degrees for each hue. But my question is: Is there any way to know the specific values that are used in the blocks that have colors as parameters? For instance, in the [optical detects blue] boolean block, what values from the optical sensor would return TRUE?
I guess this is mostly to satisfy my curiosity, but I feel it could also help with some more advanced coding with the Optical Sensor. If anyone can help, I appreciate it.
1 Like
Great question! I actually had to do a bit of digging to find the answer myself, but the related RGB codes are documented on our VEX API site. Enums — VEXcode Documentation
These pages are mainly meant to help coders set up sensors in Microsoft VS Code, but it’s a great way to take a peak under the hood and look for those values.
Here’s the specific table about color types and values from that page:
Name |
Python Enum |
Description |
Red |
RED |
The predefined color constant for red as the RGB value: (255, 0, 0). |
Green |
GREEN |
The predefined color constant for green as the RGB value: (0, 255, 0). |
Blue |
BLUE |
The predefined color constant for blue as the RGB value: (0, 0, 255). |
Yellow |
YELLOW |
The predefined color constant for yellow as the RGB value: (255, 255, 0). |
Orange |
ORANGE |
The predefined color constant for orange as the RGB value: (255, 165, 0). |
Purple |
PURPLE |
The predefined color constant for purple as the RGB value: (255, 0, 255). |
Cyan |
CYAN |
The predefined color constant for cyan as the RGB value: (0, 255, 255). |
Black |
BLACK |
The predefined color constant for black as the RGB value: (0, 0, 0). |
White |
WHITE |
The predefined color constant for white as the RGB value: (255, 255, 255). |
Transparent |
TRANSPARENT |
The predefined color constant for transparent. |
With the RGB values, you can then look at something like an online calculator or other tool to convert from the RGB to a hue value.
In addition, you could go even further and look at creating a data logging project with a Micro-SD card, the Optical Sensor, and a Brain! You could log the hue value detected each 50 MSEC (or something like that), the reported color, and then use all of that information to see at what hue range Blue is reported. This article goes through the nuts and bolts, but I’m happy to help if you want to go this testing route. I actually taught a workshop at the last VEX Educators Conference about data logging
2 Likes