                throw new Error('Failed to set color');
            }
            return response.json();
        })
        .then(data => {
            console.log('Color set successfully:', data);
        })
        .catch(error => {
            console.error('Error setting color:', error);
        });
    } else {
        alert("Invalid color code. Please enter a valid HEX color code.");
    }
}

// Function to set brightness based on the slider value and send a POST request
function setBrightness() {
  