The onboard RGB LED on CodeCell can also be controlled programmatically to display different colors based on your project's needs.
With CodeCell’s built-in function, you can set the LED color easily:
myCodeCell.LED(uint8_t r, uint8_t g, uint8_t b);
r
→ Red component (0-255)g
→ Green component (0-255)b
→ Blue component (0-255)This allows full RGB color control for your project's needs.
In this example, the onboard RGB LED turns red when an object is detected within a certain range using the light sensor’s proximity detection.
#include <CodeCell.h>
CodeCell myCodeCell;
void setup() {
Serial.begin(115200); // Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial
myCodeCell.Init(LIGHT); // Initializes light sensing, including proximity
}
void loop() {
if (myCodeCell.Run(10)) {
// Runs every 100ms to check proximity
uint16_t proximity = myCodeCell.Light_ProximityRead();
// Check if an object is within range
if (proximity > 100) {
myCodeCell.LED(0xFF, 0, 0); // Set LED to Red when proximity is detected
delay(1000); // Keep the LED on for 1 second
} else {
// No action if the object is out of range
}
}
}
Remember that the onboard RGB LED is also used for battery and power status indication. When using myCodeCell.Run()
, the LED may be overridden to reflect charging or battery conditions.
If you want to control the LED without interruptions, you may need to adjust how often myCodeCell.Run()
is called or ensure your LED commands are applied after system updates.
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.