Connection
Recommendation
Program
Basic program
RGB color detection
This program detects whether the object in front of the sensor has one of these three colors: red (R), green (G), blue (B). It displays the detected color on the LED strip.
It starts by initializing the color sensor. It then assigns the function of controlling the LED strip to pin P1.
In the main loop, the program waits (executes an empty statement) until it receives a signal from the color sensor that the value has been read. It then stores the values of the red, green, and blue components, as well as the ambient light intensity, into variables. If the sensor measures a low light value, it does not turn on the LED strip. Otherwise, it determines which component has the highest measured value. It finally displays this on the LED strip.
If the LED strip lights up even without the measured object, increase the minimum ambient light value.
Reading RGB values using an OLED display
The program starts by setting up the color sensor together with the OLED display at startup. Then, the condition is repeated again and again, which says the following. If the color sensor is ready to measure, it sets up several variables. In the last step, the variables are displayed on the OLED display.
We will be shown information about the amount of red, green and blue. But the amount of surrounding area is also important information. And using the A and B buttons on the microbit we are able to turn on additional LEDs that will brighten the measured object.





