#include #include Adafruit_VL53L0X lox = Adafruit_VL53L0X(); const int redPin = A0; const int greenPin = A1; const int bluePin = A2; void setup() { Serial.begin(9600); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(speakerPin, OUTPUT); // Initialize the VL53L0X if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while (1); } } void loop() { VL53L0X_RangingMeasurementData_t measure; lox.rangingTest(&measure, false); // Pass in 'true' to get debug data printout! int brightness = 0; if (measure.RangeStatus != 4) { // If not out of range int distance = measure.RangeMilliMeter; // Distance in mm // Map the distance to a brightness level (0 at 0 cm, 255 at 20 cm) brightness = map(distance, 0, 200, 0, 255); brightness = constrain(brightness, 0, 255); // Ensure the brightness is within 0-255 } if (Serial.available() > 0) { char command = Serial.read(); if (command == 'C') { int red = Serial.parseInt(); int green = Serial.parseInt(); int blue = Serial.parseInt(); analogWrite(redPin, red * brightness / 255); // Adjust the brightness analogWrite(greenPin, green * brightness / 255); // Adjust the brightness analogWrite(bluePin, blue * brightness / 255); // Adjust the brightness } } }