So instead of mapping, you're suggesting I divide my analog sensor values by 4 to map them to a 0-255 value?
Yes, for that specific mapping the formulas are functional equal in practice.
An example for color mixing logic
Analog values from 20-500 should control red
Analog values from 300-800 should control green
Analog values from 600-1000 should control blue
This needs a bit more complex mapping, especially the green one...
Below the translation into code of your example behaviour.
void loop()
{
// MEASUREMENT
int raw = analogRead(A0);
// DO THE MATH
// 20 is most red; 500 is no red anymore
int red = map(raw, 20, 500, 255, 0); // note the mapping is 'reverse'
red = constrain(red 0, 255); // keep the values within limits
// green is max at 550 and less in both directions
int green = 255 - abs(raw - 550); // see below (1)
green = constrain(green, 0, 255); // keep the values within limits
// blue increases from 600 -- max.
int blue = map(raw, 600, 1023, 0, 255);
blue = constrain(blue, 0, 255); // keep the values within limits
// DISPLAY CALCULATED VALUES
analogWrite(REDLED, red);
analogWrite(GREENLED, green);
analogWrite(BLUELED, blue);
}
(1) the function abs(x) returns x if x > 0 and return -x otherwise. So it returns always a positive number.
abs(raw-550) is the 'distance between raw and the value 550'
(2) note that the map function is a linear interpolation.
If the input value is outside the input range, the output will be outside the output range.
that is why constrain() is used.